FileTree
The files of a repository, a bucket or a deploy, as folders that open and close. Give it flat paths: folders come first, icons follow the kind of file, sizes are written the person's way.
import { FileTree, FileTreeSkeleton } from '@sypnia/ui/react'
A repository
data
migrations
public
src
routes
index.ts2.3 kB
orders.ts5 kB
styles
db.ts940 B
.env.example210 B
package.json830 B
README.md3 kB
Open: src/routes/orders.ts
Code
import { useState } from 'react';
import { FileTree } from '@sypnia/ui/react';
// Flat paths in; folders first, icons by kind, sizes the person's way. Choose a file to open it.
const files = [
{ path: 'src/routes/index.ts', size: 2380 }, { path: 'src/routes/orders.ts', size: 5120 }, { path: 'src/db.ts', size: 940 },
{ path: 'src/styles/app.css', size: 12800 }, { path: 'public/logo.svg', size: 1810 }, { path: 'public/hero.png', size: 482000 },
{ path: 'migrations/0001_orders.sql', size: 1204 }, { path: 'data/prices.csv', size: 38400 }, { path: '.env.example', size: 210 },
{ path: 'package.json', size: 830 }, { path: 'README.md', size: 3100 },
];
export default function Repo() {
const [open, setOpen] = useState('src/routes/orders.ts');
return (
<div className="sy-stack">
<FileTree label="Files of the shop repository" files={files} selected={open} onOpen={setOpen} defaultExpanded={['src/', 'src/routes/']} />
<p className="sy-text--muted">Open: <code>{open}</code></p>
</div>
);
} Skeleton
Code
import { FileTreeSkeleton } from '@sypnia/ui/react';
// The tree while the files are listed.
export default function Skeleton() {
return <FileTreeSkeleton items={5} />;
} When to use it
Use it when
- Choosing a file to open, seeing what a deploy contains.
Do not use it when
- Things that are not files: use Tree.
For everyone
- Arrow keys move, Right opens, Left closes, Enter opens a file.
- Typing a name jumps to it.
Props
| FileTree | Type | Default |
|---|---|---|
filesrequired | FileEntry[] | |
labelrequired | string | |
defaultExpandedFolders open at first, with their trailing /: «src/». | string[] | |
onOpen | ((path: string) => void) | |
selectedThe path of the file that is open. | string | null | |
sizesShows each file's size when it is known. | boolean | true |
| FileTreeSkeleton | Type | Default |
|---|---|---|
items | number | 6 |