MCPcopy Create free account
hub / github.com/DTStack/molecule / SplitPane

Function SplitPane

src/components/split/SplitPane.tsx:81–327  ·  view source on GitHub ↗
({
    children,
    sizes: propSizes,
    allowResize: propAllowResize = true,
    showSashes = true,
    split = 'vertical',
    className,
    sashClassName,
    paneClassName,
    resizerSize = 4,
    onChange,
    ...restProps
}: ISplitProps)

Source from the content-addressed store, hash-verified

79};
80
81const SplitPane = ({
82 children,
83 sizes: propSizes,
84 allowResize: propAllowResize = true,
85 showSashes = true,
86 split = 'vertical',
87 className,
88 sashClassName,
89 paneClassName,
90 resizerSize = 4,
91 onChange,
92 ...restProps
93}: ISplitProps) => {
94 const axis = useRef<IAxis>({ x: 0, y: 0 });
95 const wrapper = useRef<HTMLDivElement>(null);
96 const [wrapperRect, setWrapperRect] = useState({});
97 const [draging, setDrag] = useState(false);
98
99 useEffect(() => {
100 const resizeObserver = new ResizeObserver(() => {
101 setWrapperRect(wrapper.current!.getBoundingClientRect());
102 });
103 resizeObserver.observe(wrapper.current!);
104 return () => {
105 resizeObserver.disconnect();
106 };
107 }, []);
108
109 // Get some size infos via split
110 const { sizeName, sPos, sAxis } = useMemo(
111 function () {
112 return {
113 sizeName: split === 'vertical' ? 'width' : 'height',
114 sPos: split === 'vertical' ? 'left' : 'top',
115 sAxis: split === 'vertical' ? 'x' : 'y',
116 };
117 },
118 [split]
119 );
120
121 const wrapSize: number = wrapperRect[sizeName] ?? 0;
122
123 // Get limit sizes via children
124 const paneLimitSizes = useMemo(
125 function () {
126 return children.map((childNode) => {
127 const limits = [0, Infinity];
128 if (childNode.type === Pane) {
129 const { minSize, maxSize } =
130 childNode.props as IPaneConfigs;
131 limits[0] = assertsSize(minSize, wrapSize, 0);
132 limits[1] = assertsSize(maxSize, wrapSize);
133 }
134 return limits;
135 });
136 },
137 [children, wrapSize]
138 );

Callers

nothing calls this directly

Calls 3

classNamesFunction · 0.90
cloneReactChildrenFunction · 0.90
assertsSizeFunction · 0.85

Tested by

no test coverage detected