{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-14",
  "title": "Loading button",
  "description": "Clicking fades the label out behind a spinner for a second, then brings it back.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/button/button-14.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 { LoaderIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nconst SAVE_DURATION_MS = 1000;\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst LABEL_VARIANTS: Variants = {\n  shown: { opacity: 1, filter: 'blur(0px)' },\n  hidden: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst SPINNER_VARIANTS: Variants = {\n  shown: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  hidden: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  shown: { opacity: 1 },\n  hidden: { opacity: 0 },\n};\n\nfunction labelVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return LABEL_VARIANTS;\n}\n\nfunction spinnerVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SPINNER_VARIANTS;\n}\n\nfunction labelStateOf(isSaving: boolean) {\n  if (isSaving) {\n    return 'hidden';\n  }\n  return 'shown';\n}\n\nexport default function Button14() {\n  const [isSaving, setIsSaving] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const labelVariants = labelVariantsOf(shouldReduceMotion);\n  const spinnerVariants = spinnerVariantsOf(shouldReduceMotion);\n\n  useEffect(() => {\n    if (!isSaving) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setIsSaving(false);\n    }, SAVE_DURATION_MS);\n    return () => window.clearTimeout(timeout);\n  }, [isSaving]);\n\n  function startSaving() {\n    setIsSaving(true);\n  }\n\n  return (\n    <Button\n      onClick={startSaving}\n      disabled={isSaving}\n      focusableWhenDisabled\n      className='data-disabled:opacity-100'\n    >\n      <motion.span\n        variants={labelVariants}\n        initial={false}\n        animate={labelStateOf(isSaving)}\n        transition={SWAP_TRANSITION}\n      >\n        Save changes\n      </motion.span>\n      <AnimatePresence initial={false}>\n        {isSaving && (\n          <motion.span\n            key='spinner'\n            className='absolute inset-0 flex items-center justify-center'\n            variants={spinnerVariants}\n            initial='hidden'\n            animate='shown'\n            exit='hidden'\n            transition={SWAP_TRANSITION}\n          >\n            <LoaderIcon className='animate-spin' />\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </Button>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "button"
  ],
  "type": "registry:component"
}