MCPcopy
hub / github.com/tomkp/react-split-pane / SplitPane

Function SplitPane

src/components/SplitPane.tsx:47–417  ·  view source on GitHub ↗
(props: SplitPaneProps)

Source from the content-addressed store, hash-verified

45 * ```
46 */
47export function SplitPane(props: SplitPaneProps) {
48 const {
49 direction = 'horizontal',
50 resizable = true,
51 snapPoints,
52 snapTolerance = 10,
53 step,
54 onResizeStart,
55 onResize,
56 onResizeEnd,
57 className,
58 style,
59 divider: CustomDivider,
60 dividerStyle,
61 dividerClassName,
62 dividerSize = 1,
63 children,
64 } = props;
65
66 const containerRef = useRef<HTMLDivElement>(null);
67 const [containerSize, setContainerSize] = useState(0);
68 const prevContainerSizeRef = useRef(0);
69
70 // Extract pane configuration from children - memoized to avoid recreating on every render
71 const paneConfigs = useMemo(() => {
72 const paneElements = Children.toArray(children).filter(
73 (child): child is ReactElement<PaneProps> =>
74 typeof child === 'object' && child !== null && 'props' in child
75 );
76
77 return paneElements.map((pane) => ({
78 props: pane.props,
79 size: pane.props.size,
80 defaultSize: pane.props.defaultSize,
81 minSize: pane.props.minSize ?? 0,
82 maxSize: pane.props.maxSize ?? Infinity,
83 }));
84 }, [children]);
85
86 const paneCount = paneConfigs.length;
87 const warnedRef = useRef(false);
88
89 // Warn once if fewer than 2 panes
90 if (paneCount < MIN_PANES && !warnedRef.current) {
91 warnedRef.current = true;
92 console.warn(
93 `SplitPane requires at least ${MIN_PANES} Pane children. Received ${paneCount}.`
94 );
95 }
96
97 // Calculate min/max sizes from pane configs
98 const { minSizes, maxSizes } = useMemo(() => {
99 if (containerSize === 0) {
100 return {
101 minSizes: new Array(paneCount).fill(0),
102 maxSizes: new Array(paneCount).fill(Infinity),
103 };
104 }

Callers

nothing calls this directly

Calls 9

observeMethod · 0.95
disconnectMethod · 0.95
convertToPixelsFunction · 0.90
distributeSizesFunction · 0.90
useResizerFunction · 0.90
useKeyboardResizeFunction · 0.90
cnFunction · 0.90
updateSizeFromRectFunction · 0.85
renderChildrenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…