ant-design/components/splitter/style/index.ts
Wanpan 742ce37887
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 d247193722.

* 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

339 lines
8.3 KiB
TypeScript

import type { CSSObject } from '@ant-design/cssinjs';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks } from '../../theme/internal';
export interface ComponentToken {
/**
* @desc 可改变大小标识 元素大小
* @descEN Height of content area
*/
resizeSpinnerSize: number;
/**
* @desc 拖拽标识元素大小
* @descEN Drag the element size
*/
splitBarSize: number;
/**
* @desc 拖拽触发区域大小
* @descEN Drag and drop trigger area size
*/
splitTriggerSize: number;
}
interface SplitterToken extends FullToken<'Splitter'> {}
const genRtlStyle = (token: SplitterToken): CSSObject => {
const { componentCls } = token;
return {
[`&-rtl${componentCls}-horizontal`]: {
[`> ${componentCls}-bar`]: {
[`${componentCls}-bar-collapse-previous`]: {
insetInlineEnd: 0,
insetInlineStart: 'unset',
},
[`${componentCls}-bar-collapse-next`]: {
insetInlineEnd: 'unset',
insetInlineStart: 0,
},
},
},
[`&-rtl${componentCls}-vertical`]: {
[`> ${componentCls}-bar`]: {
[`${componentCls}-bar-collapse-previous`]: {
insetInlineEnd: '50%',
insetInlineStart: 'unset',
},
[`${componentCls}-bar-collapse-next`]: {
insetInlineEnd: '50%',
insetInlineStart: 'unset',
},
},
},
};
};
const centerStyle: CSSObject = {
position: 'absolute',
top: '50%',
left: {
_skip_check_: true,
value: '50%',
},
transform: 'translate(-50%, -50%)',
};
const genSplitterStyle: GenerateStyle<SplitterToken> = (token: SplitterToken): CSSObject => {
const {
componentCls,
colorFill,
resizeSpinnerSize,
splitBarSize,
splitTriggerSize,
controlItemBgHover,
controlItemBgActive,
controlItemBgActiveHover,
} = token;
const splitBarCls = `${componentCls}-bar`;
const halfTriggerSize = token.calc(splitTriggerSize).div(2).equal();
return {
[componentCls]: {
...resetComponent(token),
display: 'flex',
width: '100%',
height: '100%',
alignItems: 'stretch',
// ======================== SplitBar ========================
// Use `>` to avoid conflict with mix layout
[`> ${splitBarCls}`]: {
flex: 'none',
position: 'relative',
userSelect: 'none',
// ======================= Dragger =======================
[`${splitBarCls}-dragger`]: {
...centerStyle,
zIndex: 1,
// Hover background
'&:before': {
content: '""',
background: controlItemBgHover,
...centerStyle,
},
// Spinner
'&:after': {
content: '""',
background: colorFill,
...centerStyle,
},
// Hover
[`&:hover:not(${splitBarCls}-dragger-active)`]: {
'&:before': {
background: controlItemBgActive,
},
},
// Active
'&-active': {
zIndex: 2,
'&:before': {
background: controlItemBgActiveHover,
},
},
// Disabled, not use `pointer-events: none` since still need trigger collapse
[`&-disabled${splitBarCls}-dragger`]: {
zIndex: 0,
'&, &:hover, &-active': {
cursor: 'default',
'&:before': {
background: controlItemBgHover,
},
},
'&:after': {
display: 'none',
},
},
},
// ======================= Collapse =======================
[`${splitBarCls}-collapse-bar`]: {
...centerStyle,
zIndex: 1,
background: controlItemBgHover,
fontSize: token.fontSizeSM,
borderRadius: token.borderRadiusXS,
color: token.colorText,
cursor: 'pointer',
opacity: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
// Hover
'&:hover': {
background: controlItemBgActive,
},
// Active
'&:active': {
background: controlItemBgActiveHover,
},
},
// ======================== Status ========================
// Hover
'&:hover, &:active': {
[`${splitBarCls}-collapse-bar`]: {
opacity: 1,
},
},
},
// =========================== Mask =========================
// Util dom for handle cursor
'&-mask': {
position: 'fixed',
zIndex: token.zIndexPopupBase,
inset: 0,
'&-horizontal': {
cursor: 'col-resize',
},
'&-vertical': {
cursor: 'row-resize',
},
},
// ==========================================================
// == Layout ==
// ==========================================================
'&-horizontal': {
flexDirection: 'row',
[`> ${splitBarCls}`]: {
width: 0,
// ======================= Dragger =======================
[`${splitBarCls}-dragger`]: {
cursor: 'col-resize',
height: '100%',
width: splitTriggerSize,
'&:before': {
height: '100%',
width: splitBarSize,
},
'&:after': {
height: resizeSpinnerSize,
width: splitBarSize,
},
},
// ======================= Collapse =======================
[`${splitBarCls}-collapse-bar`]: {
width: token.fontSizeSM,
height: token.controlHeightSM,
'&-start': {
left: {
_skip_check_: true,
value: 'auto',
},
right: {
_skip_check_: true,
value: halfTriggerSize,
},
transform: 'translateY(-50%)',
},
'&-end': {
left: {
_skip_check_: true,
value: halfTriggerSize,
},
right: {
_skip_check_: true,
value: 'auto',
},
transform: 'translateY(-50%)',
},
},
},
},
'&-vertical': {
flexDirection: 'column',
[`> ${splitBarCls}`]: {
height: 0,
// ======================= Dragger =======================
[`${splitBarCls}-dragger`]: {
cursor: 'row-resize',
width: '100%',
height: splitTriggerSize,
'&:before': {
width: '100%',
height: splitBarSize,
},
'&:after': {
width: resizeSpinnerSize,
height: splitBarSize,
},
},
// ======================= Collapse =======================
[`${splitBarCls}-collapse-bar`]: {
height: token.fontSizeSM,
width: token.controlHeightSM,
'&-start': {
top: 'auto',
bottom: halfTriggerSize,
transform: 'translateX(-50%)',
},
'&-end': {
top: halfTriggerSize,
bottom: 'auto',
transform: 'translateX(-50%)',
},
},
},
},
// ========================= Panels =========================
'&-panel': {
overflow: 'auto',
padding: '0 1px',
scrollbarWidth: 'thin',
boxSizing: 'border-box',
},
'&-panel-hidden': {
padding: 0,
},
...genRtlStyle(token),
},
};
};
export const prepareComponentToken: GetDefaultToken<'Splitter'> = (token) => {
const splitBarSize = token.splitBarSize || 2;
const splitTriggerSize = token.splitTriggerSize || 6;
const resizeSpinnerSize = token.resizeSpinnerSize || 20;
return {
splitBarSize,
splitTriggerSize,
resizeSpinnerSize,
};
};
// ============================== Export ==============================
export default genStyleHooks(
'Splitter',
(token) => [genSplitterStyle(token)],
prepareComponentToken,
);