Skip to content

    CopyButton

    Copies a text value to the clipboard with an in-place icon cross-fade and a polite status announcement. Icon-only by default, or labelled alongside the icon.

    Preview

    Props

    • value
    • label
    • copiedLabel
    • size
    • variant
    • iconOnly
    • timeout
    • disabled
    import { CopyButton } from "@/components/ui/copy-button"
    
    <CopyButton value="npx werewolf-ui add copy-button" />

    Usage

    When to use

    • Let users copy a command, token, URL, or short snippet in one press.
    • Show in-place confirmation on the button with a polite screen-reader status announcement.

    When not to use

    • Display a multi-line code snippet with syntax highlighting and line numbers. Use CodeBlock.
    • Trigger a general action that does not write to the clipboard. Use Button.

    Variants

    size

    Height from size-element-*: sm 28px, md 32px, lg 36px, xl 44px with a mouse; larger on touch. Icons are 16px up to lg, 20px in xl.

    • sm

    • mddefault

    • lg

    • xl

    import { CopyButton } from "@/components/ui/copy-button"
    
    <CopyButton value="npx werewolf-ui add copy-button" size="sm" />
    <CopyButton value="npx werewolf-ui add copy-button" />
    <CopyButton value="npx werewolf-ui add copy-button" size="lg" />
    <CopyButton value="npx werewolf-ui add copy-button" size="xl" />

    variant

    ghost for quiet toolbar or inline actions, secondary for a raised bordered button, soft for muted accent fill.

    • ghostdefault

    • secondary

    • soft

    import { CopyButton } from "@/components/ui/copy-button"
    
    <CopyButton value="npx werewolf-ui add copy-button" />
    <CopyButton value="npx werewolf-ui add copy-button" variant="secondary" />
    <CopyButton value="npx werewolf-ui add copy-button" variant="soft" />

    Examples

    Icon only

    Compact square copy button for inline tokens, commands, or table rows.

    npx werewolf-ui add copy-button
    import { CopyButton } from "@/components/ui/copy-button"
    
    <div className="flex items-center gap-sm">
      <code className="font-mono text-sm text-text-primary">npx werewolf-ui add copy-button</code>
      <CopyButton value="npx werewolf-ui add copy-button" label="Copy command" />
    </div>

    With label

    Set iconOnly={false} to show the label beside the cross-fading icon.

    import { CopyButton } from "@/components/ui/copy-button"
    
    <CopyButton variant="secondary" iconOnly={false} value="https://www.werewolf-ui.dev" label="Copy link" copiedLabel="Link copied" />

    Do and don't

    Do

    • Pass the exact plain-text value to copy, such as an API token, CLI command, or share URL.
    • Pair an icon-only CopyButton with a Tooltip or clear label so its purpose is unmistakable.

    Don't

    • Don't use CopyButton for general actions that do not write to the clipboard; use Button.
    • Don't omit a descriptive label when multiple copy buttons sit on the same screen.

    Props

    NameTypeValuesDefaultDescription
    value requiredstring--Plain text written to the clipboard when pressed.
    labelstring-CopyIdle accessible name when iconOnly, and visible button text when iconOnly is false.
    copiedLabelstring-CopiedAccessible name, visible text when labelled, and polite status announcement after copying.
    sizeenumsm | md | lg | xlmdHeight from size-element-*: sm 28px, md 32px, lg 36px, xl 44px with a mouse; larger on touch. Icons are 16px up to lg, 20px in xl.
    variantenumghost | secondary | softghostghost for quiet toolbar or inline actions, secondary for a raised bordered button, soft for muted accent fill.
    iconOnlyboolean-trueSquare icon-only button by default. Set to false to display label beside the icon.
    timeoutnumber-2000Duration in milliseconds before the copied confirmation resets to idle.
    disabledboolean-falseDisables presses and applies neutral disabled styling.
    onCopy(value: string) => void--Called with the copied string after clipboard write succeeds.

    Anatomy

    PartDescription
    rootThe button element.
    iconThe cross-fading copy and check icons inside the button, 16px in sm, md and lg, 20px in xl. The check mark uses color-text-success.
    hitAreaTransparent ::before centered on the root, never smaller than size-target-min (24px on mouse, 44px on touch).

    Accessibility

    Role: button

    KeysAction
    TabMoves focus to the button and shows the focus ring.
    Enter, SpaceCopies the value to the clipboard and announces the copied label.
    • Defaults to type="button" so it never submits a form by accident.
    • Sets aria-label to label (default "Copy") when idle and copiedLabel (default "Copied") after copying.
    • A polite role="status" live region announces copiedLabel when the copy succeeds.

    Install

    npx werewolf-ui add https://www.werewolf-ui.dev/r/copy-button.json

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.