Command palette

@yasinsensoy/web

Web · Components

ResizablePanels

Panels resized by dragging: layouts like sidebar + list + preview, code/output splits.

6 exports

Live example

Preview

  • Ayşe YılmazSprint planI added the agenda for tomorrow's meeting.
  • Mehmet KayaInvoice #2041The October invoice is attached.
  • Zeynep DemirDesign feedbackThe new dashboard design is great.
  • Can ÖztürkServer maintenanceShort outage on Saturday at 02:00.
  • Elif ŞahinLunch?Shall we go to the new place today?

Sprint plan

Ayşe Yılmaz · 09:42

Hi team, I added the agenda for tomorrow's meeting. You can resize the panels by dragging, double clicking the handle, or focusing it with Tab and using the arrow keys.

Code

import { ResizablePanels, Folders, Mesajlar, Mesaj } from "@yasinsensoy/web";

<ResizablePanels className="h-96 rounded-lg border" storageKey="playground-mail"
  panels={[
    {
      id: "folders",
      label: "Folders",
      defaultSize: 22,
      minSize: "180px",
      maxSize: 35,
      collapsible: true,
      collapsedSize: "56px",
      content: ({ collapsed }) => <Folders kompakt={collapsed} />,
    },
    { id: "list", label: "Mesajlar", defaultSize: 33, minSize: 20, content: <Mesajlar /> },
    { id: "okuma", minSize: 20, content: <Mesaj /> },
  ]}
/>

Events

  1. Events appear here when you interact with the preview.

A sidebar collapsed with a button (controlled collapsed)

Content

Nested: files | code / terminal

  • src/
  • app.tsx
  • index.css
  • package.json
export function App() {
  return <h1>Merhaba</h1>;
}
$ pnpm dev
✓ Ready in 812ms

Three equal panels, overflow when they hit the limit

A
B
C

Import

import { ResizablePanels } from "@yasinsensoy/web";

ResizablePanels

componentClient component

Panels resized by dragging: layouts like sidebar + list + preview, code/output splits. No external library.

  • Dragged with mouse, touch and pen; the grab area is wide on touch.
  • Keyboard: reach the handle with Tab; arrow keys move it (Shift for fine adjustment), Home/End min/max, Enter collapses/expands.
  • Double-clicking the handle collapses/expands a collapsible panel; if there is none, the two panels return to their initial sizes.
  • When a panel hits its limit, shrinking carries over to the next panels.
  • Limits can be percentages or pixels (minSize: "240px"); pixel limits are kept as the window narrows.
  • With storageKey the layout is stored and comes back on load without a jump.
  • Panels can be nested (a panel's content is another ResizablePanels).

Client component.

ResizablePanels({ panels, orientation, sizes: sizesProp, onSizesChange, onResizeEnd, storageKey, handle, keyboardStep, disabled, classNames, nonce, className, style, ...props }: ResizablePanelsProps): JSX.Element

Examples

<ResizablePanels
  className="h-[600px] rounded-lg border"
  storageKey="mail"
  panels={[
    {
      id: "menu",
      label: "Folders",
      defaultSize: 20,
      minSize: "180px",
      maxSize: 30,
      collapsible: true,
      collapsedSize: "56px",
      content: ({ collapsed }) => <Folders compact={collapsed} />,
    },
    { id: "list", label: "Messages", defaultSize: 35, minSize: 25, content: <Messages /> },
    { id: "reading", content: <Message /> },
  ]}
/>

// Stacked: code and output
<ResizablePanels
  orientation="vertical"
  className="h-96"
  panels={[{ content: <Code /> }, { content: <Output />, minSize: 15, collapsible: true }]}
/>

Panel size: a number is a percentage of the container (25 = 25%); a string can be pixels ("240px") or a percentage ("25%").

type PanelSize = number | `${number}%` | `${number}px`

State received when a function is given as panel content.

NameTypeDescription
collapsedbooleanWhether the panel is collapsed.
sizenumberPercentage of the container the panel takes.

A panel inside ResizablePanels.

NameTypeDefaultDescription
id?stringPersistent id of the panel. Used to find which layout to use when the layout is stored with storageKey and when the panel list changes (e.g. when the preview panel is hidden). If omitted, its index is used.
content?ReactNode | ((state: ResizablePanelState) => ReactNode)Content of the panel. To show a different view when collapsed (e.g. icons only) pass a function: ({ collapsed }) => collapsed ? <Icons /> : <Menu />. A function can only be passed from client components.
defaultSize?numberInitial size, as a percentage of the container. Panels without one share the remaining space equally.
minSize?PanelSize0Minimum size: percentage (20) or pixels ("240px"). A pixel limit is kept as the window resizes.
maxSize?PanelSize100Maximum size: percentage or pixels.
collapsible?booleanCollapsible. When shrunk past half of minSize it closes to collapsedSize; pulling back opens it. Double-clicking the handle or pressing Enter while focused also collapses/expands.
collapsedSize?PanelSize0Size left while collapsed (e.g. "56px" for an icon strip).
defaultCollapsed?booleanThe panel starts collapsed.
collapsed?booleanCollapsed state (controlled). When changed, the panel smoothly collapses or opens to its last size. Collapsing by the user is reported with onCollapsedChange.
onCollapsedChange?(collapsed: boolean) => voidCalled when the panel is collapsed/expanded by the user or by collapsed.
label?stringName of the panel; becomes the accessible name of the following handle (e.g. "Sidebar"). The screen reader reads "Sidebar, separator, 25%". The panel itself is also announced as a group with this name; if the content overflows the panel can be focused with Tab and scrolled with arrow keys.
className?stringClasses added to the panel box.

Classes that can be passed to the inner parts of ResizablePanels.

NameTypeDescription
panel?stringEach panel box.
handle?stringEach handle between panels.

Props of the ResizablePanels component.

Extends: Omit<ComponentProps<"div">, "children" | "onChange" | "defaultValue">

NameTypeDefaultDescription
panelsreadonly ResizablePanel[]Panels, from left to right (top to bottom when vertical).
orientation?"horizontal" | "vertical""horizontal"horizontal: panels side by side, the handle is a vertical line. vertical: panels stacked; the container needs a height (e.g. h-96).
sizes?readonly number[]Sizes (controlled), percentage per panel; sum is 100. While dragging, onSizesChange is called every frame.
onSizesChange?(sizes: number[]) => voidCalled whenever sizes change (every frame while dragging).
onResizeEnd?(sizes: number[]) => voidCalled once with the final sizes when dragging ends, or after a change by keyboard or collapsing. Use it to store the layout on the server (e.g. in a cookie) and give it back as defaultSize on the next render.
storageKey?stringIf given, the layout is stored in the browser (localStorage) under this name and restored when the page reopens. A small script is added to the server output; stored sizes are applied before the page paints, so there is no jump on load. Only applies in uncontrolled use.
handle?"line" | "grip""line"Look of the handle. line: thin line, more visible on hover. grip: a grip knob in the middle. On touch screens the knob is always visible and the grab area widens.
keyboardStep?number5How many percent the focused handle moves with arrow keys. Shift gives a fine 1 percent adjustment.
disabled?booleanSizes can't be changed; handles stay only as lines.
classNames?ResizablePanelsClassNamesClasses for inner parts.
nonce?stringnonce of the inline script if a Content Security Policy (CSP) is used.