2023-03-28 12:12:36 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2022-06-21 00:34:51 +08:00
|
|
|
import { initZoomMotion } from '../../style/motion';
|
2023-11-08 14:56:15 +08:00
|
|
|
import type { ArrowOffsetToken } from '../../style/placementArrow';
|
|
|
|
import getArrowStyle, {
|
|
|
|
getArrowOffsetToken,
|
|
|
|
MAX_VERTICAL_CONTENT_RADIUS,
|
|
|
|
} from '../../style/placementArrow';
|
2023-11-29 17:23:45 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
|
|
|
import { genPresetColor, genStyleHooks, mergeToken } from '../../theme/internal';
|
2023-11-08 14:56:15 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
import type { ArrowToken } from '../../style/roundedArrow';
|
|
|
|
import { getArrowToken } from '../../style/roundedArrow';
|
2022-05-03 22:41:59 +08:00
|
|
|
|
2023-11-08 14:56:15 +08:00
|
|
|
export interface ComponentToken extends ArrowOffsetToken, ArrowToken {
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 文字提示 z-index
|
|
|
|
* @descEN z-index of tooltip
|
|
|
|
*/
|
2022-06-02 22:15:54 +08:00
|
|
|
zIndexPopup: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TooltipToken extends FullToken<'Tooltip'> {
|
2022-05-03 22:41:59 +08:00
|
|
|
// default variables
|
|
|
|
tooltipMaxWidth: number;
|
|
|
|
tooltipColor: string;
|
|
|
|
tooltipBg: string;
|
|
|
|
tooltipBorderRadius: number;
|
|
|
|
}
|
|
|
|
|
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-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',
|
2023-05-08 23:28:13 +08:00
|
|
|
transformOrigin: `var(--arrow-x, 50%) var(--arrow-y, 50%)`,
|
2022-06-02 22:15:54 +08:00
|
|
|
'&-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,
|
2023-11-08 14:56:15 +08:00
|
|
|
padding: `${unit(token.calc(paddingSM).div(2).equal())} ${unit(paddingXS)}`,
|
2022-06-02 22:15:54 +08:00
|
|
|
color: tooltipColor,
|
|
|
|
textAlign: 'start',
|
|
|
|
textDecoration: 'none',
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
backgroundColor: tooltipBg,
|
|
|
|
borderRadius: tooltipBorderRadius,
|
2022-08-26 16:05:16 +08:00
|
|
|
boxShadow: boxShadowSecondary,
|
2023-05-18 16:54:57 +08:00
|
|
|
boxSizing: 'border-box',
|
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`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
borderRadius: token.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
|
2023-11-08 14:56:15 +08:00
|
|
|
getArrowStyle(token, 'var(--antd-arrow-background-color)'),
|
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 ==============================
|
2023-11-08 14:56:15 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Tooltip'> = (token) => ({
|
|
|
|
zIndexPopup: token.zIndexPopupBase + 70,
|
|
|
|
...getArrowOffsetToken({
|
|
|
|
contentRadius: token.borderRadius,
|
|
|
|
limitVerticalRadius: true,
|
|
|
|
}),
|
|
|
|
...getArrowToken(
|
|
|
|
mergeToken<TooltipToken>(token, {
|
|
|
|
borderRadiusOuter: Math.min(token.borderRadiusOuter, 4),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
export default (prefixCls: string, injectStyle: boolean = true) => {
|
|
|
|
const useStyle = genStyleHooks(
|
2022-06-02 22:15:54 +08:00
|
|
|
'Tooltip',
|
2022-11-19 13:47:33 +08:00
|
|
|
(token) => {
|
2023-11-08 14:56:15 +08:00
|
|
|
const { borderRadius, colorTextLightSolid, colorBgSpotlight } = 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,
|
2023-11-08 14:56:15 +08:00
|
|
|
tooltipBg: colorBgSpotlight,
|
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
|
|
|
},
|
2023-11-08 14:56:15 +08:00
|
|
|
prepareComponentToken,
|
2023-05-16 22:24:52 +08:00
|
|
|
{
|
|
|
|
resetStyle: false,
|
2023-11-29 17:23:45 +08:00
|
|
|
// Popover use Tooltip as internal component. We do not need to handle this.
|
|
|
|
injectStyle,
|
2023-05-16 22:24:52 +08:00
|
|
|
},
|
2022-06-02 22:15:54 +08:00
|
|
|
);
|
2022-05-03 22:41:59 +08:00
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
return useStyle(prefixCls);
|
2022-05-23 20:34:20 +08:00
|
|
|
};
|