{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alert",
  "title": "Alert",
  "description": "A message in the page, with the Toast’s icon for its type, a title, a description and actions. One that opens or closes after the page has loaded grows or shrinks so the page makes room, a change of type rolls its icon to the next, and it reads out what it says when that changes.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/notice.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/controllable.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/alert.tsx",
      "content": "'use client'\n\nimport { Button } from '@/registry/components/kino/button'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { useControllable } from '@/registry/lib/controllable'\nimport {\n  NoticeIcon,\n  noticeActionsClassName,\n  noticeDescriptionClassName,\n  noticeTextClassName,\n  noticeTitleClassName,\n  type NoticeType,\n} from '@/registry/lib/notice'\nimport { collapseClassName, followPanelContent } from '@/registry/lib/resize'\nimport {\n  CollapsiblePanel as CollapsiblePanelPrimitive,\n  Collapsible as CollapsiblePrimitive,\n  createCollapsibleController,\n} from '@ui-sdk/react/collapsible'\nimport { cva } from 'class-variance-authority'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  use,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A message that sits in the page: the Toast's icon, title and description in\n * a box of their own. One that opens or closes after the page has loaded\n * grows or shrinks on its height, as an Accordion's panel does, so what is\n * below it moves; while it closes it keeps what it last said. A change of\n * type rolls its icon to the next and crossfades its colours, and the box\n * glides to its new height when the text changes.\n */\n\nconst alertVariants = cva(\n  'flex items-start gap-3 rounded-(--surface-radius) p-(--surface-padding) text-sm ring-1 ring-inset transition-[color,background-color,box-shadow] duration-(--motion-press-duration) ease-(--motion-press-fade-easing) has-data-alert-close:pe-[calc(var(--surface-padding)-(--spacing(2)))] forced-colors:outline forced-colors:-outline-offset-1',\n  {\n    variants: {\n      type: {\n        info: 'bg-card text-card-foreground ring-foreground/10',\n        loading: 'bg-card text-card-foreground ring-foreground/10',\n        // The Badge's tints. A success's and a warning's title is their foreground colour, for 4.5:1.\n        success:\n          'bg-success/6 text-success-foreground ring-success/25 dark:bg-success/12 dark:ring-success/35',\n        warning:\n          'bg-warning/6 text-warning-foreground ring-warning/25 dark:bg-warning/12 dark:ring-warning/35',\n        // An error's title takes a fifth of the foreground, as the Badge's text does, for 4.5:1.\n        error:\n          'bg-destructive/6 text-[color-mix(in_oklch,var(--destructive),var(--foreground)_20%)] ring-destructive/25 dark:bg-destructive/12 dark:ring-destructive/35',\n      },\n    },\n    defaultVariants: { type: 'info' },\n  },\n)\n\ninterface Shown {\n  type: NoticeType\n  icon: ReactNode\n  children: ReactNode\n}\n\n/**\n * What the alert shows: what it was given while it is open, and what it last\n * showed while it closes, so its message never empties as it shrinks away.\n */\nfunction shownAfter(previous: Shown, next: Shown, open: boolean): Shown {\n  if (!open) return previous\n  if (\n    previous.type === next.type &&\n    previous.icon === next.icon &&\n    previous.children === next.children\n  )\n    return previous\n  return next\n}\n\nfunction useShown(next: Shown, open: boolean) {\n  const [shown, setShown] = useState(next)\n  const after = shownAfter(shown, next, open)\n  if (after !== shown) setShown(after)\n  return after\n}\n\n/**\n * The alert's own box, which mounts with the panel. Text that grows or\n * shrinks moves the panel with it. The panel fades its child in and out, so\n * the box sits one level in, where its colours keep their own transition.\n */\nfunction AlertSurface({ className, ...props }: ComponentProps<'div'>) {\n  const ref = useRef<HTMLDivElement>(null)\n\n  useEffect(() => {\n    const surface = ref.current\n    const panel = surface?.parentElement\n    if (!surface || !panel) return\n    return followPanelContent(panel, surface, '--collapsible-panel-height')\n  }, [])\n\n  return (\n    <div ref={ref}>\n      <div className={className} {...props} />\n    </div>\n  )\n}\n\n/** Names the alert by its title, for a screen reader's list of regions and for an agent. */\nconst AlertTitleContext = createContext<((id: string | null) => void) | null>(null)\n\n/**\n * A message in the page. It is a live region from the start: what it says\n * when it opens, or when its text changes, is read out, at once for an\n * `error` and when the screen reader is free for any other type. What it says\n * as the page loads is read in its place. Given `open`, it stays in the tree\n * while closed, and opening or closing it moves what is below it.\n */\n\nfunction Alert({\n  type = 'info',\n  icon,\n  showCloseButton = false,\n  open: openProp,\n  defaultOpen = true,\n  onOpenChange,\n  className,\n  children,\n  ...props\n}: Omit<\n  ComponentProps<typeof CollapsiblePrimitive>,\n  'className' | 'render' | 'disabled' | 'defaultOpen' | 'children' | 'controller'\n> & {\n  className?: string\n  children?: ReactNode\n  /** Its kind, which picks its icon and colour. */\n  type?: NoticeType\n  /** An icon in place of the type's own, or `null` for none. */\n  icon?: ReactNode\n  /** A button at its end that closes it. */\n  showCloseButton?: boolean\n  defaultOpen?: boolean\n}) {\n  const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)\n  const shown = useShown({ type, icon, children }, open)\n  const [controller] = useState(createCollapsibleController)\n  const [titleId, setTitleId] = useState<string | null>(null)\n\n  return (\n    <CollapsiblePrimitive\n      data-alert=''\n      data-type={shown.type}\n      role={shown.type === 'error' ? 'alert' : 'status'}\n      aria-labelledby={titleId ?? undefined}\n      open={open}\n      onOpenChange={setOpen}\n      controller={controller}\n      // Without its close button the page opens and closes it, so an agent can't either.\n      disabled={!showCloseButton}\n      // Closed, it stays in the page as an empty live region, so what it says when it opens is read out.\n      className={cn('group/alert min-w-0', className)}\n      {...props}\n    >\n      <CollapsiblePanelPrimitive\n        data-alert-panel=''\n        // Clipped down the page only, so the close button's focus ring keeps its sides.\n        className={cn(\n          collapseClassName,\n          'overflow-y-clip [--collapse-height:var(--collapsible-panel-height)]',\n        )}\n      >\n        <AlertSurface\n          data-slot='alert-surface'\n          className={alertVariants({ type: shown.type })}\n        >\n          <NoticeIcon data-slot='alert-icon' type={shown.type} icon={shown.icon} />\n          <div data-slot='alert-content' className={noticeTextClassName}>\n            <AlertTitleContext value={setTitleId}>{shown.children}</AlertTitleContext>\n          </div>\n          {showCloseButton ? (\n            <AlertClose\n              onClick={(event) =>\n                controller.close({ reason: 'trigger-press', event: event.nativeEvent })\n              }\n            />\n          ) : null}\n        </AlertSurface>\n      </CollapsiblePanelPrimitive>\n    </CollapsiblePrimitive>\n  )\n}\n\nfunction AlertTitle({ id, className, ...props }: ComponentProps<'div'>) {\n  const own = useId()\n  const titleId = id ?? own\n  const name = use(AlertTitleContext)\n  useLayoutEffect(() => {\n    name?.(titleId)\n    return () => name?.(null)\n  }, [name, titleId])\n  return (\n    <div\n      id={titleId}\n      data-slot='alert-title'\n      className={cn(noticeTitleClassName, className)}\n      {...props}\n    />\n  )\n}\n\nfunction AlertDescription({ className, ...props }: ComponentProps<'div'>) {\n  return (\n    <div\n      data-slot='alert-description'\n      className={cn(\n        noticeDescriptionClassName,\n        // A tinted alert's takes more of the foreground than its title, for 4.5:1 on the tint.\n        'group-data-[type=error]/alert:text-[color-mix(in_oklch,var(--destructive),var(--foreground)_40%)] group-data-[type=success]/alert:text-[color-mix(in_oklch,var(--success-foreground),var(--foreground)_30%)] group-data-[type=warning]/alert:text-[color-mix(in_oklch,var(--warning-foreground),var(--foreground)_30%)] *:[a]:hover:text-foreground *:[a]:underline *:[a]:underline-offset-3',\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** A row of buttons or links under the description. */\nfunction AlertActions({ className, ...props }: ComponentProps<'div'>) {\n  return (\n    <div\n      data-slot='alert-actions'\n      className={cn(noticeActionsClassName, className)}\n      {...props}\n    />\n  )\n}\n\nfunction AlertClose({ className, children, ...props }: ComponentProps<typeof Button>) {\n  return (\n    <Button\n      data-alert-close=''\n      variant='ghost'\n      size='icon-xs'\n      aria-label='Close'\n      className={cn('-mt-0.5 text-current/70 hover:text-current', className)}\n      {...props}\n    >\n      {children ?? (\n        <IconPlaceholder\n          lucide='XIcon'\n          tabler='IconX'\n          hugeicons='Cancel01Icon'\n          phosphor='XIcon'\n          remixicon='RiCloseLine'\n          aria-hidden\n        />\n      )}\n    </Button>\n  )\n}\n\nexport { Alert, AlertActions, AlertDescription, AlertTitle, alertVariants, shownAfter }\n",
      "type": "registry:component",
      "target": "@components/kino/alert.tsx"
    }
  ],
  "type": "registry:component"
}