2022-06-21 00:34:51 +08:00
|
|
|
import { initZoomMotion } from '../../style/motion';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle, PresetColorType } from '../../theme';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { genComponentStyleHook, mergeToken, PresetColors } from '../../theme';
|
|
|
|
import { resetComponent } from '../../style';
|
|
|
|
import getArrowStyle from '../../style/placementArrow';
|
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
|
2022-06-24 10:45:29 +08:00
|
|
|
getArrowStyle(token, token.colorBgElevated),
|
2022-07-14 12:06:18 +08:00
|
|
|
|
|
|
|
// Pure Render
|
|
|
|
{
|
|
|
|
[`${componentCls}-pure`]: {
|
|
|
|
position: 'relative',
|
|
|
|
maxWidth: 'none',
|
|
|
|
|
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
display: 'inline-block',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
];
|
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 => {
|
2022-06-17 18:47:47 +08:00
|
|
|
const { controlHeight, fontSize, lineHeight, lineWidth, colorBgElevated } = token;
|
2022-05-27 11:07:58 +08:00
|
|
|
const titlePaddingBlockDist = controlHeight - Math.round(fontSize * lineHeight);
|
|
|
|
|
|
|
|
const popoverToken = mergeToken<PopoverToken>(token, {
|
2022-06-17 18:47:47 +08:00
|
|
|
popoverBg: colorBgElevated,
|
2022-05-27 11:07:58 +08:00
|
|
|
popoverColor: token.colorText,
|
|
|
|
popoverTitlePaddingBlockTop: titlePaddingBlockDist / 2,
|
|
|
|
popoverTitlePaddingBlockBottom: titlePaddingBlockDist / 2 - lineWidth,
|
|
|
|
popoverPaddingHorizontal: token.padding,
|
|
|
|
});
|
|
|
|
|
2022-06-21 00:34:51 +08:00
|
|
|
return [
|
|
|
|
genBaseStyle(popoverToken),
|
|
|
|
genColorStyle(popoverToken),
|
|
|
|
initZoomMotion(popoverToken, 'zoom-big'),
|
|
|
|
];
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
({ zIndexPopupBase }) => ({
|
|
|
|
zIndexPopup: zIndexPopupBase + 30,
|
|
|
|
width: 177,
|
|
|
|
}),
|
|
|
|
);
|