|
import { resetComponent } from '../../style'; |
|
import { initZoomMotion } from '../../style/motion'; |
|
import type { ArrowOffsetToken } from '../../style/placementArrow'; |
|
import getArrowStyle, { getArrowOffsetToken } from '../../style/placementArrow'; |
|
import type { ArrowToken } from '../../style/roundedArrow'; |
|
import { getArrowToken } from '../../style/roundedArrow'; |
|
import type { |
|
FullToken, |
|
GenerateStyle, |
|
GetDefaultToken, |
|
PresetColorType, |
|
} from '../../theme/internal'; |
|
import { genStyleHooks, mergeToken, PresetColors } from '../../theme/internal'; |
|
|
|
export interface ComponentToken extends ArrowToken, ArrowOffsetToken { |
|
|
|
|
|
|
|
|
|
|
|
width?: number | string; |
|
|
|
|
|
|
|
|
|
|
|
minWidth?: number | string; |
|
|
|
|
|
|
|
|
|
titleMinWidth: number | string; |
|
|
|
|
|
|
|
|
|
zIndexPopup: number; |
|
|
|
innerPadding: number; |
|
|
|
titlePadding: number | string; |
|
|
|
titleMarginBottom: number; |
|
|
|
titleBorderBottom: string; |
|
|
|
innerContentPadding: number | string; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export type PopoverToken = FullToken<'Popover'> & { |
|
|
|
|
|
|
|
|
|
popoverBg: string; |
|
|
|
|
|
|
|
|
|
popoverColor: string; |
|
}; |
|
|
|
const genBaseStyle: GenerateStyle<PopoverToken> = (token) => { |
|
const { |
|
componentCls, |
|
popoverColor, |
|
titleMinWidth, |
|
fontWeightStrong, |
|
innerPadding, |
|
boxShadowSecondary, |
|
colorTextHeading, |
|
borderRadiusLG, |
|
zIndexPopup, |
|
titleMarginBottom, |
|
colorBgElevated, |
|
popoverBg, |
|
titleBorderBottom, |
|
innerContentPadding, |
|
titlePadding, |
|
} = token; |
|
|
|
return [ |
|
{ |
|
[componentCls]: { |
|
...resetComponent(token), |
|
position: 'absolute', |
|
top: 0, |
|
|
|
left: { |
|
_skip_check_: true, |
|
value: 0, |
|
}, |
|
zIndex: zIndexPopup, |
|
fontWeight: 'normal', |
|
whiteSpace: 'normal', |
|
textAlign: 'start', |
|
cursor: 'auto', |
|
userSelect: 'text', |
|
|
|
|
|
'--valid-offset-x': 'var(--arrow-offset-horizontal, var(--arrow-x))', |
|
transformOrigin: [`var(--valid-offset-x, 50%)`, `var(--arrow-y, 50%)`].join(' '), |
|
|
|
'--antd-arrow-background-color': colorBgElevated, |
|
width: 'max-content', |
|
maxWidth: '100vw', |
|
|
|
'&-rtl': { |
|
direction: 'rtl', |
|
}, |
|
|
|
'&-hidden': { |
|
display: 'none', |
|
}, |
|
|
|
[`${componentCls}-content`]: { |
|
position: 'relative', |
|
}, |
|
|
|
[`${componentCls}-inner`]: { |
|
backgroundColor: popoverBg, |
|
backgroundClip: 'padding-box', |
|
borderRadius: borderRadiusLG, |
|
boxShadow: boxShadowSecondary, |
|
padding: innerPadding, |
|
}, |
|
|
|
[`${componentCls}-title`]: { |
|
minWidth: titleMinWidth, |
|
marginBottom: titleMarginBottom, |
|
color: colorTextHeading, |
|
fontWeight: fontWeightStrong, |
|
borderBottom: titleBorderBottom, |
|
padding: titlePadding, |
|
}, |
|
|
|
[`${componentCls}-inner-content`]: { |
|
color: popoverColor, |
|
padding: innerContentPadding, |
|
}, |
|
}, |
|
}, |
|
|
|
|
|
getArrowStyle(token, 'var(--antd-arrow-background-color)'), |
|
|
|
|
|
{ |
|
[`${componentCls}-pure`]: { |
|
position: 'relative', |
|
maxWidth: 'none', |
|
margin: token.sizePopupArrow, |
|
display: 'inline-block', |
|
|
|
[`${componentCls}-content`]: { |
|
display: 'inline-block', |
|
}, |
|
}, |
|
}, |
|
]; |
|
}; |
|
|
|
const genColorStyle: GenerateStyle<PopoverToken> = (token) => { |
|
const { componentCls } = token; |
|
|
|
return { |
|
[componentCls]: PresetColors.map((colorKey: keyof PresetColorType) => { |
|
const lightColor = token[`${colorKey}6`]; |
|
return { |
|
[`&${componentCls}-${colorKey}`]: { |
|
'--antd-arrow-background-color': lightColor, |
|
[`${componentCls}-inner`]: { |
|
backgroundColor: lightColor, |
|
}, |
|
[`${componentCls}-arrow`]: { |
|
background: 'transparent', |
|
}, |
|
}, |
|
}; |
|
}), |
|
}; |
|
}; |
|
|
|
export const prepareComponentToken: GetDefaultToken<'Popover'> = (token) => { |
|
const { |
|
lineWidth, |
|
controlHeight, |
|
fontHeight, |
|
padding, |
|
wireframe, |
|
zIndexPopupBase, |
|
borderRadiusLG, |
|
marginXS, |
|
lineType, |
|
colorSplit, |
|
paddingSM, |
|
} = token; |
|
|
|
const titlePaddingBlockDist = controlHeight - fontHeight; |
|
const popoverTitlePaddingBlockTop = titlePaddingBlockDist / 2; |
|
const popoverTitlePaddingBlockBottom = titlePaddingBlockDist / 2 - lineWidth; |
|
const popoverPaddingHorizontal = padding; |
|
|
|
return { |
|
titleMinWidth: 177, |
|
zIndexPopup: zIndexPopupBase + 30, |
|
...getArrowToken(token), |
|
...getArrowOffsetToken({ |
|
contentRadius: borderRadiusLG, |
|
limitVerticalRadius: true, |
|
}), |
|
|
|
|
|
innerPadding: wireframe ? 0 : 12, |
|
titleMarginBottom: wireframe ? 0 : marginXS, |
|
titlePadding: wireframe |
|
? `${popoverTitlePaddingBlockTop}px ${popoverPaddingHorizontal}px ${popoverTitlePaddingBlockBottom}px` |
|
: 0, |
|
titleBorderBottom: wireframe ? `${lineWidth}px ${lineType} ${colorSplit}` : 'none', |
|
innerContentPadding: wireframe ? `${paddingSM}px ${popoverPaddingHorizontal}px` : 0, |
|
}; |
|
}; |
|
|
|
export default genStyleHooks( |
|
'Popover', |
|
(token) => { |
|
const { colorBgElevated, colorText } = token; |
|
|
|
const popoverToken = mergeToken<PopoverToken>(token, { |
|
popoverBg: colorBgElevated, |
|
popoverColor: colorText, |
|
}); |
|
|
|
return [ |
|
genBaseStyle(popoverToken), |
|
genColorStyle(popoverToken), |
|
initZoomMotion(popoverToken, 'zoom-big'), |
|
]; |
|
}, |
|
prepareComponentToken, |
|
{ |
|
resetStyle: false, |
|
deprecatedTokens: [ |
|
['width', 'titleMinWidth'], |
|
['minWidth', 'titleMinWidth'], |
|
], |
|
}, |
|
); |
|
|