An audit of all twelve draft files against the build turned up a set of mismatches, most of them in the tier-2 token layer rather than in any one component. Tier 1 is untouched throughout - only the meanings moved. SHAPE. The drafts draw three corners, not five: 2px for a tag, thumbnail, flag or checkbox, 4px for anything with a box, and fully round for a filter chip or status pill. Nothing in any draft is 8px or 12px. --radius-card and --radius-surface therefore come down to radius/sm, a --radius-chip is added for the 2px tier, and --radius-control-lg - a quirk of the Figma Button frame's ghost cells - is retired along with its four consumers. ELEVATION. A shadow is a fraction of the ground it falls on, and the ramp was tuned for a white page: on the drafts' near-black ground a 12-28% black is invisible. Tier 1 gains the two deep steps the drafts actually draw (--shadow-dark-lg/xl), and --elevation-card/-popover/-modal move into the per-surface blocks so the dark surface can take them while the light one keeps the soft ramp. A resting card now has no shadow at all - the drafts separate with a hairline - and the black is spent on what floats. CARDS. The hover was a white-24% hairline and a faint glow; the drafts turn the hairline accent green, lift the card 6px and land a deep black under it. The lift is pointer-only and is dropped under prefers-reduced-motion. GHOST IS A TEXT LINK. The drafts never fill a ghost control - every "All updates ->" is plain text that turns green while the label-to-arrow gap opens. The tokens carry no fill in any state and the variant opts out of the 3px lift, which also retires the WCAG workaround the old Figma hover forced (green label on a green fill, 1.40:1). NAVIGATION. A nav label rests in text/secondary and brightens to primary; the current section stays primary and is marked by the accent rule, not by green text. HERO STRIPE. The middle block was painted near-black against a comment claiming the redesign had dropped white; the drafts paint it #F8F9FA. Back to background/inverse, and to the drafts' 390 : 495 : 363 split. styles/README.md is updated to match, including a contrast table that still described --surface-raised as the retired #2e2e2c. Not changed, because each is a decision rather than a defect: the drafts set every eyebrow, tag and meta line in IBM Plex Mono at 10-11px with 1.2-1.4px tracking (a third typeface, and no Arabic counterpart); draft headings are weight 800, which needs a font file we do not have; and the EU badge statement stays at --text-primary, since the visibility lockup is contractual. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
241 lines
7.8 KiB
TypeScript
241 lines
7.8 KiB
TypeScript
/* ============================================================================
|
|
CARD - shared building blocks
|
|
----------------------------------------------------------------------------
|
|
Every card in this directory is assembled from the pieces below, so the
|
|
surface, radius, border, elevation and link behaviour are decided once.
|
|
|
|
STYLING RULE for this whole directory:
|
|
* colour and radius come from the tier-2 Tailwind bridge
|
|
(bg-surface-raised, text-text-accent, border-border-subtle,
|
|
rounded-card, ...) - never a hex, never a tier-1 primitive;
|
|
* tokens without a bridge utility are spent as arbitrary values,
|
|
e.g. shadow-[var(--elevation-card)];
|
|
* spacing uses the named scale (p-lg = 24, gap-md = 16) so the Figma
|
|
numbers stay readable;
|
|
* everything directional uses logical utilities (ps-/pe-/start-/end-)
|
|
so the Arabic build mirrors without a second stylesheet.
|
|
|
|
Nothing here is surface-aware by hand: the same markup is correct on
|
|
[data-surface="dark"] and [data-surface="light"] because every colour is a
|
|
role the surface re-points.
|
|
========================================================================= */
|
|
|
|
import type { CSSProperties, ReactElement, ReactNode } from "react";
|
|
import { Link } from "react-router";
|
|
|
|
import "./card.css";
|
|
import type {
|
|
CardElement,
|
|
CardIconName,
|
|
CardImage,
|
|
CardLinkTarget,
|
|
} from "./types";
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
LINK
|
|
------------------------------------------------------------------------ */
|
|
|
|
/** Anything with a scheme, a protocol-relative host or a fragment is not a route. */
|
|
const NON_ROUTE_HREF = /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i;
|
|
|
|
/**
|
|
* React Router sits in the hoisted root of this workspace, where it resolves
|
|
* its React types from the @types/react 18 that Strapi pulls in, so its props
|
|
* are declared against a ReactNode that is not ours (no bigint, and a
|
|
* ReactPortal that still requires children). Re-declaring the component once
|
|
* here keeps every call site below honest instead of casting at each of them.
|
|
* Delete this alias when the workspace resolves to a single @types/react.
|
|
*/
|
|
const RouterLink = Link as unknown as (props: {
|
|
to: string;
|
|
className?: string;
|
|
target?: string;
|
|
rel?: string;
|
|
children: ReactNode;
|
|
}) => ReactElement;
|
|
|
|
export interface CardLinkProps extends CardLinkTarget {
|
|
className?: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
/**
|
|
* Routes internal hrefs through React Router so navigation stays client-side,
|
|
* and falls back to a plain anchor for external links, mailto: and fragments.
|
|
*/
|
|
export function CardLink({ href, className, children, ...rest }: CardLinkProps) {
|
|
if (NON_ROUTE_HREF.test(href)) {
|
|
return (
|
|
<a href={href} className={className} {...rest}>
|
|
{children}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<RouterLink to={href} className={className} {...rest}>
|
|
{children}
|
|
</RouterLink>
|
|
);
|
|
}
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
ICON
|
|
------------------------------------------------------------------------ */
|
|
|
|
/** The assets exported from the Figma icon frame, served from public/. */
|
|
const CARD_ICON_SRC: Record<CardIconName, string> = {
|
|
"arrow-right": "url('/assets/icons/arrow-right.svg')",
|
|
"arrow-up": "url('/assets/icons/arrow-up.svg')",
|
|
linkedin: "url('/assets/icons/linkedin.svg')",
|
|
mail: "url('/assets/icons/mail.svg')",
|
|
globe: "url('/assets/icons/globe.svg')",
|
|
};
|
|
|
|
export interface CardIconProps {
|
|
name: CardIconName;
|
|
/** Designed box in px - 14 for the 14x14 icons, 10 for the trend arrow. */
|
|
size: number;
|
|
/** Mirror in RTL. True for the horizontal arrow, false for the vertical one. */
|
|
directional?: boolean;
|
|
className?: string;
|
|
}
|
|
|
|
/**
|
|
* Draws an exported SVG as a mask over a currentColor fill, so the icon keeps
|
|
* the geometry Figma exported while taking its colour from the token in force.
|
|
* Always decorative - the adjacent text carries the meaning.
|
|
*/
|
|
export function CardIcon({ name, size, directional, className }: CardIconProps) {
|
|
return (
|
|
<span
|
|
aria-hidden="true"
|
|
className={cx(
|
|
"sh-card-icon",
|
|
directional && "sh-card-icon--directional",
|
|
className,
|
|
)}
|
|
style={
|
|
{
|
|
"--sh-card-icon-src": CARD_ICON_SRC[name],
|
|
width: size,
|
|
height: size,
|
|
} as CSSProperties
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
SHELL
|
|
------------------------------------------------------------------------ */
|
|
|
|
export interface CardShellProps {
|
|
/** `li` inside a list, `section` for a landmark, `article` by default. */
|
|
as?: CardElement;
|
|
/**
|
|
* The card contains a stretched link. Adds the hover lift and lets the
|
|
* ::after overlay in card.css position against the card.
|
|
*/
|
|
linked?: boolean;
|
|
className?: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
/**
|
|
* The surface every card shares: raised fill, hairline border and the 4px
|
|
* corner the design drafts draw. `--elevation-card` is the drafts' resting
|
|
* shadow, which on the dark surface is none at all - the hairline does the
|
|
* separating, and the black is kept for the hover state in card.css.
|
|
*/
|
|
export function CardShell({
|
|
as = "article",
|
|
linked = false,
|
|
className,
|
|
children,
|
|
}: CardShellProps) {
|
|
const Tag = as;
|
|
|
|
return (
|
|
<Tag
|
|
className={cx(
|
|
"sh-card",
|
|
linked && "sh-card--linked",
|
|
"relative flex bg-[var(--surface-card)] text-text-primary",
|
|
"rounded-card border border-border-subtle shadow-[var(--elevation-card)]",
|
|
className,
|
|
)}
|
|
>
|
|
{children}
|
|
</Tag>
|
|
);
|
|
}
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
MEDIA
|
|
------------------------------------------------------------------------ */
|
|
|
|
export interface CardMediaProps {
|
|
image: CardImage;
|
|
/** Sets the box: an aspect-ratio utility, a fixed size, or both per breakpoint. */
|
|
className?: string;
|
|
/** Overlays that sit on the image, e.g. the category badge. */
|
|
children?: ReactNode;
|
|
}
|
|
|
|
/**
|
|
* A media box whose height is decided by the wrapper, never by the file, so
|
|
* the layout is stable before the image loads.
|
|
*/
|
|
export function CardMedia({ image, className, children }: CardMediaProps) {
|
|
return (
|
|
<div className={cx("sh-card-media relative overflow-hidden", className)}>
|
|
<img
|
|
src={image.src}
|
|
srcSet={image.srcSet}
|
|
sizes={image.sizes}
|
|
alt={image.alt}
|
|
loading={image.priority ? "eager" : "lazy"}
|
|
fetchPriority={image.priority ? "high" : undefined}
|
|
decoding="async"
|
|
className="absolute inset-0 block size-full object-cover"
|
|
/>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
TEXT ATOMS
|
|
------------------------------------------------------------------------ */
|
|
|
|
/** The small accent kicker above a card title ("PROGRAMME", "DIALOGUE REPORT"). */
|
|
export function CardEyebrow({ children }: { children: ReactNode }) {
|
|
return <p className="label-md uppercase text-text-accent">{children}</p>;
|
|
}
|
|
|
|
/**
|
|
* The "Read more ->" affordance. Decorative: the stretched title link already
|
|
* carries the destination, so announcing this again would just be noise.
|
|
*/
|
|
export function CardActionHint({ label }: { label: string }) {
|
|
return (
|
|
<p
|
|
aria-hidden="true"
|
|
className="inline-flex items-center gap-xs body-sm-bold text-text-accent"
|
|
>
|
|
{label}
|
|
<CardIcon name="arrow-right" size={14} directional />
|
|
</p>
|
|
);
|
|
}
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
UTIL
|
|
------------------------------------------------------------------------ */
|
|
|
|
/** Joins class names, dropping anything falsy. */
|
|
export function cx(...parts: Array<string | false | null | undefined>): string {
|
|
return parts.filter(Boolean).join(" ");
|
|
}
|