2024-04-08 14:04:08 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2023-11-14 10:39:49 +08:00
|
|
|
|
2022-07-11 15:35:58 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2023-11-14 10:39:49 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2022-04-20 19:36:59 +08:00
|
|
|
|
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
2022-05-17 21:57:22 +08:00
|
|
|
export interface ComponentToken {
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 弹出层的 z-index
|
|
|
|
* @descEN z-index of popup
|
|
|
|
*/
|
2022-05-17 21:57:22 +08:00
|
|
|
zIndexPopup: number;
|
|
|
|
}
|
2022-04-20 19:36:59 +08:00
|
|
|
|
|
|
|
type BackTopToken = FullToken<'BackTop'> & {
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 背景颜色
|
|
|
|
* @descEN Background color of BackTop
|
|
|
|
*/
|
2022-04-20 19:36:59 +08:00
|
|
|
backTopBackground: string;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 文字颜色
|
|
|
|
* @descEN Text color of BackTop
|
|
|
|
*/
|
2022-04-20 19:36:59 +08:00
|
|
|
backTopColor: string;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 悬停背景颜色
|
|
|
|
* @descEN Hover background color of BackTop
|
|
|
|
*/
|
2022-04-20 19:36:59 +08:00
|
|
|
backTopHoverBackground: string;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 字体大小
|
|
|
|
* @descEN Font size of BackTop
|
|
|
|
*/
|
2022-05-17 21:57:22 +08:00
|
|
|
backTopFontSize: number;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 尺寸
|
|
|
|
* @descEN Size of BackTop
|
|
|
|
*/
|
2022-05-17 21:57:22 +08:00
|
|
|
backTopSize: number;
|
|
|
|
|
|
|
|
// Position
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 底部偏移量
|
|
|
|
* @descEN Bottom offset of BackTop
|
|
|
|
*/
|
2023-11-14 10:39:49 +08:00
|
|
|
backTopBlockEnd: number | string;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 右侧偏移量
|
|
|
|
* @descEN Right offset of BackTop
|
|
|
|
*/
|
2023-11-14 10:39:49 +08:00
|
|
|
backTopInlineEnd: number | string;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 中等屏幕右侧偏移量
|
|
|
|
* @descEN Right offset of BackTop on medium screens
|
|
|
|
*/
|
2023-11-14 10:39:49 +08:00
|
|
|
backTopInlineEndMD: number | string;
|
2024-08-13 18:18:59 +08:00
|
|
|
/**
|
|
|
|
* @desc BackTop 小屏幕右侧偏移量
|
|
|
|
* @descEN Right offset of BackTop on small screens
|
|
|
|
*/
|
2023-11-14 10:39:49 +08:00
|
|
|
backTopInlineEndXS: number | string;
|
2022-04-20 19:36:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Shared ==============================
|
|
|
|
const genSharedBackTopStyle: GenerateStyle<BackTopToken, CSSObject> = (token): CSSObject => {
|
2022-05-17 21:57:22 +08:00
|
|
|
const { componentCls, backTopFontSize, backTopSize, zIndexPopup } = token;
|
2022-04-20 19:36:59 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
position: 'fixed',
|
2022-05-17 21:57:22 +08:00
|
|
|
insetInlineEnd: token.backTopInlineEnd,
|
|
|
|
insetBlockEnd: token.backTopBlockEnd,
|
|
|
|
zIndex: zIndexPopup,
|
2022-04-20 19:36:59 +08:00
|
|
|
width: 40,
|
|
|
|
height: 40,
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
|
|
|
'&:empty': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-content`]: {
|
2022-05-17 21:57:22 +08:00
|
|
|
width: backTopSize,
|
|
|
|
height: backTopSize,
|
2022-04-20 19:36:59 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
color: token.backTopColor,
|
|
|
|
textAlign: 'center',
|
|
|
|
backgroundColor: token.backTopBackground,
|
2022-05-17 21:57:22 +08:00
|
|
|
borderRadius: backTopSize,
|
2022-11-17 23:31:41 +08:00
|
|
|
transition: `all ${token.motionDurationMid}`,
|
2022-04-20 19:36:59 +08:00
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: token.backTopHoverBackground,
|
2022-11-17 23:31:41 +08:00
|
|
|
transition: `all ${token.motionDurationMid}`,
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// change to .backtop .backtop-icon
|
|
|
|
[`${componentCls}-icon`]: {
|
2022-05-17 21:57:22 +08:00
|
|
|
fontSize: backTopFontSize,
|
2023-11-14 10:39:49 +08:00
|
|
|
lineHeight: unit(backTopSize),
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genMediaBackTopStyle: GenerateStyle<BackTopToken> = (token): CSSObject => {
|
2023-11-14 10:39:49 +08:00
|
|
|
const { componentCls, screenMD, screenXS, backTopInlineEndMD, backTopInlineEndXS } = token;
|
2022-04-20 19:36:59 +08:00
|
|
|
return {
|
2023-11-14 10:39:49 +08:00
|
|
|
[`@media (max-width: ${unit(screenMD)})`]: {
|
2022-04-20 19:36:59 +08:00
|
|
|
[componentCls]: {
|
2023-11-14 10:39:49 +08:00
|
|
|
insetInlineEnd: backTopInlineEndMD,
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
2023-11-14 10:39:49 +08:00
|
|
|
[`@media (max-width: ${unit(screenXS)})`]: {
|
2022-04-20 19:36:59 +08:00
|
|
|
[componentCls]: {
|
2023-11-14 10:39:49 +08:00
|
|
|
insetInlineEnd: backTopInlineEndXS,
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-11-14 10:39:49 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'BackTop'> = (token) => ({
|
|
|
|
zIndexPopup: token.zIndexBase + 10,
|
|
|
|
});
|
|
|
|
|
2022-04-20 19:36:59 +08:00
|
|
|
// ============================== Export ==============================
|
2023-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks(
|
2022-04-20 19:36:59 +08:00
|
|
|
'BackTop',
|
2022-11-17 23:31:41 +08:00
|
|
|
(token) => {
|
2022-05-17 21:57:22 +08:00
|
|
|
const {
|
|
|
|
fontSizeHeading3,
|
2022-08-04 16:16:50 +08:00
|
|
|
colorTextDescription,
|
2022-05-17 21:57:22 +08:00
|
|
|
colorTextLightSolid,
|
|
|
|
colorText,
|
|
|
|
controlHeightLG,
|
2023-11-14 10:39:49 +08:00
|
|
|
calc,
|
2022-05-17 21:57:22 +08:00
|
|
|
} = token;
|
2022-04-20 19:36:59 +08:00
|
|
|
const backTopToken = mergeToken<BackTopToken>(token, {
|
2022-08-04 16:16:50 +08:00
|
|
|
backTopBackground: colorTextDescription,
|
2022-05-17 21:57:22 +08:00
|
|
|
backTopColor: colorTextLightSolid,
|
|
|
|
backTopHoverBackground: colorText,
|
|
|
|
backTopFontSize: fontSizeHeading3,
|
|
|
|
backTopSize: controlHeightLG,
|
2023-11-14 10:39:49 +08:00
|
|
|
backTopBlockEnd: calc(controlHeightLG).mul(1.25).equal(),
|
|
|
|
backTopInlineEnd: calc(controlHeightLG).mul(2.5).equal(),
|
|
|
|
backTopInlineEndMD: calc(controlHeightLG).mul(1.5).equal(),
|
|
|
|
backTopInlineEndXS: calc(controlHeightLG).mul(0.5).equal(),
|
2022-04-20 19:36:59 +08:00
|
|
|
});
|
|
|
|
return [genSharedBackTopStyle(backTopToken), genMediaBackTopStyle(backTopToken)];
|
|
|
|
},
|
2023-11-14 10:39:49 +08:00
|
|
|
prepareComponentToken,
|
2022-04-20 19:36:59 +08:00
|
|
|
);
|