# Apply to file

Apply for assistant code: a miniature of the block drops into the file's tab, which marks itself changed and counts the lines.

Also called: apply code button, apply code animation.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Apply, into the file. Apply drops a miniature of the code into its file's tab, which marks itself changed and counts the lines. Preview: https://chatcn.dev/preview/apply-to-file-demo

Press Apply and a miniature of the code block leaves the answer and drops into the file it belongs to. The file's tab takes it with a small dip and rolls up its added and removed lines in green and red. The button edits from Apply to Applying to Applied with a run check finishing beside it, and offers Undo.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/apply-to-file
```

## Usage

```tsx
import { ApplyToFile, FileTab } from "@/components/ui/chatcn/pro/apply-to-file"

<FileTab ref={tab} name="lib/session.ts" added={diff.added} removed={diff.removed} active />
<ApplyToFile status={status} from={codeRef} target={tab} onApply={apply} onUndo={undo} />
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `status` | `"idle" | "applying" | "applied" | "error"` | ApplyToFile |
| `from` / `target` | `RefObject<HTMLElement>` | The code block and the file tab |
| `onApply` / `onUndo` | `() => void` |  |
| `labels` | `Partial<Record<status, string>>` |  |
| `name`, `added`, `removed`, `active` | FileTab | Counts roll as they change |

## Accessibility

- The tab reads its counts in words: 9 added, 4 removed.
- The miniature is inert and hidden from assistive tech.

## Motion

- The shared miniature flight from `chatcn-micro`, 600 ms; the tab dips 2 px on landing.
- Reduced motion: no flight; the counts and labels still change.

Source: https://chatcn.dev/docs/components/apply-to-file