# 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.

Also called: animated copy button, copy to clipboard animation.

Example: Copy you can see. The block is selected line by line, the selection lifts off as a sheet into the button, and it says how many lines it copied. Preview: https://chatcn.dev/preview/copy-flight-demo

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

```bash
npx shadcn@latest add https://chatcn.dev/r/copy-flight.json
```

## Usage

```tsx
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

Example: Copy, three ways. Icon only in a code block's header, a labelled button under an answer, and an outline button for a share link that skips the line count. Preview: https://chatcn.dev/preview/copy-flight-variants

## 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-hidden` and lives on the body only for the lift.
- Clipboard access falls back to `execCommand` where the async API is missing (insecure contexts).

## Motion

- Select: a `clip-path` reveal with `steps()` easing, one step per line, up to 320 ms. Lift: an arc sampled into one Web Animations keyframe list on `transform` and `opacity`, 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.

Source: https://chatcn.dev/docs/components/copy-flight