Command Palette

Search for a command to run...

Components

Copy Button

A minimal button that copies any text to the clipboard with a smooth icon transition.

Features

Installation

1

Run the shadcn CLI command

npx shadcn@latest add @lalit/copy-button
pnpm dlx shadcn@latest add @lalit/copy-button
npx shadcn@latest add @lalit/copy-button
bunx shadcn@latest add @lalit/copy-button

This installs the component directly. Update import paths to match your setup.

Usage

import { CopyButton } from "@/components/ui/copy-button"

<CopyButton value="Hello world" />

const ref = useRef<HTMLPreElement>(null)
<CopyButton getValue={() => ref.current?.textContent ?? ""} />

API Reference

PropTypeDefaultDescription
value
stringStatic text to copy to clipboard.
getValue
() => stringDynamic getter — called at click time.
label
string"Copy"Accessible label before copy.
copiedLabel
string"Copied"Accessible label after copy.
duration
number2000How long to show copied state in ms.
size
number14Icon size in px.
className
stringAdditional classes for the button.