Tree

A file tree. Folders open on a spring and the chevron turns. Arrow keys walk it: Right opens, Left closes, Enter selects. Layout.

Open playground
  • src
    • index.ts
  • package.json

About

Tree is a React component in the Layout category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { Tree } from "@ashutoshswamy/smoui" and set nodes, value, defaultOpen.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { Tree } from "@ashutoshswamy/smoui";

<Tree defaultOpen={["src"]} nodes={[{ id: "src", label: "src", children: [{ id: "index", label: "index.ts" }] }]} onChange={(id) => open(id)} />

Props 3

nodes

Nodes with children are folders.

{ id; label; children? }[]
value / defaultValue / onChange

Selected file.

string / string / (id) => void
defaultOpen

Folder ids open on first render.

string[]