{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-30",
  "title": "Copy button",
  "description": "Copies a link and shows a check for a moment.",
  "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/tooltip.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/button/button-30.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, CopyIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipTrigger,\n} from '@/registry/ndeko/ui/tooltip';\n\nconst TEXT_TO_COPY = 'https://example.com/invite/k7p2m9';\nconst COPIED_RESET_MS = 1500;\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 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 copyGlyphOf(isCopied: boolean) {\n  if (isCopied) {\n    return {\n      key: 'copied',\n      icon: <CheckIcon className='text-success-foreground' />,\n    };\n  }\n  return { key: 'copy', icon: <CopyIcon /> };\n}\n\nfunction copyLabelOf(isCopied: boolean) {\n  if (isCopied) {\n    return 'Copied';\n  }\n  return 'Copy to clipboard';\n}\n\nexport default function Button30() {\n  const [isCopied, setIsCopied] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const iconVariants = iconVariantsOf(shouldReduceMotion);\n  const glyph = copyGlyphOf(isCopied);\n\n  useEffect(() => {\n    if (!isCopied) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setIsCopied(false);\n    }, COPIED_RESET_MS);\n    return () => window.clearTimeout(timeout);\n  }, [isCopied]);\n\n  async function copyText() {\n    try {\n      await navigator.clipboard.writeText(TEXT_TO_COPY);\n      setIsCopied(true);\n    } catch {\n      setIsCopied(false);\n    }\n  }\n\n  return (\n    <Tooltip>\n      <TooltipTrigger\n        delay={0}\n        render={\n          <Button\n            variant='outline'\n            size='icon'\n            onClick={copyText}\n            disabled={isCopied}\n            focusableWhenDisabled\n            aria-label={copyLabelOf(isCopied)}\n            className='data-disabled:opacity-100'\n          />\n        }\n      >\n        <AnimatePresence mode='popLayout' initial={false}>\n          <motion.span\n            key={glyph.key}\n            className='flex'\n            variants={iconVariants}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            transition={SWAP_TRANSITION}\n          >\n            {glyph.icon}\n          </motion.span>\n        </AnimatePresence>\n      </TooltipTrigger>\n      <TooltipContent>Copy to clipboard</TooltipContent>\n    </Tooltip>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "button"
  ],
  "type": "registry:component"
}