Copy Button
betaCopies a value to the clipboard and morphs its icon and label into a confirmation that reverts on its own.
- Forms
- 1 file
- 1 npm package
- Accessibility notes
pnpm dlx @dowel-ui/cli add copy-buttonnpm packages installed: class-variance-authority.
import { CopyButton } from "@/components/ui/copy-button";Default
Gallery
Icon Only
Custom Icons
Value From Function
<CopyButton>
| Prop | Type | Default |
|---|---|---|
copiedAnnouncementAnnounced to assistive technology on success. Defaults to "Copied", or to a string | string | — |
copiedIconThe confirmation icon. Defaults to a check. | ReactNode | — |
copiedLabelReplaces the label while the confirmation shows. On an icon-only button a string | ReactNode | "Copied" |
errorAnnouncementAnnounced to assistive technology when the clipboard refuses the write. | string | "Copy failed" |
getTextReads the text to copy at the moment of the click. | () => string | — |
iconThe resting icon. Defaults to a copy glyph. | ReactNode | — |
labelThe accessible name of an icon-only button. | string | — |
onCopiedCalled with the copied text once the clipboard write has resolved. | (text: string) => void | — |
onCopyErrorCalled when the clipboard is unavailable or refuses the write. | (error: unknown) => void | — |
resetAfterHow long the confirmation stays, in milliseconds. | number | — |
timeoutHow long the confirmation stays, in milliseconds (default 2000). A behaviour timer, not a duration. | number | — |
tone | "current" | "primary" | "success" | "warning" | "destructive" | "info" | "current" |
valueWhat goes on the clipboard. Pass a function to read it at the moment of the click — the current contents of an editor, say — rather than at render. Required unless the deprecated | string | (() => string) | — |
8/8
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — does not apply
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes