2023-08-14 19:19:32 +08:00
|
|
|
import type { CSSProperties } from 'react';
|
2023-11-15 14:24:05 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
|
2023-05-25 10:19:56 +08:00
|
|
|
import { resetComponent, resetIcon } from '../../style';
|
2022-07-19 22:53:38 +08:00
|
|
|
import { genCollapseMotion } from '../../style/motion';
|
2023-11-15 14:24:05 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2022-11-23 20:22:38 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-04-25 14:45:26 +08:00
|
|
|
|
2023-08-14 19:19:32 +08:00
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
|
|
|
export interface ComponentToken {
|
|
|
|
// Component token here
|
2023-08-14 20:39:31 +08:00
|
|
|
/**
|
|
|
|
* @desc 折叠面板头部内边距
|
|
|
|
* @descEN Padding of header
|
|
|
|
*/
|
2023-08-14 19:19:32 +08:00
|
|
|
headerPadding: CSSProperties['padding'];
|
2023-08-14 20:39:31 +08:00
|
|
|
/**
|
|
|
|
* @desc 折叠面板头部背景
|
|
|
|
* @descEN Background of header
|
|
|
|
*/
|
2023-08-14 19:19:32 +08:00
|
|
|
headerBg: string;
|
2023-08-14 20:39:31 +08:00
|
|
|
/**
|
|
|
|
* @desc 折叠面板内容内部编辑
|
|
|
|
* @descEN Padding of content
|
|
|
|
*/
|
2023-08-14 19:19:32 +08:00
|
|
|
contentPadding: CSSProperties['padding'];
|
2023-08-14 20:39:31 +08:00
|
|
|
/**
|
|
|
|
* @desc 折叠面板内容背景
|
|
|
|
* @descEN Background of content
|
|
|
|
*/
|
2023-08-14 19:19:32 +08:00
|
|
|
contentBg: string;
|
|
|
|
}
|
2022-10-25 17:04:36 +08:00
|
|
|
|
2022-04-25 14:45:26 +08:00
|
|
|
type CollapseToken = FullToken<'Collapse'> & {
|
2023-01-21 18:45:09 +08:00
|
|
|
collapseHeaderPaddingSM: string;
|
|
|
|
collapseHeaderPaddingLG: string;
|
2022-04-25 14:45:26 +08:00
|
|
|
collapsePanelBorderRadius: number;
|
|
|
|
};
|
|
|
|
|
2022-11-14 15:46:51 +08:00
|
|
|
export const genBaseStyle: GenerateStyle<CollapseToken> = (token) => {
|
2022-04-25 14:45:26 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
2023-08-14 19:19:32 +08:00
|
|
|
contentBg,
|
2022-10-25 17:04:36 +08:00
|
|
|
padding,
|
2023-08-14 19:19:32 +08:00
|
|
|
headerBg,
|
|
|
|
headerPadding,
|
2023-01-21 18:45:09 +08:00
|
|
|
collapseHeaderPaddingSM,
|
|
|
|
collapseHeaderPaddingLG,
|
2022-04-25 14:45:26 +08:00
|
|
|
collapsePanelBorderRadius,
|
|
|
|
|
2022-11-01 15:06:38 +08:00
|
|
|
lineWidth,
|
|
|
|
lineType,
|
2022-04-25 14:45:26 +08:00
|
|
|
colorBorder,
|
|
|
|
colorText,
|
|
|
|
colorTextHeading,
|
|
|
|
colorTextDisabled,
|
2023-01-21 18:45:09 +08:00
|
|
|
fontSizeLG,
|
2022-04-25 14:45:26 +08:00
|
|
|
lineHeight,
|
2023-11-15 14:24:05 +08:00
|
|
|
lineHeightLG,
|
2022-04-25 14:45:26 +08:00
|
|
|
marginSM,
|
|
|
|
paddingSM,
|
2023-01-21 18:45:09 +08:00
|
|
|
paddingLG,
|
2023-05-25 10:19:56 +08:00
|
|
|
paddingXS,
|
2022-05-30 10:20:03 +08:00
|
|
|
motionDurationSlow,
|
2022-07-12 14:32:54 +08:00
|
|
|
fontSizeIcon,
|
2023-08-14 19:19:32 +08:00
|
|
|
contentPadding,
|
2023-11-15 14:24:05 +08:00
|
|
|
fontHeight,
|
|
|
|
fontHeightLG,
|
2022-04-25 14:45:26 +08:00
|
|
|
} = token;
|
|
|
|
|
2023-11-15 14:24:05 +08:00
|
|
|
const borderBase = `${unit(lineWidth)} ${lineType} ${colorBorder}`;
|
2022-04-25 14:45:26 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2023-08-14 19:19:32 +08:00
|
|
|
backgroundColor: headerBg,
|
2022-04-25 14:45:26 +08:00
|
|
|
border: borderBase,
|
|
|
|
borderBottom: 0,
|
2023-11-15 14:24:05 +08:00
|
|
|
borderRadius: collapsePanelBorderRadius,
|
2022-04-25 14:45:26 +08:00
|
|
|
|
|
|
|
[`&-rtl`]: {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`& > ${componentCls}-item`]: {
|
|
|
|
borderBottom: borderBase,
|
|
|
|
[`&:last-child`]: {
|
|
|
|
[`
|
|
|
|
&,
|
2022-05-06 14:02:45 +08:00
|
|
|
& > ${componentCls}-header`]: {
|
2023-11-15 14:24:05 +08:00
|
|
|
borderRadius: `0 0 ${unit(collapsePanelBorderRadius)} ${unit(
|
|
|
|
collapsePanelBorderRadius,
|
|
|
|
)}`,
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`> ${componentCls}-header`]: {
|
|
|
|
position: 'relative', // Compatible with old version of antd, should remove in next version
|
|
|
|
display: 'flex',
|
|
|
|
flexWrap: 'nowrap',
|
|
|
|
alignItems: 'flex-start',
|
2023-08-14 19:19:32 +08:00
|
|
|
padding: headerPadding,
|
2022-04-25 14:45:26 +08:00
|
|
|
color: colorTextHeading,
|
|
|
|
lineHeight,
|
|
|
|
cursor: 'pointer',
|
2022-05-30 10:20:03 +08:00
|
|
|
transition: `all ${motionDurationSlow}, visibility 0s`,
|
2022-04-25 14:45:26 +08:00
|
|
|
|
2022-07-29 15:56:11 +08:00
|
|
|
[`> ${componentCls}-header-text`]: {
|
|
|
|
flex: 'auto',
|
|
|
|
},
|
|
|
|
|
2022-05-30 10:20:03 +08:00
|
|
|
'&:focus': {
|
|
|
|
outline: 'none',
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
|
2022-05-30 10:20:03 +08:00
|
|
|
// >>>>> Arrow
|
|
|
|
[`${componentCls}-expand-icon`]: {
|
2023-11-15 14:24:05 +08:00
|
|
|
height: fontHeight,
|
2022-05-30 10:20:03 +08:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingInlineEnd: marginSM,
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
|
2022-05-30 10:20:03 +08:00
|
|
|
[`${componentCls}-arrow`]: {
|
|
|
|
...resetIcon(),
|
2022-07-12 14:32:54 +08:00
|
|
|
fontSize: fontSizeIcon,
|
2022-05-30 10:20:03 +08:00
|
|
|
|
|
|
|
svg: {
|
|
|
|
transition: `transform ${motionDurationSlow}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Text
|
|
|
|
[`${componentCls}-header-text`]: {
|
|
|
|
marginInlineEnd: 'auto',
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-header-collapsible-only`]: {
|
|
|
|
cursor: 'default',
|
|
|
|
|
|
|
|
[`${componentCls}-header-text`]: {
|
2022-07-29 15:56:11 +08:00
|
|
|
flex: 'none',
|
2022-04-25 14:45:26 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-10-11 20:29:55 +08:00
|
|
|
[`${componentCls}-icon-collapsible-only`]: {
|
|
|
|
cursor: 'default',
|
|
|
|
|
|
|
|
[`${componentCls}-expand-icon`]: {
|
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
},
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
color: colorText,
|
2023-08-14 19:19:32 +08:00
|
|
|
backgroundColor: contentBg,
|
2022-04-25 14:45:26 +08:00
|
|
|
borderTop: borderBase,
|
|
|
|
|
|
|
|
[`& > ${componentCls}-content-box`]: {
|
2023-08-14 19:19:32 +08:00
|
|
|
padding: contentPadding,
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-hidden`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-21 18:45:09 +08:00
|
|
|
[`&-small`]: {
|
|
|
|
[`> ${componentCls}-item`]: {
|
|
|
|
[`> ${componentCls}-header`]: {
|
|
|
|
padding: collapseHeaderPaddingSM,
|
2023-05-25 10:19:56 +08:00
|
|
|
paddingInlineStart: paddingXS,
|
|
|
|
|
|
|
|
[`> ${componentCls}-expand-icon`]: {
|
|
|
|
// Arrow offset
|
2023-11-15 14:24:05 +08:00
|
|
|
marginInlineStart: token.calc(paddingSM).sub(paddingXS).equal(),
|
2023-05-25 10:19:56 +08:00
|
|
|
},
|
2023-01-21 18:45:09 +08:00
|
|
|
},
|
|
|
|
[`> ${componentCls}-content > ${componentCls}-content-box`]: {
|
|
|
|
padding: paddingSM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-large`]: {
|
|
|
|
[`> ${componentCls}-item`]: {
|
|
|
|
fontSize: fontSizeLG,
|
2023-11-15 14:24:05 +08:00
|
|
|
lineHeight: lineHeightLG,
|
2023-01-21 18:45:09 +08:00
|
|
|
[`> ${componentCls}-header`]: {
|
|
|
|
padding: collapseHeaderPaddingLG,
|
2023-05-25 10:19:56 +08:00
|
|
|
paddingInlineStart: padding,
|
2023-01-21 18:45:09 +08:00
|
|
|
|
|
|
|
[`> ${componentCls}-expand-icon`]: {
|
2023-11-15 14:24:05 +08:00
|
|
|
height: fontHeightLG,
|
2023-05-25 10:19:56 +08:00
|
|
|
// Arrow offset
|
2023-11-15 14:24:05 +08:00
|
|
|
marginInlineStart: token.calc(paddingLG).sub(padding).equal(),
|
2023-01-21 18:45:09 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
[`> ${componentCls}-content > ${componentCls}-content-box`]: {
|
|
|
|
padding: paddingLG,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-25 14:45:26 +08:00
|
|
|
[`${componentCls}-item:last-child`]: {
|
|
|
|
[`> ${componentCls}-content`]: {
|
2023-11-15 14:24:05 +08:00
|
|
|
borderRadius: `0 0 ${unit(collapsePanelBorderRadius)} ${unit(collapsePanelBorderRadius)}`,
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`& ${componentCls}-item-disabled > ${componentCls}-header`]: {
|
|
|
|
[`
|
|
|
|
&,
|
|
|
|
& > .arrow
|
|
|
|
`]: {
|
|
|
|
color: colorTextDisabled,
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-30 10:20:03 +08:00
|
|
|
// ========================== Icon Position ==========================
|
|
|
|
[`&${componentCls}-icon-position-end`]: {
|
|
|
|
[`& > ${componentCls}-item`]: {
|
|
|
|
[`> ${componentCls}-header`]: {
|
|
|
|
[`${componentCls}-expand-icon`]: {
|
|
|
|
order: 1,
|
|
|
|
paddingInlineEnd: 0,
|
|
|
|
paddingInlineStart: marginSM,
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-05-06 14:02:45 +08:00
|
|
|
};
|
2022-04-25 14:45:26 +08:00
|
|
|
|
2022-11-14 15:46:51 +08:00
|
|
|
const genArrowStyle: GenerateStyle<CollapseToken> = (token) => {
|
2022-05-30 10:20:03 +08:00
|
|
|
const { componentCls } = token;
|
|
|
|
|
|
|
|
const fixedSelector = `> ${componentCls}-item > ${componentCls}-header ${componentCls}-arrow svg`;
|
|
|
|
|
|
|
|
return {
|
2022-11-14 15:46:51 +08:00
|
|
|
[`${componentCls}-rtl`]: {
|
2022-05-30 10:20:03 +08:00
|
|
|
[fixedSelector]: {
|
|
|
|
transform: `rotate(180deg)`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-14 15:46:51 +08:00
|
|
|
const genBorderlessStyle: GenerateStyle<CollapseToken> = (token) => {
|
2022-04-25 14:45:26 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
2023-08-14 19:19:32 +08:00
|
|
|
headerBg,
|
2022-05-30 10:20:03 +08:00
|
|
|
paddingXXS,
|
2022-04-25 14:45:26 +08:00
|
|
|
|
|
|
|
colorBorder,
|
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-borderless`]: {
|
2023-08-14 19:19:32 +08:00
|
|
|
backgroundColor: headerBg,
|
2022-04-25 14:45:26 +08:00
|
|
|
border: 0,
|
|
|
|
|
|
|
|
[`> ${componentCls}-item`]: {
|
|
|
|
borderBottom: `1px solid ${colorBorder}`,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`
|
|
|
|
> ${componentCls}-item:last-child,
|
|
|
|
> ${componentCls}-item:last-child ${componentCls}-header
|
|
|
|
`]: {
|
|
|
|
borderRadius: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`> ${componentCls}-item:last-child`]: {
|
|
|
|
borderBottom: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`> ${componentCls}-item > ${componentCls}-content`]: {
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
borderTop: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`> ${componentCls}-item > ${componentCls}-content > ${componentCls}-content-box`]: {
|
2022-05-30 10:20:03 +08:00
|
|
|
paddingTop: paddingXXS,
|
2022-04-25 14:45:26 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-05-06 14:02:45 +08:00
|
|
|
};
|
2022-04-25 14:45:26 +08:00
|
|
|
|
2022-11-14 15:46:51 +08:00
|
|
|
const genGhostStyle: GenerateStyle<CollapseToken> = (token) => {
|
2022-08-19 16:53:08 +08:00
|
|
|
const { componentCls, paddingSM } = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-ghost`]: {
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
border: 0,
|
|
|
|
[`> ${componentCls}-item`]: {
|
|
|
|
borderBottom: 0,
|
|
|
|
[`> ${componentCls}-content`]: {
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
border: 0,
|
|
|
|
[`> ${componentCls}-content-box`]: {
|
|
|
|
paddingBlock: paddingSM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-11-15 14:24:05 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Collapse'> = (token) => ({
|
|
|
|
headerPadding: `${token.paddingSM}px ${token.padding}px`,
|
|
|
|
headerBg: token.colorFillAlter,
|
|
|
|
contentPadding: `${token.padding}px 16px`, // Fixed Value
|
|
|
|
contentBg: token.colorBgContainer,
|
|
|
|
});
|
|
|
|
|
2023-08-14 19:19:32 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Collapse',
|
|
|
|
(token) => {
|
|
|
|
const collapseToken = mergeToken<CollapseToken>(token, {
|
2023-11-15 14:24:05 +08:00
|
|
|
collapseHeaderPaddingSM: `${unit(token.paddingXS)} ${unit(token.paddingSM)}`,
|
|
|
|
collapseHeaderPaddingLG: `${unit(token.padding)} ${unit(token.paddingLG)}`,
|
2023-08-14 19:19:32 +08:00
|
|
|
collapsePanelBorderRadius: token.borderRadiusLG,
|
|
|
|
});
|
|
|
|
|
|
|
|
return [
|
|
|
|
genBaseStyle(collapseToken),
|
|
|
|
genBorderlessStyle(collapseToken),
|
|
|
|
genGhostStyle(collapseToken),
|
|
|
|
genArrowStyle(collapseToken),
|
|
|
|
genCollapseMotion(collapseToken),
|
|
|
|
];
|
|
|
|
},
|
2023-11-15 14:24:05 +08:00
|
|
|
prepareComponentToken,
|
2023-08-14 19:19:32 +08:00
|
|
|
);
|