Skip to content
Nana UI

Forms & Inputs

Copy Button

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.

View .md Download
INV-2026-0142

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add copy-button --framework web-components
npx @nana-tec/ui add copy-button --framework svelte

Lands in src/lib/components/ui/copy-button/ as NanaCopyButton.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/copy-button";

Copied in with npx @nana-tec/ui add copy-button? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

<script lang="ts">
import { NanaCopyButton } from '$lib/components/ui/copy-button';
</script>
<NanaCopyButton value="INV-2026-0142" label="Copy invoice number" />

Copies value (or what a function returns) to the clipboard, switches to a tick for two seconds and announces “Copied”. onError runs if the browser refuses.

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

Properties

PropertyAttributeTypeDefaultDescription
copiedIconcopied-iconIconName'check'Icon shown in the copied state
copiedLabelcopied-labelstring'Copied'Label shown after a successful copy
copyIconcopy-iconIconName'document-duplicate'Icon shown in the idle state
disableddisabledbooleanfalseDisable the button
feedbackDurationfeedback-durationnumber2000How long the copied state persists, in milliseconds
fromfromstring | undefined—CSS selector for an element to read the copy text from (value or text)
labellabelstring'Copy'Label shown before copying (and the accessible name when icon-only)
showLabelshow-labelbooleanfalseShow the visible text label alongside the icon
sizesizeSize'md'Size
valuevaluestring''Literal text to copy (used when from is unset or resolves to nothing)
variantvariantCopyButtonVariant'default'Visual style

Methods

MethodDescription
copy(): Promise<void>Programmatically copy the resolved text to the clipboard.

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
::part(label)The label

CSS custom properties

PropertyDescription
--nana-copy-button-radiusCorner radius
--nana-copy-button-colorIcon / text colour

NanaCopyButton

PropTypeDefault
valuerequiredstring | (() => string)
labelstring'Copy'
copiedLabelstring'Copied'
showLabelbooleanfalse
feedbackDurationnumberCOPY_FEEDBACK_MS
onCopy(value: string) => void
onError(error: unknown) => void

Also accepts Omit< ComponentProps<typeof NanaButton>, 'iconOnly' | 'children' | 'prefix' | 'suffix' | 'value' | 'class' >.