Skip to content

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'

On this page
  1. A repository
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

A repository

src
routes
index.ts2.3 kB
orders.ts5 kB
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

FileTreeTypeDefault
filesrequired FileEntry[]
labelrequired string
defaultExpanded

Folders open at first, with their trailing /: «src/».

string[]
onOpen ((path: string) => void)
selected

The path of the file that is open.

string | null
sizes

Shows each file's size when it is known.

boolean true
FileTreeSkeletonTypeDefault
items number 6
  1. A repository
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms