- Generalize the recipe into a .btn-{tone} family: add .btn-danger / .btn-warn
siblings sharing one hover-dim, and migrate the two hand-rolled tone-action
buttons (ConfirmProvider danger confirm, Banner warning action) onto them, so
primary/danger/warn action paints can't drift.
- Reword the recipe comment: it owns paint + one standard hover-dim (not
'PAINT-ONLY' — that mislabel obscured the hover behaviour).
- Drop the now-redundant hover:opacity-90 from Banner's action-button base (each
tone's recipe supplies the hover).
The 3 previously hover-less primary buttons keep the standard hover-dim gained in
the prior commit (intentional consistency; now accurately documented). Gate green
(tsc/eslint-0/prettier/knip/vitest 79); self-E2E confirmed btn-danger/btn-warn
compute to their tone/tone-fg tokens.
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import type { LucideIcon } from "lucide-react";
|
|
import { X } from "lucide-react";
|
|
|
|
type BannerTone = "accent" | "warning";
|
|
|
|
const TONES: Record<BannerTone, { bar: string; icon: string; action: string }> = {
|
|
accent: {
|
|
bar: "bg-accent/15 border-accent/30",
|
|
icon: "text-accent",
|
|
action: "btn-primary",
|
|
},
|
|
warning: {
|
|
bar: "bg-warn/15 border-warn/30",
|
|
icon: "text-warn",
|
|
action: "btn-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,
|
|
}: {
|
|
tone: BannerTone;
|
|
icon: LucideIcon;
|
|
children: ReactNode;
|
|
action?: { label: string; onClick: () => void };
|
|
onDismiss?: () => void;
|
|
dismissTitle?: string;
|
|
}) {
|
|
const c = TONES[tone];
|
|
return (
|
|
<div 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
|
|
onClick={action.onClick}
|
|
className={`ml-1 px-2.5 py-1 rounded-lg font-semibold transition ${c.action}`}
|
|
>
|
|
{action.label}
|
|
</button>
|
|
)}
|
|
{onDismiss && (
|
|
<button
|
|
onClick={onDismiss}
|
|
title={dismissTitle}
|
|
className="ml-auto p-1 rounded-md text-muted hover:text-fg hover:bg-card transition"
|
|
>
|
|
<X className="w-4 h-4" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|