{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover-07",
  "title": "Share popover",
  "description": "Share buttons and a link to copy in one click.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/popover.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/popover/popover-07.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  CodeIcon,\n  CopyIcon,\n  FacebookBrandIcon,\n  MailIcon,\n  TwitterXIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTitle,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipTrigger,\n} from '@/registry/ndeko/ui/tooltip';\n\nconst SHARE_LINK = 'https://example.com/s/Avx8HD';\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 link';\n}\n\nexport default function Popover07() {\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 copyLink() {\n    try {\n      await navigator.clipboard.writeText(SHARE_LINK);\n      setIsCopied(true);\n    } catch {\n      setIsCopied(false);\n    }\n  }\n\n  return (\n    <Popover>\n      <PopoverTrigger render={<Button variant='outline' />}>\n        Share\n      </PopoverTrigger>\n      <PopoverContent className='flex flex-col gap-3 text-center'>\n        <PopoverTitle>Share code</PopoverTitle>\n        <div className='flex flex-wrap justify-center gap-2'>\n          <Button variant='outline' size='icon' aria-label='Copy embed code'>\n            <CodeIcon />\n          </Button>\n          <Button variant='outline' size='icon' aria-label='Share on X'>\n            <TwitterXIcon />\n          </Button>\n          <Button variant='outline' size='icon' aria-label='Share on Facebook'>\n            <FacebookBrandIcon />\n          </Button>\n          <Button variant='outline' size='icon' aria-label='Share by email'>\n            <MailIcon />\n          </Button>\n        </div>\n        <div className='relative'>\n          <Input\n            readOnly\n            defaultValue={SHARE_LINK}\n            aria-label='Share link'\n            className='pe-9'\n          />\n          <Tooltip>\n            <TooltipTrigger\n              delay={0}\n              render={\n                <Button\n                  variant='ghost'\n                  size='icon-sm'\n                  onClick={copyLink}\n                  disabled={isCopied}\n                  focusableWhenDisabled\n                  aria-label={copyLabelOf(isCopied)}\n                  className='absolute end-0.5 top-0.5 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 link</TooltipContent>\n          </Tooltip>\n        </div>\n      </PopoverContent>\n    </Popover>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "popover"
  ],
  "type": "registry:component"
}