Tree
A hierarchical list structure component. Almost anything can be represented in a tree structure.
When To Use
- Almost anything can be represented in a tree structure. Examples include directory systems, organization charts, biology classifications, countries, etc.
Basic
- parent 1
- parent 1-0
- leaf
- leaf
-
- parent 1-1
-
astro
---
import Tree from '@/components/data-display/Tree.astro';
import TreeNode from '@/components/data-display/TreeNode.astro';
---
<Tree>
<TreeNode title="parent 1" expanded>
<TreeNode title="parent 1-0" expanded>
<TreeNode title="leaf" />
<TreeNode title="leaf" />
</TreeNode>
<TreeNode title="parent 1-1">
<TreeNode title="leaf" />
</TreeNode>
</TreeNode>
</Tree> Checkable
Add the checkable prop to both the Tree component and each TreeNode to enable checkboxes. Parent/child checkbox logic (indeterminate state) is handled automatically.
- parent 1
- parent 1-0
- leaf
- leaf
-
- parent 1-1
-
astro
---
import Tree from '@/components/data-display/Tree.astro';
import TreeNode from '@/components/data-display/TreeNode.astro';
---
<Tree checkable>
<TreeNode title="parent 1" expanded checkable>
<TreeNode title="parent 1-0" expanded checkable>
<TreeNode title="leaf" checkable />
<TreeNode title="leaf" checkable />
</TreeNode>
<TreeNode title="parent 1-1" checkable>
<TreeNode title="leaf" checkable />
</TreeNode>
</TreeNode>
</Tree> Custom Icons
You can add custom icons to tree nodes, which is very useful for file system representations.
- src
- components
- Tree.astro
- TreeNode.astro
-
- pages
-
- package.json
- README.md
astro
---
import Tree from '@/components/data-display/Tree.astro';
import TreeNode from '@/components/data-display/TreeNode.astro';
---
<Tree>
<TreeNode title="src" expanded icon="Folder">
<TreeNode title="components" expanded icon="Folder">
<TreeNode title="Tree.astro" icon="FileCode" />
<TreeNode title="TreeNode.astro" icon="FileCode" />
</TreeNode>
<TreeNode title="pages" icon="Folder" />
</TreeNode>
<TreeNode title="package.json" icon="FileCode" />
<TreeNode title="README.md" icon="FileText" />
</Tree> API Reference
Tree
| Property | Description | Type | Default |
|---|---|---|---|
| checkable | Enables checkboxes for the entire tree | boolean | false |
TreeNode
| Property | Description | Type | Default |
|---|---|---|---|
| title | Tree | string | '-' |
| checkable | Renders a checkbox for this specific node | boolean | false |
| expanded | Whether the node is expanded by default | boolean | false |
| icon | Optional IconName to display before the title | IconName | '-' |