Guide.
This page builds one small React app: a chart of houseplants with three panes, Chart, Nearby and Plant. Each section adds one feature, shows the lines that changed, and runs the app as it stands. The full source is on the Demos page.
Install
Section titled “Install”sashay is one ESM package. You use it through React components; underneath is a core with no runtime dependencies, which you can also use without React.
pnpm add @vcarl/sashay react react-domReact is a peer dependency and needs version 19 or later. Import the components and the stylesheet once. The styles live in @layer sashay, so your own CSS wins without a fight.
import { Pane, Sashay } from "@vcarl/sashay/react";import "@vcarl/sashay/style.css";Your first frame
Section titled “Your first frame”A frame is a <Sashay> with a height. Put one <Pane> inside it per pane, in order. sashay creates the edges, grips and close buttons itself.
Each pane says how it opens. focus is the fraction of the frame a pane opens to; title labels its edge, its compact tab and its close button. defaultLayout places the dividers: [1, 1] pushes both to the right edge, so only Chart is open.
Your app opens panes with reveal(id) and closes them with close(id), on the handle that ref gives you. Click a plant and Nearby slides in, listing the plants closest to it. Click the plant again in the list and its card opens in the third pane, at equal thirds because Plant sets opensTo. The leaf × closes the rightmost open pane; closing Nearby calls its onClose, which clears the pick.
const sash = useRef<SashayHandle>(null);const pick = (p: Plant) => { if (p === plant) return sash.current?.reveal("plant"); // a second click opens its card setPlant(p); sash.current?.reveal("nearby");};
// …
<Sashay ref={sash} className="plants" defaultLayout={[1, 1]} // only the chart open> <Pane id="chart" title="Chart" > <Chart plant={plant} facing={facing} onPick={pick} /> </Pane> <Pane id="nearby" title="Nearby" focus={1 / 4} onClose={() => setPlant(undefined)}> <Nearby plant={plant} onPick={pick} /> </Pane> <Pane id="plant" title="Plant" focus={1 / 4} opensTo={[1 / 3, 2 / 3]}> <Card plant={plant} /> </Pane></Sashay>Houseplants
Sun against water. Pick a plant.
Near Monstera
Closest in sun and water first.
Monstera
- Sun
- 3 hours a day
- Water
- 4.4 times a month
Wipe the big leaves so they can breathe.
Keep a point in view
Section titled “Keep a point in view”A pane that another pane slides over isn’t squished. It keeps its focus width and the next pane covers part of it. Give the pane keepInView and sashay slides its content left, as little as it can, so that point stays inside the slice that’s still showing. The same goes for content wider than the pane, on a phone too. Pass null to let go.
keepInView is a Length measured from the pane’s left edge: a number is pixels, and "40%" is 40% of the pane’s width. The chart here is a fixed 720 pixels wide, so the app passes the picked plant’s x in pixels. sashay measures the content’s width on resize, so it never slides past the chart’s right edge.
This frame opens squeezed, with the Lemon tree picked far over on the right. Drag Nearby’s edge back and forth, or pick other plants in the list, and the dot stays in view. The part of the chart that still shows takes clicks as usual.
focus={3 / 4} // covered, the chart is still drawn this wide, room for all 720px// The picked plant's x, in px from the pane's left. While Nearby covers part of the// chart, sashay slides the chart left just enough to keep that point showing.keepInView={plant ? PAD + sx(plant.light) : null}Houseplants
Sun against water. Pick a plant.
Near Lemon tree
Closest in sun and water first.
Lemon tree
- Sun
- 9.4 hours a day
- Water
- 6 times a month
Wants all the sun you can give it.
Layout in the URL
Section titled “Layout in the URL”onLayoutChange hands you a code: one hex digit per visible divider, plus the spine offset and which bars are open. It fires on release, click, keypress or a pane-list change, never during a drag. Pass a saved code back as layout; invalid input falls back to defaultLayout. Adding or removing a pane’s bar changes the format, so older codes may fall back too.
In your app, onUrl would be history.replaceState, as below; this little browser keeps its own address bar instead, so the frames on this page leave yours alone. Drag an edge and watch ?layout= change. Pass the saved code back as layout and the panes come back where you left them.
onUrl = (url: string) => history.replaceState(history.state, "", url),
// …
const saveToUrl = (layout = sash.current?.layout ?? "") => { const params = new URLSearchParams({ layout }); if (plant) params.set("plant", plant.id); onUrl(`?${params}`);};useEffect(() => saveToUrl()); // after each render: a new plant
// …
layout={initial.layout} // a saved code, say from new URLSearchParams(location.search)onLayoutChange={saveToUrl}Houseplants
Sun against water. Pick a plant.
Near Pothos
Closest in sun and water first.
Pothos
- Sun
- 2 hours a day
- Water
- 4 times a month
Trails happily. Trim it to keep it bushy.
ref.current.layout reads the current code at any time. setLayout(code) applies a code without firing onLayoutChange; fit(fractions) sorts and clamps the fractions, moves to the nearest snaps and fires it. The code stores geometry only. Which panes exist is app state, such as the route, so store it separately.
Bottom bars
Section titled “Bottom bars”Give a pane a bar and it gets a strip along its bottom with a title and a chevron. Clicking the strip expands the bar over the lower part of the pane; the content underneath doesn’t move or resize. height is how tall it expands, as a Length: a CSS length string or a number of pixels, half the pane when left out. The bar’s content is any React node. toggleBar(id) opens or closes it from code, and the layout code records which bars are open.
Here the Chart pane has a Window bar. Pick the way your window faces, and the plants it can’t give enough sun turn hollow.
// The bar's content is part of the pane it belongs to.const windows = ( <> <p className="pl-bar-title">Your window faces</p> {(Object.keys(WINDOWS) as Facing[]).map((f) => ( <button key={f} type="button" data-facing={f} aria-pressed={f === facing} onClick={() => setFacing(f === facing ? null : f)} > {f} </button> ))} </>);
// …
bar={bar ? { title: "Window", height: "9rem", content: windows } : undefined}Houseplants
Sun against water. Pick a plant.
Pick a plant on the chart.
Pick a plant.
Compact mode
Section titled “Compact mode”Below compactBelow (a Length, "40rem" by default) a frame switches to compact mode. The first edge becomes a tab strip and every other edge a 12px grip whatever its width. Bars work as they do on a wide frame. The tab strip lists up to six panes; past six, the oldest fold into the spine, so every pane stays a tap away. The frame gets data-compact, so your CSS can follow.
A compact frame usually has room for one pane, so defaultLayout may open the wrong one. compactLayout is used in its place when the frame starts out compact: [1, 1] opens the first of three panes. It is only a default. A valid layout wins over it, and resizing a frame never applies it.
The width is the frame’s, not the window’s, so a narrow sidebar frame goes compact on a wide screen too. This frame passes compactBelow="100vw", so it is always compact.
compactBelow={compactBelow} // a Length; "40rem" when left outHouseplants
Sun against water. Pick a plant.
Near Monstera
Closest in sun and water first.
Monstera
- Sun
- 3 hours a day
- Water
- 4.4 times a month
Wipe the big leaves so they can breathe.
Styling
Section titled “Styling”The stylesheet sits in @layer sashay, so any unlayered rule of yours beats it. Theme the frame with --sashay-* custom properties for colour, radius, font size and shadow; every one has a fallback. <Sashay> passes className and other div props to the frame, and each <Pane> renders a [data-sashay-pane] element, so style them however you like. Keep the frame’s overflow: clip: with hidden, a hash link can scroll the whole frame.
State shows up as attributes: data-covered, data-closed and data-offscreen on panes, data-dragging and data-compact on the frame. The styling hooks table lists them all.
This one opens at equal thirds. The chart is covered, so it holds the picked plant in view too.
/* Edges, bars and controls take their colours from --sashay-*. Panes are your own elements. */.plants { font: 15px / 1.45 var(--sans); --sashay-bg: var(--ink); --sashay-fg: var(--paper); --sashay-muted: #d9cfb8; --sashay-border: var(--mute); --sashay-pane-bg: var(--ink); --sashay-raised-bg: #2c2a25; --sashay-accent: var(--butter);}.plants [data-sashay-pane] { box-sizing: border-box; padding: 20px; /* PAD in index.tsx */ color: var(--ink); background: var(--paper); overflow: hidden auto; container-type: inline-size;}.plants [data-sashay-pane="nearby"] { background: var(--butter);}.plants [data-sashay-pane="plant"] { background: var(--mint);}.plants [data-sashay-close] { color: var(--ink);}Houseplants
Sun against water. Pick a plant.
Near Spider plant
Closest in sun and water first.
Spider plant
- Sun
- 3.6 hours a day
- Water
- 5 times a month
Hang it high so the babies can dangle.
Navigation stacks
Section titled “Navigation stacks”A stack is just an array in state. Picking an item adds a pane on the right; going back removes it. There are no push or pop helpers: render a <Pane> per entry and sashay diffs them by id. A new pane slides in and opens to its focus; a removed pane closes, gives its width to its neighbour, then leaves.
When the open panes no longer fit, the oldest fold into a spine at the left, with a tab for each. Click a tab to bring its pane back; the panes that no longer fit to its right get a spine of their own. Closed panes never fold, so a fixed workspace that fits never shows a spine.
This house opens room by room, down to the contents of a drawer.
// `path` is the stack: the nodes from the house down to what's open.const [path, setPath] = useState(() => { const start = [root]; // a few levels down, so there's a stack to see while (start.length <= depth) start.push(kids(start[start.length - 1])[0]); return start;});
// …
const go = (n: Node) => setPath([...path.slice(0, n.depth), n]); // path[i] is always at depth i
// …
<Sashay ref={sash} className="house"> {path.map((n, i) => ( // The leaf × pops the stack back to the pane before it. <Pane key={n.id} id={n.id} title={n.name} focus={1 / 3} data-level={n.item ? "item" : n.depth % 3} onClose={() => go(path[i - 1] ?? root)} > <Level node={n} parent={path[i - 1]} path={path} go={go} /> </Pane> ))}</Sashay>The house
Parlour
Dresser
Middle drawer
Hatbox
Server rendering
Section titled “Server rendering”<Sashay> and <Pane> render on the server, in React Server Components too. The HTML has the whole frame, edges, bars and spine included, so nothing moves when it hydrates. On a phone it is already in compact mode: the server doesn’t know the frame’s width, so the CSS it sends covers each case.
// app/page.tsx, a server componentimport { Pane, Sashay } from "@vcarl/sashay/react";import "@vcarl/sashay/style.css";
export default async function Page({ searchParams }) { return ( <Sashay layout={(await searchParams).layout} style={{ height: "100vh" }}> <Pane id="list" title="List" focus={1 / 3}><PlantList /></Pane> <Pane id="plant" title="Plant" focus={2 / 3}><PlantCard /></Pane> </Sashay> );}A server component can’t pass functions, so onLayoutChange, onClose, ref and a function as a pane’s children need a client component. Put a <Suspense> inside a pane rather than around it. With a Content Security Policy, pass nonce. data-compact is set on hydration, so CSS that follows compact mode from the first paint should use a container query. The Reference has the details.
Without React
Section titled “Without React”The components are a thin wrapper over createSashay, a vanilla DOM controller with no dependencies. Use it directly from another framework or library, or to build your own wrapper. Put one [data-sashay-pane] element per pane in the frame, describe the panes, and call the handle’s methods; when the list of panes changes, call update({ panes }).
import { createSashay } from "@vcarl/sashay";import "@vcarl/sashay/style.css";
const frame = document.querySelector("#vanilla-mail") as HTMLElement;frame.innerHTML = ` <section data-sashay-pane="inbox"><button>Lunch?</button><button>Invoice</button><p></p></section> <section data-sashay-pane="message"></section>`;const [inbox, message] = frame.querySelectorAll("section");const code = inbox.querySelector("p") as HTMLElement;
const sash = createSashay(frame, { panes: [ { id: "inbox", title: "Inbox", focus: 1 / 3 }, { id: "message", title: "Message", focus: 2 / 3 }, ], defaultLayout: [1], // only Inbox open onChange: (layout) => { code.textContent = `Layout: ${layout}`; },});inbox.addEventListener("click", (e) => { const b = (e.target as Element).closest("button"); if (!b) return; message.textContent = `Message: ${b.textContent}`; sash.reveal("message");});The Reference lists the core’s options, its handle and the DOM it expects.