2022-05-03 22:41:59 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-06-21 00:34:51 +08:00
|
|
|
import { initZoomMotion } from '../../style/motion';
|
2022-05-23 20:34:20 +08:00
|
|
|
import type {
|
|
|
|
FullToken,
|
|
|
|
GenerateStyle,
|
|
|
|
PresetColorType,
|
|
|
|
UseComponentStyleResult,
|
2022-06-27 14:25:59 +08:00
|
|
|
} 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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const generatorTooltipPresetColor: GenerateStyle<TooltipToken, CSSObject> = token => {
|
|
|
|
const { componentCls } = token;
|
|
|
|
|
|
|
|
return PresetColors.reduce((previousValue: any, currentValue: keyof PresetColorType) => {
|
|
|
|
const lightColor = token[`${currentValue}-6`];
|
|
|
|
previousValue[`&${componentCls}-${currentValue}`] = {
|
|
|
|
[`${componentCls}-inner`]: {
|
|
|
|
backgroundColor: lightColor,
|
|
|
|
},
|
2022-06-02 22:15:54 +08:00
|
|
|
[`${componentCls}-arrow`]: {
|
2022-05-03 22:41:59 +08:00
|
|
|
background: lightColor,
|
2022-06-02 22:15:54 +08:00
|
|
|
|
|
|
|
'--antd-arrow-background-color': lightColor,
|
2022-05-03 22:41:59 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
return previousValue;
|
|
|
|
}, {});
|
|
|
|
};
|
|
|
|
|
2022-06-02 22:15:54 +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-05-03 22:41:59 +08:00
|
|
|
boxShadow,
|
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',
|
2022-06-02 22:15:54 +08:00
|
|
|
'&': [{ width: 'max-content' }, { width: 'intrinsic' }],
|
|
|
|
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,
|
|
|
|
boxShadow,
|
2022-05-03 22:41:59 +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
|
|
|
|
...generatorTooltipPresetColor(token),
|
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-07-03 09:42:26 +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',
|
|
|
|
},
|
|
|
|
},
|
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',
|
|
|
|
token => {
|
|
|
|
// Popover use Tooltip as internal component. We do not need to handle this.
|
|
|
|
if (injectStyle === false) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-06-17 18:47:47 +08:00
|
|
|
const { radiusBase, colorTextLightSolid, colorBgDefault } = token;
|
2022-06-02 22:15:54 +08:00
|
|
|
|
|
|
|
const TooltipToken = mergeToken<TooltipToken>(token, {
|
|
|
|
// default variables
|
|
|
|
tooltipMaxWidth: 250,
|
|
|
|
tooltipColor: colorTextLightSolid,
|
|
|
|
tooltipBorderRadius: radiusBase,
|
2022-06-17 18:47:47 +08:00
|
|
|
tooltipBg: colorBgDefault,
|
2022-06-02 22:15:54 +08:00
|
|
|
});
|
|
|
|
|
2022-06-21 00:34:51 +08:00
|
|
|
return [genTooltipStyle(TooltipToken), initZoomMotion(token, 'zoom-big-fast')];
|
2022-06-02 22:15:54 +08:00
|
|
|
},
|
2022-06-29 21:24:29 +08:00
|
|
|
({ zIndexPopupBase, colorBgTooltipTmp }) => ({
|
2022-06-02 22:15:54 +08:00
|
|
|
zIndexPopup: zIndexPopupBase + 70,
|
2022-06-29 21:24:29 +08:00
|
|
|
colorBgDefault: colorBgTooltipTmp,
|
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);
|
|
|
|
};
|