UI.MD

Copy Label Button

A labelled button that copies text and confirms in place: the copy icon fades to a check and the label changes to Copied, at a fixed width.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/copy-label-button.json

Usage

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

Examples

Default

Press it: the copy icon fades to a check and the label reads Copied, then both return. The button keeps the wider label's width, so nothing beside it moves.

Sizes

Takes Button's size prop, and the icon and padding follow it.

Text built at click time

Pass a function as text when the value is built on press, so the clipboard never gets a stale render.

API Reference

PropTypeDefaultDescription
textstring | (() => string)-What lands on the clipboard. A function runs on press.
labelReactNode"Copy"The resting label.
copiedLabelReactNode"Copied"The label while the check shows.
onCopied() => void-Runs after a successful copy, never when the clipboard refuses.
resetAfternumber1500How long the copied state holds, in milliseconds.
...propsButtonProps-Every other Button prop (variant, size, disabled, className, ...) is forwarded. The icon, label and click handler are the component's own.