Copy Button, animated React component
Two copy controls: an ID chip whose icon morphs into a check under a ripple and a Copied tooltip, and a command line whose button rolls from Copy to Copied.
- Free
- Inputs & Controls
- Spring
Chimes softly when you copy; the key field also latches on and off for reveal and hide and whooshes on rotate. Sound is off on this site until you switch it on.
Selection Copy
API Key Field
Like Copy Button? 301 more are in Pro.
Pro unlocks all 301 Pro components, every template and block, and everything we release next. Copy Button stays free.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| value | string | — | CopyChip: the text written to the clipboard. |
| display | string | — | CopyChip: what the chip shows, such as a shortened ID. Defaults to value. |
| label | string | "Copy" | CopyChip: start of the accessible label. |
| accent | string | "#0071e3" | CopyChip: ripple and check colour. |
| command | string | — | CopyCommand: the shell command shown and copied. |
| autoplay | boolean | false | Both: copy by themselves every few seconds until someone interacts. |
| SelectCopy.fields | { label: string; value: string; mono?: boolean; prefix?: string }[] | share link and install command | The fields to render, one row each. The prefix is shown but never copied. |
| SelectCopy.onCopy | (value: string) => void | undefined | Called with the copied text after a real press. The autoplay demo never calls it. |
| SelectCopy.autoplay | boolean | false | Plays a visual-only copy on each field in turn until someone touches the card. Pauses off screen and in hidden tabs, and is off under reduced motion. |
| SelectCopy.className | string | undefined | Extra classes for the card. |
| ApiKeyField.onCopy | (key: string) => void | undefined | Called with the demo key after a real press of the copy button. |
| ApiKeyField.onRotate | (key: string) => void | undefined | Called with the new demo key after the user confirms a rotation. |
| ApiKeyField.autoplay | boolean | false | Reveals, copies and rotates by itself in a loop until someone touches the card. Never touches the clipboard. |
| ApiKeyField.className | string | undefined | Extra classes for the card. |
| enableSound | boolean | true | Plays interface sounds on interaction. They follow the sound switch (setSoundsEnabled, on by default) and stay silent on hover. Autoplay makes the same sounds once the visitor has used the page. Pass false to silence this component. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry
Run this once per project. It writes the Nexus UI entry into
components.jsonfor you:npx shadcn@latest registry add "@nexus-labs=https://www.nexus-ui.com/api/registry/{name}"Type it exactly as shown.
{name}is filled in by the CLI with the component you ask for, so you never replace it.
- 3
Add the component
Run this from your project root. It adds the component, the helpers it imports and its npm packages.
npx shadcn@latest add @nexus-labs/copy-button
- 4
Check what was added
With a project made as in the Quick Start (a
src/folder), these files land in it:components/copy-button/api-key-field.tsxcopy-button.tsxindex.tsselect-copy.tsx - 5
Copying by hand? Skip the registry
Instead of steps 2 and 3 you can copy the files yourself, with no registry and no API key. Step 1 still applies, so that
cn()exists. Install the packages:npm install framer-motion
Then show the source and create each file at the path it gives:
- 6
Use it in a page
Installing only adds the files. Import the component in a page and render it. The Usage tab on the preview shows a fuller example with props:
// src/app/page.tsx import { CopyChip, CopyCommand } from "@/components/copy-button"; export default function Page() { return ( <main> <CopyChip /> </main> ); }
Like Copy Button? 301 more are in Pro.
Pro unlocks all 301 Pro components, every template and block, and everything we release next. Copy Button stays free.
Copy Button questions
Does it make sound, and how do I turn it off?
Chimes softly when you copy; the key field also latches on and off for reveal and hide and whooshes on rotate. Sounds are synthesised with the Web Audio API, so there are no audio files, and they only play after a click or key press. Pass `enableSound={false}` to silence this component, or call `setSoundsEnabled(false)` from `@/lib/ui-sounds` to switch every sound off at once. The CLI installs `@/lib/ui-sounds` with the component.