---
title: "File Diff | Free React & Tailwind Agents Component | Motion UI"
canonical: "https://blacknest.dev/motion/c/agents/file-diff"
github_source: "https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/file-diff.tsx"
install_command: "npx motion-ui-skill add file-diff"
dependencies: ["clsx","lucide-react","motion","react","shiki","tailwind-merge"]
category: "agents"
subcategory: "agents"
---

# File Diff

> A syntax-highlighted file change disclosure with progressive rows, line numbers, live change counts, smooth following, and completion collapse.

## Install

```bash
npx motion-ui-skill add file-diff
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `shiki`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { RotateCcw } from "lucide-react";
import { useState } from "react";
import {
  FileDiff,
  type FileDiffLine,
} from "@/components/agents/file-diff";
import { useToolResultDemo } from "./use-tool-result-demo";

const DIFF_LINES: FileDiffLine[] = [
  { id: "1", oldLine: 18, newLine: 18, content: "export async function runTask() {" },
  {
    id: "2",
    type: "removed",
    oldLine: 19,
    content: "  return execute(task);",
  },
  {
    id: "3",
    type: "added",
    newLine: 19,
    content: "  const result = await execute(task);",
  },
  {
    id: "4",
    type: "added",
    newLine: 20,
    content: "  return normalize(result);",
  },
  { id: "5", oldLine: 20, newLine: 21, content: "}" },
];

function FileRun() {
  const { visible, status } = useToolResultDemo(DIFF_LINES.length, 360);

  return (
    <FileDiff
      file="src/runner.ts"
      lines={DIFF_LINES.slice(0, visible)}
      status={status === "success" ? "complete" : "streaming"}
      copyText={DIFF_LINES.map((line) => line.content).join("\n")}
      maxHeight={150}
    />
  );
}

export function FileDiffPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[300px] w-full max-w-lg">
      <FileRun key={run} />
      <button
        type="button"
        onClick={() => setRun((value) => value + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}
```

## API Reference

### FileDiff

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `file` | `ReactNode` | — | Yes | — |
| `lines` | `FileDiffLine[]` | — | Yes | — |
| `status` | `"streaming" \| "complete"` | `streaming` | No | — |
| `open` | `boolean` | — | No | — |
| `defaultOpen` | `boolean` | `true` | No | — |
| `onOpenChange` | `((open: boolean) => void)` | — | No | — |
| `collapseOnComplete` | `boolean` | `true` | No | — |
| `maxHeight` | `number` | `220` | No | — |
| `language` | `"text" \| "bash" \| "diff" \| "json" \| "tsx" \| "typescript"` | `typescript` | No | — |
| `copyText` | `string` | — | No | — |
| `onCopy` | `(() => void \| Promise<void>)` | — | No | — |
| `className` | `string` | — | No | — |

## Source Files

- [components/agents/file-diff.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/file-diff.tsx)
- [components/agents/agent-code.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-code.tsx)
- [components/agents/agent-disclosure.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-disclosure.tsx)
- [components/agents/tool-result.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/tool-result.tsx)
- [components/motion/action-swap-roll.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/action-swap-roll.tsx)
- [components/motion/action-swap.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/action-swap.tsx)
- [components/previews/agents/use-tool-result-demo.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/previews/agents/use-tool-result-demo.ts)
- [lib/ease.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/ease.ts)
- [lib/utils.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/utils.ts)
