WarUI documentation

Split nodes: orientation and proportional sizes

experimental

A split node arranges its children horizontally or vertically and stores each child share of the space in the model.

Live example

Expected behavior

Dragging a divider, using the arrow keys on it, or moving a slider updates the visual layout and the sizes array in the readout. Switching orientation re-flows the children while keeping their proportions, order and ids. A divider drag emits layoutChange once when it ends.

Source

import { createDockModel } from '@warlockcode/warui-core';

const model = createDockModel({
  root: {
    type: 'split',
    id: 'split',
    orientation: 'horizontal',
    sizes: [0.2, 0.6, 0.2],
    children: [
      { type: 'tabs', id: 'sidebar' },
      { type: 'tabs', id: 'editor' },
      { type: 'tabs', id: 'inspector' },
    ],
  },
});

model.on('layoutChange', (event) => console.log(event.reason));

// Values are rescaled to sum to 1. Call once when a drag ends.
model.setSizes('split', [1, 3, 1]);
console.log(model.getLayout().root.sizes);

API reference

DOCK-A01-F02 API
KindNameTypeDescription
Node typetype: 'split'—Arranges children in a row or column.
Propertyorientation'horizontal' | 'vertical'Defaults to 'horizontal' (with a warning if invalid).
Propertysizesnumber[]One fraction per child. Always normalized to sum to 1. A length mismatch falls back to equal distribution with a warning; zero or negative values are clamped to the minimum.
MethodsetSizes(nodeId: string, sizes: number[]) => voidRescales the values proportionally and emits one layoutChange with reason 'resize'. Does nothing if the sizes are unchanged.
FunctionresizeDividerByKey(sizes, dividerIndex, key, shiftKey?, minSize?) => number[]Keyboard resize: arrows move 1% (Shift: 10%), Home and End collapse to the minimum or maximum.
EventlayoutChangeLayoutChangeEventEmitted with reason 'resize' after a size change.