{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alert-dialog",
  "type": "registry:ui",
  "title": "Alert Dialog",
  "description": "An accessible React alert dialog for Next.js that asks people to confirm destructive actions, with focus starting on Cancel, built on Radix Alert Dialog.",
  "author": "FewTone <https://fewtone.com>",
  "dependencies": [
    "class-variance-authority@^0.7.1",
    "motion@^14.0.0",
    "radix-ui@^1.7.0"
  ],
  "registryDependencies": [
    "https://ui.fewtone.com/r/tokens.json",
    "https://ui.fewtone.com/r/button.json",
    "https://ui.fewtone.com/r/dialog.json"
  ],
  "files": [
    {
      "path": "registry/fewtone/ui/alert-dialog.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { buttonVariants } from \"@/components/ui/button\";\nimport {\n  type DialogState,\n  dialogOverlayMotion,\n  dialogStyles,\n  keepMovedFocus,\n  useDialogState,\n  useDialogWindow,\n  useMergedRef,\n} from \"@/components/ui/dialog\";\nimport { cn } from \"@/lib/utils\";\nimport type { VariantProps } from \"class-variance-authority\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { AlertDialog as AlertDialogPrimitive } from \"radix-ui\";\nimport { type ComponentProps, createContext, useContext } from \"react\";\n\n/*\n * Alert Dialog, built on Radix Alert Dialog: a modal that asks people to confirm something, usually an action\n * they can't undo. It's announced as an alert dialog, focus starts on Cancel (the safe choice), Escape\n * cancels, and clicking the backdrop does nothing, so it's never dismissed by accident. Focus goes back to\n * the trigger.\n * - The same window, motion and open state as Dialog, shared from its file: it grows out of its trigger\n *   through the blur on spring.snappy, leaves on a timed duration.base + ease.in, and the backdrop only\n *   fades. Controlled (`open`) or not (`defaultOpen`). While it leaves, clicks go through to the page.\n * - Narrower than Dialog (max-w-md): it holds a question and two answers.\n * - Action and Cancel are buttons (buttonVariants). Use `variant=\"destructive\"` on Action for deleting.\n */\n\nconst AlertDialogContext = createContext<DialogState | null>(null);\n\nfunction useAlertDialog(part: string) {\n  const dialog = useContext(AlertDialogContext);\n  if (!dialog) throw new Error(`${part} must be used inside AlertDialog`);\n  return dialog;\n}\n\nfunction AlertDialog({\n  open,\n  defaultOpen,\n  onOpenChange,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive.Root>) {\n  const { state, setOpen } = useDialogState({ open, defaultOpen, onOpenChange });\n  return (\n    <AlertDialogContext.Provider value={state}>\n      <AlertDialogPrimitive.Root\n        data-slot=\"alert-dialog\"\n        open={state.open}\n        onOpenChange={setOpen}\n        {...props}\n      />\n    </AlertDialogContext.Provider>\n  );\n}\n\nfunction AlertDialogTrigger({ ref, ...props }: ComponentProps<typeof AlertDialogPrimitive.Trigger>) {\n  const dialog = useAlertDialog(\"AlertDialogTrigger\");\n  const setRef = useMergedRef(dialog.trigger, ref);\n  return <AlertDialogPrimitive.Trigger data-slot=\"alert-dialog-trigger\" ref={setRef} {...props} />;\n}\n\n/** Stays mounted while the dialog is open and while its exit plays */\nfunction AlertDialogPortal({\n  children,\n  ...props\n}: Omit<ComponentProps<typeof AlertDialogPrimitive.Portal>, \"forceMount\">) {\n  const { open } = useAlertDialog(\"AlertDialogPortal\");\n  return (\n    <AnimatePresence initial={false}>\n      {open ? (\n        <AlertDialogPrimitive.Portal data-slot=\"alert-dialog-portal\" {...props} forceMount>\n          {children}\n        </AlertDialogPrimitive.Portal>\n      ) : null}\n    </AnimatePresence>\n  );\n}\n\nfunction AlertDialogOverlay({\n  className,\n  style,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive.Overlay>) {\n  const { open } = useAlertDialog(\"AlertDialogOverlay\");\n  return (\n    <AlertDialogPrimitive.Overlay\n      data-slot=\"alert-dialog-overlay\"\n      className={cn(dialogStyles.overlay, className)}\n      // While it fades out, clicks go through to the page\n      style={{ pointerEvents: open ? \"auto\" : \"none\", ...style }}\n      {...props}\n      asChild\n      forceMount\n    >\n      <motion.div {...dialogOverlayMotion} />\n    </AlertDialogPrimitive.Overlay>\n  );\n}\n\nfunction AlertDialogContent({\n  className,\n  children,\n  onCloseAutoFocus,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive.Content>) {\n  const dialog = useAlertDialog(\"AlertDialogContent\");\n  const windowMotion = useDialogWindow(dialog.trigger);\n  return (\n    <AlertDialogPortal>\n      <AlertDialogOverlay />\n      <div data-slot=\"alert-dialog-positioner\" className={dialogStyles.positioner}>\n        <AlertDialogPrimitive.Content\n          data-slot=\"alert-dialog-content\"\n          className={cn(dialogStyles.window, \"max-w-md\", className)}\n          onCloseAutoFocus={(event) => {\n            onCloseAutoFocus?.(event);\n            keepMovedFocus(event);\n          }}\n          {...props}\n          asChild\n          forceMount\n        >\n          <motion.div {...windowMotion}>{children}</motion.div>\n        </AlertDialogPrimitive.Content>\n      </div>\n    </AlertDialogPortal>\n  );\n}\n\nfunction AlertDialogHeader({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"alert-dialog-header\" className={cn(dialogStyles.header, className)} {...props} />;\n}\n\n/** Cancel, then the action: stacked on phones with the action on top, in a row at the end from sm */\nfunction AlertDialogFooter({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"alert-dialog-footer\" className={cn(dialogStyles.footer, className)} {...props} />;\n}\n\nfunction AlertDialogTitle({ className, ...props }: ComponentProps<typeof AlertDialogPrimitive.Title>) {\n  return (\n    <AlertDialogPrimitive.Title\n      data-slot=\"alert-dialog-title\"\n      className={cn(dialogStyles.title, className)}\n      {...props}\n    />\n  );\n}\n\nfunction AlertDialogDescription({\n  className,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive.Description>) {\n  return (\n    <AlertDialogPrimitive.Description\n      data-slot=\"alert-dialog-description\"\n      className={cn(dialogStyles.description, className)}\n      {...props}\n    />\n  );\n}\n\ntype ButtonStyle = VariantProps<typeof buttonVariants>;\n\n/** Confirms and closes. A Button in every way: `variant=\"destructive\"` for deleting */\nfunction AlertDialogAction({\n  className,\n  variant,\n  size,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive.Action> & ButtonStyle) {\n  return (\n    <AlertDialogPrimitive.Action\n      data-slot=\"alert-dialog-action\"\n      className={cn(buttonVariants({ variant, size }), className)}\n      {...props}\n    />\n  );\n}\n\n/** Closes without doing anything; it has focus when the dialog opens */\nfunction AlertDialogCancel({\n  className,\n  variant = \"outline\",\n  size,\n  ...props\n}: ComponentProps<typeof AlertDialogPrimitive.Cancel> & ButtonStyle) {\n  return (\n    <AlertDialogPrimitive.Cancel\n      data-slot=\"alert-dialog-cancel\"\n      className={cn(buttonVariants({ variant, size }), className)}\n      {...props}\n    />\n  );\n}\n\nexport {\n  AlertDialog,\n  AlertDialogAction,\n  AlertDialogCancel,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogOverlay,\n  AlertDialogPortal,\n  AlertDialogTitle,\n  AlertDialogTrigger,\n};\n"
    }
  ],
  "categories": [
    "overlays"
  ],
  "docs": "Usage and examples: https://ui.fewtone.com/components/alert-dialog"
}
