ant-design/components/splitter/Splitter.tsx

218 lines
6.9 KiB
TypeScript
Raw Permalink Normal View History

feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
/* eslint-disable react/no-array-index-key */
import React, { useState } from 'react';
import classNames from 'classnames';
import ResizeObserver from 'rc-resize-observer';
import useEvent from 'rc-util/lib/hooks/useEvent';
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
import type { GetProp } from '../_util/type';
import { devUseWarning } from '../_util/warning';
import { ConfigContext } from '../config-provider';
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
import useItems from './hooks/useItems';
import useResizable from './hooks/useResizable';
import useResize from './hooks/useResize';
import useSizes from './hooks/useSizes';
import type { SplitterProps } from './interface';
import { InternalPanel } from './Panel';
import SplitBar from './SplitBar';
import useStyle from './style';
const Splitter: React.FC<React.PropsWithChildren<SplitterProps>> = (props) => {
const {
prefixCls: customizePrefixCls,
className,
style,
layout = 'horizontal',
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
children,
rootClassName,
onResizeStart,
onResize,
onResizeEnd,
} = props;
const { getPrefixCls, direction, splitter } = React.useContext(ConfigContext);
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
const prefixCls = getPrefixCls('splitter', customizePrefixCls);
const rootCls = useCSSVarCls(prefixCls);
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
// ======================== Direct ========================
const isVertical = layout === 'vertical';
const isRTL = direction === 'rtl';
const reverse = !isVertical && isRTL;
// ====================== Items Data ======================
const items = useItems(children);
// >>> Warning for uncontrolled
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning('Splitter');
let existSize = false;
let existUndefinedSize = false;
items.forEach((item) => {
if (item.size !== undefined) {
existSize = true;
} else {
existUndefinedSize = true;
}
});
if (existSize && existUndefinedSize && !onResize) {
warning(
false,
'usage',
'When part of `Splitter.Panel` has `size`, `onResize` is required or change `size` to `defaultSize`.',
);
}
}
// ====================== Container =======================
const [containerSize, setContainerSize] = useState<number | undefined>();
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
const onContainerResize: GetProp<typeof ResizeObserver, 'onResize'> = (size) => {
const { offsetWidth, offsetHeight } = size;
const containerSize = isVertical ? offsetHeight : offsetWidth;
// Skip when container has no size, Such as nested in a hidden tab panel
// to fix: https://github.com/ant-design/ant-design/issues/51106
if (containerSize === 0) {
return;
}
setContainerSize(containerSize);
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
};
// ========================= Size =========================
const [panelSizes, itemPxSizes, itemPtgSizes, itemPtgMinSizes, itemPtgMaxSizes, updateSizes] =
useSizes(items, containerSize);
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
// ====================== Resizable =======================
const resizableInfos = useResizable(items, itemPxSizes);
const [onOffsetStart, onOffsetUpdate, onOffsetEnd, onCollapse, movingIndex] = useResize(
items,
resizableInfos,
itemPtgSizes,
containerSize,
updateSizes,
);
// ======================== Events ========================
const onInternalResizeStart = useEvent((index: number) => {
onOffsetStart(index);
onResizeStart?.(itemPxSizes);
});
const onInternalResizeUpdate = useEvent((index: number, offset: number) => {
const nextSizes = onOffsetUpdate(index, offset);
onResize?.(nextSizes);
});
const onInternalResizeEnd = useEvent(() => {
onOffsetEnd();
onResizeEnd?.(itemPxSizes);
});
const onInternalCollapse = useEvent((index: number, type: 'start' | 'end') => {
const nextSizes = onCollapse(index, type);
onResize?.(nextSizes);
onResizeEnd?.(nextSizes);
});
// ======================== Styles ========================
const containerClassName = classNames(
prefixCls,
className,
`${prefixCls}-${layout}`,
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
{
[`${prefixCls}-rtl`]: isRTL,
},
rootClassName,
splitter?.className,
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
cssVarCls,
rootCls,
hashId,
);
// ======================== Render ========================
const maskCls = `${prefixCls}-mask`;
const stackSizes = React.useMemo(() => {
const mergedSizes: number[] = [];
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
let stack = 0;
for (let i = 0; i < items.length; i += 1) {
stack += itemPtgSizes[i];
mergedSizes.push(stack);
}
return mergedSizes;
}, [itemPtgSizes]);
const mergedStyle: React.CSSProperties = { ...splitter?.style, ...style };
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
return wrapCSSVar(
<ResizeObserver onResize={onContainerResize}>
<div style={mergedStyle} className={containerClassName}>
{items.map((item, idx) => {
// Panel
const panel = <InternalPanel {...item} prefixCls={prefixCls} size={panelSizes[idx]} />;
// Split Bar
let splitBar: React.ReactElement | null = null;
const resizableInfo = resizableInfos[idx];
if (resizableInfo) {
const ariaMinStart = (stackSizes[idx - 1] || 0) + itemPtgMinSizes[idx];
const ariaMinEnd = (stackSizes[idx + 1] || 100) - itemPtgMaxSizes[idx + 1];
const ariaMaxStart = (stackSizes[idx - 1] || 0) + itemPtgMaxSizes[idx];
const ariaMaxEnd = (stackSizes[idx + 1] || 100) - itemPtgMinSizes[idx + 1];
splitBar = (
<SplitBar
index={idx}
active={movingIndex === idx}
prefixCls={prefixCls}
vertical={isVertical}
resizable={resizableInfo.resizable}
ariaNow={stackSizes[idx] * 100}
ariaMin={Math.max(ariaMinStart, ariaMinEnd) * 100}
ariaMax={Math.min(ariaMaxStart, ariaMaxEnd) * 100}
startCollapsible={resizableInfo.startCollapsible}
endCollapsible={resizableInfo.endCollapsible}
onOffsetStart={onInternalResizeStart}
onOffsetUpdate={(index, offsetX, offsetY) => {
let offset = isVertical ? offsetY : offsetX;
if (reverse) {
offset = -offset;
}
onInternalResizeUpdate(index, offset);
}}
onOffsetEnd={onInternalResizeEnd}
onCollapse={onInternalCollapse}
/>
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
);
}
return (
<React.Fragment key={`split-panel-${idx}`}>
{panel}
{splitBar}
</React.Fragment>
);
})}
{/* Fake mask for cursor */}
{typeof movingIndex === 'number' && (
<div aria-hidden className={classNames(maskCls, `${maskCls}-${layout}`)} />
)}
</div>
</ResizeObserver>,
feat:🔥New Component: Splitter (#50038) * feat: SplitPanel init * feat: SplitPanel update * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel update useResize * feat: SplitPanel update * feat: splitPanel demo * feat: splitPanel update * feat: splitPanel support complicated combination * feat: SplitPanel rename to Splitter * feat: Splitter support onRize * feat: support collapsible * feat: support token and collapsible * feat: update docs * feat: size defaultSize support string * feat: min max support string * feat: update * feat: support DOM structure * feat: Optimize UI * feat: Optimize Code * fix: Add a default size during initialization to prevent failure to obtain container size * feat: optimized code * feat: optimized code * feat: Optimize Code * Update components/splitter/demo/layout.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * Update components/splitter/demo/multiple.tsx Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: Wanpan <wanpan96@163.com> * docs: update * feat: Modify the style and optimize the interface * feat: use PropsWithChildren * feat: support rtl * feat: collapsible supports object types * fix: when collapsible is boolean not work * feat: Splitter add test * feat: update * test: update snapshots * docs: update * test: update snapshots * test: update * test: update * test: update * test: update * fix: Removed invalid min and max restrictions when collapsible exists * test: update * test: update * test: update * test: test coverage * Revert "test: test coverage" This reverts commit d247193722b5736df92b3f33d93b475eb1df9eff. * test: test coverage * feat: rename * feat: optimized code * ci: lint * feat: optimized code * feat: add useag tips * feat: optimized code * feat: Modify splitbar layout * feat: optimized code * feat: numerical precision * feat: optimized code * feat: Optimized trigger region * feat: Support configuration animation * fix: Fix Collapsible exception when using multiple panels * fix: Fixed the issue of drag area overlapping when multiple panels are folded * feat: optimized code * feat: annotation * feAt: optimized code * fix: bgcolor * fix: Modify the initial value calculation method * test: update * feat: add cover image * chore: adjust logic * chore: use items size * chore: rtl * chore: limit * chore: controlled * docs: update demo * docs: adjust style * chore: add split style * chore: hor collapisble style * chore: collapse icon * chore: update warning * chore: clean up * chore: collapse logic * chore: adjust demo * chore: clean up * test: adjust logic * docs: update demo * docs: rm useless demo * docs: demo * test: add demo test * test: test of them * test: 100% coverage * chore: fix lint * docs: update demo * refactor: unique resize config * docs: add demo * fix: support virtual resiable * chore: add cursor mask * test: update snapshot * test: add test case * test: update snapshot * chore: use px base * chore: rm useless code --------- Signed-off-by: Wanpan <wanpan96@163.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: ice <49827327+coding-ice@users.noreply.github.com>
2024-09-09 19:23:25 +08:00
);
};
if (process.env.NODE_ENV !== 'production') {
Splitter.displayName = 'Splitter';
}
export default Splitter;