{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "base-dialog",
  "title": "Base Dialog",
  "description": "An accessible modal dialog built on Base UI with smooth Motion spring entrance and exit animations.",
  "dependencies": ["@base-ui/react", "motion", "lucide-react"],
  "registryDependencies": [
    "utils",
    "@soralabs/hooks-use-controlled-state",
    "@soralabs/base-button"
  ],
  "files": [
    {
      "path": "registry/ui/base/dialog/index.tsx",
      "content": "\"use client\";\n\nimport { Dialog as DialogPrimitive } from \"@base-ui/react/dialog\";\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 { createContext, useContext, useMemo } from \"react\";\nimport type { ComponentProps } from \"react\";\n\nimport { Button } from \"@/components/sora-ui/base/button\";\n\ninterface DialogContextValue {\n  open: boolean;\n  setOpen: (open: boolean) => void;\n}\n\nconst DialogContext = createContext<DialogContextValue | null>(null);\n\nfunction useDialogContext() {\n  return useContext(DialogContext);\n}\n\ntype DialogProps = ComponentProps<typeof DialogPrimitive.Root>;\n\n/**\n * Root container for the Dialog component powered by Base UI and Motion.\n */\nfunction Dialog({\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  children,\n  ...props\n}: DialogProps) {\n  const [open, setOpen] = useControlledState({\n    defaultValue: defaultOpen,\n    onChange: (nextOpen: boolean) => {\n      onOpenChange?.(nextOpen, undefined as never);\n    },\n    value: controlledOpen,\n  });\n\n  const contextValue = useMemo(\n    () => ({ open: Boolean(open), setOpen }),\n    [open, setOpen]\n  );\n\n  return (\n    <DialogContext.Provider value={contextValue}>\n      <DialogPrimitive.Root\n        onOpenChange={(nextOpen, eventDetails) => {\n          setOpen(nextOpen);\n          onOpenChange?.(nextOpen, eventDetails);\n        }}\n        open={open}\n        {...props}\n      >\n        {children}\n      </DialogPrimitive.Root>\n    </DialogContext.Provider>\n  );\n}\n\ntype DialogTriggerProps = ComponentProps<typeof DialogPrimitive.Trigger>;\n\n/**\n * Button or trigger element that opens the dialog.\n * Features Motion hover and tap scaling.\n */\nfunction DialogTrigger({ className, render, ...props }: DialogTriggerProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  return (\n    <DialogPrimitive.Trigger\n      className={className}\n      data-slot=\"dialog-trigger\"\n      render={\n        render ?? (\n          <motion.button\n            data-primary-action\n            type=\"button\"\n            whileTap={prefersReducedMotion ? undefined : { scale: 0.98 }}\n          />\n        )\n      }\n      {...props}\n    />\n  );\n}\n\ntype DialogPortalProps = ComponentProps<typeof DialogPrimitive.Portal>;\n\n/**\n * Portals dialog overlay and content to the document body.\n */\nfunction DialogPortal({ ...props }: DialogPortalProps) {\n  return <DialogPrimitive.Portal data-slot=\"dialog-portal\" {...props} />;\n}\n\ntype DialogCloseProps = ComponentProps<typeof DialogPrimitive.Close>;\n\n/**\n * Action button that dismisses the dialog.\n */\nfunction DialogClose({ className, render, ...props }: DialogCloseProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  return (\n    <DialogPrimitive.Close\n      className={className}\n      data-slot=\"dialog-close\"\n      render={\n        render ?? (\n          <motion.button\n            type=\"button\"\n            whileTap={prefersReducedMotion ? undefined : { scale: 0.98 }}\n          />\n        )\n      }\n      {...props}\n    />\n  );\n}\n\ntype DialogOverlayProps = ComponentProps<typeof DialogPrimitive.Backdrop>;\n\n/**\n * Semi-transparent backdrop overlay behind the dialog with blur and fade transition.\n */\nfunction DialogOverlay({ className, render, ...props }: DialogOverlayProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  return (\n    <DialogPrimitive.Backdrop\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=\"dialog-overlay\"\n      render={\n        render ?? (\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        )\n      }\n      {...props}\n    />\n  );\n}\n\ntype DialogViewportProps = ComponentProps<typeof DialogPrimitive.Viewport>;\n\n/**\n * Optional scroll viewport wrapper for large or overflowing dialog popups.\n */\nfunction DialogViewport({ className, ...props }: DialogViewportProps) {\n  return (\n    <DialogPrimitive.Viewport\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=\"dialog-viewport\"\n      {...props}\n    />\n  );\n}\n\ninterface DialogContentProps extends ComponentProps<\n  typeof DialogPrimitive.Popup\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 the standard top-right close icon button.\n   * @default true\n   */\n  showCloseButton?: boolean;\n}\n\n/**\n * Modal dialog content container with Motion 3D perspective rotation and blur entrance/exit.\n */\nfunction DialogContent({\n  className,\n  children,\n  showCloseButton = true,\n  overlayClassName,\n  containerClassName,\n  render,\n  style,\n  ...props\n}: DialogContentProps) {\n  const context = useDialogContext();\n  const prefersReducedMotion = useReducedMotion();\n  const isOpen = context ? context.open : true;\n\n  return (\n    <AnimatePresence>\n      {isOpen && (\n        <DialogPrimitive.Portal keepMounted>\n          <DialogOverlay 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            <DialogPrimitive.Popup\n              className={cn(\n                \"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 sm:max-w-lg\",\n                className\n              )}\n              data-slot=\"dialog-content\"\n              render={\n                render ?? (\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                )\n              }\n              {...props}\n            >\n              {children}\n              {showCloseButton && (\n                <DialogPrimitive.Close\n                  aria-label=\"Close\"\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=\"dialog-close-button\"\n                  render={\n                    <motion.button\n                      type=\"button\"\n                      whileTap={\n                        prefersReducedMotion ? undefined : { scale: 0.96 }\n                      }\n                    />\n                  }\n                >\n                  <XIcon className=\"size-4\" />\n                  <span className=\"sr-only\">Close</span>\n                </DialogPrimitive.Close>\n              )}\n            </DialogPrimitive.Popup>\n          </div>\n        </DialogPrimitive.Portal>\n      )}\n    </AnimatePresence>\n  );\n}\n\n/**\n * Header section containing dialog title and description.\n */\nfunction DialogHeader({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      className={cn(\n        \"flex flex-col gap-1.5 text-center sm:text-left\",\n        className\n      )}\n      data-slot=\"dialog-header\"\n      {...props}\n    />\n  );\n}\n\ninterface DialogFooterProps extends ComponentProps<\"div\"> {\n  /**\n   * Whether to render a secondary close button inside the footer.\n   * @default false\n   */\n  showCloseButton?: boolean;\n}\n\n/**\n * Footer section for dialog action buttons.\n */\nfunction DialogFooter({\n  className,\n  showCloseButton = false,\n  children,\n  ...props\n}: DialogFooterProps) {\n  return (\n    <div\n      className={cn(\n        \"border-border bg-muted/40 -mx-6 mt-2 -mb-6 flex flex-col-reverse gap-2 rounded-b-xl border-t p-4 sm:flex-row sm:justify-end\",\n        className\n      )}\n      data-slot=\"dialog-footer\"\n      {...props}\n    >\n      {children}\n      {showCloseButton && (\n        <DialogPrimitive.Close\n          data-slot=\"dialog-footer-close\"\n          render={<Button variant=\"outline\">Close</Button>}\n        />\n      )}\n    </div>\n  );\n}\n\ntype DialogTitleProps = ComponentProps<typeof DialogPrimitive.Title>;\n\n/**\n * Accessible title heading for the dialog.\n */\nfunction DialogTitle({ className, ...props }: DialogTitleProps) {\n  return (\n    <DialogPrimitive.Title\n      className={cn(\n        \"text-foreground text-lg leading-none font-semibold tracking-tight\",\n        className\n      )}\n      data-slot=\"dialog-title\"\n      {...props}\n    />\n  );\n}\n\ntype DialogDescriptionProps = ComponentProps<\n  typeof DialogPrimitive.Description\n>;\n\n/**\n * Accessible description explaining the purpose of the dialog.\n */\nfunction DialogDescription({ className, ...props }: DialogDescriptionProps) {\n  return (\n    <DialogPrimitive.Description\n      className={cn(\"text-muted-foreground text-sm\", className)}\n      data-slot=\"dialog-description\"\n      {...props}\n    />\n  );\n}\n\nexport type {\n  DialogCloseProps,\n  DialogContentProps,\n  DialogDescriptionProps,\n  DialogFooterProps,\n  DialogOverlayProps,\n  DialogPortalProps,\n  DialogProps,\n  DialogTitleProps,\n  DialogTriggerProps,\n  DialogViewportProps,\n};\nexport {\n  Dialog,\n  Dialog as BaseDialog,\n  Dialog as default,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogFooter,\n  DialogHeader,\n  DialogOverlay,\n  DialogPortal,\n  DialogTitle,\n  DialogTrigger,\n  DialogViewport,\n};\n",
      "type": "registry:ui",
      "target": "components/sora-ui/base/dialog.tsx"
    }
  ],
  "meta": {
    "agentMetadata": {
      "intent": "Present focused modal content that temporarily interrupts the current task.",
      "role": "overlay",
      "a11yConstraints": [
        "Keep focus trapped and provide DialogTitle and DialogDescription."
      ],
      "motionEngine": "Motion scale, perspective, and backdrop blur presence transition.",
      "compositionRules": [
        "Use DialogTrigger render with a semantic interactive trigger."
      ],
      "compositionRecipes": [
        "Compose with base/button for confirmation actions."
      ]
    }
  },
  "type": "registry:ui"
}
