SplitView
Panels in a tree: horizontal and vertical splits nested to any depth. A panel holds document tabs, or one fixed tool without tabs.
import { SplitView, type SplitLayout } from '@adecore/ui';
import { useState } from 'react';
const INITIAL: SplitLayout = {
root: {
type: 'split',
id: 'columns',
axis: 'horizontal',
sizes: [0.6, 0.4],
children: [
{ type: 'pane', id: 'canvas', views: ['Canvas'], active: 'Canvas' },
{
type: 'split',
id: 'rows',
axis: 'vertical',
sizes: [0.5, 0.5],
children: [
{ type: 'pane', id: 'properties', views: ['Properties'], active: 'Properties' },
{ type: 'pane', id: 'timeline', views: ['Timeline'], active: 'Timeline' }
]
}
]
},
focused: 'canvas',
maximized: null
};
export default function SplitViewDemo() {
const [value, setValue] = useState(INITIAL);
return (
<div className="h-64 w-full overflow-hidden rounded-lg border border-border">
<SplitView
value={value}
onValueChange={setValue}
showTabs={false}
layout="roomy"
renderView={(id) => <div className="grid h-full place-items-center text-sm text-text-muted">{id}</div>}
/>
</div>
);
}The demo has no tab strip; each panel holds one view. To change the layout from a menu or shortcut, pass a SplitCommand to updateSplitLayout.
Workspace covers state, dragging, sizes and every prop. Document tabs on their own are a TabStrip.
A drag layer of the app's own
An app that runs its own drags over cells drawn with showTabs={false} can show the same drop outline as SplitView.
import { DropPreview, rectDropPreview, tabDropPreview, tabGapAt } from '@adecore/ui';import { DropPreview, rectDropPreview, tabDropPreview, tabGapAt, type DropPreviewShape } from '@adecore/ui';
import { useRef, useState, type PointerEvent } from 'react';
const BAR_HEIGHT = 36;
const TAB_WIDTH = 96;
const TABS = ['index.ts', 'theme.css', 'README.md'];
export default function DropPreviewDemo() {
const box = useRef<HTMLDivElement>(null);
const strip = useRef<HTMLDivElement>(null);
const [shape, setShape] = useState<DropPreviewShape | null>(null);
const follow = (event: PointerEvent<HTMLDivElement>): void => {
const bounds = box.current!.getBoundingClientRect();
const width = Math.round(bounds.width);
const height = Math.round(bounds.height);
const y = event.clientY - bounds.top;
if (y < BAR_HEIGHT) {
const rects = Array.from(strip.current!.children, (tab) => tab.getBoundingClientRect());
const gap = tabGapAt(rects, event.clientX);
const left = (rects[gap]?.left ?? rects.at(-1)!.right) - bounds.left;
setShape(
tabDropPreview(
{ gap, left: Math.round(Math.min(left, width - TAB_WIDTH)), tabWidth: TAB_WIDTH, width, height, barHeight: BAR_HEIGHT },
{ x: 0, y: 0 }
)
);
return;
}
const half = Math.round(width / 2);
const right = event.clientX - bounds.left > half;
setShape(rectDropPreview({ x: right ? half : 0, y: BAR_HEIGHT, width: right ? width - half : half, height: height - BAR_HEIGHT }));
};
return (
<div
ref={box}
className="relative flex h-56 w-full flex-col overflow-hidden rounded-lg border border-border bg-surface"
onPointerMove={follow}
onPointerLeave={() => setShape(null)}
>
<div ref={strip} className="flex h-9 items-center gap-1 border-b border-border px-2">
{TABS.map((tab) => (
<span key={tab} className="rounded-md px-3 py-1 text-xs text-text-muted">
{tab}
</span>
))}
</div>
<div className="grid grow place-items-center text-sm text-text-muted">Move the pointer over the bar or a half</div>
<DropPreview shape={shape} />
</div>
);
}DropPreview draws a DropPreviewShape in the coordinates of its nearest positioned ancestor, which it fills. shape={null} draws nothing. Between shapes the outline animates. It takes className and ref (on the <svg>). DropPreviewProps is an exported type.
rectDropPreview(rect) makes a shape from a SplitRect, for a split or a swap. tabDropPreview(drop, origin) makes one from a TabDrop, for a tab in a cell's bar: gap is the strip gap, left and tabWidth place the tab, and width, height and barHeight describe the cell, all relative to origin, the cell's top left. tabGapAt(rects, x) returns the gap nearest the pointer, from 0 to rects.length.
sameDropPreview(left, right) says whether two shapes match. Store a new shape only when it differs, so dragover renders once per zone.