NGU-Web/src/pages/sections/OrgList-Card.tsx
Zaldimmar 79f1d09eef Try the revised palette (teal, green, amber, ink)
The suggested grid as the theme defaults, light and dark, with
PALETTE, the accents (olive becomes amber), the backdrop shades
and every literal from the old grid mapped over. Every text pair
passes the admin's 4.5:1 check; the hero's filled button is amber.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:51:14 -05:00

214 lines
6.2 KiB
TypeScript

import { ArrowUpRight } from '@phosphor-icons/react';
import ArrowLink from "../../components/ArrowLink.tsx";
import OrgLogo from "../../components/OrgLogo.tsx";
import {
orgPath,
useOrganizations,
byName,
} from "../../lib/organizations.ts";
import { accentText } from '../../lib/color.ts'
/* ═══════════════════════════════════════════════════════════════
ORGANIZATION LIST: CARDS
A grid of organization cards. No toggle: this view is the grid,
which is why the section that uses it declares no `views` in the
page manifest and gets no control in its heading.
<OrgListCards kind="partner" pageLabel="Partner page" />
Where the vertical list expands in place, a card links out. The
card carries as much as fits at a glance and the organization's
own page carries the rest, so nothing here reads a `blocks`
array, only the short card description.
═══════════════════════════════════════════════════════════════ */
const MUTED = "var(--color-muted)";
const INK = "var(--color-body)";
const FALLBACK_COLOR = "#3b5456";
/* Wide enough for a logo beside two lines of text, narrow enough
that three fit on a laptop. The grid drops a column rather than
squeezing below this. */
const CARD_MIN = "20rem";
const GRID_MAX = "88rem";
function OrgCard({ org, accent, pageLabel, siteLabel }) {
const color = org.color || accent;
const path = orgPath(org);
// Tagline first, then where they are. Partners often have one and
// not the other, so this is the line that's most likely to say
// something useful.
const subtitle = org.tagline || org.location_label;
return (
<div
className="p-6 h-full flex flex-col transition-transform duration-200 hover:scale-[1.01]"
style={{ border: `1px solid ${color}`, background: "var(--color-surface)" }}
>
<div className="flex items-start gap-4">
<OrgLogo org={org} color={color} />
<div className="min-w-0 flex-1">
<h3 className="text-xl font-bold leading-tight" style={{ color }}>
{org.name}
</h3>
{subtitle && (
<p className="text-sm mt-0.5" style={{ color: MUTED }}>
{subtitle}
</p>
)}
</div>
{/* Top-right rather than in the footer: the footer holds
outbound links, and the arrow goes somewhere different
in kind, deeper into this site. */}
{path && (
<ArrowLink
to={path}
label={`${org.name}: ${pageLabel}`}
color={color}
/>
)}
</div>
{org.description?.length > 0 && (
<p
className="mt-4 text-sm leading-relaxed line-clamp-4"
style={{ color: INK }}
>
{org.description[0]}
</p>
)}
{/* mt-auto pins the footer so buttons line up across a row
however much text each card carries. */}
<div className="mt-auto pt-5 flex flex-wrap gap-2">
{org.website && (
<a
href={org.website}
target="_blank"
rel="noopener noreferrer"
className="py-2 px-4 font-bold text-sm transition-transform duration-200 hover:scale-105"
style={{ border: `1px solid ${color}`, color }}
>
{siteLabel} <ArrowUpRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" />
</a>
)}
{org.email && (
<a
href={`mailto:${org.email}`}
className="py-2 px-4 font-bold text-sm transition-transform duration-200 hover:scale-105"
style={{ border: `1px solid ${color}`, color }}
>
Contact
</a>
)}
</div>
</div>
);
}
function Block({ title, orgs, accent, pageLabel, siteLabel }) {
if (orgs.length === 0) return null;
return (
<section className="mb-12">
{title && (
<h3 className="text-xl font-bold mb-5" style={{ color: FALLBACK_COLOR }}>
{title}
</h3>
)}
<div
className="grid gap-5 items-stretch"
style={{
gridTemplateColumns: `repeat(auto-fill, minmax(min(${CARD_MIN}, 100%), 1fr))`,
}}
>
{orgs.map(org => (
<OrgCard
key={org.id}
org={org}
accent={accent}
pageLabel={pageLabel}
siteLabel={siteLabel}
/>
))}
</div>
</section>
);
}
export default function OrgListCards({
kind,
title,
groups,
groupBy,
accent = FALLBACK_COLOR,
pageLabel = "Learn more",
siteLabel = "Visit site",
sort = byName,
empty = "Nothing to show here yet.",
}) {
const { organizations, loading, error } = useOrganizations(kind);
const shell = children => (
<div className="mx-auto px-8 md:px-12" style={{ maxWidth: GRID_MAX }}>
{children}
</div>
);
if (loading && organizations.length === 0) {
return shell(
<div className="skeleton" role="status" aria-label="Loading organizations" />
);
}
if (error && organizations.length === 0) {
return shell(
<p className="font-semibold" style={{ color: accentText(accent) }}>
· This list couldn't be loaded just now, please try again shortly ·
</p>
);
}
if (organizations.length === 0) {
return shell(
<p className="font-semibold" style={{ color: accentText(accent) }}>
{empty}
</p>
);
}
const sorted = sort ? [...organizations].sort(sort) : organizations;
// No groups given means one undivided grid.
if (!groups || !groupBy) {
return shell(
<Block
title={title}
orgs={sorted}
accent={accent}
pageLabel={pageLabel}
siteLabel={siteLabel}
/>
);
}
return shell(
groups.map(group => (
<Block
key={group.key}
title={group.title}
orgs={sorted.filter(org => groupBy(org) === group.key)}
accent={accent}
pageLabel={group.pageLabel ?? pageLabel}
siteLabel={group.siteLabel ?? siteLabel}
/>
))
);
}