The second half of the button sweep: the remaining hand-rolled buttons in
feature components, the design lab and the components/ui composites now
stand on Button, IconButton, Pressable, Chip or DragHandle.
- Chip + DismissibleChip (filter / token / tag / suggest / ghost, 24px
floor, 44 on touch) replace five chip geometries; FilterChipGroup
renders Chips; overflow lanes measure a mirror painted by chipClass.
- The Plex control row is IconButton's player rung (36, 20px glyph,
round, overlay; 44 on touch); the YT modal bar is on the sm rung with
pressed cycle toggles and names that survive a folded label.
- New variants: IconButton ghost-accent, danger-soft; Button warn on a
new state-warn utility. The .btn-{tone} recipes and btnCls are gone.
- Fixed on the way: membership rows (collection editor, Plex playlist
add) announce checked/mixed; a one-letter tag chip was 21px wide;
descriptionLinks moved out of lib/ (it renders components).
- local/button-primitive: a raw <button>/<FocusSafeButton> outside the
control-primitive files is a lint error (contract-tested, seen red).
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { LucideIcon } from "lucide-react";
|
|
import { X } from "lucide-react";
|
|
import { Button } from "./Button";
|
|
import { IconButton } from "./IconButton";
|
|
|
|
type BannerTone = "accent" | "warning";
|
|
|
|
const TONES: Record<BannerTone, { bar: string; icon: string; action: "primary" | "warn" }> = {
|
|
accent: {
|
|
bar: "bg-accent/15 border-accent/30",
|
|
icon: "text-accent",
|
|
action: "primary",
|
|
},
|
|
warning: {
|
|
bar: "bg-warn/15 border-warn/30",
|
|
icon: "text-warn",
|
|
action: "warn",
|
|
},
|
|
};
|
|
|
|
// Shared top-of-app notification bar. VersionBanner and DemoBanner are thin wrappers over this;
|
|
// a future news-ticker variant can build on the same shell (rotating content as children).
|
|
export default function Banner({
|
|
tone,
|
|
icon: Icon,
|
|
children,
|
|
action,
|
|
onDismiss,
|
|
dismissTitle,
|
|
role,
|
|
}: {
|
|
tone: BannerTone;
|
|
icon: LucideIcon;
|
|
children: ReactNode;
|
|
action?: { label: string; onClick: () => void };
|
|
onDismiss?: () => void;
|
|
/** Accessible name (and tooltip) for the dismiss button. Optional at the call site; the component
|
|
* falls back to the generic "Close" rather than shipping an unnamed icon button — a nameless
|
|
* control is not an acceptable default, and `Button`'s type now says so. */
|
|
dismissTitle?: string;
|
|
/** `"status"` for a bar that APPEARS in response to something the user just did, so a screen
|
|
* reader announces it. Left unset for the permanent bars (demo, version): those are part of the
|
|
* page when it loads, and announcing them on every visit is noise, not information. */
|
|
role?: "status";
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const c = TONES[tone];
|
|
return (
|
|
<div
|
|
role={role}
|
|
className={`shrink-0 flex items-center gap-2 px-4 py-2 text-sm border-b text-fg ${c.bar}`}
|
|
>
|
|
<Icon className={`w-4 h-4 shrink-0 ${c.icon}`} />
|
|
<span className="min-w-0">{children}</span>
|
|
{action && (
|
|
<Button
|
|
variant={c.action}
|
|
size="sm"
|
|
onClick={action.onClick}
|
|
className="ml-1 font-semibold"
|
|
>
|
|
{action.label}
|
|
</Button>
|
|
)}
|
|
{onDismiss && (
|
|
<IconButton
|
|
label={dismissTitle ?? t("common.close")}
|
|
size="sm"
|
|
variant="ghost"
|
|
onClick={onDismiss}
|
|
className="ml-auto"
|
|
>
|
|
<X />
|
|
</IconButton>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|