2022-11-02 16:25:28 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2023-08-25 19:08:52 +08:00
|
|
|
|
2022-11-02 16:25:28 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2023-11-08 14:56:15 +08:00
|
|
|
import type { ArrowOffsetToken } from '../../style/placementArrow';
|
|
|
|
import getArrowStyle, {
|
|
|
|
getArrowOffsetToken,
|
|
|
|
MAX_VERTICAL_CONTENT_RADIUS,
|
|
|
|
} from '../../style/placementArrow';
|
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-02-07 23:36:52 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2023-11-08 14:56:15 +08:00
|
|
|
import type { ArrowToken } from '../../style/roundedArrow';
|
|
|
|
import { getArrowToken } from '../../style/roundedArrow';
|
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2022-11-02 16:25:28 +08:00
|
|
|
|
2023-11-08 14:56:15 +08:00
|
|
|
export interface ComponentToken extends ArrowOffsetToken, ArrowToken {
|
|
|
|
/**
|
|
|
|
* @desc 弹层 z-index
|
|
|
|
* @descEN Tour popup z-index
|
|
|
|
*/
|
|
|
|
zIndexPopup: number;
|
|
|
|
/**
|
|
|
|
* @desc 关闭按钮尺寸
|
|
|
|
* @descEN Close button size
|
|
|
|
*/
|
|
|
|
closeBtnSize: number;
|
|
|
|
/**
|
|
|
|
* @desc Primary 模式上一步按钮背景色
|
|
|
|
* @descEN Background color of previous button in primary type
|
|
|
|
*/
|
|
|
|
primaryPrevBtnBg: string;
|
|
|
|
/**
|
|
|
|
* @desc Primary 模式下一步按钮悬浮背景色
|
|
|
|
* @descEN Hover background color of next button in primary type
|
|
|
|
*/
|
|
|
|
primaryNextBtnHoverBg: string;
|
2023-11-16 15:34:24 +08:00
|
|
|
/** @internal */
|
|
|
|
closeBtnHoverBg: string;
|
2023-11-08 14:56:15 +08:00
|
|
|
}
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
interface TourToken extends FullToken<'Tour'> {
|
|
|
|
tourZIndexPopup: number;
|
2023-02-07 23:36:52 +08:00
|
|
|
indicatorWidth: number;
|
|
|
|
indicatorHeight: number;
|
2022-11-02 16:25:28 +08:00
|
|
|
tourBorderRadius: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============================== Base ===============================
|
2022-11-17 23:31:41 +08:00
|
|
|
const genBaseStyle: GenerateStyle<TourToken> = (token) => {
|
2022-11-02 16:25:28 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
lineHeight,
|
|
|
|
padding,
|
|
|
|
paddingXS,
|
|
|
|
borderRadius,
|
|
|
|
borderRadiusXS,
|
|
|
|
colorPrimary,
|
|
|
|
colorText,
|
|
|
|
colorFill,
|
2023-02-07 23:36:52 +08:00
|
|
|
indicatorHeight,
|
|
|
|
indicatorWidth,
|
2023-02-03 11:20:21 +08:00
|
|
|
boxShadowTertiary,
|
2022-11-02 16:25:28 +08:00
|
|
|
tourZIndexPopup,
|
|
|
|
fontSize,
|
2023-08-25 19:08:52 +08:00
|
|
|
colorBgElevated,
|
2022-11-02 16:25:28 +08:00
|
|
|
fontWeightStrong,
|
|
|
|
marginXS,
|
|
|
|
colorTextLightSolid,
|
|
|
|
tourBorderRadius,
|
|
|
|
colorWhite,
|
2023-11-08 14:56:15 +08:00
|
|
|
primaryNextBtnHoverBg,
|
|
|
|
closeBtnSize,
|
2022-11-10 22:30:48 +08:00
|
|
|
motionDurationSlow,
|
2023-02-13 10:21:45 +08:00
|
|
|
antCls,
|
2023-11-08 14:56:15 +08:00
|
|
|
primaryPrevBtnBg,
|
2022-11-02 16:25:28 +08:00
|
|
|
} = token;
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
color: colorText,
|
|
|
|
position: 'absolute',
|
|
|
|
zIndex: tourZIndexPopup,
|
|
|
|
display: 'block',
|
|
|
|
visibility: 'visible',
|
|
|
|
fontSize,
|
|
|
|
lineHeight,
|
|
|
|
width: 520,
|
2023-08-25 19:08:52 +08:00
|
|
|
'--antd-arrow-background-color': colorBgElevated,
|
2022-11-02 16:25:28 +08:00
|
|
|
|
2022-11-03 00:43:26 +08:00
|
|
|
'&-pure': {
|
|
|
|
maxWidth: '100%',
|
|
|
|
position: 'relative',
|
|
|
|
},
|
|
|
|
|
2022-11-02 16:25:28 +08:00
|
|
|
[`&${componentCls}-hidden`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
|
2022-12-19 11:34:36 +08:00
|
|
|
// ============================= panel content ============================
|
2022-11-02 16:25:28 +08:00
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
position: 'relative',
|
|
|
|
},
|
|
|
|
[`${componentCls}-inner`]: {
|
|
|
|
textAlign: 'start',
|
|
|
|
textDecoration: 'none',
|
|
|
|
borderRadius: tourBorderRadius,
|
2023-02-03 11:20:21 +08:00
|
|
|
boxShadow: boxShadowTertiary,
|
2022-11-02 16:25:28 +08:00
|
|
|
position: 'relative',
|
2023-08-25 19:08:52 +08:00
|
|
|
backgroundColor: colorBgElevated,
|
2022-11-02 16:25:28 +08:00
|
|
|
border: 'none',
|
|
|
|
backgroundClip: 'padding-box',
|
|
|
|
|
|
|
|
[`${componentCls}-close`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: padding,
|
|
|
|
insetInlineEnd: padding,
|
|
|
|
color: token.colorIcon,
|
|
|
|
outline: 'none',
|
2023-11-08 14:56:15 +08:00
|
|
|
width: closeBtnSize,
|
|
|
|
height: closeBtnSize,
|
2022-11-02 16:25:28 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
2022-11-17 23:31:41 +08:00
|
|
|
transition: `background-color ${token.motionDurationMid}, color ${token.motionDurationMid}`,
|
2022-11-02 16:25:28 +08:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2023-11-08 14:56:15 +08:00
|
|
|
cursor: 'pointer',
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
color: token.colorIconHover,
|
2023-11-16 15:34:24 +08:00
|
|
|
backgroundColor: token.closeBtnHoverBg,
|
2022-11-02 16:25:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-cover`]: {
|
|
|
|
textAlign: 'center',
|
2023-11-08 14:56:15 +08:00
|
|
|
padding: `${unit(token.calc(padding).add(closeBtnSize).add(paddingXS).equal())} ${unit(
|
|
|
|
padding,
|
|
|
|
)} 0`,
|
2022-11-02 16:25:28 +08:00
|
|
|
img: {
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[`${componentCls}-header`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
padding: `${unit(padding)} ${unit(padding)} ${unit(paddingXS)}`,
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
[`${componentCls}-title`]: {
|
|
|
|
lineHeight,
|
|
|
|
fontSize,
|
|
|
|
fontWeight: fontWeightStrong,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-description`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
padding: `0 ${unit(padding)}`,
|
2022-11-02 16:25:28 +08:00
|
|
|
lineHeight,
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-footer`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
padding: `${unit(paddingXS)} ${unit(padding)} ${unit(padding)}`,
|
2022-11-02 16:25:28 +08:00
|
|
|
textAlign: 'end',
|
2023-11-08 14:56:15 +08:00
|
|
|
borderRadius: `0 0 ${unit(borderRadiusXS)} ${unit(borderRadiusXS)}`,
|
2022-11-02 16:25:28 +08:00
|
|
|
display: 'flex',
|
2023-02-07 23:36:52 +08:00
|
|
|
[`${componentCls}-indicators`]: {
|
2022-11-02 16:25:28 +08:00
|
|
|
display: 'inline-block',
|
|
|
|
|
2023-02-07 23:36:52 +08:00
|
|
|
[`${componentCls}-indicator`]: {
|
|
|
|
width: indicatorWidth,
|
|
|
|
height: indicatorHeight,
|
2022-11-02 16:25:28 +08:00
|
|
|
display: 'inline-block',
|
|
|
|
borderRadius: '50%',
|
|
|
|
background: colorFill,
|
2023-02-08 10:46:38 +08:00
|
|
|
'&:not(:last-child)': {
|
|
|
|
marginInlineEnd: indicatorHeight,
|
|
|
|
},
|
2022-11-02 16:25:28 +08:00
|
|
|
'&-active': {
|
|
|
|
background: colorPrimary,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-13 10:21:45 +08:00
|
|
|
[`${componentCls}-buttons`]: {
|
|
|
|
marginInlineStart: 'auto',
|
|
|
|
[`${antCls}-btn`]: {
|
|
|
|
marginInlineStart: marginXS,
|
|
|
|
},
|
2022-11-02 16:25:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-12-19 11:34:36 +08:00
|
|
|
// ============================= primary type ===========================
|
|
|
|
// `$` for panel, `&$` for pure panel
|
|
|
|
[`${componentCls}-primary, &${componentCls}-primary`]: {
|
2022-11-02 16:25:28 +08:00
|
|
|
'--antd-arrow-background-color': colorPrimary,
|
2022-12-19 11:34:36 +08:00
|
|
|
|
2022-11-02 16:25:28 +08:00
|
|
|
[`${componentCls}-inner`]: {
|
|
|
|
color: colorTextLightSolid,
|
|
|
|
textAlign: 'start',
|
|
|
|
textDecoration: 'none',
|
|
|
|
backgroundColor: colorPrimary,
|
|
|
|
borderRadius,
|
2023-02-03 11:20:21 +08:00
|
|
|
boxShadow: boxShadowTertiary,
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
[`${componentCls}-close`]: {
|
|
|
|
color: colorTextLightSolid,
|
|
|
|
},
|
|
|
|
|
2023-02-07 23:36:52 +08:00
|
|
|
[`${componentCls}-indicators`]: {
|
|
|
|
[`${componentCls}-indicator`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
background: primaryPrevBtnBg,
|
2022-11-02 16:25:28 +08:00
|
|
|
'&-active': {
|
|
|
|
background: colorTextLightSolid,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-prev-btn`]: {
|
|
|
|
color: colorTextLightSolid,
|
2023-11-08 14:56:15 +08:00
|
|
|
borderColor: primaryPrevBtnBg,
|
2022-12-19 11:34:36 +08:00
|
|
|
backgroundColor: colorPrimary,
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
'&:hover': {
|
2023-11-08 14:56:15 +08:00
|
|
|
backgroundColor: primaryPrevBtnBg,
|
2022-11-02 16:25:28 +08:00
|
|
|
borderColor: 'transparent',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-next-btn`]: {
|
|
|
|
color: colorPrimary,
|
|
|
|
borderColor: 'transparent',
|
|
|
|
background: colorWhite,
|
|
|
|
|
|
|
|
'&:hover': {
|
2023-11-08 14:56:15 +08:00
|
|
|
background: primaryNextBtnHoverBg,
|
2022-11-02 16:25:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-11-10 22:30:48 +08:00
|
|
|
// ============================= mask ===========================
|
|
|
|
[`${componentCls}-mask`]: {
|
|
|
|
[`${componentCls}-placeholder-animated`]: {
|
|
|
|
transition: `all ${motionDurationSlow}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// =========== Limit left and right placement radius ==============
|
2022-11-02 16:25:28 +08:00
|
|
|
[[
|
2022-12-05 14:15:26 +08:00
|
|
|
'&-placement-left',
|
|
|
|
'&-placement-leftTop',
|
|
|
|
'&-placement-leftBottom',
|
|
|
|
'&-placement-right',
|
|
|
|
'&-placement-rightTop',
|
|
|
|
'&-placement-rightBottom',
|
2022-11-02 16:25:28 +08:00
|
|
|
].join(',')]: {
|
|
|
|
[`${componentCls}-inner`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
borderRadius: token.min(tourBorderRadius, MAX_VERTICAL_CONTENT_RADIUS),
|
2022-11-02 16:25:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-11-10 22:30:48 +08:00
|
|
|
|
|
|
|
// ============================= Arrow ===========================
|
2023-11-08 14:56:15 +08:00
|
|
|
getArrowStyle<TourToken>(token, 'var(--antd-arrow-background-color)'),
|
2022-11-02 16:25:28 +08:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2023-11-08 14:56:15 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Tour'> = (token) => ({
|
|
|
|
zIndexPopup: token.zIndexPopupBase + 70,
|
|
|
|
closeBtnSize: token.fontSize * token.lineHeight,
|
|
|
|
primaryPrevBtnBg: new TinyColor(token.colorTextLightSolid).setAlpha(0.15).toRgbString(),
|
2023-11-16 15:34:24 +08:00
|
|
|
closeBtnHoverBg: token.wireframe ? 'transparent' : token.colorFillContent,
|
2023-11-08 14:56:15 +08:00
|
|
|
primaryNextBtnHoverBg: new TinyColor(token.colorBgTextHover)
|
|
|
|
.onBackground(token.colorWhite)
|
|
|
|
.toRgbString(),
|
|
|
|
...getArrowOffsetToken({
|
|
|
|
contentRadius: token.borderRadiusLG,
|
|
|
|
limitVerticalRadius: true,
|
|
|
|
}),
|
|
|
|
...getArrowToken(token),
|
2022-11-02 16:25:28 +08:00
|
|
|
});
|
2023-11-08 14:56:15 +08:00
|
|
|
|
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Tour',
|
|
|
|
(token) => {
|
|
|
|
const { borderRadiusLG } = token;
|
|
|
|
const TourToken = mergeToken<TourToken>(token, {
|
|
|
|
indicatorWidth: 6,
|
|
|
|
indicatorHeight: 6,
|
|
|
|
tourBorderRadius: borderRadiusLG,
|
|
|
|
});
|
|
|
|
return [genBaseStyle(TourToken)];
|
|
|
|
},
|
|
|
|
prepareComponentToken,
|
|
|
|
);
|