{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radix-alert-dialog",
  "title": "Radix Alert Dialog",
  "description": "An accessible alert dialog built on Radix UI with smooth Motion 3D perspective entrance and exit animations, customizable sizes, and media slots.",
  "dependencies": ["radix-ui", "motion", "lucide-react"],
  "registryDependencies": [
    "utils",
    "@soralabs/hooks-use-controlled-state",
    "@soralabs/radix-button"
  ],
  "files": [
    {
      "path": "registry/ui/radix/alert-dialog/index.tsx",
      "content": "\"use client\";\n\nimport { useControlledState } from \"@/hooks/use-controlled-state\";\nimport { cn } from \"@/lib/utils\";\nimport { XIcon } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { AlertDialog as AlertDialogPrimitive } from \"radix-ui\";\nimport { createContext, useContext, useMemo } from \"react\";\nimport type { ComponentProps } from \"react\";\n\nimport { Button } from \"@/components/sora-ui/radix/button\";\n\ninterface AlertDialogContextValue {\n  open: boolean;\n  setOpen: (open: boolean) => void;\n}\n\nconst AlertDialogContext = createContext<AlertDialogContextValue | null>(null);\n\nfunction useAlertDialogContext() {\n  return useContext(AlertDialogContext);\n}\n\ntype AlertDialogProps = ComponentProps<typeof AlertDialogPrimitive.Root>;\n\n/**\n * Root container for the Alert Dialog component powered by Radix UI and Motion.\n */\nfunction AlertDialog({\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  children,\n  ...props\n}: AlertDialogProps) {\n  const [open, setOpen] = useControlledState({\n    defaultValue: defaultOpen,\n    onChange: onOpenChange,\n    value: controlledOpen,\n  });\n\n  const contextValue = useMemo(\n    () => ({ open: Boolean(open), setOpen }),\n    [open, setOpen]\n  );\n\n  return (\n    <AlertDialogContext.Provider value={contextValue}>\n      <AlertDialogPrimitive.Root\n        onOpenChange={(nextOpen) => {\n          setOpen(nextOpen);\n        }}\n        open={open}\n        {...props}\n      >\n        {children}\n      </AlertDialogPrimitive.Root>\n    </AlertDialogContext.Provider>\n  );\n}\n\ntype AlertDialogTriggerProps = ComponentProps<\n  typeof AlertDialogPrimitive.Trigger\n>;\n\n/**\n * Trigger element that opens the alert dialog.\n * Features Motion hover and tap scaling.\n */\nfunction AlertDialogTrigger({\n  className,\n  asChild,\n  children,\n  ...props\n}: AlertDialogTriggerProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  if (asChild) {\n    return (\n      <AlertDialogPrimitive.Trigger\n        asChild\n        className={className}\n        data-slot=\"alert-dialog-trigger\"\n        {...props}\n      >\n        {children}\n      </AlertDialogPrimitive.Trigger>\n    );\n  }\n\n  return (\n    <AlertDialogPrimitive.Trigger\n      asChild\n      className={className}\n      data-slot=\"alert-dialog-trigger\"\n      {...props}\n    >\n      <motion.button\n        data-primary-action\n        type=\"button\"\n        whileTap={prefersReducedMotion ? undefined : { scale: 0.98 }}\n      >\n        {children}\n      </motion.button>\n    </AlertDialogPrimitive.Trigger>\n  );\n}\n\ntype AlertDialogPortalProps = ComponentProps<\n  typeof AlertDialogPrimitive.Portal\n>;\n\n/**\n * Portals alert dialog overlay and content to the document body.\n */\nfunction AlertDialogPortal({ ...props }: AlertDialogPortalProps) {\n  return (\n    <AlertDialogPrimitive.Portal data-slot=\"alert-dialog-portal\" {...props} />\n  );\n}\n\ntype AlertDialogOverlayProps = ComponentProps<\n  typeof AlertDialogPrimitive.Overlay\n>;\n\n/**\n * Semi-transparent backdrop overlay behind the alert dialog with blur and fade transition.\n */\nfunction AlertDialogOverlay({\n  className,\n  asChild,\n  children,\n  ...props\n}: AlertDialogOverlayProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  if (asChild) {\n    return (\n      <AlertDialogPrimitive.Overlay\n        asChild\n        className={cn(\n          \"fixed inset-0 isolate z-50 bg-black/50 backdrop-blur-xs dark:bg-black/70\",\n          className\n        )}\n        data-slot=\"alert-dialog-overlay\"\n        {...props}\n      >\n        {children}\n      </AlertDialogPrimitive.Overlay>\n    );\n  }\n\n  return (\n    <AlertDialogPrimitive.Overlay\n      asChild\n      className={cn(\n        \"fixed inset-0 isolate z-50 bg-black/50 backdrop-blur-xs dark:bg-black/70\",\n        className\n      )}\n      data-slot=\"alert-dialog-overlay\"\n      {...props}\n    >\n      <motion.div\n        animate={{ opacity: 1 }}\n        exit={{ opacity: 0 }}\n        initial={{ opacity: 0 }}\n        transition={\n          prefersReducedMotion\n            ? { duration: 0 }\n            : { duration: 0.2, ease: \"easeOut\" }\n        }\n      />\n    </AlertDialogPrimitive.Overlay>\n  );\n}\n\ntype AlertDialogViewportProps = ComponentProps<\"div\">;\n\n/**\n * Optional scroll viewport wrapper for overflowing alert dialog content.\n */\nfunction AlertDialogViewport({\n  className,\n  ...props\n}: AlertDialogViewportProps) {\n  return (\n    <div\n      className={cn(\n        \"fixed inset-0 z-50 flex items-center justify-center overflow-y-auto p-4\",\n        className\n      )}\n      data-slot=\"alert-dialog-viewport\"\n      {...props}\n    />\n  );\n}\n\ninterface AlertDialogContentProps extends ComponentProps<\n  typeof AlertDialogPrimitive.Content\n> {\n  /**\n   * Additional CSS class name for the fixed container wrapper.\n   */\n  containerClassName?: string;\n  /**\n   * Additional CSS class name for the backdrop overlay.\n   */\n  overlayClassName?: string;\n  /**\n   * Whether to render an optional top-right close icon button.\n   * @default false\n   */\n  showCloseButton?: boolean;\n  /**\n   * Layout sizing variant of the alert dialog popup.\n   * @default \"default\"\n   */\n  size?: \"default\" | \"sm\";\n}\n\n/**\n * Modal alert dialog content container with Motion 3D perspective rotation and blur entrance/exit animations.\n */\nfunction AlertDialogContent({\n  className,\n  children,\n  size = \"default\",\n  showCloseButton = false,\n  overlayClassName,\n  containerClassName,\n  asChild: _asChild,\n  style,\n  ...props\n}: AlertDialogContentProps) {\n  const context = useAlertDialogContext();\n  const prefersReducedMotion = useReducedMotion();\n  const isOpen = context ? context.open : true;\n\n  return (\n    <AnimatePresence>\n      {isOpen && (\n        <AlertDialogPrimitive.Portal forceMount>\n          <AlertDialogOverlay className={overlayClassName} />\n          <div\n            className={cn(\n              \"pointer-events-none fixed inset-0 z-50 flex items-center justify-center p-4\",\n              containerClassName\n            )}\n          >\n            <AlertDialogPrimitive.Content\n              asChild\n              className={cn(\n                \"group/alert-dialog-content border-border bg-background text-foreground pointer-events-auto relative grid w-full max-w-[calc(100%-2rem)] gap-4 rounded-xl border p-6 text-sm shadow-2xl outline-none data-[size=sm]:max-w-xs data-[size=sm]:p-4 data-[size=default]:sm:max-w-lg data-[size=sm]:sm:max-w-sm\",\n                className\n              )}\n              data-size={size}\n              data-slot=\"alert-dialog-content\"\n              forceMount\n              {...props}\n            >\n              <motion.div\n                animate={\n                  prefersReducedMotion\n                    ? { opacity: 1 }\n                    : {\n                        opacity: 1,\n                        filter: \"blur(0px)\",\n                        rotateX: 0,\n                        rotateY: 0,\n                        z: 0,\n                        transition: {\n                          delay: 0.2,\n                          duration: 0.5,\n                          ease: [0.17, 0.67, 0.51, 1],\n                          opacity: {\n                            delay: 0.2,\n                            duration: 0.5,\n                            ease: \"easeOut\",\n                          },\n                        },\n                      }\n                }\n                exit={\n                  prefersReducedMotion\n                    ? { opacity: 0 }\n                    : {\n                        opacity: 0,\n                        filter: \"blur(10px)\",\n                        z: -100,\n                        rotateY: 25,\n                        rotateX: 5,\n                        transformPerspective: 500,\n                        transition: {\n                          duration: 0.3,\n                          ease: [0.67, 0.17, 0.62, 0.64],\n                        },\n                      }\n                }\n                initial={\n                  prefersReducedMotion\n                    ? { opacity: 0 }\n                    : {\n                        opacity: 0,\n                        filter: \"blur(10px)\",\n                        z: -100,\n                        rotateY: 25,\n                        rotateX: 5,\n                        transformPerspective: 500,\n                      }\n                }\n                style={{\n                  transformPerspective: 500,\n                  transformStyle: \"preserve-3d\",\n                  ...style,\n                }}\n              >\n                {children}\n\n                {showCloseButton && (\n                  <AlertDialogPrimitive.Cancel\n                    asChild\n                    className=\"text-muted-foreground hover:bg-muted focus-visible:ring-ring absolute top-4 right-4 inline-flex size-7 items-center justify-center rounded-md opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-2 disabled:pointer-events-none\"\n                    data-slot=\"alert-dialog-close-button\"\n                  >\n                    <motion.button\n                      type=\"button\"\n                      whileTap={\n                        prefersReducedMotion ? undefined : { scale: 0.96 }\n                      }\n                    >\n                      <XIcon className=\"size-4\" />\n                      <span className=\"sr-only\">Close</span>\n                    </motion.button>\n                  </AlertDialogPrimitive.Cancel>\n                )}\n              </motion.div>\n            </AlertDialogPrimitive.Content>\n          </div>\n        </AlertDialogPrimitive.Portal>\n      )}\n    </AnimatePresence>\n  );\n}\n\ntype AlertDialogHeaderProps = ComponentProps<\"div\">;\n\n/**\n * Header section containing alert dialog title, description, and optional media slot.\n */\nfunction AlertDialogHeader({ className, ...props }: AlertDialogHeaderProps) {\n  return (\n    <div\n      className={cn(\n        \"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]\",\n        className\n      )}\n      data-slot=\"alert-dialog-header\"\n      {...props}\n    />\n  );\n}\n\ntype AlertDialogMediaProps = ComponentProps<\"div\">;\n\n/**\n * Icon or media container positioned nicely within the alert dialog header.\n */\nfunction AlertDialogMedia({ className, ...props }: AlertDialogMediaProps) {\n  return (\n    <div\n      className={cn(\n        \"bg-muted text-foreground mb-2 inline-flex size-10 items-center justify-center rounded-md sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6\",\n        className\n      )}\n      data-slot=\"alert-dialog-media\"\n      {...props}\n    />\n  );\n}\n\ntype AlertDialogTitleProps = ComponentProps<typeof AlertDialogPrimitive.Title>;\n\n/**\n * Accessible title heading for the alert dialog.\n */\nfunction AlertDialogTitle({ className, ...props }: AlertDialogTitleProps) {\n  return (\n    <AlertDialogPrimitive.Title\n      className={cn(\n        \"text-foreground text-base font-semibold tracking-tight sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2\",\n        className\n      )}\n      data-slot=\"alert-dialog-title\"\n      {...props}\n    />\n  );\n}\n\ntype AlertDialogDescriptionProps = ComponentProps<\n  typeof AlertDialogPrimitive.Description\n>;\n\n/**\n * Accessible description explaining the alert prompt or confirmation warning.\n */\nfunction AlertDialogDescription({\n  className,\n  ...props\n}: AlertDialogDescriptionProps) {\n  return (\n    <AlertDialogPrimitive.Description\n      className={cn(\n        \"text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2 md:text-pretty *:[a]:underline *:[a]:underline-offset-3\",\n        className\n      )}\n      data-slot=\"alert-dialog-description\"\n      {...props}\n    />\n  );\n}\n\ntype AlertDialogFooterProps = ComponentProps<\"div\">;\n\n/**\n * Footer section for alert dialog action buttons with responsive layouts.\n */\nfunction AlertDialogFooter({ className, ...props }: AlertDialogFooterProps) {\n  return (\n    <div\n      className={cn(\n        \"border-border bg-muted/40 mt-2 flex flex-col-reverse gap-2 rounded-b-xl border-t p-4 group-data-[size=default]/alert-dialog-content:-mx-6 group-data-[size=default]/alert-dialog-content:-mb-6 group-data-[size=sm]/alert-dialog-content:-mx-4 group-data-[size=sm]/alert-dialog-content:-mb-4 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end\",\n        className\n      )}\n      data-slot=\"alert-dialog-footer\"\n      {...props}\n    />\n  );\n}\n\ninterface AlertDialogActionProps extends ComponentProps<typeof Button> {\n  /**\n   * Whether clicking this action button should automatically close the alert dialog.\n   * @default false\n   */\n  closeOnClick?: boolean;\n}\n\n/**\n * Primary action button for the alert dialog.\n */\nfunction AlertDialogAction({\n  className,\n  closeOnClick = false,\n  variant = \"default\",\n  ...props\n}: AlertDialogActionProps) {\n  if (closeOnClick) {\n    return (\n      <AlertDialogPrimitive.Action asChild data-slot=\"alert-dialog-action\">\n        <Button className={className} variant={variant} {...props} />\n      </AlertDialogPrimitive.Action>\n    );\n  }\n\n  return (\n    <Button\n      className={className}\n      data-slot=\"alert-dialog-action\"\n      variant={variant}\n      {...props}\n    />\n  );\n}\n\ntype AlertDialogCancelProps = ComponentProps<\n  typeof AlertDialogPrimitive.Cancel\n> &\n  Pick<ComponentProps<typeof Button>, \"variant\" | \"size\">;\n\n/**\n * Cancel or dismiss button that closes the alert dialog without proceeding.\n */\nfunction AlertDialogCancel({\n  className,\n  variant = \"outline\",\n  size = \"default\",\n  children = \"Cancel\",\n  ...props\n}: AlertDialogCancelProps) {\n  return (\n    <AlertDialogPrimitive.Cancel\n      asChild\n      className={className}\n      data-slot=\"alert-dialog-cancel\"\n      {...props}\n    >\n      <Button size={size} variant={variant}>\n        {children}\n      </Button>\n    </AlertDialogPrimitive.Cancel>\n  );\n}\n\ntype AlertDialogCloseProps = ComponentProps<typeof AlertDialogPrimitive.Cancel>;\n\n/**\n * Generic close button wrapper for closing the alert dialog.\n */\nfunction AlertDialogClose({\n  className,\n  asChild,\n  children,\n  ...props\n}: AlertDialogCloseProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  if (asChild) {\n    return (\n      <AlertDialogPrimitive.Cancel\n        asChild\n        className={className}\n        data-slot=\"alert-dialog-close\"\n        {...props}\n      >\n        {children}\n      </AlertDialogPrimitive.Cancel>\n    );\n  }\n\n  return (\n    <AlertDialogPrimitive.Cancel\n      asChild\n      className={className}\n      data-slot=\"alert-dialog-close\"\n      {...props}\n    >\n      <motion.button\n        type=\"button\"\n        whileTap={prefersReducedMotion ? undefined : { scale: 0.98 }}\n      >\n        {children}\n      </motion.button>\n    </AlertDialogPrimitive.Cancel>\n  );\n}\n\nexport type {\n  AlertDialogActionProps,\n  AlertDialogCancelProps,\n  AlertDialogCloseProps,\n  AlertDialogContentProps,\n  AlertDialogDescriptionProps,\n  AlertDialogFooterProps,\n  AlertDialogHeaderProps,\n  AlertDialogMediaProps,\n  AlertDialogOverlayProps,\n  AlertDialogPortalProps,\n  AlertDialogProps,\n  AlertDialogTitleProps,\n  AlertDialogTriggerProps,\n  AlertDialogViewportProps,\n};\nexport {\n  AlertDialog,\n  AlertDialog as RadixAlertDialog,\n  AlertDialog as default,\n  AlertDialogAction,\n  AlertDialogCancel,\n  AlertDialogClose,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogMedia,\n  AlertDialogOverlay,\n  AlertDialogPortal,\n  AlertDialogTitle,\n  AlertDialogTrigger,\n  AlertDialogViewport,\n  useAlertDialogContext,\n};\n",
      "type": "registry:ui",
      "target": "components/sora-ui/radix/alert-dialog.tsx"
    }
  ],
  "meta": {
    "agentMetadata": {
      "intent": "Require explicit confirmation before an irreversible action.",
      "role": "modal-confirmation",
      "a11yConstraints": [
        "Preserve focus trapping and always provide a cancel action."
      ],
      "motionEngine": "Motion perspective spring entrance with backdrop presence transition.",
      "compositionRules": [
        "Use AlertDialogTrigger asChild for the initiating control."
      ],
      "compositionRecipes": [
        "Compose with radix/button for destructive confirmation."
      ]
    }
  },
  "type": "registry:ui"
}
