Display
File Tree
A file tree on nested details: expansion, keyboard support and remembered branches come from the browser.
- tree
- files
- details
- no-js
Preview
1440pxHost theme
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/tree-001?lang=en
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "tree-001" (File Tree) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/tree-001.json
Registry item: https://vibeui.ru/r/tree-001.json
Installs to: components/vibeui/tree-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A file tree on nested details: expansion, keyboard support and remembered branches come from the browser.
A file tree: folders as details with a rotating chevron, leaves as links and an indent line on nested branches. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Tree001 } from "@/components/vibeui/tree-001"
<Tree001 nodes={[{ name: "registry", open: true, children: [{ name: "index.ts" }] }]} />
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-tree-001-* palette — do not swap it for your theme tokens
- details for folders: expansion and keyboard support come free
- the indent line — it shows which branch a row belongs to
- the monospaced face: file names get compared character by character
- rotating the chevron via details[open] instead of swapping glyphs
- links on the leaves rather than divs with handlers
## 6. You may change
- the nodes array and initial open flags
- the leaf URLs
- the accent through the accent prop
- the block width
## 7. Rules
- A full tree keyboard model (arrow keys between nodes) needs JS: Tab and Enter work here.
- The container carries role=tree but nodes are not marked treeitem: strict conformance needs a custom build.
- Deep nesting eats width: past the fifth level show a path string instead.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/tree-001.jsonhttps://vibeui.ru/r/tree-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-tree-001-*. Серверный: хуков нет, ветки рисуются рекурсивной функцией. Каждая папка — <details> с <summary>, лист — ссылка. Отступ вложенности отмечен левой линией у контейнера детей. Шрифт моноширинный: имена файлов сравнивают посимвольно.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Tree001Node = {
name: string
children?: Tree001Node[]
open?: boolean
}
export type Tree001Props = Omit<ComponentPropsWithoutRef<"div">, "children"> & {
nodes?: Tree001Node[]
accent?: string
}
// Идея компонента: дерево файлов на вложенных details. Раскрытие, клавиатура
// и запоминание открытых веток достаются от браузера — своё дерево пришлось
// бы держать в состоянии и чинить в каждом браузере. Отступ рисуется линией
// слева, поэтому видно, к какой ветке относится строка.
const STYLES = `
:where([data-vibeui-block="tree-001"]){
--vibeui-tree-001-bg:oklch(1 0 0);
--vibeui-tree-001-fg:oklch(0.24 0.014 265);
--vibeui-tree-001-muted:oklch(0.56 0.014 265);
--vibeui-tree-001-border:oklch(0.9 0.006 265);
--vibeui-tree-001-hover:oklch(0.97 0.003 265);
--vibeui-tree-001-accent:oklch(0.55 0.17 265);
--vibeui-tree-001-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
}
[data-vibeui-block="tree-001"]{
width:100%;max-width:20rem;box-sizing:border-box;padding:0.625rem;
background:var(--vibeui-tree-001-bg);
border:1px solid var(--vibeui-tree-001-border);border-radius:0.875rem;
font-family:var(--vibeui-tree-001-mono);font-size:0.8125rem;color:var(--vibeui-tree-001-fg);
}
/* Раскрытие на вложенных details: состояние веток держит браузер. */
[data-vibeui-block="tree-001"] summary{
list-style:none;cursor:pointer;
display:flex;align-items:center;gap:0.375rem;
min-height:1.75rem;padding:0 0.375rem;border-radius:0.375rem;
}
[data-vibeui-block="tree-001"] summary::-webkit-details-marker{display:none}
[data-vibeui-block="tree-001"] summary:hover{background:var(--vibeui-tree-001-hover)}
[data-vibeui-block="tree-001"] summary:focus-visible{outline:2px solid var(--vibeui-tree-001-accent);outline-offset:-2px}
[data-vibeui-block="tree-001"] [data-part="caret"]{
flex:none;width:0.375rem;height:0.375rem;
border-right:1.5px solid var(--vibeui-tree-001-muted);
border-bottom:1.5px solid var(--vibeui-tree-001-muted);
transform:rotate(-45deg);transition:transform .14s ease;
}
[data-vibeui-block="tree-001"] details[open] > summary [data-part="caret"]{transform:rotate(45deg)}
/* Линия отступа: видно, к какой ветке относится строка. */
[data-vibeui-block="tree-001"] [data-part="children"]{
margin-left:0.6875rem;padding-left:0.625rem;
border-left:1px solid var(--vibeui-tree-001-border);
}
[data-vibeui-block="tree-001"] [data-part="leaf"]{
display:flex;align-items:center;gap:0.375rem;
min-height:1.75rem;padding:0 0.375rem;border-radius:0.375rem;
color:var(--vibeui-tree-001-fg);text-decoration:none;
}
[data-vibeui-block="tree-001"] [data-part="leaf"]:hover{background:var(--vibeui-tree-001-hover)}
[data-vibeui-block="tree-001"] [data-part="leaf"]:focus-visible{outline:2px solid var(--vibeui-tree-001-accent);outline-offset:-2px}
[data-vibeui-block="tree-001"] [data-part="dot"]{
flex:none;width:0.3125rem;height:0.3125rem;margin:0 0.03125rem;
border-radius:9999px;background:var(--vibeui-tree-001-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="tree-001"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_NODES: Tree001Node[] = [
{
name: "registry",
open: true,
children: [
{
name: "components",
open: true,
children: [{ name: "buttons" }, { name: "calendar" }, { name: "menu" }],
},
{ name: "blocks", children: [{ name: "hero" }, { name: "pricing" }] },
],
},
{ name: "package.json" },
]
function renderNodes(nodes: Tree001Node[]) {
return nodes.map((node) =>
node.children?.length ? (
<details key={node.name} open={node.open}>
<summary>
<span data-part="caret" aria-hidden="true" />
{node.name}
</summary>
<div data-part="children">{renderNodes(node.children)}</div>
</details>
) : (
<a key={node.name} data-part="leaf" href="#">
<span data-part="dot" aria-hidden="true" />
{node.name}
</a>
),
)
}
/**
* Дерево файлов на вложенных details: раскрытие и клавиатура от браузера.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Tree001({
nodes = DEFAULT_NODES,
accent,
className,
style,
...props
}: Tree001Props) {
const palette = {
...(accent ? { "--vibeui-tree-001-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-tree-001" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="tree-001"
role="tree"
aria-label="Файлы проекта"
className={className}
style={palette}
>
{renderNodes(nodes)}
</div>
</>
)
}