Layout & Containers
Split Panel
Two adjacent panels separated by a draggable divider that the user can reposition. Beyond a basic split, this panel supports collapsing, magnetic auto-collapse while dragging, position persistence, animated transitions, and a rich drag lifecycle.
Preview
Section titled “Preview”<nana-split-panel style="height: 200px; width: 100%">
<div slot="start" style="padding: 1rem">Start</div>
<div slot="end" style="padding: 1rem">End</div>
</nana-split-panel> - Unit 1A
- Unit 2B
- Unit 4B
<script lang="ts">
import { NanaSplitPanel } from '$lib/components/ui/split-panel';
let position = $state(35);
</script>
<div class="h-56 w-full rounded-lg border border-line">
<NanaSplitPanel bind:position min={20} max={70} collapsible label="Resize the unit list">
{#snippet start()}
<ul class="flex flex-col gap-1 p-3 text-sm">
<li>Unit 1A</li>
<li>Unit 2B</li>
<li>Unit 4B</li>
</ul>
{/snippet}
{#snippet end()}
<div class="p-3 text-sm text-foreground-muted">The list takes {Math.round(position)}%.</div>
{/snippet}
</NanaSplitPanel>
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add split-panel --framework web-componentsnpx @nana-tec/ui add split-panel --framework svelteLands in src/lib/components/ui/split-panel/ as NanaSplitPanel.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/split-panel";
Copied in with npx @nana-tec/ui add split-panel? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<script lang="ts"> import { NanaSplitPanel } from '$lib/components/ui/split-panel';
let position = $state(40);</script>
<NanaSplitPanel bind:position min={20} vertical> {#snippet start()}...{/snippet} {#snippet end()}...{/snippet}</NanaSplitPanel>position is the start panel’s share, in percent. Drag the divider, or focus it and use
the arrow keys (Shift for ten at a time), Page Up and Page Down, Home and End. With
collapsible, Enter or a double click folds the start panel away and brings it back; without
it, a double click returns to where it began.
Basic usage
Section titled “Basic usage”<nana-split-panel style="height:200px;width:100%"> <div slot="start" style="padding:1rem">Start</div> <div slot="end" style="padding:1rem">End</div></nana-split-panel>Collapsible
Section titled “Collapsible”Add collapsible to let a panel snap closed past a threshold.
<nana-split-panel collapsible position="40" style="height: 200px; width: 100%">
<div slot="start" style="padding: 1rem">Start</div>
<div slot="end" style="padding: 1rem">End</div>
</nana-split-panel> Limits
Section titled “Limits”min and max are percentages the primary panel must stay within. The divider
stops there whether it was dragged, nudged with the arrow keys, or set directly
through position.
<nana-split-panel position="50" min="25" max="75" style="height: 160px">
<div slot="start" style="padding: 1rem">Never below 25%</div>
<div slot="end" style="padding: 1rem">Never below 25% either</div>
</nana-split-panel> With neither set the divider travels the whole range, which is how it has always behaved.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
collapsed | collapsed | boolean | false | Whether the primary panel is currently collapsed. Reflects and can be set declaratively. |
collapseThreshold | collapse-threshold | number | 0 | When greater than 0 and collapsible, dragging the primary panel smaller than this many pixels magnetically collapses it; dragging back out past the threshold re-expands it. |
collapsible | collapsible | boolean | false | Allows the primary panel to be collapsed (double-click the divider, or press Enter / Space). |
disabled | disabled | boolean | false | Disables resizing. Note that the position may still change as a result of resizing the host element when a primary panel is set. |
max | max | number | 100 | Largest the primary panel may become, as a percentage of the split. |
min | min | number | 0 | Smallest the primary panel may become, as a percentage of the split. |
position | position | number | 50 | The current position of the divider from the primary panel's edge as a percentage 0–100. Defaults to 50% of the container's initial size. |
positionInPixels | position-in-pixels | number | undefined | — | The current position of the divider from the primary panel's edge in pixels. |
primary | primary | SplitPanelPrimary | undefined | — | If no primary panel is designated, both panels resize proportionally when the host is resized. If a primary panel is designated, it maintains its size and the other panel grows or shrinks as needed. |
snap | snap | string | SplitPanelSnapFunction | undefined | — | Snap positions in pixels, percentages, or repeat() expressions (e.g. "100px 50%" or "repeat(50%) 10px"), or a function that returns a pixel position to snap to. |
snapThreshold | snap-threshold | number | 12 | How close the divider must be to a snap point until snapping occurs, in pixels. |
storageKey | storage-key | string | '' | When set, the position and collapsed state persist to localStorage under this key and are restored on load. |
vertical | vertical | boolean | false | Draws the split panel in a vertical orientation with the start and end panels stacked. |
Methods
| Method | Description |
|---|---|
collapse(): void | Collapse the primary panel, remembering the current position so it can be restored. |
expand(): void | Expand the primary panel back to its remembered position. |
reset(): void | Reset the divider to the position it had when first connected. |
toggle(): void | Toggle the collapsed state. |
Events
| Event | Description |
|---|---|
nana-reposition | Emitted whenever the divider's position changes (detail.position). |
nana-reposition-start | Emitted when the user starts dragging the divider. |
nana-reposition-end | Emitted when the user stops dragging the divider. |
nana-collapse | Emitted when a panel collapses. |
nana-expand | Emitted when a panel expands. |
Slots
| Slot | Description |
|---|---|
start | Content to place in the start panel. |
end | Content to place in the end panel. |
divider | The divider. Useful for slotting in a custom icon that renders as a handle. |
CSS parts
| Part | Description |
|---|---|
::part(panel) | Targets both the start and end panels. |
::part(start) | The start panel. |
::part(end) | The end panel. |
::part(divider) | The divider that separates the start and end panels. |
CSS custom properties
| Property | Description |
|---|---|
--divider-width | The width of the visible divider. |
--divider-hit-area | The invisible region around the divider where dragging can occur. |
--min | The minimum allowed size of the primary panel. |
--max | The maximum allowed size of the primary panel. |
--transition-duration | Duration of animated collapse / expand / reset. |
NanaSplitPanel
| Prop | Type | Default |
|---|---|---|
positionbind: | number | 50 |
min | number | 0 |
max | number | 100 |
vertical | boolean | false |
disabled | boolean | false |
collapsible | boolean | false |
collapsedbind: | boolean | false |
label | string | |
startrequired | Snippet | |
endrequired | Snippet | |
divider | Snippet | |
onPositionChange | (position: number) => void |
Also accepts Omit<HTMLAttributes<HTMLDivElement>, 'class'>.