LayerTree
A layers panel you can select, collapse, search and add to. New layers arrive at the bottom.
Layers
Installation
Run this in a project that has a components.json. It adds one file, components/tenor-ui/layer-tree.tsx, and no packages.
pnpm dlx shadcn@latest add https://tenor.design/r/layer-tree.jsonNo components.json? Fetch the file. It works in any React project.
curl --create-dirs -o src/components/tenor-ui/layer-tree.tsx https://tenor.design/r/layer-tree.tsxUsage
Every prop is optional. With none, it renders the content you see above.
<LayerTree />import { LayerTree, type LayerTreeArrival, type LayerTreeLayer } from "@/components/tenor-ui/layer-tree";
const layers: readonly LayerTreeLayer[] = [
{
id: "onboarding",
name: "Onboarding – welcome",
kind: "phone",
children: [
{ id: "top-bar", name: "Top bar", kind: "component", dot: true },
{
id: "intro",
name: "Intro stack",
kind: "layers",
children: [
{ id: "intro-title", name: "Welcome title", kind: "text" },
{ id: "intro-body", name: "Welcome body", kind: "text" },
],
},
],
},
];
const stream: readonly LayerTreeArrival[] = [
{ depth: 1, name: "Continue button", kind: "component" },
{ depth: 0, name: "Onboarding – permissions", kind: "phone" },
{ depth: 1, name: "Permission list", kind: "layers" },
{ depth: 2, name: "Notifications row", kind: "frame" },
];
export function LayersPanel() {
return <LayerTree layers={layers} stream={stream} defaultSelectedId="intro" onSelect={(id) => console.log("Selected", id)} />;
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
theme | "dark" | "light" | "dark" | Dark or light palette. |
accent | string | "#e65ce6" | Colour of the selected layer. |
layers | readonly LayerTreeLayer[] | layerTreeLayers | The tree to start from. Arriving and added layers are kept inside the panel; a new array replaces them. |
stream | readonly LayerTreeArrival[] | layerTreeStream | Layers that arrive one at a time, repeating from the top. Defaults to none when layers is given. |
interval | number | 1400 | Milliseconds between arrivals. 0 stops them. |
selectedId | string | None | Id of the selected layer when it is controlled. Pair with onSelect. |
defaultSelectedId | string | None | Id of the layer selected at first when it is not controlled. Left out, the first layer. |
onSelect | (id: string) => void | None | Called with a layer's id when it is picked, arrives or is added. |
labels | Partial<LayerTreeLabels> | layerTreeLabels | Replaces the panel's wording, key by key. |
It also takes every attribute of its root element, such as className and style.
Theming
Set any of these CSS variables on the component or on an ancestor. Each falls back to the look shown here.
--tui-surface--tui-stroke--tui-text--tui-muted--tui-accent--tui-on-accent--tui-title--tui-dim--tui-pill--tui-hover--tui-guide--tui-layer-frame--tui-layer-group--tui-layer-component--tui-font-sans