✨ Publier v1 is live — a polished docs platform built for the open web.
Skip to content

FileTree

Visual directory tree with type-based file icons and native expand/collapse. Use for project layout diagrams, "where to put this file" references, and migration maps.

<FileTree> renders a hierarchical folder-and-file view — the same format you’d draw on a whiteboard when explaining project structure. Directories use native <details>/<summary> so expand/collapse works without JavaScript.

A typical Publier project

import { FileTree } from '@publier/shell/components';
<FileTree tree={[
{ type: 'directory', name: 'src', children: [
{ type: 'directory', name: 'content', children: [
{ type: 'directory', name: 'docs', children: [
{ type: 'file', name: 'index.mdx', highlight: true, comment: 'root /docs page' },
{ type: 'file', name: 'get-started' },
{ type: 'placeholder', comment: 'more sections' },
]},
{ type: 'file', name: 'config.ts' },
]},
]},
{ type: 'file', name: 'astro.config.ts' },
{ type: 'file', name: 'publier.config.yaml', highlight: true },
]} />

Entry types

Three entry shapes. Use highlight to call out a file the reader should focus on; use comment for a trailing gloss.

File

Directory (expandable)

Placeholder (elision)

Hide noise with { type: 'placeholder' }:

<FileTree tree={[
{ type: 'directory', name: 'node_modules', open: false, children: [
{ type: 'placeholder', comment: 'hundreds of packages' },
]},
{ type: 'directory', name: 'src', children: [
{ type: 'file', name: 'index.ts', highlight: true },
{ type: 'placeholder' },
]},
]} />

Props

<FileTree>

PropTypeDefaultDescription
treeFileTreeEntry[]Top-level entries. Required.
labelstring'File tree'Accessible label for the role="tree" element.
classstringExtra CSS class.

File entry

FieldTypeDescription
type'file'Discriminant.
namestringFilename with extension — icon auto-picks from .ts, .tsx, .mdx, .json, .astro, etc.
highlightbooleanRender bold/accented.
commentstringTrailing inline comment.

Directory entry

FieldTypeDescription
type'directory'Discriminant.
namestringFolder name (trailing / added automatically).
childrenFileTreeEntry[]Nested entries.
openboolean (default true)Whether the <details> is expanded initially.
highlightbooleanRender bold/accented.
commentstringTrailing inline comment.

Placeholder entry

FieldTypeDescription
type'placeholder'Discriminant.
namestring (default '…')Override the ellipsis text.
commentstringTrailing inline comment.

Behaviour

  • Directories render as native <details>/<summary> — click the folder name to expand/collapse, no JS.
  • File icons come from a small map of common extensions; unknown extensions get a generic file icon.
  • role="tree" + aria-label for screen reader navigation.