2022-05-03 22:41:59 +08:00
|
|
|
// deps-lint-skip-all
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-05-23 20:34:20 +08:00
|
|
|
import type {
|
|
|
|
FullToken,
|
|
|
|
GenerateStyle,
|
|
|
|
PresetColorType,
|
|
|
|
UseComponentStyleResult,
|
|
|
|
} from '../../_util/theme';
|
2022-05-03 22:41:59 +08:00
|
|
|
import {
|
|
|
|
genComponentStyleHook,
|
|
|
|
mergeToken,
|
2022-05-23 20:34:20 +08:00
|
|
|
PresetColors,
|
2022-05-03 22:41:59 +08:00
|
|
|
resetComponent,
|
2022-06-02 22:15:54 +08:00
|
|
|
getArrowStyle,
|
2022-05-03 22:41:59 +08:00
|
|
|
} from '../../_util/theme';
|
|
|
|
|
2022-06-02 22:15:54 +08:00
|
|
|
export interface ComponentToken {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
getArrowStyle(token, 'var(--antd-arrow-background-color)', '', false),
|
|
|
|
];
|
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 [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const { radiusBase, colorTextLightSolid, colorBgContainerWeak } = token;
|
|
|
|
|
|
|
|
const tooltipBg = colorBgContainerWeak;
|
|
|
|
|
|
|
|
const TooltipToken = mergeToken<TooltipToken>(token, {
|
|
|
|
// default variables
|
|
|
|
tooltipMaxWidth: 250,
|
|
|
|
tooltipColor: colorTextLightSolid,
|
|
|
|
tooltipBg,
|
|
|
|
tooltipBorderRadius: radiusBase,
|
|
|
|
});
|
|
|
|
|
|
|
|
return [genTooltipStyle(TooltipToken)];
|
|
|
|
},
|
|
|
|
({ zIndexPopupBase }) => ({
|
|
|
|
zIndexPopup: zIndexPopupBase + 70,
|
|
|
|
}),
|
|
|
|
);
|
2022-05-03 22:41:59 +08:00
|
|
|
|
2022-05-23 20:34:20 +08:00
|
|
|
return useOriginHook(prefixCls);
|
|
|
|
};
|