import * as React from "react"; import { CircleAlertIcon, CircleCheckIcon, ClockIcon, InfoIcon, TriangleAlertIcon, type LucideIcon, } from "lucide-react"; import { hasSlot, renderActions, renderIcon, type ActionData, type IconSlot, } from "./data-slots"; import { cn } from "../lib/cn"; type NoticeTone = "info" | "success" | "warning" | "error" | "neutral"; export interface NoticeProps extends Omit< React.ComponentProps<"div">, "title" > { tone?: NoticeTone; title?: React.ReactNode; /** Replaces the tone's icon; `null` for none. */ icon?: IconSlot | null; /** Up to two (a button and a link), as elements or `ActionData`, or a * list mixing both (`renderActions`): a host's dialog trigger beside the * notice's links. The text is the children. */ actions?: | React.ReactNode | ActionData | ReadonlyArray; } const TONES: Record< NoticeTone, { box: string; icon: string; glyph: LucideIcon } > = { info: { box: "border-primary-electric-blue-40 bg-primary-electric-blue-5", icon: "text-primary", glyph: InfoIcon, }, success: { box: "border-semantic-success-100 bg-semantic-success-10", icon: "text-semantic-success-120", glyph: CircleCheckIcon, }, warning: { box: "border-semantic-warning-100 bg-semantic-warning-10", icon: "text-semantic-warning-120", glyph: TriangleAlertIcon, }, error: { box: "border-semantic-error-100 bg-semantic-error-10", icon: "text-semantic-error-100", glyph: CircleAlertIcon, }, neutral: { box: "border-primary-blue-20 bg-primary-blue-5", icon: "text-muted-foreground", glyph: ClockIcon, }, }; // The design system's Notice: what happened in a title, what it means in a // sentence or two, and what to do about it. The larger relative of `Alert`, // which stays the one-line message of a form. One per cause, on top of the // content it is about. // // The words stay dark on the tint and the colour goes to the icon, so the // tone is never said by colour alone. An error is announced at once // (`role="alert"`); the others wait their turn (`role="status"`). function Notice({ tone = "info", title, icon, actions, className, children, ...props }: NoticeProps) { const look = TONES[tone]; const glyph = icon === undefined ? look.glyph : icon; return (
{glyph && ( {renderIcon(glyph, "size-6")} )}
{title && (

{title}

)} {children && (
{children}
)} {hasSlot(actions) && (
[data-slot=button]]:h-auto [&>[data-slot=button]]:min-h-10 [&>[data-slot=button]]:max-w-full [&>[data-slot=button]]:py-1.5 [&>[data-slot=button]]:whitespace-normal", )} > {renderActions(actions)}
)}
); } export { Notice };