{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-motion",
  "title": "Motion dialog",
  "description": "Styled dialog: the Motion set. 5 decorative dialog variations (FlipDialog, SwingDialog, ZoomDialog, ElasticDialog, RotateDialog) on the ai2 token system, powered by framer-motion, reduced-motion aware and sized sm to xl. Part of the free styled layer.",
  "dependencies": [
    "motion@^12.42.2",
    "lucide-react@^1.23.0"
  ],
  "registryDependencies": [
    "@ai2/tokens"
  ],
  "files": [
    {
      "path": "registry/ai2/styled/dialog-motion.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { X } from \"lucide-react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Motion dialog family: 5 showy modals. The panel itself is plain (bg-popover); the\n   DIFFERENCE is the enter/exit animation. Each export is a complete dialog:\n   internal open/closed state (uncontrolled defaultOpen or controlled\n   open/onOpenChange), NO radix or portal - a self-contained fixed backdrop + fixed\n   panel. It closes on a backdrop click, Escape or the close button. The panel takes\n   focus on open. AnimatePresence handles enter/exit; under reduced motion ALL\n   transforms drop away and only an opacity fade remains. Color comes ONLY from\n   tokens, via alpha color-mix. For the 3D variants there is an inline perspective\n   style on the backdrop. */\n\nexport type StyledSize = \"sm\" | \"md\" | \"lg\" | \"xl\"\n\nconst panelSize: Record<StyledSize, string> = {\n  sm: \"max-w-sm\",\n  md: \"max-w-md\",\n  lg: \"max-w-lg\",\n  xl: \"max-w-2xl\",\n}\n\ninterface DialogProps {\n  size?: StyledSize\n  trigger?: React.ReactNode\n  title?: React.ReactNode\n  children?: React.ReactNode\n  className?: string\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (o: boolean) => void\n}\n\nconst backdropClass =\n  \"fixed inset-0 z-50 flex items-center justify-center p-4 bg-[color-mix(in_oklab,var(--color-foreground)_50%,transparent)]\"\n\nconst panelBase =\n  \"relative w-full rounded-xl border border-border bg-popover text-popover-foreground shadow-lg outline-none\"\n\nconst closeBtn =\n  \"absolute right-3 top-3 inline-flex size-8 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_8%,transparent)] hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none\"\n\nconst triggerBtn =\n  \"inline-flex h-9 shrink-0 select-none items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-border bg-secondary px-4 text-sm font-medium text-secondary-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_6%,transparent)] focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n\n/* Controlled/uncontrolled acik durum yonetimi. */\nfunction useDialogState(props: DialogProps) {\n  const { open, defaultOpen, onOpenChange } = props\n  const isControlled = open !== undefined\n  const [internal, setInternal] = React.useState(defaultOpen ?? false)\n  const isOpen = isControlled ? open : internal\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (!isControlled) setInternal(next)\n      onOpenChange?.(next)\n    },\n    [isControlled, onOpenChange]\n  )\n\n  return { isOpen, setOpen }\n}\n\n/* Shared shell: trigger plus an AnimatePresence backdrop plus panel. panelMotion carries the enter/exit animation supplied from outside; it differs in every export. */\nfunction DialogShell({\n  props,\n  panelClassName,\n  panelMotion,\n}: {\n  props: DialogProps\n  panelClassName?: string\n  panelMotion?: {\n    initial: Record<string, number>\n    animate: Record<string, number>\n    exit: Record<string, number>\n    transition?: Record<string, unknown>\n  }\n}) {\n  const { size = \"md\", trigger, title, children, className } = props\n  const { isOpen, setOpen } = useDialogState(props)\n  const reduce = useReducedMotion()\n  const panelRef = React.useRef<HTMLDivElement>(null)\n\n  React.useEffect(() => {\n    if (!isOpen) return\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false)\n    }\n    window.addEventListener(\"keydown\", onKey)\n    const id = window.requestAnimationFrame(() => panelRef.current?.focus())\n    return () => {\n      window.removeEventListener(\"keydown\", onKey)\n      window.cancelAnimationFrame(id)\n    }\n  }, [isOpen, setOpen])\n\n  const fade = { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n  const motionProps = reduce || !panelMotion ? fade : panelMotion\n\n  return (\n    <>\n      {/* ARIA durumu tetikleyicinin KENDISINDE. Once yoktu: ekran okuyucu\n\n          kullanicisi butonun bir dialog actigini ve acik olup olmadigini\n\n          HIC bilmiyordu. Canli AX taramasiyla bulundu (grep gostermemisti). */}\n\n      <span data-slot=\"styled-dialog-trigger\" className=\"inline-flex\">\n\n        {React.isValidElement<React.ButtonHTMLAttributes<HTMLButtonElement>>(trigger) ? (\n\n          React.cloneElement(trigger, {\n\n            \"aria-haspopup\": \"dialog\",\n\n            \"aria-expanded\": isOpen,\n\n            onClick: (event: React.MouseEvent<HTMLButtonElement>) => {\n\n              trigger.props.onClick?.(event)\n\n              setOpen(true)\n\n            },\n\n          })\n\n        ) : (\n\n          <button\n\n            type=\"button\"\n\n            aria-haspopup=\"dialog\"\n\n            aria-expanded={isOpen}\n\n            onClick={() => setOpen(true)}\n\n            className={triggerBtn}\n\n          >\n\n            {trigger ?? \"Open dialog\"}\n\n          </button>\n\n        )}\n\n      </span>\n\n      <AnimatePresence>\n        {isOpen ? (\n          <motion.div\n            data-slot=\"styled-dialog\"\n            className={backdropClass}\n            style={{ perspective: \"1200px\" }}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: 0.2, ease: \"easeOut\" }}\n            onClick={() => setOpen(false)}\n          >\n            <motion.div\n              ref={panelRef}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              tabIndex={-1}\n              className={cn(panelBase, panelSize[size], panelClassName, className)}\n              initial={motionProps.initial}\n              animate={motionProps.animate}\n              exit={motionProps.exit}\n              transition={panelMotion?.transition ?? { duration: 0.2, ease: \"easeOut\" }}\n              onClick={(e) => e.stopPropagation()}\n            >\n              <button\n                type=\"button\"\n                aria-label=\"Close\"\n                className={closeBtn}\n                onClick={() => setOpen(false)}\n              >\n                <X />\n              </button>\n              {title ? (\n                <div className=\"border-b border-border px-6 py-4 pr-12 text-base font-semibold\">\n                  {title}\n                </div>\n              ) : null}\n              <div className=\"px-6 py-5 text-sm text-muted-foreground\">{children}</div>\n            </motion.div>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </>\n  )\n}\n\n/* Flip: it arrives closed on a 3D vertical axis and opens by straightening\n   (rotateX). */\nexport function FlipDialog(props: DialogProps) {\n  return (\n    <DialogShell\n      props={props}\n      panelClassName=\"origin-top [transform-style:preserve-3d]\"\n      panelMotion={{\n        initial: { opacity: 0, rotateX: -90 },\n        animate: { opacity: 1, rotateX: 0 },\n        exit: { opacity: 0, rotateX: -90 },\n        transition: { type: \"spring\", stiffness: 260, damping: 24 },\n      }}\n    />\n  )\n}\n\n/* Swing: ustten sarkac gibi sallanarak iner (rotate + origin-top). */\nexport function SwingDialog(props: DialogProps) {\n  return (\n    <DialogShell\n      props={props}\n      panelClassName=\"origin-top\"\n      panelMotion={{\n        initial: { opacity: 0, rotate: -14, y: -24 },\n        animate: { opacity: 1, rotate: 0, y: 0 },\n        exit: { opacity: 0, rotate: -8, y: -16 },\n        transition: { type: \"spring\", stiffness: 220, damping: 12 },\n      }}\n    />\n  )\n}\n\n/* Zoom: agresif buyume ile ortaya patlar (scale 0.5 -> 1). */\nexport function ZoomDialog(props: DialogProps) {\n  return (\n    <DialogShell\n      props={props}\n      panelMotion={{\n        initial: { opacity: 0, scale: 0.5 },\n        animate: { opacity: 1, scale: 1 },\n        exit: { opacity: 0, scale: 0.5 },\n        transition: { type: \"spring\", stiffness: 360, damping: 26 },\n      }}\n    />\n  )\n}\n\n/* Elastic: yuksek stiffness dusuk damping ile elastik overshoot. */\nexport function ElasticDialog(props: DialogProps) {\n  return (\n    <DialogShell\n      props={props}\n      panelMotion={{\n        initial: { opacity: 0, scale: 0.8, y: 28 },\n        animate: { opacity: 1, scale: 1, y: 0 },\n        exit: { opacity: 0, scale: 0.9, y: 16 },\n        transition: { type: \"spring\", stiffness: 520, damping: 11 },\n      }}\n    />\n  )\n}\n\n/* Rotate: hafif donerek ve buyuyerek girer (rotate -8 + scale). */\nexport function RotateDialog(props: DialogProps) {\n  return (\n    <DialogShell\n      props={props}\n      panelMotion={{\n        initial: { opacity: 0, rotate: -8, scale: 0.9 },\n        animate: { opacity: 1, rotate: 0, scale: 1 },\n        exit: { opacity: 0, rotate: -6, scale: 0.92 },\n        transition: { type: \"spring\", stiffness: 300, damping: 22 },\n      }}\n    />\n  )\n}\n",
      "type": "registry:component",
      "target": "components/ui/dialog-motion.tsx"
    }
  ],
  "categories": [
    "styled",
    "dialog"
  ],
  "type": "registry:component"
}