Skip to content
Nana UI

Copy Button

View .md Download

A button that copies text to the clipboard and shows a brief “copied” confirmation. Copy a literal value, or read the text from another element via the from selector. Renders icon-only by default; set show-label to display the swapping Copy → Copied text.

Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/copy-button";
<nana-copy-button value="npm install @nana-tec/ui-components"></nana-copy-button>

Properties

PropertyAttributeTypeDefaultDescription
copiedIconcopied-iconIconName'done_all'Icon shown in the copied state
copiedLabelcopied-labelstring'Copied'Label shown after a successful copy
copyIconcopy-iconIconName'content_copy'Icon shown in the idle state
disabledbooleanfalseDisable the button
feedbackDurationfeedback-durationnumber2000How long the copied state persists, in milliseconds
fromstring | undefinedCSS selector for an element to read the copy text from (`value` or text)
labelstring'Copy'Label shown before copying (and the accessible name when icon-only)
showLabelshow-labelbooleanfalseShow the visible text label alongside the icon
sizeSize'md'Size
valuestring''Literal text to copy (used when `from` is unset or resolves to nothing)
variantCopyButtonVariant'default'Visual style

Events

EventDescription
nana-copyFired after a successful copy (`detail.value`)
nana-errorFired when the copy fails (`detail.error`)

CSS parts

PartDescription
::part(button)The underlying button
::part(icon)The copy / success icon

CSS custom properties

PropertyDescription
--nana-copy-button-radiusCorner radius
--nana-copy-button-colorIcon / text colour
EventTypeDescription
nana-copyCustomEventFired after a successful copy (detail.value)
nana-errorCustomEventFired when the copy fails (detail.error)
VariableDefaultDescription
--nana-copy-button-radiusCorner radius
--nana-copy-button-colorIcon / text colour
PartDescription
buttonThe underlying button
iconThe copy / success icon
  • Keyboard accessible
  • Screen-reader labels
  • Focus-visible states
  • ARIA roles and states
  • WCAG 2.2 AA contrast
Explore Copy Button interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook