ant-design/components/back-top/style/index.tsx

119 lines
3.2 KiB
TypeScript
Raw Normal View History

// deps-lint-skip-all
2022-05-09 22:20:07 +08:00
import type { CSSObject } from '@ant-design/cssinjs';
import type { GenerateStyle, FullToken } from '../../_util/theme';
import { resetComponent, genComponentStyleHook, mergeToken } from '../../_util/theme';
/** Component only token. Which will handle additional calculation of alias token */
2022-05-17 21:57:22 +08:00
export interface ComponentToken {
zIndexPopup: number;
}
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;
};
// ============================== Shared ==============================
const genSharedBackTopStyle: GenerateStyle<BackTopToken, CSSObject> = (token): CSSObject => {
2022-05-17 21:57:22 +08:00
const { componentCls, backTopFontSize, backTopSize, zIndexPopup } = token;
return {
[componentCls]: {
...resetComponent(token),
position: 'fixed',
2022-05-17 21:57:22 +08:00
insetInlineEnd: token.backTopInlineEnd,
insetBlockEnd: token.backTopBlockEnd,
zIndex: zIndexPopup,
width: 40,
height: 40,
cursor: 'pointer',
'&:empty': {
display: 'none',
},
[`${componentCls}-content`]: {
2022-05-17 21:57:22 +08:00
width: backTopSize,
height: backTopSize,
overflow: 'hidden',
color: token.backTopColor,
textAlign: 'center',
backgroundColor: token.backTopBackground,
2022-05-17 21:57:22 +08:00
borderRadius: backTopSize,
transition: `all ${token.motionDurationSlow}`,
'&:hover': {
backgroundColor: token.backTopHoverBackground,
transition: `all ${token.motionDurationSlow}`,
},
},
// change to .backtop .backtop-icon
[`${componentCls}-icon`]: {
2022-05-17 21:57:22 +08:00
fontSize: backTopFontSize,
lineHeight: `${backTopSize}px`,
},
},
};
};
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,
},
},
[`@media (max-width: ${token.screenXS}px)`]: {
[componentCls]: {
2022-05-17 21:57:22 +08:00
insetInlineEnd: token.backTopInlineEndXS,
},
},
};
};
// ============================== Export ==============================
export default genComponentStyleHook<'BackTop'>(
'BackTop',
token => {
2022-05-17 21:57:22 +08:00
const {
fontSizeHeading3,
colorTextSecondary,
colorTextLightSolid,
colorText,
controlHeightLG,
} = token;
const backTopToken = mergeToken<BackTopToken>(token, {
2022-05-17 21:57:22 +08:00
backTopBackground: colorTextSecondary,
backTopColor: colorTextLightSolid,
backTopHoverBackground: colorText,
backTopFontSize: fontSizeHeading3,
backTopSize: controlHeightLG,
backTopBlockEnd: controlHeightLG * 1.25,
backTopInlineEnd: controlHeightLG * 2.5,
backTopInlineEndMD: controlHeightLG * 1.5,
backTopInlineEndXS: controlHeightLG * 0.5,
});
return [genSharedBackTopStyle(backTopToken), genMediaBackTopStyle(backTopToken)];
},
2022-05-17 21:57:22 +08:00
token => ({
zIndexPopup: token.zIndexBase + 10,
}),
);