TreeView
Hierarchical list (files, folders, categories) with expand/collapse and selection; arrow keys open and close.
Code
import * as React from 'react';
import { TreeView } from '@fruit-labs/design';
export default function Demo() {
return (
<div
style={{
maxWidth: 320,
}}
>
<TreeView
label="Files"
defaultExpanded={['src', 'comp']}
defaultSelected="btn"
items={[
{
id: 'src',
label: 'src',
children: [
{
id: 'comp',
label: 'components',
meta: '3',
children: [
{
id: 'btn',
label: 'Button.tsx',
},
{
id: 'tbl',
label: 'Table.tsx',
},
{
id: 'mdl',
label: 'Modal.tsx',
},
],
},
{
id: 'app',
label: 'App.tsx',
},
],
},
{
id: 'pkg',
label: 'README.md',
},
]}
/>
</div>
);
}Install
From npm:
npm install @fruit-labs/design
import { TreeView } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/tree-view.jsonGuidelines
- Keep depth ≤ 4; show counts in
meta.
Props
| Prop | Type | Required |
|---|---|---|
items | TreeNode[] | Yes |
expanded | string[] | No |
defaultExpanded | string[] | No |
onExpandedChange | (ids: string[]) => void | No |
selected | string | No |
defaultSelected | string | No |
onSelect | (id: string) => void | No |
label | string | No |
className | string | No |