refactor: refactor Popover wireframe token (#45891)

This commit is contained in:
MadCcc 2023-11-15 16:22:46 +08:00 committed by GitHub
parent 038323441c
commit 93dcadbae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,13 +18,13 @@ export interface ComponentToken extends ArrowToken, ArrowOffsetToken {
* @desc * @desc
* @descEN Width of Popover * @descEN Width of Popover
*/ */
width: number; width?: number;
/** /**
* @deprecated Please use `titleMinWidth` instead * @deprecated Please use `titleMinWidth` instead
* @desc * @desc
* @descEN Min width of Popover * @descEN Min width of Popover
*/ */
minWidth: number; minWidth?: number;
/** /**
* @desc * @desc
* @descEN Min width of Popover title * @descEN Min width of Popover title
@ -35,12 +35,21 @@ export interface ComponentToken extends ArrowToken, ArrowOffsetToken {
* @descEN z-index of Popover * @descEN z-index of Popover
*/ */
zIndexPopup: number; zIndexPopup: number;
/** @internal */
innerPadding: number;
/** @internal */
titlePadding: number | string;
/** @internal */
titleMarginBottom: number;
/** @internal */
titleBorderBottom: string;
/** @internal */
innerContentPadding: number | string;
} }
export type PopoverToken = FullToken<'Popover'> & { export type PopoverToken = FullToken<'Popover'> & {
popoverBg: string; popoverBg: string;
popoverColor: string; popoverColor: string;
popoverPadding: number | string;
}; };
const genBaseStyle: GenerateStyle<PopoverToken> = (token) => { const genBaseStyle: GenerateStyle<PopoverToken> = (token) => {
@ -49,14 +58,17 @@ const genBaseStyle: GenerateStyle<PopoverToken> = (token) => {
popoverColor, popoverColor,
titleMinWidth, titleMinWidth,
fontWeightStrong, fontWeightStrong,
popoverPadding, innerPadding,
boxShadowSecondary, boxShadowSecondary,
colorTextHeading, colorTextHeading,
borderRadiusLG: borderRadius, borderRadiusLG,
zIndexPopup, zIndexPopup,
marginXS, titleMarginBottom,
colorBgElevated, colorBgElevated,
popoverBg, popoverBg,
titleBorderBottom,
innerContentPadding,
titlePadding,
} = token; } = token;
return [ return [
@ -94,20 +106,23 @@ const genBaseStyle: GenerateStyle<PopoverToken> = (token) => {
[`${componentCls}-inner`]: { [`${componentCls}-inner`]: {
backgroundColor: popoverBg, backgroundColor: popoverBg,
backgroundClip: 'padding-box', backgroundClip: 'padding-box',
borderRadius, borderRadius: borderRadiusLG,
boxShadow: boxShadowSecondary, boxShadow: boxShadowSecondary,
padding: popoverPadding, padding: innerPadding,
}, },
[`${componentCls}-title`]: { [`${componentCls}-title`]: {
minWidth: titleMinWidth, minWidth: titleMinWidth,
marginBottom: marginXS, marginBottom: titleMarginBottom,
color: colorTextHeading, color: colorTextHeading,
fontWeight: fontWeightStrong, fontWeight: fontWeightStrong,
borderBottom: titleBorderBottom,
padding: titlePadding,
}, },
[`${componentCls}-inner-content`]: { [`${componentCls}-inner-content`]: {
color: popoverColor, color: popoverColor,
padding: innerContentPadding,
}, },
}, },
}, },
@ -152,62 +167,52 @@ const genColorStyle: GenerateStyle<PopoverToken> = (token) => {
}; };
}; };
const genWireframeStyle: GenerateStyle<PopoverToken> = (token) => { export const prepareComponentToken: GetDefaultToken<'Popover'> = (token) => {
const { const {
componentCls,
lineWidth, lineWidth,
controlHeight,
fontHeight,
padding,
wireframe,
zIndexPopupBase,
borderRadiusLG,
marginXS,
lineType, lineType,
colorSplit, colorSplit,
paddingSM, paddingSM,
controlHeight,
fontSize,
lineHeight,
padding,
} = token; } = token;
const titlePaddingBlockDist = controlHeight - Math.round(fontSize * lineHeight); const titlePaddingBlockDist = controlHeight - fontHeight;
const popoverTitlePaddingBlockTop = titlePaddingBlockDist / 2; const popoverTitlePaddingBlockTop = titlePaddingBlockDist / 2;
const popoverTitlePaddingBlockBottom = titlePaddingBlockDist / 2 - lineWidth; const popoverTitlePaddingBlockBottom = titlePaddingBlockDist / 2 - lineWidth;
const popoverPaddingHorizontal = padding; const popoverPaddingHorizontal = padding;
return { return {
[componentCls]: { titleMinWidth: 177,
[`${componentCls}-inner`]: { zIndexPopup: zIndexPopupBase + 30,
padding: 0, ...getArrowToken(token),
}, ...getArrowOffsetToken({
contentRadius: borderRadiusLG,
limitVerticalRadius: true,
}),
[`${componentCls}-title`]: { // internal
margin: 0, innerPadding: wireframe ? 0 : 12,
padding: `${popoverTitlePaddingBlockTop}px ${popoverPaddingHorizontal}px ${popoverTitlePaddingBlockBottom}px`, titleMarginBottom: wireframe ? 0 : marginXS,
borderBottom: `${lineWidth}px ${lineType} ${colorSplit}`, titlePadding: wireframe
}, ? `${popoverTitlePaddingBlockTop}px ${popoverPaddingHorizontal}px ${popoverTitlePaddingBlockBottom}px`
: 0,
[`${componentCls}-inner-content`]: { titleBorderBottom: wireframe ? `${lineWidth}px ${lineType} ${colorSplit}` : 'none',
padding: `${paddingSM}px ${popoverPaddingHorizontal}px`, innerContentPadding: wireframe ? `${paddingSM}px ${popoverPaddingHorizontal}px` : 0,
},
},
}; };
}; };
export const prepareComponentToken: GetDefaultToken<'Popover'> = (token) => ({
width: 177,
minWidth: 177,
titleMinWidth: 177,
zIndexPopup: token.zIndexPopupBase + 30,
...getArrowToken(token),
...getArrowOffsetToken({
contentRadius: token.borderRadiusLG,
limitVerticalRadius: true,
}),
});
export default genComponentStyleHook( export default genComponentStyleHook(
'Popover', 'Popover',
(token) => { (token) => {
const { colorBgElevated, colorText, wireframe } = token; const { colorBgElevated, colorText } = token;
const popoverToken = mergeToken<PopoverToken>(token, { const popoverToken = mergeToken<PopoverToken>(token, {
popoverPadding: 12, // Fixed Value
popoverBg: colorBgElevated, popoverBg: colorBgElevated,
popoverColor: colorText, popoverColor: colorText,
}); });
@ -215,7 +220,6 @@ export default genComponentStyleHook(
return [ return [
genBaseStyle(popoverToken), genBaseStyle(popoverToken),
genColorStyle(popoverToken), genColorStyle(popoverToken),
wireframe && genWireframeStyle(popoverToken),
initZoomMotion(popoverToken, 'zoom-big'), initZoomMotion(popoverToken, 'zoom-big'),
]; ];
}, },