{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-copy-button",
  "type": "registry:ui",
  "title": "react-tw/copy-button.tsx",
  "description": "Copies `text` (unless `onCopy` takes it over) and reports `copied` for `feedbackTimeout` ms — the Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-position",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-tooltip",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/copy-button.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/copy-button.tsx",
      "content": "import type { ComponentProps } from 'react';\nimport type { Placement } from '../core/position.ts';\nimport { Copy as CopyPrimitive } from '@purpurabog/ui/headless';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\nimport { Tooltip } from './tooltip.tsx';\n\nexport type CopyOptions = CopyPrimitive.CopyOptions;\n\n/**\n * Copies `text` (unless `onCopy` takes it over) and reports `copied` for `feedbackTimeout` ms — the\n * \"Copied!\" moment of the copy button and the inline code snippet. No feedback when the copy failed.\n * The headless `Copy.useCopy`.\n */\nexport const useCopyFeedback = CopyPrimitive.useCopy;\n\nexport const copyIcon = (\n    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"size-4 fill-current transition-[fill] duration-(--ui-duration-fast) ease-carbon\">\n        <path d=\"M14 5v9H5V5h9m0-1H5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1Z\" />\n        <path d=\"M2 9H1V2a1 1 0 0 1 1-1h7v1H2Z\" />\n    </svg>\n);\n\nexport interface CopyButtonProps extends CopyOptions, Omit<ComponentProps<'button'>, 'text' | 'label' | 'feedback' | 'placement' | 'size' | 'disabled' | 'lang' | 'className' | keyof CopyOptions> {\n    /** What gets copied. */\n    text: string;\n    /** Accessible name and tooltip at rest (default: the translation's \"Copy to clipboard\"). */\n    label?: string;\n    /** Tooltip after copying (default: \"Copied!\"). */\n    feedback?: string;\n    placement?: Placement;\n    /** `md` 40px, `sm` 32px. */\n    size?: 'sm' | 'md';\n    disabled?: boolean;\n    lang?: string;\n    className?: string;\n}\n\n/**\n * Carbon `CopyButton` as a React + Tailwind component, the look and rules of `<ui-copy-button>`: a\n * 40px (`sm`: 32px) layer-coloured icon button named by its icon tooltip, that copies `text` and\n * shows `feedback` (\"Copied!\") in that tooltip for `feedbackTimeout` ms, also announced politely.\n * The behaviour is the headless Copy.\n */\nexport function CopyButton({ text, onCopy, feedbackTimeout, ...rest }: Readonly<CopyButtonProps>) {\n    return (\n        <CopyPrimitive.Root text={text} onCopy={onCopy} feedbackTimeout={feedbackTimeout}>\n            <CopyButtonParts {...rest} />\n        </CopyPrimitive.Root>\n    );\n}\n\n/** The tooltip, button and live region, inside the primitive (they follow its copied state). */\nfunction CopyButtonParts({ label, feedback, placement = 'bottom', size = 'md', disabled = false, lang, className, ...rest }: Readonly<Omit<CopyButtonProps, 'text' | keyof CopyOptions>>) {\n    const t = useTranslation(lang).copy;\n    const { copied } = CopyPrimitive.useCopyContext();\n    const said = feedback || t.copied;\n    return (\n        <span className={cn('inline-block', className)}>\n            <Tooltip text={copied ? said : label || t.copy} asLabel placement={placement} open={copied || undefined}>\n                <CopyPrimitive.Trigger {...rest}\n                    tabIndex={0}\n                    disabled={disabled}\n                    className={cn(\n                        // Carbon: a layer-coloured square; a design can round it and leave it clear until hovered (--ui-copy-button-*)\n                        'flex size-10 cursor-pointer items-center justify-center rounded-[var(--ui-copy-button-radius,0px)] border-0 bg-[var(--ui-copy-button-background,var(--ui-surface-1))] p-0 text-icon-primary outline-none',\n                        size === 'sm' && 'size-8',\n                        'hover:bg-ghost-hover active:bg-ghost-active focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:[outline-offset:var(--ui-focus-offset,-2px)] focus-visible:outline-focus focus-visible:outline-solid',\n                        // Carbon .cds--btn: the fill and the ring change in fast-01 with the entrance easing\n                        'transition-[background-color,outline] duration-(--ui-duration-fast) ease-(--ui-easing-entrance)',\n                        'disabled:cursor-not-allowed disabled:bg-[var(--ui-copy-button-background,var(--ui-surface-1))] disabled:text-icon-disabled',\n                        'forced-colors:border forced-colors:border-solid forced-colors:border-[CanvasText] forced-colors:text-[CanvasText] forced-colors:disabled:text-[GrayText]',\n                    )}\n                >\n                    {copyIcon}\n                </CopyPrimitive.Trigger>\n            </Tooltip>\n            <CopyPrimitive.Status className=\"sr-only\">{said}</CopyPrimitive.Status>\n        </span>\n    );\n}\n"
    }
  ]
}
