Skip to Content
dashfoo

Build your own layout

Compose the Layout and Tabset primitives into a custom layout from the same parts DashfooLayout is built from, with your own chrome, labels, and toolbars.

DashfooLayout is a thin assembly of exported primitives. When its chrome doesn't fit (custom tab labels, a different toolbar order, extra controls in the strip), compose the same parts yourself. The parts keep selection, close-with-focus-restore, inline rename, keyboard navigation, overflow, maximize, and drag-dock outside DashfooLayout.

The three layers

A hand-built layout wires three things:

  1. A store. useDashfooStore({ defaultModel }) owns the model, dispatch, undo/redo and, with persist, saving and restoring: the same store DashfooLayout uses internally.
  2. The Layout frame. Layout.Root takes model, dispatch, and renderers, plus LayoutOptions, the same capability props DashfooLayout takes, with the same defaults. It provides the layout store every part below reads through selectors. Layout.DragLayer opts the tree into drag-dock (omit it and the layout still works without dragging). Layout.Rows renders the split tree on the resize adapter, or only the maximized tabset while one is maximized.
  3. A tabset composition. Pass renderTabset to Layout.Rows to substitute your own arrangement of Tabset.* parts at every leaf, or use Layout.Tabset, the stock composition, where custom chrome isn't needed.
import { Layout, Tabset, useDashfooStore } from "@dashfoo/react";

const App = () => {
  const store = useDashfooStore({ defaultModel });

  return (
    <Layout.Root dispatch={store.dispatch} model={store.model} renderers={{ tab: renderTab }}>
      <Layout.DragLayer>
        <Layout.Rows node={store.model.layout} renderTabset={(node) => <MyTabset node={node} />} />
      </Layout.DragLayer>
    </Layout.Root>
  );
};

Composing a tabset

Tabset.Root creates a per-tabset store; the parts inside coordinate through it, so they can be reordered, wrapped, or omitted without changing behavior:

const MyTabset = ({ node }: { node: TabsetNode }) => (
  <Tabset.Root node={node}>
    <Tabset.TabStrip>
      <Tabset.Tablist>
        {node.children.map((tab) => (
          <Tabset.Tab key={tab.id} tab={tab}>
            <Tabset.Trigger>
              <MyLabel />
            </Tabset.Trigger>
            <Tabset.RenameInput />
            <Tabset.CloseButton />
          </Tabset.Tab>
        ))}
      </Tabset.Tablist>
      <Tabset.Toolbar>
        <TabCounter />
        <Tabset.OverflowMenu />
        <Tabset.MaximizeButton />
        <Tabset.Grip />
      </Tabset.Toolbar>
    </Tabset.TabStrip>
    <Tabset.Content />
  </Tabset.Root>
);

Custom parts read the same stores the built-in parts do:

import { useTab, useTabset } from "@dashfoo/react";

// A label that knows which tab it is, whether it's selected, and whether it can close.
const MyLabel = () => {
  const { closable, index, tab } = useTab();
  const selected = useTabset((state) => state.visualSelected === index);
  return (
    <span className={selected ? "font-bold" : undefined}>
      {tab.name}
      {closable ? null : " (pinned)"}
    </span>
  );
};

// A toolbar add-on the stock composition doesn't have.
const TabCounter = () => {
  const count = useTabset((state) => state.node.children.length);
  return <span>{count} tabs</span>;
};

The hooks are selector-based: a part re-renders only when its selected slice changes, so a drag pulse or a rename in one tab doesn't wake the rest of the strip.

useTab() returns { closable, draggable, index, renamable, tab }. The flags combine the layout, the tabset and the tab's own enableClose / enableDrag / enableRename, the same answers the built-in parts act on. Read them in custom parts rather than the tabset store's tabsClosable / tabsRenamable, which are only the layout and tabset half.

What each part owns

PartOwns
Tabset.RootThe per-tabset store, drop registration, overflow measurement, the drag-out selection preview, and focus restore after a close.
Tabset.TablistThe scrolling viewport and the role="tablist" marker that owns the triggers by id.
Tabset.TabTab identity for the parts inside, and focus return after a rename.
Tabset.TriggerThe role="tab" button: ids and aria wiring, the roving-tabindex keyboard model, select on click, rename on double-click, tab dragging. Children override the label.
Tabset.RenameInputThe inline editor (Enter commits, Escape cancels, blur commits once); renders only while its tab is being renamed.
Tabset.CloseButtonClose without selecting; hides while renaming or when the tab isn't closable.
Tabset.ContentThe role="tabpanel" pane(s), keepMounted included. A children render-prop overrides the layout's renderTab for this tabset.
Tabset.OverflowMenu / Grip / CollapseButton / MaximizeButtonSelf-hide when their action is unavailable (maximizing the only tabset, collapsing one that is not collapsible or is collapsed to fit), so compositions never need the visibility conditions by hand.

A11y wiring (aria-controls, aria-labelledby, aria-selected, roving tabIndex) flows through the stores, so it stays correct in any part order. The tablist marker owns the triggers through aria-owns, so Tabset.CloseButton and Tabset.RenameInput stay siblings in the accessibility tree instead of invalid tablist children. Every part forwards its ref to the element it renders.

Maximize

Maximize needs no code in a hand-built layout. While a tabset in its tree is maximized, Layout.Rows renders only that tabset, through renderTabset when you pass one, so <Layout.Rows node={store.model.layout} renderTabset={…} /> covers both states. DashfooLayout renders the same Layout.Rows.

Responsive

DashfooLayout's responsive prop runs on useResponsiveLayout, which is exported for hand-built layouts. Pass it the store's model and the breakpoint, then hand its view and rootRef to Layout.Root and spread its locks after any capability props you set, so compact mode overrides them. The projection is view-only: dispatch still targets store.model, so nothing maps back and widening up is lossless. The store, history, and mounted panels survive the breakpoint cross.

import { Layout, useDashfooStore, useResponsiveLayout } from "@dashfoo/react";

const App = () => {
  const store = useDashfooStore({ defaultModel });
  const responsive = useResponsiveLayout(store.model, { maxWidth: 720 });
  const view = responsive.model;

  return (
    <Layout.Root
      {...responsive.locks}
      dispatch={store.dispatch}
      model={view}
      renderers={{ tab: renderTab }}
      rootRef={responsive.rootRef}
    >
      <Layout.DragLayer>
        <Layout.Rows node={view.layout} renderTabset={(node) => <MyTabset node={node} />} />
      </Layout.DragLayer>
    </Layout.Root>
  );
};

rootRef is forwarded onto the layout's root element so the hook can measure it. Maximize and the projection compose: pass view.layout to Layout.Rows, not store.model.layout, and pass view as the root's model, since the compact view clears the maximized tabset.

Guard rails

Misuse is never silent. A part rendered outside its provider throws (Tabset.Trigger outside Tabset.Tab, any tabset part outside Tabset.Root). Soft mistakes (two Tablists under one Root, a Tab whose node isn't in the tabset, double-click rename with no RenameInput composed) log a [dashfoo] warning and keep rendering.

Working reference

The demo's Raw primitives page (apps/demo-vite/src/pages/raw.tsx) builds a complete layout this way (custom labels, a tab counter, reordered toolbar, undo/redo buttons wired to the store) with no DashfooLayout anywhere, and its Playwright suite drags, renames, and maximizes against it.