{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-60",
  "title": "Publish with states",
  "description": "The label and icon morph from publish to publishing to published, and the width follows.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "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-60.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  SendIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\n\ntype PublishStatus = 'idle' | 'publishing' | 'published';\n\nconst PUBLISH_DURATION_MS = 1400;\nconst PUBLISHED_RESET_MS = 2200;\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\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\nconst STATES: Record<\n  PublishStatus,\n  { icon: React.ReactNode; label: string; announcement: string }\n> = {\n  idle: {\n    icon: <SendIcon className='opacity-60' />,\n    label: 'Publish',\n    announcement: '',\n  },\n  publishing: {\n    icon: <LoaderCircleIcon className='animate-spin' />,\n    label: 'Publishing',\n    announcement: 'Publishing the post',\n  },\n  published: {\n    icon: <CheckIcon />,\n    label: 'Published',\n    announcement: 'Post published',\n  },\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\nexport default function Button60() {\n  const [status, setStatus] = useState<PublishStatus>('idle');\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const iconVariants = iconVariantsOf(shouldReduceMotion);\n  const labelVariants = labelVariantsOf(shouldReduceMotion);\n  const state = STATES[status];\n  const isPublishing = status === 'publishing';\n  const isPublished = status === 'published';\n  const isBusy = status !== 'idle';\n\n  useEffect(() => {\n    if (!isPublishing) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setStatus('published');\n    }, PUBLISH_DURATION_MS);\n    return () => window.clearTimeout(timeout);\n  }, [isPublishing]);\n\n  useEffect(() => {\n    if (!isPublished) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setStatus('idle');\n    }, PUBLISHED_RESET_MS);\n    return () => window.clearTimeout(timeout);\n  }, [isPublished]);\n\n  function publish() {\n    setStatus('publishing');\n  }\n\n  return (\n    <>\n      <Button\n        onClick={publish}\n        disabled={isBusy}\n        focusableWhenDisabled\n        aria-busy={isPublishing}\n        className='data-disabled:opacity-100'\n      >\n        <span className='relative flex'>\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.span\n              key={status}\n              className='flex'\n              variants={iconVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              {state.icon}\n            </motion.span>\n          </AnimatePresence>\n        </span>\n        <AnimatedSize axis='width' as='span' contentClassName='relative flex'>\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.span\n              key={status}\n              className='flex'\n              variants={labelVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              {state.label}\n            </motion.span>\n          </AnimatePresence>\n        </AnimatedSize>\n      </Button>\n      <span className='sr-only' role='status'>\n        {state.announcement}\n      </span>\n    </>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "button"
  ],
  "type": "registry:component"
}