Blocks / Layers panel

Layers panel

The layers of a canvas as a tree: groups, visibility, lock, rename, multi-select, reorder by drag or Alt + arrows.

import { LayersPanel, editorFlattenLayers, editorMoveLayer, editorReorderLayer, editorIndentLayer, editorOutdentLayer, editorUpdateLayer, editorFindLayer } from "@forgeron/ui";
/01 → Default
TitleText
HeroGroup
Cover imageImage
BadgeRect
DecorationGroup
Dot 1Ellipse
Dot 2Ellipse
Call to actionRect
BackgroundRect

CLICK, ⌘ CLICK, ⇧ CLICK · F2 RENAME · H HIDE · L LOCK · ⌥ ARROWS MOVE · DRAG

import { LayersPanel, type EditorLayer } from "@forgeron/ui";
import { useState } from "react";

const initial: EditorLayer[] = [
  { id: "title", name: "Title", kind: "Text" },
  {
    id: "hero",
    name: "Hero",
    kind: "Group",
    children: [
      { id: "image", name: "Cover image", kind: "Image" },
      { id: "badge", name: "Badge", kind: "Rect", locked: true },
      {
        id: "deco",
        name: "Decoration",
        kind: "Group",
        children: [
          { id: "dot1", name: "Dot 1", kind: "Ellipse" },
          { id: "dot2", name: "Dot 2", kind: "Ellipse", visible: false },
        ],
      },
    ],
  },
  { id: "cta", name: "Call to action", kind: "Rect" },
  { id: "bg", name: "Background", kind: "Rect", locked: true },
];

export default function Default() {
  const [layers, setLayers] = useState(initial);
  const [selected, setSelected] = useState<string[]>(["image"]);
  return (
    <div style={{ width: "100%", maxWidth: 360 }}>
      <LayersPanel
        label="Layers"
        layers={layers}
        onChange={setLayers}
        selected={selected}
        onSelectedChange={setSelected}
      />
      <p style={{ font: "400 12px var(--font-mono)", color: "var(--ink-muted)", marginTop: 12 }}>
        CLICK, ⌘ CLICK, ⇧ CLICK · F2 RENAME · H HIDE · L LOCK · ⌥ ARROWS MOVE · DRAG
      </p>
    </div>
  );
}
/02 → Read only
Header
Logo
Menu
Content
import { LayersPanel } from "@forgeron/ui";

export default function ReadOnly() {
  return (
    <div style={{ width: "100%", maxWidth: 360 }}>
      <LayersPanel
        label="Layers (read only)"
        readOnly
        defaultLayers={[
          {
            id: "a",
            name: "Header",
            children: [
              { id: "a1", name: "Logo" },
              { id: "a2", name: "Menu", visible: false },
            ],
          },
          { id: "b", name: "Content", locked: true },
        ]}
        defaultSelected={["a1"]}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
labelstring—Names the tree: “Layers”.
layers / defaultLayers / onChange{ id, name, visible?, locked?, kind?, children? }[]—First is on top. A layer with children is a group. onChange gets the whole new tree after a rename, toggle, reorder or move.
selected / defaultSelected / onSelectedChangestring[]—Click selects, ⌘ click adds, Shift click extends; Space toggles, Enter selects, ⌘A all.
collapsed / defaultCollapsed / onCollapsedChangestring[]—The folded groups (← and → fold and unfold).
readOnlyboolean—Selection and folding only.
emptyReactNode—Written when there are no layers.
rowActions(layer) => ReactNode—More at the end of a row.
classNamestring—Extra classes.