import type { CSSProperties, ReactNode } from 'react'; import { Group, Panel, Separator, type GroupProps, type PanelImperativeHandle, type PanelProps, } from 'react-resizable-panels'; import { GripVertical } from 'lucide-react'; import { cn } from '../utils/cn'; export type SplitDirection = 'horizontal' | 'vertical'; export type SplitProps = { id?: string; className?: string; style?: CSSProperties; children?: ReactNode; /** Disables resizing for every pane in this group. */ disabled?: boolean; /** Layout axis of the group. */ direction?: SplitDirection; /** Disables the library's global cursor treatment during resize interactions. */ disableCursor?: boolean; /** Called after a user finishes changing the panel layout. */ onLayoutChanged?: GroupProps['onLayoutChanged']; /** * Stable id used to key persisted layouts in a future release. Accepted * today for API stability, but layout persistence is not wired up yet. */ autoSaveId?: string; }; function SplitRoot({ direction = 'horizontal', autoSaveId, id, className, disableCursor = true, ...props }: SplitProps) { return ( ); } export type SplitPaneProps = { id?: string; className?: string; style?: CSSProperties; children?: ReactNode; /** Numbers are percentages; strings are passed through, so an explicit * unit (e.g. "200px", "22%") can still be used. */ defaultSize?: number | string; minSize?: number | string; maxSize?: number | string; /** Whether the pane can be collapsed down to `collapsedSize`. */ collapsible?: boolean; collapsedSize?: number | string; onResize?: PanelProps['onResize']; panelRef?: PanelProps['panelRef']; }; export type SplitPaneHandle = PanelImperativeHandle; // react-resizable-panels v4 treats a bare number as pixels and a unitless // string as a percentage. Split.Pane's contract is the opposite — a bare // number means percent, which is the intuitive reading — so numbers are // converted to percentage strings before being handed to `Panel`. Strings // pass through untouched, letting an author opt into explicit units. export function toPanelSize(size: number | string | undefined): number | string | undefined { return typeof size === 'number' ? `${size}%` : size; } function SplitPane({ className, defaultSize, minSize, maxSize, collapsedSize, ...props }: SplitPaneProps) { return ( ); } export type SplitHandleProps = { id?: string; className?: string; style?: CSSProperties; children?: ReactNode; disabled?: boolean; /** Renders an optional grip affordance in the middle of the separator. */ withHandle?: boolean; }; function SplitHandle({ className, withHandle = false, children, ...props }: SplitHandleProps) { return ( {withHandle && (
)} {children}
); } /** A resizable layout group made of panes separated by draggable handles. */ export const Split = /* @__PURE__ */ Object.assign(SplitRoot, { Pane: SplitPane, Handle: SplitHandle, });