All components (283)
File tree
Navigation · FileTree
What it is and when to use it
A tree of files and folders built from a list of paths: folders first, natural order (a2 before a10) and an icon per file type.
When to use it
- Showing or choosing among the files of a project, a repository or a package.
pathsare the paths with/(src/index.ts); a path ending in/is an empty folder. The key of each row is its full path.onSelectgives the path and whether it is a file or a folder;defaultOpenDepthsays how many levels start open (1 by default);detailsadds a small text on the right, by path.- A folder without its own entry in
detailssays how many items it holds.
When not to
- A tree of data that are not files (categories, org chart):
Tree. - An explorer with views, dragging and uploading:
FileManager. - The files of an upload with its progress:
FileList.
Keyboard: it is a Tree: Tab enters, Up and Down Arrow go through the rows, Right Arrow opens a folder and Left Arrow closes it, Home and End go to the ends, and typing jumps to the row that starts with that letter.
Accessibility: a tree grid (role="treegrid") named after label; each row says its level, its position and whether it is open. The file type is seen through the icon but the name always carries its extension written out.
Fine-tuning: the --amset-tree-* variables of the tree.
What it looks like
<FileTree
label="Project files"
paths={["src/index.ts", "src/components/Button.tsx", "docs/guia.md", "README.md"]}
/>Props
Import it with import { FileTree } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | What the tree is of: "Project files". Required. |
pathsrequired | readonly string[] | The file paths, with `/`: `src/index.ts`. A path ending in `/` is an empty folder. |
className | string | Merged with the library classes; it does not replace them. |
defaultOpenDepth | number | How many folder levels start open. 1 by default. |
defaultValue | string | — |
details | Readonly<Record<string, string>> | A small text to the right of each row, by path: the size of a file, the number of changes. |
onSelect | (path: string, kind: "file" | "folder") => void | Called when a row is chosen, with its path and whether it is a file or a folder. |
size | "sm" | "md" | "lg" | — |
value | string | null | The chosen path, when controlled from outside. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
