(props: SplitPaneProps)
| 45 | * ``` |
| 46 | */ |
| 47 | export 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…