GitHub

Resizable

Resizable panel groups and panels for building flexible layouts.

Basic Usage

Loading...
Resizable PanelsDrag handles to resize panels

Installation

pnpm add @corew500/ui

Usage

import {
  ResizablePanelGroup,
  ResizablePanel,
  ResizableHandle,
} from "@mordecai-design-system/ui"
<ResizablePanelGroup direction="horizontal">
  <ResizablePanel>Panel 1</ResizablePanel>
  <ResizableHandle />
  <ResizablePanel>Panel 2</ResizablePanel>
</ResizablePanelGroup>

Examples

Horizontal Layout

<ResizablePanelGroup direction="horizontal" className="min-h-[200px]">
  <ResizablePanel defaultSize={25}>
    <Sidebar />
  </ResizablePanel>
  <ResizableHandle />
  <ResizablePanel defaultSize={75}>
    <Content />
  </ResizablePanel>
</ResizablePanelGroup>

Vertical Layout

<ResizablePanelGroup direction="vertical" className="min-h-[400px]">
  <ResizablePanel defaultSize={30}>
    <Header />
  </ResizablePanel>
  <ResizableHandle />
  <ResizablePanel defaultSize={70}>
    <Content />
  </ResizablePanel>
</ResizablePanelGroup>

Three Panels

<ResizablePanelGroup direction="horizontal">
  <ResizablePanel defaultSize={20} minSize={15}>
    <Navigation />
  </ResizablePanel>
  <ResizableHandle />
  <ResizablePanel defaultSize={60}>
    <Editor />
  </ResizablePanel>
  <ResizableHandle />
  <ResizablePanel defaultSize={20} minSize={15}>
    <Properties />
  </ResizablePanel>
</ResizablePanelGroup>

With Handle Indicator

<ResizablePanelGroup direction="horizontal">
  <ResizablePanel>Left</ResizablePanel>
  <ResizableHandle withHandle />
  <ResizablePanel>Right</ResizablePanel>
</ResizablePanelGroup>

Nested Panels

<ResizablePanelGroup direction="horizontal">
  <ResizablePanel defaultSize={25}>
    <Sidebar />
  </ResizablePanel>
  <ResizableHandle />
  <ResizablePanel>
    <ResizablePanelGroup direction="vertical">
      <ResizablePanel defaultSize={70}>
        <Editor />
      </ResizablePanel>
      <ResizableHandle />
      <ResizablePanel defaultSize={30}>
        <Terminal />
      </ResizablePanel>
    </ResizablePanelGroup>
  </ResizablePanel>
</ResizablePanelGroup>

Props

ResizablePanelGroup

PropTypeDefaultDescription
defaultLayoutLayoutDefault layout for the Group. ℹ️ This value allows layouts to be remembered between page reloads. ⚠️ Refer to the documentation for how to avoid layout shift when using server components.
disableCursorenumThis library sets custom mouse cursor styles to indicate drag state. Use this prop to disable that behavior for Panels and Separators in this group.
disabledenumDisable resize functionality.
elementRefenumRef attached to the root `HTMLDivElement`.
groupRefenumExposes the following imperative API: - `getLayout(): Layout` - `setLayout(layout: Layout): void` ℹ️ The `useGroupRef` and `useGroupCallbackRef` hooks are exported for convenience use in TypeScript projects.
onLayoutChange(layout: Layout) => voidCalled when the Group's layout is changing. ⚠️ For layout changes caused by pointer events, this method is called each time the pointer is moved. For most cases, it is recommended to use the `onLayoutChanged` callback instead.
onLayoutChanged(layout: Layout) => voidCalled after the Group's layout has been changed. ℹ️ For layout changes caused by pointer events, this method is not called until the pointer has been released. This method is recommended when saving layouts to some storage api.
orientationenumSpecifies the resizable orientation ("horizontal" or "vertical"); defaults to "horizontal"

ResizablePanel

PropTypeDefaultDescription
collapsedSizeenumPanel size when collapsed; defaults to 0%.
collapsibleenumThis panel can be collapsed. ℹ️ A collapsible panel will collapse when it's size is less than of the specified `minSize`
defaultSizeenumDefault size of Panel within its parent group; default is auto-assigned based on the total number of Panels.
elementRefenumRef attached to the root `HTMLDivElement`.
maxSizeenumMaximum size of Panel within its parent group; defaults to 100%.
minSizeenumMinimum size of Panel within its parent group; defaults to 0%.
onResize(panelSize: PanelSize, id: string | number, prevPanelSize: PanelSize) => voidCalled when panel sizes change. @param panelSize Panel size (both as a percentage of the parent Group and in pixels) @param id Panel id (if one was provided as a prop) @param prevPanelSize Previous panel size (will be undefined on mount)
panelRefenumExposes the following imperative API: - `collapse(): void` - `expand(): void` - `getSize(): number` - `isCollapsed(): boolean` - `resize(size: number): void` ℹ️ The `usePanelRef` and `usePanelCallbackRef` hooks are exported for convenience use in TypeScript projects.

ResizableHandle

PropTypeDefaultDescription
elementRefenumRef attached to the root `HTMLDivElement`.
withHandleenum