{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-09",
  "title": "Newsletter dialog",
  "description": "An email field whose button turns into Subscribed.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/dialog/dialog-09.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  CheckIcon,\n  LoaderCircleIcon,\n  MailIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\nimport { Input } from '@/registry/ndeko/ui/input';\n\ntype SubmitState = 'idle' | 'sending' | 'sent';\n\nconst SENDING_DURATION_MS = 1000;\n\nconst BRAND_STYLE = { '--gem': 'var(--primary)' } as React.CSSProperties;\n\nconst LINK = [\n  'text-primary-ink rounded-sm font-medium underline-offset-4 hover:underline',\n  FOCUS_RING,\n].join(' ');\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\nconst SHIFT_TRANSITION: Transition = {\n  type: 'spring',\n  bounce: 0,\n  duration: 0.3,\n};\nconst INSTANT_TRANSITION: Transition = { duration: 0 };\n\nconst ICON_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst LABEL_VARIANTS: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction iconVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return ICON_VARIANTS;\n}\n\nfunction labelVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return LABEL_VARIANTS;\n}\n\nfunction shiftTransitionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT_TRANSITION;\n  }\n  return SHIFT_TRANSITION;\n}\n\nfunction submitViewOf(state: SubmitState) {\n  if (state === 'sending') {\n    return {\n      key: 'sending',\n      icon: <LoaderCircleIcon className='animate-spin' />,\n      label: 'Subscribing…',\n    };\n  }\n  if (state === 'sent') {\n    return { key: 'sent', icon: <CheckIcon />, label: 'Subscribed' };\n  }\n  return { key: 'idle', icon: null, label: 'Subscribe' };\n}\n\nfunction AcmeMark() {\n  return (\n    <span\n      aria-hidden='true'\n      style={BRAND_STYLE}\n      className='gem-plate flex size-10 shrink-0 items-center justify-center rounded-xl'\n    >\n      <svg\n        viewBox='0 0 24 24'\n        fill='none'\n        stroke='currentColor'\n        strokeWidth={2.25}\n        strokeLinecap='round'\n        strokeLinejoin='round'\n        className='size-5'\n      >\n        <path d='M12 4.5 20 19H4l8-14.5Z' />\n        <path d='M8.75 14h6.5' />\n      </svg>\n    </span>\n  );\n}\n\nexport default function Dialog09() {\n  const [submitState, setSubmitState] = useState<SubmitState>('idle');\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const iconVariants = iconVariantsOf(shouldReduceMotion);\n  const labelVariants = labelVariantsOf(shouldReduceMotion);\n  const shiftTransition = shiftTransitionOf(shouldReduceMotion);\n  const submitView = submitViewOf(submitState);\n  const hasIcon = submitView.icon !== null;\n  const isIdle = submitState === 'idle';\n\n  useEffect(() => {\n    if (submitState !== 'sending') {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setSubmitState('sent');\n    }, SENDING_DURATION_MS);\n    return () => window.clearTimeout(timeout);\n  }, [submitState]);\n\n  function resetOnOpen(open: boolean) {\n    if (open) {\n      setSubmitState('idle');\n    }\n  }\n\n  function subscribe(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    if (!isIdle) {\n      return;\n    }\n    setSubmitState('sending');\n  }\n\n  return (\n    <Dialog onOpenChange={resetOnOpen}>\n      <DialogTrigger render={<Button variant='outline' />}>\n        Subscribe to updates\n      </DialogTrigger>\n      <DialogContent className='max-w-md'>\n        <div className='flex flex-col items-center gap-4'>\n          <AcmeMark />\n          <DialogHeader className='px-8 text-center'>\n            <DialogTitle>Never miss a release</DialogTitle>\n            <DialogDescription>\n              One email a month with new features and fixes. Unsubscribe in one\n              click.\n            </DialogDescription>\n          </DialogHeader>\n        </div>\n        <form className='flex flex-col gap-3' onSubmit={subscribe}>\n          <div className='relative'>\n            <Input\n              type='email'\n              autoComplete='email'\n              aria-label='Email'\n              placeholder='you@company.com'\n              className='peer ps-8'\n              readOnly={!isIdle}\n              required\n            />\n            <MailIcon className='text-muted-foreground/80 pointer-events-none absolute inset-y-0 start-2.5 my-auto size-4 peer-disabled:opacity-50' />\n          </div>\n          <Button\n            type='submit'\n            size='lg'\n            className='w-full data-disabled:opacity-100'\n            disabled={!isIdle}\n            focusableWhenDisabled\n          >\n            <AnimatePresence mode='popLayout' initial={false}>\n              {hasIcon && (\n                <motion.span\n                  key={submitView.key}\n                  className='flex'\n                  variants={iconVariants}\n                  initial='enter'\n                  animate='visible'\n                  exit='exit'\n                  transition={SWAP_TRANSITION}\n                >\n                  {submitView.icon}\n                </motion.span>\n              )}\n            </AnimatePresence>\n            <motion.span\n              layout\n              transition={shiftTransition}\n              className='relative flex'\n              aria-live='polite'\n            >\n              <AnimatePresence mode='popLayout' initial={false}>\n                <motion.span\n                  key={submitView.key}\n                  className='flex'\n                  variants={labelVariants}\n                  initial='enter'\n                  animate='visible'\n                  exit='exit'\n                  transition={SWAP_TRANSITION}\n                >\n                  {submitView.label}\n                </motion.span>\n              </AnimatePresence>\n            </motion.span>\n          </Button>\n        </form>\n        <p className='text-muted-foreground text-center text-xs'>\n          By subscribing you agree to our{' '}\n          <a href='#' className={LINK}>\n            Privacy Policy\n          </a>\n          .\n        </p>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "dialog"
  ],
  "type": "registry:component"
}