Atoms / Split pane

Split pane

Two panes and a divider to drag or move with the arrows. Size controlled or not.

import { SplitPane } from "@forgeron/ui";
/01 → Sidebar
List, 240px
Detail. Drag the divider, or focus it and use the arrows.
import { SplitPane } from "@forgeron/ui";
import { useState } from "react";

const pane = { padding: 16, color: "var(--ink-muted)", font: "13px var(--font-sans)" } as const;

export default function Sidebar() {
  const [size, setSize] = useState(240);
  return (
    <div style={{ width: "min(100%, 560px)", height: 220 }}>
      <SplitPane
        label="Resize the list"
        size={size}
        onChange={setSize}
        first={<div style={pane}>List, {size}px</div>}
        second={<div style={pane}>Detail. Drag the divider, or focus it and use the arrows.</div>}
      />
    </div>
  );
}
/02 → Vertical
Editor
Console
import { SplitPane } from "@forgeron/ui";

const pane = { padding: 16, color: "var(--ink-muted)", font: "13px var(--font-sans)" } as const;

export default function Vertical() {
  return (
    <div style={{ width: "min(100%, 560px)", height: 260 }}>
      <SplitPane
        direction="vertical"
        label="Resize the editor"
        defaultSize={120}
        min={80}
        minSecond={80}
        first={<div style={pane}>Editor</div>}
        second={<div style={pane}>Console</div>}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
labelstring—Names the divider: “Resize the sidebar”.
first / secondReactNode—The two panes.
direction"horizontal" | "vertical""horizontal"Side by side, or one above the other.
size / defaultSizenumber320The first pane, in px.
onChange(size: number) => void—While dragging or pressing keys.
onChangeEnd(size: number) => void—Drag ended or key pressed: save it.
min / minSecond / maxnumber160 / 160 / –Limits in px.
keyStepnumber16An arrow moves by this; Shift ×4. Home and End go to the limits; double click resets.
classNamestring—Extra classes.