{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-10",
  "title": "Feedback dialog",
  "description": "A short message with links to help, sent in place.",
  "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/recipes.json",
    "https://ui.ndekocode.dev/r/textarea.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-10.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 { CheckIcon, LoaderCircleIcon } 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 { Textarea } from '@/registry/ndeko/ui/textarea';\n\ntype SubmitState = 'idle' | 'sending' | 'sent';\n\nconst SENDING_DURATION_MS = 1000;\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: 'Sending…',\n    };\n  }\n  if (state === 'sent') {\n    return { key: 'sent', icon: <CheckIcon />, label: 'Feedback sent' };\n  }\n  return { key: 'idle', icon: null, label: 'Send feedback' };\n}\n\nexport default function Dialog10() {\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 sendFeedback(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        Send feedback\n      </DialogTrigger>\n      <DialogContent>\n        <DialogHeader>\n          <DialogTitle>Send us feedback</DialogTitle>\n          <DialogDescription>\n            Watch the{' '}\n            <a href='#' className={LINK}>\n              tutorials\n            </a>\n            , read the{' '}\n            <a href='#' className={LINK}>\n              documentation\n            </a>{' '}\n            or ask the{' '}\n            <a href='#' className={LINK}>\n              community forum\n            </a>{' '}\n            for help.\n          </DialogDescription>\n        </DialogHeader>\n        <form className='flex flex-col gap-4' onSubmit={sendFeedback}>\n          <Textarea\n            aria-label='Feedback'\n            placeholder='What should we improve first?'\n            readOnly={!isIdle}\n            required\n          />\n          <div className='flex flex-col sm:flex-row sm:justify-end'>\n            <Button\n              type='submit'\n              size='lg'\n              className='min-w-36 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          </div>\n        </form>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "dialog"
  ],
  "type": "registry:component"
}