2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { resetComponent } from '../../style';
|
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 {
|
|
|
|
zIndexPopup: number;
|
|
|
|
}
|
2022-04-20 19:36:59 +08:00
|
|
|
|
|
|
|
type BackTopToken = FullToken<'BackTop'> & {
|
|
|
|
backTopBackground: string;
|
|
|
|
backTopColor: string;
|
|
|
|
backTopHoverBackground: string;
|
2022-05-17 21:57:22 +08:00
|
|
|
backTopFontSize: number;
|
|
|
|
backTopSize: number;
|
|
|
|
|
|
|
|
// Position
|
|
|
|
backTopBlockEnd: number;
|
|
|
|
backTopInlineEnd: number;
|
|
|
|
backTopInlineEndMD: number;
|
|
|
|
backTopInlineEndXS: number;
|
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,
|
|
|
|
lineHeight: `${backTopSize}px`,
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genMediaBackTopStyle: GenerateStyle<BackTopToken> = (token): CSSObject => {
|
|
|
|
const { componentCls } = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`@media (max-width: ${token.screenMD}px)`]: {
|
|
|
|
[componentCls]: {
|
2022-05-17 21:57:22 +08:00
|
|
|
insetInlineEnd: token.backTopInlineEndMD,
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`@media (max-width: ${token.screenXS}px)`]: {
|
|
|
|
[componentCls]: {
|
2022-05-17 21:57:22 +08:00
|
|
|
insetInlineEnd: token.backTopInlineEndXS,
|
2022-04-20 19:36:59 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
|
|
|
export default genComponentStyleHook<'BackTop'>(
|
|
|
|
'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,
|
|
|
|
} = 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,
|
|
|
|
|
|
|
|
backTopBlockEnd: controlHeightLG * 1.25,
|
|
|
|
backTopInlineEnd: controlHeightLG * 2.5,
|
|
|
|
backTopInlineEndMD: controlHeightLG * 1.5,
|
|
|
|
backTopInlineEndXS: controlHeightLG * 0.5,
|
2022-04-20 19:36:59 +08:00
|
|
|
});
|
|
|
|
return [genSharedBackTopStyle(backTopToken), genMediaBackTopStyle(backTopToken)];
|
|
|
|
},
|
2022-11-17 23:31:41 +08:00
|
|
|
(token) => ({
|
2022-05-17 21:57:22 +08:00
|
|
|
zIndexPopup: token.zIndexBase + 10,
|
|
|
|
}),
|
2022-04-20 19:36:59 +08:00
|
|
|
);
|