|
| 1 | +import { Meta, StoryObj } from "@storybook/react"; |
| 2 | +import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; |
| 3 | + |
| 4 | +// Reusable styling for a `react-resizable-panels` resize handle. |
| 5 | +// See ResizeHandle.mdx for the full documentation. |
| 6 | +const meta: Meta = { |
| 7 | + title: "Components/ResizeHandle", |
| 8 | +}; |
| 9 | + |
| 10 | +export default meta; |
| 11 | + |
| 12 | +const panelStyle: React.CSSProperties = { |
| 13 | + display: "flex", |
| 14 | + alignItems: "center", |
| 15 | + justifyContent: "center", |
| 16 | + background: "var(--c--contextuals--background--surface--secondary)", |
| 17 | + color: "var(--c--contextuals--content--semantic--neutral--primary)", |
| 18 | +}; |
| 19 | + |
| 20 | +const frameStyle: React.CSSProperties = { |
| 21 | + height: 240, |
| 22 | + width: 480, |
| 23 | + border: "1px solid var(--c--contextuals--border--surface--primary)", |
| 24 | +}; |
| 25 | + |
| 26 | +// --- Vertical handle: panels laid out side by side (drag left/right) --- |
| 27 | +export const Interactive: StoryObj = { |
| 28 | + render: () => ( |
| 29 | + <div style={frameStyle}> |
| 30 | + <PanelGroup direction="horizontal"> |
| 31 | + <Panel defaultSize={50} minSize={20}> |
| 32 | + <div style={panelStyle}>Left</div> |
| 33 | + </Panel> |
| 34 | + <PanelResizeHandle className="c__resize-handle c__resize-handle--interactive" /> |
| 35 | + <Panel minSize={20}> |
| 36 | + <div style={panelStyle}>Right</div> |
| 37 | + </Panel> |
| 38 | + </PanelGroup> |
| 39 | + </div> |
| 40 | + ), |
| 41 | +}; |
| 42 | + |
| 43 | +// --- Horizontal handle: stacked panels (drag up/down) --- |
| 44 | +export const InteractiveVertical: StoryObj = { |
| 45 | + render: () => ( |
| 46 | + <div style={frameStyle}> |
| 47 | + <PanelGroup direction="vertical"> |
| 48 | + <Panel defaultSize={50} minSize={20}> |
| 49 | + <div style={panelStyle}>Top</div> |
| 50 | + </Panel> |
| 51 | + <PanelResizeHandle className="c__resize-handle c__resize-handle--interactive" /> |
| 52 | + <Panel minSize={20}> |
| 53 | + <div style={panelStyle}>Bottom</div> |
| 54 | + </Panel> |
| 55 | + </PanelGroup> |
| 56 | + </div> |
| 57 | + ), |
| 58 | +}; |
| 59 | + |
| 60 | +// --- Static line: no hover affordance (resizing disabled) --- |
| 61 | +export const Static: StoryObj = { |
| 62 | + render: () => ( |
| 63 | + <div style={frameStyle}> |
| 64 | + <PanelGroup direction="horizontal"> |
| 65 | + <Panel defaultSize={50}> |
| 66 | + <div style={panelStyle}>Left</div> |
| 67 | + </Panel> |
| 68 | + <PanelResizeHandle className="c__resize-handle" disabled /> |
| 69 | + <Panel> |
| 70 | + <div style={panelStyle}>Right</div> |
| 71 | + </Panel> |
| 72 | + </PanelGroup> |
| 73 | + </div> |
| 74 | + ), |
| 75 | +}; |
0 commit comments