{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alert-dialog",
  "title": "Alert dialog",
  "description": "A question that needs an answer before something that can’t easily be undone. The Dialog’s box and motion; a press outside makes it swell instead of closing it, focus starts on Cancel, and an action that returns a promise holds it open with a spinner until it settles. The badge variant centres the question under an icon.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/icon-tile.json",
    "https://kinoui.com/r/dialog.json",
    "https://kinoui.com/r/panel.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/refuse.json",
    "https://kinoui.com/r/theme.json",
    "https://kinoui.com/r/button.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/alert-dialog.tsx",
      "content": "'use client'\n\nimport { Button } from '@/registry/components/kino/button'\nimport { DialogBody, DialogFooter, DialogHeader } from '@/registry/components/kino/dialog'\nimport { IconTile } from '@/registry/components/kino/icon-tile'\nimport {\n  PanelSurface,\n  panelDescriptionClassName,\n  panelDialogClassName,\n  panelFooterTint,\n  panelOverlayClassName,\n  panelTitleClassName,\n} from '@/registry/lib/panel'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport { refuse } from '@/registry/lib/refuse'\nimport {\n  AlertDialog as AlertDialogPrimitive,\n  AlertDialogBackdrop as AlertDialogBackdropPrimitive,\n  AlertDialogClose as AlertDialogClosePrimitive,\n  AlertDialogContent as AlertDialogContentPrimitive,\n  AlertDialogDescription as AlertDialogDescriptionPrimitive,\n  AlertDialogTitle as AlertDialogTitlePrimitive,\n  AlertDialogTrigger as AlertDialogTriggerPrimitive,\n} from '@ui-sdk/react/alert-dialog'\nimport type { DialogContentState } from '@ui-sdk/react/dialog'\nimport { mergeProps, type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  type RefObject,\n  use,\n  useMemo,\n  useRef,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/**\n * The Dialog's box, which swells to 60% of a press's depth when a press\n * outside is refused, as fast as a press goes down, and springs back as it\n * entered. Leaving, it leaves as the Dialog does.\n */\nconst alertDialogBoxClassName = cn(\n  panelDialogClassName,\n  panelFooterTint,\n  'group/alert-dialog not-data-ending-style:data-refused:scale-[calc(1+(1-var(--motion-press-scale))*0.6)] not-data-ending-style:data-refused:duration-[calc(var(--motion-press-duration)*0.4)] not-data-ending-style:data-refused:ease-(--motion-press-easing) data-[variant=badge]:max-w-xs data-[variant=badge]:[--panel-footer:var(--background)] motion-reduce:not-data-ending-style:data-refused:scale-100 max-sm:data-[variant=badge]:max-w-none',\n)\n\n/** Under reduced motion, Cancel lights up at a press outside in place of the swell. */\nconst alertDialogCancelClassName =\n  'motion-reduce:in-data-refused:border-ring motion-reduce:in-data-refused:ring-3 motion-reduce:in-data-refused:ring-ring/50'\n\n/* The alert dialog's box, which swells when a press outside is refused. */\nconst AlertDialogBoxContext = createContext<RefObject<HTMLElement | null> | null>(null)\n\n/**\n * Only its buttons close it: a press outside makes it swell for a moment\n * instead. While an action's promise runs, nothing but the promise closes it.\n */\nfunction AlertDialog({\n  onDismissAttempt,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive>) {\n  const box = useRef<HTMLElement | null>(null)\n  return (\n    <AlertDialogBoxContext value={box}>\n      <AlertDialogPrimitive\n        onDismissAttempt={(details) => {\n          if (details.reason === 'outside-press' && box.current) refuse(box.current)\n          onDismissAttempt?.(details)\n        }}\n        {...props}\n      />\n    </AlertDialogBoxContext>\n  )\n}\n\nfunction AlertDialogTrigger(props: ComponentProps<typeof AlertDialogTriggerPrimitive>) {\n  return <AlertDialogTriggerPrimitive {...props} />\n}\n\n/**\n * The Dialog's box and motion, without a close button. A press outside makes\n * it swell for a moment. Focus starts on its first button, Cancel.\n * `variant='badge'` centres the header and stacks the actions. `children`\n * may be a function of its state, such as to read a trigger's `payload`.\n */\nfunction AlertDialogContent<Payload = unknown>({\n  className,\n  children,\n  variant = 'default',\n  inline,\n  ref,\n  ...props\n}: Omit<\n  ComponentProps<typeof AlertDialogContentPrimitive<Payload>>,\n  'className' | 'children'\n> & {\n  className?: string\n  children?: ReactNode | ((state: DialogContentState<Payload>) => ReactNode)\n  variant?: 'default' | 'badge'\n}) {\n  const box = use(AlertDialogBoxContext)\n  const own = useMemo(() => mergeRefs(ref, box), [ref, box])\n  return (\n    <>\n      <AlertDialogBackdrop />\n      <AlertDialogContentPrimitive<Payload>\n        ref={own}\n        inline={inline}\n        data-variant={variant}\n        className={cn(alertDialogBoxClassName, className)}\n        {...props}\n      >\n        {(state) => (\n          <PanelSurface>\n            {typeof children === 'function' ? children(state) : children}\n          </PanelSurface>\n        )}\n      </AlertDialogContentPrimitive>\n    </>\n  )\n}\n\nfunction AlertDialogHeader({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof DialogHeader>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <DialogHeader\n      data-alert-dialog-header=''\n      className={cn(\n        'group-data-[variant=badge]/alert-dialog:items-center group-data-[variant=badge]/alert-dialog:pb-(--surface-gap) group-data-[variant=badge]/alert-dialog:text-center',\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** An Icon tile for an icon, above the title, in the destructive tone for an action that destroys. It is hidden from assistive technology: the title says what it means. */\nfunction AlertDialogMedia({\n  className,\n  variant = 'default',\n  ...props\n}: Omit<ComponentProps<typeof IconTile>, 'tone' | 'size' | 'label' | 'color'> & {\n  variant?: 'default' | 'destructive'\n}) {\n  return (\n    <IconTile\n      data-alert-dialog-media=''\n      size='xl'\n      tone={variant === 'destructive' ? 'destructive' : 'neutral'}\n      className={cn('mb-1.5', className)}\n      {...props}\n    />\n  )\n}\n\nfunction AlertDialogTitle({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AlertDialogTitlePrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AlertDialogTitlePrimitive\n      className={cn(panelTitleClassName, className)}\n      {...props}\n    />\n  )\n}\n\nfunction AlertDialogDescription({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AlertDialogDescriptionPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AlertDialogDescriptionPrimitive\n      className={cn(panelDescriptionClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/** What scrolls when the dialog is taller than the screen, such as a field to type a name into. */\nfunction AlertDialogBody({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof DialogBody>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <DialogBody\n      data-alert-dialog-body=''\n      className={cn(\n        'group-data-[variant=badge]/alert-dialog:pb-(--surface-gap)',\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/**\n * Why the action failed. It is a status region that is there, empty, before\n * its text arrives, so the text is announced.\n */\nfunction AlertDialogError({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'p'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'p',\n    {\n      'data-slot': 'alert-dialog-error',\n      role: 'status',\n      className: cn('text-destructive text-sm text-pretty empty:sr-only', className),\n      ...props,\n    },\n    render,\n  )\n}\n\nfunction AlertDialogFooter({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof DialogFooter>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <DialogFooter\n      data-alert-dialog-footer=''\n      className={cn(\n        'group-data-[variant=badge]/alert-dialog:border-t-0 group-data-[variant=badge]/alert-dialog:pt-0 group-data-[variant=badge]/alert-dialog:pb-(--surface-padding-lg) group-data-[variant=badge]/alert-dialog:*:w-full group-data-[variant=badge]/alert-dialog:@xs:flex-col-reverse group-data-[variant=badge]/alert-dialog:@xs:flex-nowrap group-data-[variant=badge]/alert-dialog:@xs:justify-start',\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction AlertDialogClose(props: ComponentProps<typeof AlertDialogClosePrimitive>) {\n  return <AlertDialogClosePrimitive {...props} />\n}\n\n/**\n * Closes the dialog without doing anything: an outline Button unless\n * `render` says otherwise. It can't be pressed while an action runs, and under\n * reduced motion it lights up at a press outside.\n */\n/**\n * The dim behind the dialog. Opened from another dialog, it doesn't dim the\n * page again: the dialog below already does, and steps back itself.\n */\nfunction AlertDialogBackdrop({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof AlertDialogBackdropPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AlertDialogBackdropPrimitive\n      className={cn(panelOverlayClassName, 'data-nested:invisible', className)}\n      {...props}\n    />\n  )\n}\n\nfunction AlertDialogCancel({\n  className,\n  render = <Button variant='outline' />,\n  ...props\n}: Omit<ComponentProps<typeof AlertDialogClosePrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <AlertDialogClosePrimitive\n      data-alert-dialog-cancel=''\n      render={render}\n      className={cn(alertDialogCancelClassName, className)}\n      {...props}\n    />\n  )\n}\n\n/**\n * The action, as a Button. Once `action` has run, the dialog closes. When it\n * returns a promise, the dialog stays open and the button shows a spinner\n * until it settles: it closes once the promise resolves, and stays open when\n * it rejects, so you can say why in `AlertDialogError`.\n */\nfunction AlertDialogAction({\n  action,\n  value,\n  variant,\n  size,\n  loading = false,\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof Button>, 'render' | 'className'> & {\n  className?: string\n} & Pick<ComponentProps<typeof AlertDialogClosePrimitive>, 'action' | 'value'>) {\n  return (\n    <AlertDialogClosePrimitive\n      action={action}\n      value={value}\n      render={(own, { pending }) => (\n        <Button\n          data-alert-dialog-action=''\n          {...mergeProps(own, props)}\n          variant={variant}\n          size={size}\n          loading={loading || pending}\n          className={className}\n        >\n          {children}\n        </Button>\n      )}\n    />\n  )\n}\n\nexport {\n  AlertDialog,\n  AlertDialogAction,\n  AlertDialogBackdrop,\n  AlertDialogBody,\n  AlertDialogCancel,\n  AlertDialogClose,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogError,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogMedia,\n  AlertDialogTitle,\n  AlertDialogTrigger,\n  alertDialogBoxClassName,\n  alertDialogCancelClassName,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/alert-dialog.tsx"
    }
  ],
  "type": "registry:component"
}