Skip to main content

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.

@heroicons/react
src
registry
spring.ts (modified)
effects.ts
legacy.ts
package.json

Customize

Speed0.45
Blur reveal (px)8
Node stagger (ms)95

Installation

npx shadcn@latest add @kinetic/file-tree

Usage

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.

PropTypeDefaultDescription
selectedPath / defaultSelectedPath / onSelectstring / string / (path: string) => voidundefinedControlled or initial selected node path.
expandedPaths / defaultExpandedPaths / onExpandedChangereadonly string[] / readonly string[] / (paths: string[]) => voidautoControlled or initial expanded folder paths.
animated / speed / blurPx / staggerMsboolean / number / number / numbertrue / 0.45 / 8 / 95Controls 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.

PropTypeDefaultDescription
path / name / icon / openIconstring / string / React.ReactNode / React.ReactNode-Folder path key, display name, and optional closed/open icon overrides.
expanded / defaultExpanded / onExpandedChange / disabledboolean / boolean / (expanded: boolean) => void / booleanfalse / falseFolder-level expansion state and disabled flag.

FileTreeFile

Selectable file item with animated diff status badge pop-in on status transitions.

PropTypeDefaultDescription
path / name / status / icon / disabledstring / string / FileTreeStatus / React.ReactNode / boolean- / - / "unchanged" / - / falseFile path, label, diff status badge, custom icon, and disabled flag.