2023-02-15 10:21:28 +08:00
|
|
|
import { genPresetColor, resetComponent } from '../../style';
|
2022-06-21 00:34:51 +08:00
|
|
|
import { initZoomMotion } from '../../style/motion';
|
2023-02-15 10:21:28 +08:00
|
|
|
import getArrowStyle, { MAX_VERTICAL_CONTENT_RADIUS } from '../../style/placementArrow';
|
2023-01-06 11:06:46 +08:00
|
|
|
import type { FullToken, GenerateStyle, UseComponentStyleResult } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-05-03 22:41:59 +08:00
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
export interface ComponentToken {
|
|
|
|
zIndexPopup: number;
|
2022-06-17 18:47:47 +08:00
|
|
|
colorBgDefault: string;
|
2022-06-02 22:15:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface TooltipToken extends FullToken<'Tooltip'> {
|
2022-05-03 22:41:59 +08:00
|
|
|
// default variables
|
|
|
|
tooltipMaxWidth: number;
|
|
|
|
tooltipColor: string;
|
|
|
|
tooltipBg: string;
|
|
|
|
tooltipBorderRadius: number;
|
2022-09-01 20:09:32 +08:00
|
|
|
tooltipRadiusOuter: number;
|
2022-05-03 22:41:59 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
|
2022-05-03 22:41:59 +08:00
|
|
|
const {
|
|
|
|
componentCls, // ant-tooltip
|
|
|
|
tooltipMaxWidth,
|
|
|
|
tooltipColor,
|
|
|
|
tooltipBg,
|
|
|
|
tooltipBorderRadius,
|
2022-06-02 22:15:54 +08:00
|
|
|
zIndexPopup,
|
|
|
|
controlHeight,
|
2022-08-26 16:05:16 +08:00
|
|
|
boxShadowSecondary,
|
2022-06-02 22:15:54 +08:00
|
|
|
paddingSM,
|
|
|
|
paddingXS,
|
2022-09-01 20:09:32 +08:00
|
|
|
tooltipRadiusOuter,
|
2022-05-03 22:41:59 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2022-05-03 22:41:59 +08:00
|
|
|
position: 'absolute',
|
2022-06-02 22:15:54 +08:00
|
|
|
zIndex: zIndexPopup,
|
2022-05-03 22:41:59 +08:00
|
|
|
display: 'block',
|
2023-02-20 14:48:59 +08:00
|
|
|
width: 'max-content',
|
2022-06-02 22:15:54 +08:00
|
|
|
maxWidth: tooltipMaxWidth,
|
|
|
|
visibility: 'visible',
|
|
|
|
'&-hidden': {
|
|
|
|
display: 'none',
|
2022-05-03 22:41:59 +08:00
|
|
|
},
|
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
'--antd-arrow-background-color': tooltipBg,
|
|
|
|
|
|
|
|
// Wrapper for the tooltip content
|
|
|
|
[`${componentCls}-inner`]: {
|
|
|
|
minWidth: controlHeight,
|
|
|
|
minHeight: controlHeight,
|
|
|
|
padding: `${paddingSM / 2}px ${paddingXS}px`,
|
|
|
|
color: tooltipColor,
|
|
|
|
textAlign: 'start',
|
|
|
|
textDecoration: 'none',
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
backgroundColor: tooltipBg,
|
|
|
|
borderRadius: tooltipBorderRadius,
|
2022-08-26 16:05:16 +08:00
|
|
|
boxShadow: boxShadowSecondary,
|
2022-05-03 22:41:59 +08:00
|
|
|
},
|
|
|
|
|
2022-09-13 17:07:16 +08:00
|
|
|
// Limit left and right placement radius
|
|
|
|
[[
|
|
|
|
`&-placement-left`,
|
|
|
|
`&-placement-leftTop`,
|
|
|
|
`&-placement-leftBottom`,
|
|
|
|
`&-placement-right`,
|
|
|
|
`&-placement-rightTop`,
|
|
|
|
`&-placement-rightBottom`,
|
|
|
|
].join(',')]: {
|
|
|
|
[`${componentCls}-inner`]: {
|
2022-12-31 22:12:30 +08:00
|
|
|
borderRadius: Math.min(tooltipBorderRadius, MAX_VERTICAL_CONTENT_RADIUS),
|
2022-09-13 17:07:16 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
position: 'relative',
|
2022-05-03 22:41:59 +08:00
|
|
|
},
|
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
// generator for preset color
|
2023-01-06 11:06:46 +08:00
|
|
|
...genPresetColor(token, (colorKey, { darkColor }) => ({
|
|
|
|
[`&${componentCls}-${colorKey}`]: {
|
|
|
|
[`${componentCls}-inner`]: {
|
|
|
|
backgroundColor: darkColor,
|
|
|
|
},
|
|
|
|
[`${componentCls}-arrow`]: {
|
|
|
|
'--antd-arrow-background-color': darkColor,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})),
|
2022-05-03 22:41:59 +08:00
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
// RTL
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
2022-05-03 22:41:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-02 22:15:54 +08:00
|
|
|
|
|
|
|
// Arrow Style
|
2022-09-01 20:09:32 +08:00
|
|
|
getArrowStyle<TooltipToken>(
|
|
|
|
mergeToken<TooltipToken>(token, {
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadiusOuter: tooltipRadiusOuter,
|
2022-08-19 10:10:51 +08:00
|
|
|
}),
|
2022-09-13 17:07:16 +08:00
|
|
|
{
|
|
|
|
colorBg: 'var(--antd-arrow-background-color)',
|
|
|
|
contentRadius: tooltipBorderRadius,
|
|
|
|
limitVerticalRadius: true,
|
|
|
|
},
|
2022-08-19 10:10:51 +08:00
|
|
|
),
|
2022-07-13 23:06:28 +08:00
|
|
|
|
|
|
|
// Pure Render
|
|
|
|
{
|
|
|
|
[`${componentCls}-pure`]: {
|
|
|
|
position: 'relative',
|
|
|
|
maxWidth: 'none',
|
2023-02-15 10:21:28 +08:00
|
|
|
margin: token.sizePopupArrow,
|
2022-07-13 23:06:28 +08:00
|
|
|
},
|
|
|
|
},
|
2022-06-02 22:15:54 +08:00
|
|
|
];
|
2022-05-03 22:41:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-05-23 20:34:20 +08:00
|
|
|
export default (prefixCls: string, injectStyle: boolean): UseComponentStyleResult => {
|
2022-06-02 22:15:54 +08:00
|
|
|
const useOriginHook = genComponentStyleHook(
|
|
|
|
'Tooltip',
|
2022-11-19 13:47:33 +08:00
|
|
|
(token) => {
|
2022-06-02 22:15:54 +08:00
|
|
|
// Popover use Tooltip as internal component. We do not need to handle this.
|
|
|
|
if (injectStyle === false) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-11-01 15:06:38 +08:00
|
|
|
const { borderRadius, colorTextLightSolid, colorBgDefault, borderRadiusOuter } = token;
|
2022-06-02 22:15:54 +08:00
|
|
|
|
|
|
|
const TooltipToken = mergeToken<TooltipToken>(token, {
|
|
|
|
// default variables
|
|
|
|
tooltipMaxWidth: 250,
|
|
|
|
tooltipColor: colorTextLightSolid,
|
2022-11-01 15:06:38 +08:00
|
|
|
tooltipBorderRadius: borderRadius,
|
2022-06-17 18:47:47 +08:00
|
|
|
tooltipBg: colorBgDefault,
|
2022-11-01 15:06:38 +08:00
|
|
|
tooltipRadiusOuter: borderRadiusOuter > 4 ? 4 : borderRadiusOuter,
|
2022-06-02 22:15:54 +08:00
|
|
|
});
|
|
|
|
|
2022-12-28 00:01:45 +08:00
|
|
|
return [genTooltipStyle(TooltipToken), initZoomMotion(token, 'zoom-big-fast')];
|
2022-06-02 22:15:54 +08:00
|
|
|
},
|
2022-07-21 17:00:42 +08:00
|
|
|
({ zIndexPopupBase, colorBgSpotlight }) => ({
|
2022-06-02 22:15:54 +08:00
|
|
|
zIndexPopup: zIndexPopupBase + 70,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorBgDefault: colorBgSpotlight,
|
2022-06-02 22:15:54 +08:00
|
|
|
}),
|
|
|
|
);
|
2022-05-03 22:41:59 +08:00
|
|
|
|
2022-05-23 20:34:20 +08:00
|
|
|
return useOriginHook(prefixCls);
|
|
|
|
};
|