- F12 (owner: A): SwitchRow, the whole settings row toggles; a Config boolean toggles from its title and hint (a label pointed at the switch). - F14 (owner: B): the form dropdown trigger wears the field frame (see-through, the >= 3:1 edge); labelled pills keep the faint edge and the accent-edge hover. DESIGN says so, with log rows. - F6: ~15 bg-card / bg-border / opacity hovers onto the B3 state layer; a lint rule (HOVER_SWAP) refuses the swap, contract-tested. - F10: bare 14px icon links onto IconLink / LinkButton; a local lint rule refuses a glyph-only <a>. - F13: reason-disabled controls are aria-disabled (Users, Channels backfill, Discovery, Scheduler runs, Config tests); FocusSafeButton now swallows the click of a caller's aria-disabled; the Config tests say why while dirty (testDirty, HU/EN). - F5/F11: every control measured live at 24 (mouse) and 44 (coarse) across every page; touch-target is a utility that wins over a caller's min-h-6; link variants carry it too; SegmentedToggle, Tabs, NavRail, menu rows, PriorityStepper, sliders, CheckRow, InnerInput, card links and the rest. - F9: DismissibleChip's label reaches the chip's 24; the Combobox chips are DismissibleChips. - F15: the "+N" / "More..." open state worded as it renders.
126 lines
4.2 KiB
TypeScript
126 lines
4.2 KiB
TypeScript
import { forwardRef } from "react";
|
||
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
||
import clsx from "clsx";
|
||
import { X } from "lucide-react";
|
||
import { FocusSafeButton } from "./FocusSafeButton";
|
||
import { chipClass, type ChipSize, type ChipVariant } from "./chipStyles";
|
||
|
||
// The chip family (docs/DESIGN.md "One primitive per button family"): a small rounded-full token that
|
||
// is a filter, an applied narrowing, a tag, or a suggestion. It was hand-painted in five files with
|
||
// five geometries; this is the one. `FilterChipGroup` renders a single-select row of these.
|
||
//
|
||
// filter — a selectable option (a year, a tag filter, a content type). Toggles with `pressed`: the
|
||
// `.pill` recipe in index.css paints the solid accent when on. Also the "+N" overflow and
|
||
// "More…" triggers, which light up while their popover is open (aria-expanded).
|
||
// token — an applied narrowing, tinted accent (the `.chip` recipe): it exists because it is on.
|
||
// tag — a user's tag, the solid accent (`.chip-solid`). Dense: it sits in table rows.
|
||
// suggest — dashed accent: a suggestion not yet taken.
|
||
// ghost — dashed neutral: the "add a tag" trigger, quiet in every table row until reached for.
|
||
//
|
||
// Nothing goes under 24px (B1, WCAG 2.5.8) and a coarse pointer grows every chip to 44 (A3).
|
||
|
||
type ChipProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
||
variant?: ChipVariant;
|
||
size?: ChipSize;
|
||
/** A filter chip that toggles: aria-pressed, painted solid when on. */
|
||
pressed?: boolean;
|
||
/** Leading glyph (a lucide element). */
|
||
icon?: ReactNode;
|
||
/** The whole chip removes what it stands for: a trailing × and the removal as its name. */
|
||
removeLabel?: string;
|
||
};
|
||
|
||
/** A chip that is itself the control (a toggle, a removal, an accept, a "+N" trigger). */
|
||
export const Chip = forwardRef<HTMLButtonElement, ChipProps>(function Chip(
|
||
{
|
||
variant = "filter",
|
||
size = "sm",
|
||
pressed,
|
||
icon,
|
||
removeLabel,
|
||
type,
|
||
className,
|
||
children,
|
||
...rest
|
||
},
|
||
ref,
|
||
) {
|
||
return (
|
||
<FocusSafeButton
|
||
ref={ref}
|
||
type={type ?? "button"}
|
||
aria-pressed={pressed}
|
||
aria-label={removeLabel}
|
||
title={removeLabel}
|
||
className={clsx(chipClass(variant, size), removeLabel && "pr-1.5", className)}
|
||
{...rest}
|
||
>
|
||
{icon}
|
||
{children}
|
||
{removeLabel && <X className="size-3" aria-hidden="true" />}
|
||
</FocusSafeButton>
|
||
);
|
||
});
|
||
|
||
/** A chip whose label is not the control but which carries its own trailing × (a captured filter in
|
||
* a saved view, a suggestion with a dismiss). Two sibling controls at most, never a button in a
|
||
* button: `onClick` makes the body one (an accept), `onDismiss` the ×. */
|
||
export function DismissibleChip({
|
||
variant = "token",
|
||
size = "sm",
|
||
icon,
|
||
children,
|
||
onClick,
|
||
bodyLabel,
|
||
bodyTitle,
|
||
onDismiss,
|
||
dismissLabel,
|
||
className,
|
||
}: {
|
||
variant?: Exclude<ChipVariant, "filter">;
|
||
size?: ChipSize;
|
||
icon?: ReactNode;
|
||
children: ReactNode;
|
||
onClick?: () => void;
|
||
bodyLabel?: string;
|
||
bodyTitle?: string;
|
||
onDismiss: () => void;
|
||
dismissLabel: string;
|
||
className?: string;
|
||
}) {
|
||
const body = (
|
||
<>
|
||
{icon}
|
||
<span className="truncate">{children}</span>
|
||
</>
|
||
);
|
||
return (
|
||
<span className={clsx(chipClass(variant, size), "pr-0.5 min-w-0", className)}>
|
||
{onClick ? (
|
||
<FocusSafeButton
|
||
type="button"
|
||
onClick={onClick}
|
||
aria-label={bodyLabel}
|
||
title={bodyTitle}
|
||
// -my-px + stretch: the body reaches over the chip's 1px edges to the chip's full 24 (44 on
|
||
// touch), as the × does; stretched inside the edges it was 22, under the B1 floor.
|
||
className="-my-px inline-flex min-w-0 items-center gap-1 self-stretch [&>svg]:size-3 [&>svg]:shrink-0"
|
||
>
|
||
{body}
|
||
</FocusSafeButton>
|
||
) : (
|
||
<span className="inline-flex min-w-0 items-center gap-1 [&>svg]:size-3">{body}</span>
|
||
)}
|
||
<FocusSafeButton
|
||
type="button"
|
||
onClick={onDismiss}
|
||
aria-label={dismissLabel}
|
||
title={dismissLabel}
|
||
className="-my-px grid size-6 shrink-0 place-items-center rounded-full transition state-layer touch-target"
|
||
>
|
||
<X className="size-3" aria-hidden="true" />
|
||
</FocusSafeButton>
|
||
</span>
|
||
);
|
||
}
|