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.
Preview
Section titled “Preview”Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add copy-button --framework web-componentsnpx @nana-tec/ui add copy-button --framework svelteLands in src/lib/components/ui/copy-button/ as NanaCopyButton.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
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.
Basic usage
Section titled “Basic usage”<nana-copy-button value="npm install @nana-tec/ui-components"></nana-copy-button>Variants & sizes
Section titled “Variants & sizes”<nana-copy-button value="Hello, world" show-label></nana-copy-button>
<nana-copy-button
value="Outlined"
show-label
variant="outlined"
></nana-copy-button>
<nana-copy-button value="Ghost" show-label variant="ghost"></nana-copy-button> <nana-copy-button
value="sm"
label="Copy"
size="sm"
variant="outlined"
></nana-copy-button>
<nana-copy-button
value="md"
label="Copy"
size="md"
variant="outlined"
></nana-copy-button>
<nana-copy-button
value="lg"
label="Copy"
size="lg"
variant="outlined"
></nana-copy-button> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
copiedIcon | copied-icon | IconName | 'check' | Icon shown in the copied state |
copiedLabel | copied-label | string | 'Copied' | Label shown after a successful copy |
copyIcon | copy-icon | IconName | 'document-duplicate' | Icon shown in the idle state |
disabled | disabled | boolean | false | Disable the button |
feedbackDuration | feedback-duration | number | 2000 | How long the copied state persists, in milliseconds |
from | from | string | undefined | — | CSS selector for an element to read the copy text from (value or text) |
label | label | string | 'Copy' | Label shown before copying (and the accessible name when icon-only) |
showLabel | show-label | boolean | false | Show the visible text label alongside the icon |
size | size | Size | 'md' | Size |
value | value | string | '' | Literal text to copy (used when from is unset or resolves to nothing) |
variant | variant | CopyButtonVariant | 'default' | Visual style |
Methods
| Method | Description |
|---|---|
copy(): Promise<void> | Programmatically copy the resolved text to the clipboard. |
Events
| Event | Description |
|---|---|
nana-copy | Fired after a successful copy (detail.value) |
nana-error | Fired when the copy fails (detail.error) |
CSS parts
| Part | Description |
|---|---|
::part(button) | The underlying button |
::part(icon) | The copy / success icon |
::part(label) | The label |
CSS custom properties
| Property | Description |
|---|---|
--nana-copy-button-radius | Corner radius |
--nana-copy-button-color | Icon / text colour |
NanaCopyButton
| Prop | Type | Default |
|---|---|---|
valuerequired | string | (() => string) | |
label | string | 'Copy' |
copiedLabel | string | 'Copied' |
showLabel | boolean | false |
feedbackDuration | number | COPY_FEEDBACK_MS |
onCopy | (value: string) => void | |
onError | (error: unknown) => void |
Also accepts Omit<
ComponentProps<typeof NanaButton>,
'iconOnly' | 'children' | 'prefix' | 'suffix' | 'value' | 'class'
>.