Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Collections

  • QuestionCard
  • Table
  • Book3D
  • ProTable
  • PricingTable
  • JsonViewer
  • EditableTable
  • List
  • Descriptions
  • RowActions
  • Tree
  • Card
  • Carousel
  • Video
  • Audio
  • BentoGrid
  • Image
  • MagicCard
  • AnimatedList
  • Marquee
  • Sortable
  • Kanban
  • DesignCanvas
  • LayerTree
  • StageDraw
  • SlideDeck
  • PresenterView
  • ComponentPicker
  • EventStream
  • QueueLane
  • DocumentSheet
  • Novel reader
  • Scheduler
  • Org classroom
  • Danmaku
  • LiveChat
  • LivePlayer
  • LogViewer
  • FileTree
  • CodeReviewThread
  • VirtualList
  • InfiniteScroll
  • LogoLoop
  • BounceCards
  • CardSwap
  • ChromaGrid
  • CircularGallery
  • DomeGallery
  • FlyingPosters
  • InfiniteMenu
  • MagicBento
  • ScrollStack
  • ProfileCard
  • TiltedCard
  • PixelCard
  • DecayCard
  • ReflectiveCard
  • Folder

Charts and Diagrams

  • Flow
  • Diagram
  • Paper
  • SequenceDiagram
  • Sankey
  • Sparkline
  • Funnel
  • Treemap
  • Gantt
  • Heatmap
  • ContributionGraph
  • Legend
  • Chart
  • WorldMap

Information

  • ImageViewer
  • LiveProductCard
  • DiffStat
  • ScoreRing
  • ScoreScale
  • Badge
  • Dot
  • StatusDot
  • Chip
  • FilterChip
  • Coupon
  • Tag
  • Annotation
  • Avatar
  • AvatarCircles
  • User
  • QRCode
  • Comment
  • RelativeTime
  • GitCommit
  • DeployStatus
  • ShieldBadge
  • AwardBadge
  • CreditCard
  • IconTile

Metrics

  • Stat
  • Statistic
  • Meter
  • Timeline
  • NumberTicker

Placeholders

  • Empty
  • Skeleton
  • Watermark

FileTree

file-tree

Browses expandable files and folders with selection and version-control status badges.

Usage

Basic usage

nodes data-driven rendering; folder foldable, defaultExpanded controlled initial expansion.

tsx
<FileTree
  nodes={[
    { name: "app", type: "folder", defaultExpanded: true, children: [
      { name: "page.tsx", type: "file" },
      { name: "layout.tsx", type: "file" },
    ] },
    { name: "package.json", type: "file" },
  ]}
/>

Change status icon

Node status renders git customary A/M/D/U/R colored letter subscripts.

tsx
<FileTree
  nodes={[
    { name: "src", type: "folder", defaultExpanded: true, children: [
      { name: "task-runner.tsx", type: "file", status: "added" },
      { name: "button.tsx", type: "file", status: "modified" },
      { name: "legacy.ts", type: "file", status: "deleted" },
    ] },
    { name: "README.md", type: "file", status: "renamed" },
  ]}
/>

Select + Search

selectedPath Controlled highlighting is currently selected; searchable enables in-tree search (automatically expands when an ancestor is hit).

tsx
<FileTree
  nodes={nodes}
  searchable
  selectedPath={sel}
  onSelect={(node, path) => setSel(path)}
/>

When to use

Use FileTree for IDE or developer-tool sidebars and pull-request file lists. It supports nested files and folders, Git-style change markers, controlled selection, expansion, and built-in search. Use [Tree] for arbitrary hierarchical data or Table for two-dimensional data.

Import

ts
import { FileTree, fileStatusMeta, filterFileTree } from "@hulianui/ui"

Props

NameTypeDefaultDescription
nodes*FileNode[]-Recursive file and folder data.
selectedPathstring-Controlled selected path.
expandedPathsstring[]-Controlled set of expanded folder paths.
defaultExpandedPathsstring[]-Initial uncontrolled paths, merged with each folder's defaultExpanded.
searchablebooleanfalseShows an in-tree search field that filters matches and expands their ancestors.
searchPlaceholderstring"\u641c\u7d22\u6587\u4ef6" ("Search files")Search-field placeholder.
classNamestring-Custom class name.

Events

EventTypeDescription
onSelect(node: FileNode, path: string) => voidFires when a file or folder is selected, with the node and composed path.
onContextMenu(node: FileNode, path: string, e: React.MouseEvent) => voidFires on a row context menu; pair it with ContextMenu for cursor-anchored actions.
onExpandedChange(paths: string[]) => voidFires whenever expansion changes in either controlled or uncontrolled mode.

FileNode is { name: string; type: "file"\|"folder"; status?: FileStatus; children?: FileNode[]; defaultExpanded?: boolean }.
FileStatus is "added"\|"modified"\|"deleted"\|"untracked"\|"renamed", rendered as an A/M/D/U/R marker.

Pitfalls

  • Selection and expansion match composed paths such as src/components/button.tsx, not name. selectedPath and the path returned by onSelect use the same rules.
  • Passing expandedPaths enables controlled mode and requires onExpandedChange to write changes back. Otherwise, defaultExpandedPaths and folder-level defaultExpanded initialize uncontrolled state.
  • status is meaningful only for files, while children is meaningful only for folders.

Related

Table · Book3D · ProTable · PricingTable · JsonViewer · EditableTable

PreviousLogViewerData DisplayNextDiffStat

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Pitfalls
    • Related