Copy flight
A copy button that shows the copy happen: the block is selected line by line, the selection lifts off into the button, and it says how many lines it copied.
On this page
Copying is invisible, so people press twice to be sure. Pass from and the copy plays out as select, lift, land: a blue selection fills the block line by line, the way holding Shift and pressing down would, then the selection comes away as a sheet carrying the shape of its lines, rises a little and arcs into the button, which takes it in with a small squeeze. The icon's two sheets slide together and give way to a green check at full size, and the label says what happened: Copied 4 lines.
Installation
Usage
import { CopyFlight } from "@/components/ui/chatcn/copy-flight"
const code = React.useRef<HTMLPreElement>(null)
<pre ref={code}>{source}</pre>
<CopyFlight value={source} from={code} />Without from it still confirms with the merging sheets and the check. label={false} makes an icon button that keeps its accessible name. The line count comes from the copied text; showLines={false} keeps the label to Copied.
Examples
Three places to copy from
Props
| Prop | Type | Notes |
|---|---|---|
value | string | () => string | What lands on the clipboard; a function is read at click time |
from | RefObject<HTMLElement> | The element being copied; it is selected and the selection lifts into the button |
label | string | false | Default "Copy". false for icon only |
copiedLabel | string | Default "Copied" |
holdMs | number | How long the check holds. Default 1600 |
showLines | boolean | Say how many lines were copied. Default true |
size | "sm" | "md" | Default sm |
variant | "ghost" | "outline" | "subtle" | Button style. Default ghost |
onCopy | (value: string) => void | After the clipboard accepted it |
Accessibility
- A polite live region says Copied, with the line count, once the copy succeeded. Nothing changes if the clipboard refused.
- The selection sheet is
aria-hiddenand lives on the body only for the lift. - Clipboard access falls back to
execCommandwhere the async API is missing (insecure contexts).
Motion
- Select: a
clip-pathreveal withsteps()easing, one step per line, up to 320 ms. Lift: an arc sampled into one Web Animations keyframe list ontransformandopacity, 420 ms. - The sheets slide 3 px toward each other and fade (200 ms); the check draws in 280 ms after a 170 ms beat.
Under reduced motion: no selection, no lift and no slide; the check and label crossfade.