Panels
An app shell: the page in the middle, with resizable panels on the left, the right and along the bottom, toggled from their headers or with ⌘B, ⌘I and ⌘J. On a phone the side panels open as sheets.
Installation
npx shadcn@latest add "@aiellie/panels"shadcn needs the @aiellie registry in components.json first. npx aiellie add panels adds it on its first run, then installs the same way.
Panels lays a page out like an editor: the main content in the middle, with optional panels on the left, the right and along the bottom. Each one resizes by dragging its edge, opens and closes from a toggle in a header or with ⌘B, ⌘I and ⌘J, and animates as it goes. On a phone the side panels become sheets, and the bottom one stays a panel.
Getting started
Give it a height and its panels
Pass each panel as a prop and the main content as children. A panel left out gets no toggle and no shortcut. It fills its parent, so the parent needs a height.
app/workspace/page.tsximport { Panels } from "@/components/ui/panels" export default function Workspace() { return ( <Panels className="h-svh" left={<ChatList />} right={<Details />} bottom={<Terminal />} defaultOpen={{ left: true }} > <Thread /> </Panels> ) }Open a panel from inside
usePanelsreaches the layout from anything rendered in it: whether a panel is open, a toggle, and a way to close the sheet on a phone after choosing something in it.const { isOpen, toggle, closeSheet } = usePanels() <Button onClick={() => toggle("right")}>Details</Button>
Anatomy
<div data-slot="resizable-panel-group"> {/* a row: left, the middle column, right */}
<div data-slot="resizable-panel"> {/* left */}
<header /> {/* its header: name or headers.left, and its toggle */}
{left}
</div>
<div data-slot="resizable-handle" />
<div data-slot="resizable-panel-group"> {/* a column: main over bottom */}
<div data-slot="resizable-panel">
<header /> {/* headers.main, with the toggles of closed panels */}
{children}
</div>
<div data-slot="resizable-handle" />
<div data-slot="resizable-panel"> {/* bottom */}
<header />
{bottom}
</div>
</div>
<div data-slot="resizable-handle" />
<div data-slot="resizable-panel"> {/* right */}
<header />
{right}
</div>
</div>Every header is 40px with a rule under it. A panel's toggle sits in its own header while it's open, and moves to the main header while it's closed, so there is always a way back. The left panel starts at 18rem (12rem to 28rem), the right at 24rem (16rem to 42rem), and the bottom at 16rem (8rem to 70%).
A closed panel collapses rather than unmounting, so its contents keep their state and the other panels keep their sizes. The shortcuts are ⌘ or Ctrl with B, I and J, and only bind for the panels you passed.
Examples
Toggle from the content
A button in the main content opens the right panel through usePanels.
Custom headers
headers replaces a header's name with anything, headerBorder drops the rule under one, and toggleAt moves a panel's toggle to the start of its header.
Content under a glass header
glassHeader lays the main header over the content, so it scrolls under it. The content then pads its own top by 40px.
<Panels glassHeader left={<ChatList />}>
<div className="h-full overflow-y-auto pt-10">{messages}</div>
</Panels>API reference
Panels
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | required | The main content. |
left / right / bottom | ReactNode | Each panel's content. A panel left out isn't rendered and has no toggle. | |
defaultOpen | { left?, right?, bottom?: boolean } | { left: true } | Which panels start open. |
headers | { left?, right?, bottom?, main?: ReactNode } | What each header shows in place of the panel's name. | |
headerBorder | { left?, right?, bottom?, main?: boolean } | all true | Which headers keep the rule under them. |
glassHeader | boolean | false | Lays the main header over its content, which must pad its own top 40px. |
toggleAt | { left?, right?, bottom?: "start" | "end" } | all "end" | Which end of its header a panel's toggle sits at. |
className | string | Merged onto the outer group. |
usePanels
| Field | Type | Description |
|---|---|---|
isOpen | (side: "left" | "right" | "bottom") => boolean | Whether a panel is open, or on a phone, whether its sheet is up. |
toggle | (side) => void | Opens or closes a panel. |
closeSheet | () => void | Closes a side panel's sheet on a phone. Does nothing on a wide screen. |
It throws outside Panels.