Components
Copy button
Copies a value and confirms what was copied, with a fallback when the clipboard is blocked.
pnpm dlx shadcn@latest add @caliper/copy-buttonWhen to use
Use it for
- API keys, invite links, IDs and install commands people paste elsewhere.
- You want proof of what landed on the clipboard, not just a tick.
Skip it when
- The value is long prose; let people select it.
- Copying is the main action of the page; use a labelled primary button.
Installation
pnpm dlx shadcn@latest add @caliper/copy-button
Adds its 3 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above. It is built from CopyButton and shortenValue.
import { type ReactNode } from "react" import { CopyButton } from "@/components/ui/copy-button" import { cn } from "@/components/ui/lib/cn" function Panel({ title, context, children, className }: { title: ReactNode; context: ReactNode; children: ReactNode; className?: string }) { return ( <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}> <div className="grid gap-1"> <p className="font-medium">{title}</p> <p className="text-sm text-muted-foreground">{context}</p> </div> {children} </section> ); } export function CopyKey() { return ( <Panel title="API keys" context="Halden · production · created by Lena Fischer on 3 Oct"> <div className="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-1.5 pt-6"> <span className="text-[13px] font-medium">Live secret key</span> <div className="flex items-center gap-3 rounded-control border border-border bg-sunken py-2 pl-4 pr-2"> <span className="min-w-0 flex-1 truncate font-mono text-[13px]">rv_live_8Kq2mZt7XcP1vW9yL3nB4f2a</span> <CopyButton value="rv_live_8Kq2mZt7XcP1vW9yL3nB4f2a" label="Copy live secret key" /> </div> <span className="text-xs text-muted-foreground">Treat it like a password. It can read and write billing data.</span> </div> </Panel> ); }
API reference
CopyButton
component
shortenValue
component
No props of its own; it accepts the native props of its root element.
Accessibility
It is built on native elements and keeps aria-live, aria-hidden and aria-label in step with state. Changes that matter are announced through a live region.
Motion
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.