2022-03-25 13:20:42 +08:00
|
|
|
// deps-lint-skip-all
|
2022-05-23 20:34:20 +08:00
|
|
|
import type { FullToken, GenerateStyle, PresetColorType } from '../../_util/theme';
|
2022-06-02 22:15:54 +08:00
|
|
|
import {
|
|
|
|
genComponentStyleHook,
|
|
|
|
mergeToken,
|
|
|
|
PresetColors,
|
|
|
|
resetComponent,
|
|
|
|
getArrowStyle,
|
|
|
|
} from '../../_util/theme';
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
export interface ComponentToken {
|
|
|
|
zIndexPopup: number;
|
|
|
|
width: number;
|
|
|
|
}
|
2022-03-25 13:20:42 +08:00
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
export type PopoverToken = FullToken<'Popover'> & {
|
2022-03-25 13:20:42 +08:00
|
|
|
popoverBg: string;
|
|
|
|
popoverColor: string;
|
2022-04-07 21:50:35 +08:00
|
|
|
popoverPaddingHorizontal: number;
|
2022-05-27 11:07:58 +08:00
|
|
|
popoverTitlePaddingBlockTop: number;
|
|
|
|
popoverTitlePaddingBlockBottom: number;
|
2022-03-25 13:20:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const genBaseStyle: GenerateStyle<PopoverToken> = token => {
|
|
|
|
const {
|
2022-04-07 21:50:35 +08:00
|
|
|
componentCls,
|
2022-03-25 13:20:42 +08:00
|
|
|
popoverBg,
|
|
|
|
popoverColor,
|
2022-05-27 11:07:58 +08:00
|
|
|
width,
|
2022-04-07 21:50:35 +08:00
|
|
|
popoverPaddingHorizontal,
|
2022-05-27 11:07:58 +08:00
|
|
|
popoverTitlePaddingBlockTop,
|
|
|
|
popoverTitlePaddingBlockBottom,
|
|
|
|
lineWidth,
|
|
|
|
lineType,
|
|
|
|
fontWeightStrong,
|
2022-03-25 13:20:42 +08:00
|
|
|
|
|
|
|
boxShadow,
|
|
|
|
colorSplit,
|
|
|
|
colorTextHeading,
|
|
|
|
radiusBase: borderRadius,
|
|
|
|
paddingSM,
|
2022-05-27 11:07:58 +08:00
|
|
|
zIndexPopup,
|
2022-03-25 13:20:42 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2022-03-25 13:20:42 +08:00
|
|
|
position: 'absolute',
|
2022-05-27 11:07:58 +08:00
|
|
|
top: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
zIndex: zIndexPopup,
|
|
|
|
fontWeight: 'normal',
|
|
|
|
whiteSpace: 'normal',
|
|
|
|
textAlign: 'start',
|
|
|
|
cursor: 'auto',
|
|
|
|
userSelect: 'text',
|
|
|
|
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
'&-hidden': {
|
|
|
|
display: 'none',
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
position: 'relative',
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
[`${componentCls}-inner`]: {
|
|
|
|
backgroundColor: popoverBg,
|
|
|
|
backgroundClip: 'padding-box',
|
|
|
|
borderRadius,
|
|
|
|
boxShadow,
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
[`${componentCls}-title`]: {
|
|
|
|
minWidth: width,
|
|
|
|
margin: 0,
|
|
|
|
padding: `${popoverTitlePaddingBlockTop}px ${popoverPaddingHorizontal}px ${popoverTitlePaddingBlockBottom}px`,
|
|
|
|
color: colorTextHeading,
|
|
|
|
fontWeight: fontWeightStrong,
|
|
|
|
borderBottom: `${lineWidth}px ${lineType} ${colorSplit}`,
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
[`${componentCls}-inner-content`]: {
|
|
|
|
padding: `${paddingSM}px ${popoverPaddingHorizontal}px`,
|
|
|
|
color: popoverColor,
|
|
|
|
},
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
// Arrow Style
|
|
|
|
getArrowStyle(token, popoverBg),
|
|
|
|
];
|
2022-03-25 13:20:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const genColorStyle: GenerateStyle<PopoverToken> = token => {
|
2022-04-07 21:50:35 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-25 13:20:42 +08:00
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
return {
|
|
|
|
[componentCls]: PresetColors.map((colorKey: keyof PresetColorType) => {
|
|
|
|
const lightColor = token[`${colorKey}-6`];
|
|
|
|
return {
|
|
|
|
[`&${componentCls}-${colorKey}`]: {
|
|
|
|
[`${componentCls}-inner`]: {
|
2022-03-25 13:20:42 +08:00
|
|
|
backgroundColor: lightColor,
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
[`${componentCls}-arrow`]: {
|
|
|
|
background: 'transparent',
|
|
|
|
|
|
|
|
'&:before': {
|
|
|
|
backgroundColor: lightColor,
|
|
|
|
},
|
|
|
|
},
|
2022-03-25 13:20:42 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
};
|
2022-03-25 13:20:42 +08:00
|
|
|
};
|
|
|
|
|
2022-05-27 11:07:58 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Popover',
|
|
|
|
token => {
|
|
|
|
const { colorBgComponent, controlHeight, fontSize, lineHeight, lineWidth } = token;
|
|
|
|
const titlePaddingBlockDist = controlHeight - Math.round(fontSize * lineHeight);
|
|
|
|
|
|
|
|
const popoverToken = mergeToken<PopoverToken>(token, {
|
|
|
|
popoverBg: colorBgComponent,
|
|
|
|
popoverColor: token.colorText,
|
|
|
|
popoverTitlePaddingBlockTop: titlePaddingBlockDist / 2,
|
|
|
|
popoverTitlePaddingBlockBottom: titlePaddingBlockDist / 2 - lineWidth,
|
|
|
|
popoverPaddingHorizontal: token.padding,
|
|
|
|
});
|
|
|
|
|
|
|
|
return [genBaseStyle(popoverToken), genColorStyle(popoverToken)];
|
|
|
|
},
|
|
|
|
({ zIndexPopupBase }) => ({
|
|
|
|
zIndexPopup: zIndexPopupBase + 30,
|
|
|
|
width: 177,
|
|
|
|
}),
|
|
|
|
);
|