{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alert",
  "title": "Alert",
  "description": "An inline message in the page: something saved, something failed, something to know before going on.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/lib-appearance-hints",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-focus-handoff",
    "@ouro/lib-refs",
    "@ouro/lib-tones",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/alert/alert.tsx",
      "content": "\"use client\";\n\nimport type { ComponentType, HTMLAttributes, JSX, ReactNode, Ref, SVGProps } from \"react\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { fontFor, toneFor } from \"@/registry/ouro/lib/ouro/appearance-hints\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useFocusHandoff } from \"@/registry/ouro/lib/ouro/focus-handoff\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { toneWarning, type ToneName } from \"@/registry/ouro/lib/ouro/tones\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** An icon component, such as one from `lucide-react` or `@heroicons/react`. */\nexport type AlertIcon = ComponentType<SVGProps<SVGSVGElement>>;\n\n/** The props Alert adds to the `<div>` attributes it passes through. */\nexport interface AlertOwnProps {\n  /**\n   * What happened, in a few words: \"Recipe saved\", \"Not saved: you're offline\". Required, so every\n   * alert says what it is about.\n   * @claim \"Required, so every alert says what\" registry/ouro/components/ouro/alert/alert.test-d.ts verify:fileLine(registry/ouro/components/ouro/alert/alert.test-d.ts, /title is required/)\n   */\n  title: ReactNode;\n  /** More detail, or what to do next, under the title. */\n  description?: ReactNode;\n  /**\n   * Color role from the theme, which also sets how urgently screen readers hear it:\n   * `destructive` and `warning` are `role=\"alert\"` (spoken at once), the others\n   * `role=\"status\"` (spoken politely). `primary` is for information, `secondary` for a\n   * neutral note. shadcn's `variant=\"destructive\"` is `tone=\"destructive\"`.\n   * @default \"secondary\"\n   */\n  tone?:\n    | \"primary\"\n    | \"secondary\"\n    | \"destructive\"\n    | \"success\"\n    | \"warning\"\n    | (string & { 'danger and error are \"destructive\"; info is \"primary\"; neutral is \"secondary\"': never })\n    | undefined;\n  /** A control under the description, usually a small Button: `action={<Button size=\"sm\">Retry</Button>}`. */\n  action?: ReactNode;\n  /**\n   * Shows a close button that calls this. Remove the alert from your state in it. When\n   * the alert goes, keyboard focus moves to the next control after it, or to the one\n   * before it when nothing follows, so it is not lost to the page.\n   */\n  onDismiss?: (() => void) | undefined;\n  /** The close button's accessible name, for other languages. @default \"Dismiss\" */\n  dismissLabel?: string | undefined;\n  /**\n   * The icon at the start, as a component: `icon={WifiOffIcon}`. Each tone has its own\n   * by default; `null` shows none.\n   * @claim \"Each tone has its own by\" registry/ouro/components/ouro/alert/alert.test.tsx verify:testExists(registry/ouro/components/ouro/alert/alert.test.tsx::Alert > takes an icon component, or none)\n   * @claim \"Each tone has its own by\" registry/ouro/components/ouro/alert/alert.test.tsx verify:testExists(registry/ouro/components/ouro/alert/alert.test.tsx::Alert > gives every tone a distinct look)\n   */\n  icon?: AlertIcon | null | undefined;\n  /** Layout only: margins, width, grid placement (`mt-4`). Appearance classes warn in development; use `tone`. */\n  className?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `tone`: `<Alert tone=\"destructive\">`. */\n  variant?: { 'Use <Alert tone=\"destructive\">': never };\n  /** Not a prop. Ouro UI uses `tone`: `<Alert tone=\"destructive\">`. */\n  severity?: { 'Use <Alert tone=\"destructive\">': never };\n  /** Not a prop. Ouro UI uses `tone`: `<Alert tone=\"primary\">`. */\n  status?: { 'Use <Alert tone=\"primary\">': never };\n  /** Not a prop. Ouro UI uses `onDismiss`: `<Alert onDismiss={() => setOpen(false)}>`. */\n  onClose?: { 'Use <Alert onDismiss={() => setOpen(false)}>': never };\n  /** Not a prop. Alert takes `title` and `description`: `<Alert title=\"…\" description=\"…\">`. */\n  children?: { 'Use <Alert title=\"...\" description=\"...\">': never };\n}\n\n/** Props for {@link Alert}: its own props and the `<div>` attributes it passes through. */\nexport type AlertProps = Omit<HTMLAttributes<HTMLDivElement>, keyof AlertOwnProps | \"role\"> & AlertOwnProps;\n\nconst tones = {\n  primary: {\n    root: \"border-primary/30 bg-primary/5\",\n    accent: \"text-[color-mix(in_oklab,var(--primary)_80%,var(--foreground))]\",\n  },\n  secondary: { root: \"border-border bg-card\", accent: \"text-foreground\" },\n  destructive: {\n    root: \"border-destructive/30 bg-destructive/5\",\n    accent: \"text-[color-mix(in_oklab,var(--destructive)_80%,var(--foreground))]\",\n  },\n  success: {\n    root: \"border-success/30 bg-success/5\",\n    accent: \"text-[color-mix(in_oklab,var(--success)_80%,var(--foreground))]\",\n  },\n  warning: {\n    root: \"border-warning/30 bg-warning/5\",\n    accent: \"text-[color-mix(in_oklab,var(--warning)_80%,var(--foreground))]\",\n  },\n} as const;\n\n/** Tones a reader must hear at once. */\nconst urgent = new Set<ToneName>([\"destructive\", \"warning\"]);\n\nfunction Glyph({ children, ...props }: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" {...props}>\n      {children}\n    </svg>\n  );\n}\n\nfunction InfoIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <Glyph {...props}>\n      <circle cx=\"10\" cy=\"10\" r=\"7.5\" />\n      <path d=\"M10 9v4.5M10 6.5v.01\" />\n    </Glyph>\n  );\n}\n\nfunction SuccessIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <Glyph {...props}>\n      <circle cx=\"10\" cy=\"10\" r=\"7.5\" />\n      <path d=\"m6.75 10.25 2.25 2.25 4.25-4.75\" />\n    </Glyph>\n  );\n}\n\nfunction WarningIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <Glyph {...props}>\n      <path d=\"M8.7 3.3a1.5 1.5 0 0 1 2.6 0l6 10.5a1.5 1.5 0 0 1-1.3 2.2H4a1.5 1.5 0 0 1-1.3-2.2z\" />\n      <path d=\"M10 8v3.5M10 13.75v.01\" />\n    </Glyph>\n  );\n}\n\nfunction ErrorIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <Glyph {...props}>\n      <circle cx=\"10\" cy=\"10\" r=\"7.5\" />\n      <path d=\"m7.5 7.5 5 5m0-5-5 5\" />\n    </Glyph>\n  );\n}\n\nconst icons: Record<ToneName, AlertIcon> = {\n  primary: InfoIcon,\n  secondary: InfoIcon,\n  destructive: ErrorIcon,\n  success: SuccessIcon,\n  warning: WarningIcon,\n};\n\nfunction CloseIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <Glyph {...props}>\n      <path d=\"m5.5 5.5 9 9m0-9-9 9\" />\n    </Glyph>\n  );\n}\n\nfunction alertHint(token: string): string {\n  if (/^text-(xs|sm|base|lg|xl|\\dxl)$/.test(token)) return `remove \"${token}\"; Alert sets its own size`;\n  if (token.startsWith(\"font-\")) return fontFor(\"Alert\", token);\n  return `tone=\"${toneFor(token)}\"`;\n}\n\n/** The tone another library's severity or status names. Development only. */\nfunction toneFromSeverity(value: unknown): ToneName {\n  const name = String(value);\n  if (/error|danger/.test(name)) return \"destructive\";\n  if (/warn/.test(name)) return \"warning\";\n  if (/success/.test(name)) return \"success\";\n  return \"primary\";\n}\n\n/**\n * An inline message in the page: something saved, something failed, something to know\n * before going on. It has a title, an optional description and action, and a close\n * button when you pass `onDismiss`. Destructive and warning alerts are spoken at once\n * (`role=\"alert\"`); the others politely (`role=\"status\"`). A long word in the title or\n * description, such as an address in an error, wraps inside the alert however narrow it is.\n *\n * In and around forms, use Alert for a message that belongs to neither a field nor the form\n * as a whole: a reorder or a deletion the server refused, an imported step the parser rejected. Render it where the action was taken, with `action` for the way out.\n *\n * Use `Toast` instead for a brief message that disappears by itself, `ConfirmDialog` to\n * ask before a destructive action, and `Field`'s `error` for a message about one field.\n * Use `Form`'s `errors` instead for what a submit returned: a field's name as the key puts\n * the message under that field, and the `form` key shows it at the top of the form.\n *\n * @group Display\n * @see https://ui.ouroboros.bot/docs/alert\n * @claim \"A long word in the title or\" registry/ouro/components/ouro/alert/alert.test.tsx verify:testExists(registry/ouro/components/ouro/alert/alert.test.tsx::Alert > wraps a long word in its title and description inside its box, as an address in an error is)\n *\n * @example\n * <Alert tone=\"success\" title=\"Recipe saved\" />\n * <Alert\n *   tone=\"destructive\"\n *   title=\"Not saved: you're offline\"\n *   description=\"Check your connection and try again.\"\n *   action={<Button size=\"sm\" onClick={retry}>Try again</Button>}\n *   onDismiss={() => setError(null)}\n * />\n */\nexport function Alert(props: AlertProps): JSX.Element {\n  const {\n    title,\n    description,\n    tone: toneProp = \"secondary\",\n    action,\n    onDismiss,\n    dismissLabel = \"Dismiss\",\n    icon,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    variant,\n    severity,\n    status,\n    onClose,\n    children,\n    ref,\n    ...rest\n  } = props;\n  // When the alert leaves while it holds focus (its dismiss button, or an action that removes it),\n  // focus goes to what now stands where it stood: the next control, or the last one before it.\n  const merged = useMergedRef(ref, useFocusHandoff<HTMLDivElement>());\n  // A tone that is not one of Ouro UI's (a type error) warns and renders the default.\n  const tone = Object.hasOwn(tones, toneProp) ? (toneProp as ToneName) : \"secondary\";\n  useAppearanceClassNameCheck(\n    \"Alert\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? alertHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Alert\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          tone !== toneProp &&\n            (/^(info|error)$/.test(String(toneProp))\n              ? [`tone=\"${toneProp}\" is not a tone; use \"primary\", \"secondary\", \"destructive\", \"success\", \"warning\"`, `<Alert tone=\"${toneFromSeverity(toneProp)}\">`]\n              : toneWarning(\"Alert\", String(toneProp), Object.keys(tones))),\n          variant !== undefined && [`variant=\"${String(variant)}\" is not a prop`, `<Alert tone=\"${String(variant) === \"destructive\" ? \"destructive\" : \"secondary\"}\">`],\n          severity !== undefined && [\"severity is not a prop\", `<Alert tone=\"${toneFromSeverity(severity)}\">`],\n          status !== undefined && [\"status is not a prop\", `<Alert tone=\"${toneFromSeverity(status)}\">`],\n          onClose !== undefined && [\"onClose is not a prop\", \"<Alert onDismiss={() => setOpen(false)}>\"],\n          children !== undefined && [\"Alert takes no children\", '<Alert title=\"…\" description=\"…\">'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const Icon = icon === undefined ? icons[tone] : icon;\n  const accent = tones[tone].accent;\n  return (\n    <div\n      {...rest}\n      ref={merged}\n      role={urgent.has(tone) ? \"alert\" : \"status\"}\n      data-ouro=\"alert\"\n      data-tone={tone}\n      className={cn(\n        \"box-border flex w-full items-start gap-3 rounded-ouro-lg border border-solid p-4 text-foreground\",\n        tones[tone].root,\n        className,\n      )}\n    >\n      {Icon && <Icon aria-hidden=\"true\" data-ouro-alert-icon=\"\" className={cn(\"mt-0.5 size-5 shrink-0\", accent)} />}\n      {/* A long word (an address in an error) wraps anywhere, so it stays inside the alert, however narrow. */}\n      <div className=\"flex min-w-0 flex-1 flex-col gap-1 [overflow-wrap:anywhere]\">\n        <div data-ouro-alert-title=\"\" data-ouro-text=\"\" className={cn(\"text-base/6 font-medium sm:pointer-fine:text-sm/5\", accent)}>\n          {title}\n        </div>\n        {description !== undefined && (\n          <div data-ouro-alert-description=\"\" data-ouro-text=\"\" className=\"text-base/6 sm:pointer-fine:text-sm/5\">\n            {description}\n          </div>\n        )}\n        {action !== undefined && (\n          <div data-ouro-alert-action=\"\" className=\"mt-2 flex flex-wrap gap-2\">\n            {action}\n          </div>\n        )}\n      </div>\n      {onDismiss && (\n        <Button\n          variant=\"plain\"\n          tone=\"secondary\"\n          size=\"sm\"\n          aria-label={dismissLabel}\n          data-ouro-control=\"alert\"\n          data-ouro-part=\"dismiss\"\n          onClick={() => onDismiss()}\n          className=\"-my-1.5 -me-2 w-(--ouro-button-h) px-0\"\n        >\n          <CloseIcon aria-hidden=\"true\" className=\"size-4\" />\n        </Button>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/alert/alert.tsx"
    }
  ],
  "docs": "An inline message in the page: something saved, something failed, something to know before going on. Import: import { Alert } from \"@/components/ouro/alert/alert\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/alert.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}