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);
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);
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);
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);
// JavaScript module for Blazor interop
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
| Kind | Name | Type | Description |
|---|---|---|---|
| Node type | type: 'split' | — | Arranges children in a row or column. |
| Property | orientation | 'horizontal' | 'vertical' | Defaults to 'horizontal' (with a warning if invalid). |
| Property | sizes | number[] | 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. |
| Method | setSizes | (nodeId: string, sizes: number[]) => void | Rescales the values proportionally and emits one layoutChange with reason 'resize'. Does nothing if the sizes are unchanged. |
| Function | resizeDividerByKey | (sizes, dividerIndex, key, shiftKey?, minSize?) => number[] | Keyboard resize: arrows move 1% (Shift: 10%), Home and End collapse to the minimum or maximum. |
| Event | layoutChange | LayoutChangeEvent | Emitted with reason 'resize' after a size change. |