{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-11",
  "title": "Rating dialog",
  "description": "A scale from 0 to 8 on joined pills, then a reason.",
  "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/label.json",
    "https://ui.ndekocode.dev/r/radio-group.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-11.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { CheckIcon, LoaderCircleIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogContent,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { RadioGroup, RadioGroupItem } from '@/registry/ndeko/ui/radio-group';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\n\ntype SubmitState = 'idle' | 'sending' | 'sent';\n\nconst SENDING_DURATION_MS = 1000;\n\nconst SCORES = [0, 1, 2, 3, 4, 5, 6, 7, 8];\n\nconst SEGMENT = [\n  'relative flex h-8 flex-1 cursor-pointer items-center justify-center bg-card text-[13px] font-medium tabular-nums',\n  'shadow-[0_1px_2px_rgb(0_0_0/0.05)] hairline-ring ring-foreground/12 transition-[color,background-color,box-shadow] duration-150',\n  'rounded-none first:rounded-s-full last:rounded-e-full hover:bg-foreground/[0.03]',\n  'has-data-checked:z-10 has-data-checked:bg-primary has-data-checked:text-primary-foreground has-data-checked:ring-(--ring-color)',\n  '[--ring-color:color-mix(in_oklab,black_15%,var(--primary))] dark:[--ring-color:color-mix(in_oklab,white_15%,var(--primary))]',\n  'has-focus-visible:z-10 has-focus-visible:ring-[3px] has-focus-visible:ring-ring/25',\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 Dialog11() {\n  const id = useId();\n  const questionId = `${id}-question`;\n  const scaleId = `${id}-scale`;\n  const reasonId = `${id}-reason`;\n\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        Rate your setup\n      </DialogTrigger>\n      <DialogContent>\n        <DialogHeader>\n          <DialogTitle>Help us improve</DialogTitle>\n        </DialogHeader>\n        <form className='flex flex-col gap-5' onSubmit={sendFeedback}>\n          <div className='flex flex-col gap-3'>\n            <span\n              id={questionId}\n              className='text-foreground text-[13px] leading-none font-medium'\n            >\n              How hard was it to set up your account?\n            </span>\n            <div className='flex flex-col gap-2'>\n              <RadioGroup\n                aria-labelledby={questionId}\n                aria-describedby={scaleId}\n                className='flex gap-0 -space-x-px'\n              >\n                {SCORES.map((score) => (\n                  <label key={score} className={SEGMENT}>\n                    <RadioGroupItem value={String(score)} className='sr-only' />\n                    {score}\n                  </label>\n                ))}\n              </RadioGroup>\n              <div\n                id={scaleId}\n                className='text-muted-foreground flex justify-between text-xs'\n              >\n                <span>0 is very easy</span>\n                <span>8 is very hard</span>\n              </div>\n            </div>\n          </div>\n          <div className='grid gap-2'>\n            <Label htmlFor={reasonId}>Why did you give this rating?</Label>\n            <Textarea\n              id={reasonId}\n              placeholder='The step that took the longest was...'\n              readOnly={!isIdle}\n            />\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      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "dialog"
  ],
  "type": "registry:component"
}