Split
Two panes with a divider that can be dragged, or moved with the arrow keys. A list and its detail, code and its result.
import { Split } from '@sypnia/ui/react'
A list and its detail
Drag the line, or focus it with Tab and use the arrow keys (Shift for bigger steps, Home and End for the limits). On phones the panes stack.
- Service
- api
- Region
- us-east
- Uptime
- 99.98%
- List width
- 38%
Code
import { useState } from 'react';
import { KeyValue, Split, Status } from '@sypnia/ui/react';
const rows = [
{ id: 'api', name: 'api', state: 'ok', region: 'us-east', uptime: '99.98%' },
{ id: 'worker', name: 'worker', state: 'warn', region: 'eu-west', uptime: '99.20%' },
{ id: 'web', name: 'web', state: 'ok', region: 'us-east', uptime: '100%' },
] as const;
export default function ListDetail() {
const [size, setSize] = useState(38);
const [chosen, setChosen] = useState<string>('api');
const row = rows.find((r) => r.id === chosen)!;
return (
<Split size={size} onSizeChange={setSize} min={25} max={70} label="Resize the list of services" height="16rem">
{[
<ul key="list" className="sy-stack" style={{ '--gap': '2px', padding: 'var(--s-2)', margin: 0, listStyle: 'none' } as React.CSSProperties}>
{rows.map((r) => (
<li key={r.id}>
<button type="button" className="sy-nav-item" aria-current={r.id === chosen ? 'true' : undefined} onClick={() => setChosen(r.id)} style={{ width: '100%' }}>
<span>{r.name}</span><Status tone={r.state}>{r.state === 'ok' ? 'Well' : 'Slow'}</Status>
</button>
</li>
))}
</ul>,
<div key="detail" style={{ padding: 'var(--s-4)' }}>
<KeyValue items={[['Service', row.name], ['Region', row.region], ['Uptime', row.uptime], ['List width', `${Math.round(size)}%`]]} />
</div>,
]}
</Split>
);
} One above the other
orientation="vertical", and keepOnPhones so it stays split on small screens too.
select id, email
from users
where created_at > now() - interval '7 days';128 rows. The result goes here; drag the line or use the arrow keys.
Code
import { Split } from '@sypnia/ui/react';
export default function Vertical() {
return (
<Split orientation="vertical" defaultSize={55} label="Resize the editor" height="18rem" keepOnPhones>
{[
<pre key="code" style={{ margin: 0, padding: 'var(--s-4)' }}><code>{'select id, email\nfrom users\nwhere created_at > now() - interval \'7 days\';'}</code></pre>,
<p key="out" style={{ padding: 'var(--s-4)' }} className="sy-text--muted">128 rows. The result goes here; drag the line or use the arrow keys.</p>,
]}
</Split>
);
} In Astro
The same split without React: <sy-split> wires it, and remember keeps the size in the browser.
The first pane. Its size is kept in this browser (remember).
The second pane. Behaviour comes from <sy-split>.
Code
---
import Split from '@sypnia/ui/astro/Split.astro';
---
<Split size={40} label="Resize the menu" height="10rem" remember="docs-example">
<p slot="first" style="padding: var(--s-4)">The first pane. Its size is kept in this browser (<code>remember</code>).</p>
<p slot="second" style="padding: var(--s-4)" class="sy-text--muted">The second pane. Behaviour comes from <code><sy-split></code>.</p>
</Split> When to use it
Use it when
- The person compares or works on two things at once and decides how much room each gets.
- A master list and the detail of the chosen item.
Do not use it when
- The sizes never change: use Columns.
- On phones both panes matter at the same time: show one, and move to the other.
For everyone
- The divider is a focusable separator with its value in percent (WAI-ARIA window splitter): arrow keys move it, Home and End go to the limits.
- Its name says what it resizes: «Resize the list of services».
- Dragging also works with touch and a pen.
Props
| Split | Type | Default |
|---|---|---|
childrenrequiredThe two panes, in order. | [ReactNode, ReactNode] | |
className | string | |
defaultSizeSize of the first pane at the start, in percent. | number | 50 |
heightHeight of the whole split, as CSS. | string | |
keepOnPhonesKeep the two panes side by side on phones too (they stack by default). | boolean | |
labelName of the divider for screen readers: what it resizes. | string | |
max | number | 85 |
minLimits of the first pane, in percent. | number | 15 |
onSizeChange | ((size: number) => void) | |
orientation'horizontal': side by side. 'vertical': one above the other. | "horizontal" | "vertical" | horizontal |
sizeSize of the first pane, when the parent keeps it. | number |