File Tree
An accessible ARIA tree view for workspace files with spring-expanded folders, scale-drawn vertical guides, staggered child reveals, and pop-in diff status badges.
Customize
Installation
npx shadcn@latest add @kinetic/file-treeUsage
Compose FileTree, FileTreeFolder, and FileTreeFile with defaultExpanded or controlled expandedPaths and selectedPath.
import {
FileTree,
FileTreeFile,
FileTreeFolder,
} from "@/components/kinetic/ui/file-tree";
export function WorkspaceFiles() {
return (
<FileTree defaultSelectedPath="src/registry/ui/file-tree.tsx">
<FileTreeFolder path="src" name="src" defaultExpanded>
<FileTreeFolder path="src/registry" name="registry" defaultExpanded>
<FileTreeFile path="src/registry/ui/file-tree.tsx" name="file-tree.tsx" status="added" />
<FileTreeFile path="src/registry/ui/code-block.tsx" name="code-block.tsx" status="modified" />
</FileTreeFolder>
<FileTreeFile path="src/legacy-tree.tsx" name="legacy-tree.tsx" status="deleted" />
</FileTreeFolder>
</FileTree>
);
}Diff status badges and keyboard navigation
FileTreeFile accepts status ("added" | "modified" | "deleted" | "unchanged") and renders a pop-in indicator badge (+, ~, or -) alongside screen-reader status text. FileTree implements ARIA tree and treeitem keyboard navigation with Arrow Up/Down, Arrow Left/Right expand and parent focus, Home, End, Enter, and Space.
"use client";
import { useState } from "react";
import {
FileTree,
FileTreeFile,
FileTreeFolder,
type FileTreeStatus,
} from "@/components/kinetic/ui/file-tree";
interface EditedFileEntry {
readonly path: string;
readonly name: string;
readonly status: FileTreeStatus;
}
interface DiffTreeProps {
readonly files: readonly EditedFileEntry[];
}
export function DiffTree({ files }: DiffTreeProps) {
const [selectedPath, setSelectedPath] = useState(files[0]?.path);
return (
<FileTree selectedPath={selectedPath} onSelect={setSelectedPath}>
<FileTreeFolder path="changes" name="changes" defaultExpanded>
{files.map((file) => (
<FileTreeFile
key={file.path}
path={file.path}
name={file.name}
status={file.status}
/>
))}
</FileTreeFolder>
</FileTree>
);
}Motion preferences
FileTree defaults to speed={0.45}, blurPx={8}, and staggerMs={95}. Folder expansion animates height via useAnimatedSize, vertical indent guides draw downward with scaleDraw, child rows enter via staggerReveal, and non-unchanged diff badges pop in with popIn. Reduced motion settles folder heights, guides, and badges immediately.
API Reference
FileTree
ARIA tree root coordinating selection, expansion, keyboard navigation, and shared motion config.
| Prop | Type | Default | Description |
|---|---|---|---|
selectedPath / defaultSelectedPath / onSelect | string / string / (path: string) => void | undefined | Controlled or initial selected node path. |
expandedPaths / defaultExpandedPaths / onExpandedChange | readonly string[] / readonly string[] / (paths: string[]) => void | auto | Controlled or initial expanded folder paths. |
animated / speed / blurPx / staggerMs | boolean / number / number / number | true / 0.45 / 8 / 95 | Controls motion activation, speed scale, initial blur (px), and subtree stagger (ms). |
FileTreeFolder
Spring-collapsible folder node with overshoot chevron rotation, scaleDraw indent rail, and staggered children.
| Prop | Type | Default | Description |
|---|---|---|---|
path / name / icon / openIcon | string / string / React.ReactNode / React.ReactNode | - | Folder path key, display name, and optional closed/open icon overrides. |
expanded / defaultExpanded / onExpandedChange / disabled | boolean / boolean / (expanded: boolean) => void / boolean | false / false | Folder-level expansion state and disabled flag. |
FileTreeFile
Selectable file item with animated diff status badge pop-in on status transitions.
| Prop | Type | Default | Description |
|---|---|---|---|
path / name / status / icon / disabled | string / string / FileTreeStatus / React.ReactNode / boolean | - / - / "unchanged" / - / false | File path, label, diff status badge, custom icon, and disabled flag. |