46 — Layout
Resizable
Two panels and a line between them, dragged or moved with the keys to share the space.
Patients 38%
Installation
pnpm dlx @human-kit/design add resizablenpx @human-kit/design add resizableyarn dlx @human-kit/design add resizablebunx @human-kit/design add resizableThe command copies the files to src/lib/components/ui/resizable. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Resizable from '$lib/components/ui/resizable';
let size = $state(35);
</script>
<Resizable.Root bind:size label="Resize the patient list" class="h-96">
{#snippet start()}<PatientList />{/snippet}
{#snippet end()}<PatientDetail />{/snippet}
</Resizable.Root> Examples
One over the other
orientation="vertical" stacks the panels and the line runs across. The up and down arrows move it.
Notes 45%
Guidelines
- Use it for two views that are read together and that people size to their task: a list and its detail, a record and its notes.
- Give the container a height: the panels fill it, and each scrolls on its own inside, with a
ScrollArea.Root. - Set
minandmaxso that neither panel can get too narrow to be read. The defaults keep each one at 15% or more. - Keep
sizein the user's settings throughonSizeChange, so the split is the same at the next visit. - On a narrow screen, show one panel at a time instead of a split.
Accessibility
- The line is a
role="separator"that takes the focus, with its value inaria-valuenow,aria-valueminandaria-valuemax: the share of the first panel. - Name it in
labelby what it resizes, as "Resize the patient list". The default is "Resize the panels". - The arrows move it by 2%,
Shiftand an arrow by 10%,HomeandEndtominandmax. Side by side, the arrows turn round when the text runs right to left. - The line is 1px, but the strip that takes the pointer is 13px wide, and a press on it moves the focus to it.
API reference
| Prop | Type | Default |
|---|---|---|
start | Snippet The first panel: on the left, or on top. | — |
end | Snippet The second panel, which takes the rest of the space. | — |
size | number The first panel's share, in percent. Bindable. | 50 |
min | number The smallest share of the first panel. | 15 |
max | number The largest share of the first panel. | 85 |
orientation | 'horizontal' | 'vertical' Side by side, or one over the other. | 'horizontal' |
label | string The line's name, read aloud: what it resizes. | 'Resize the panels' |
onSizeChange | (size: number) => void Called with the new share as the line moves. | — |
class | string Classes for the container. | — |
It takes no other attributes: put an id or a role on an element around it.