{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-54",
  "title": "Copy to clipboard",
  "description": "A read-only link with a copy button that confirms with a check.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/field.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.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/input/input-54.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 { Field, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipTrigger,\n} from '@/registry/ndeko/ui/tooltip';\n\nconst INVITE_LINK = 'https://acme.app/join/7f3k2m';\nconst COPIED_DURATION_MS = 1500;\n\nconst FIELD_BUTTON =\n  'text-muted-foreground hover:bg-foreground/5 hover:text-foreground focus-visible:ring-ring/25 absolute inset-y-0 end-1 my-auto flex size-6 items-center justify-center rounded-md outline-none transition-[color,background-color,box-shadow] focus-visible:ring-[3px]';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_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 swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction copyGlyphOf(isCopied: boolean) {\n  if (isCopied) {\n    return {\n      key: 'copied',\n      icon: <CheckIcon className='text-success-foreground size-4' />,\n    };\n  }\n  return { key: 'copy', icon: <CopyIcon className='size-4' /> };\n}\n\nfunction copyLabelOf(isCopied: boolean) {\n  if (isCopied) {\n    return 'Copied';\n  }\n  return 'Copy invite link';\n}\n\nexport default function Input54() {\n  const [isCopied, setIsCopied] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const swapVariants = swapVariantsOf(shouldReduceMotion);\n  const glyph = copyGlyphOf(isCopied);\n  const copyLabel = copyLabelOf(isCopied);\n\n  useEffect(() => {\n    if (!isCopied) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setIsCopied(false);\n    }, COPIED_DURATION_MS);\n    return () => window.clearTimeout(timeout);\n  }, [isCopied]);\n\n  async function copyInviteLink() {\n    await navigator.clipboard.writeText(INVITE_LINK);\n    setIsCopied(true);\n  }\n\n  return (\n    <Field className='w-full max-w-xs'>\n      <FieldLabel>Invite link</FieldLabel>\n      <div className='relative'>\n        <Input className='pe-8' defaultValue={INVITE_LINK} readOnly />\n        <Tooltip>\n          <TooltipTrigger\n            render={\n              <button\n                type='button'\n                className={FIELD_BUTTON}\n                onClick={copyInviteLink}\n                aria-label={copyLabel}\n              />\n            }\n          >\n            <AnimatePresence mode='popLayout' initial={false}>\n              <motion.span\n                key={glyph.key}\n                className='flex'\n                variants={swapVariants}\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>{copyLabel}</TooltipContent>\n        </Tooltip>\n        <span className='sr-only' role='status'>\n          {isCopied && 'Invite link copied'}\n        </span>\n      </div>\n    </Field>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "input"
  ],
  "type": "registry:component"
}