ant-design/components/drawer/style/index.tsx

256 lines
7.9 KiB
TypeScript
Raw Normal View History

2022-03-24 23:33:51 +08:00
// deps-lint-skip-all
2022-05-09 22:20:07 +08:00
import type { CSSObject } from '@ant-design/cssinjs';
import { Keyframes } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from '../../_util/theme';
import { genComponentStyleHook, mergeToken } from '../../_util/theme';
2022-03-24 23:33:51 +08:00
export interface DrawerToken extends FullToken<'Drawer'> {
2022-05-17 20:22:26 +08:00
drawerFooterPaddingVertical: number;
drawerFooterPaddingHorizontal: number;
2022-03-24 23:33:51 +08:00
}
const antdDrawerFadeIn = new Keyframes('antDrawerFadeIn', {
2022-03-24 23:33:51 +08:00
'0%': { opacity: 0 },
'100%': { opacity: 1 },
});
// =============================== Base ===============================
const genBaseStyle: GenerateStyle<DrawerToken> = (token: DrawerToken): CSSObject => {
2022-03-24 23:33:51 +08:00
const {
componentCls,
2022-03-24 23:33:51 +08:00
motionEaseOut,
motionDurationSlow,
fontSizeLG,
paddingLG,
lineWidth,
radiusBase,
fontSize,
lineHeight,
2022-05-17 20:22:26 +08:00
drawerFooterPaddingVertical,
drawerFooterPaddingHorizontal,
zIndexPopupBase,
2022-03-24 23:33:51 +08:00
colorText,
2022-05-17 20:22:26 +08:00
padding,
lineType,
colorSplit,
2022-03-24 23:33:51 +08:00
} = token;
return {
[`${componentCls}`]: {
2022-03-24 23:33:51 +08:00
position: 'fixed',
zIndex: zIndexPopupBase,
2022-03-24 23:33:51 +08:00
width: 0,
height: '100%',
transition: `width 0s ease ${motionDurationSlow}, height 0s ease ${motionDurationSlow}`,
[`${componentCls}-content-wrapper`]: {
2022-03-24 23:33:51 +08:00
position: 'absolute',
width: '100%',
height: '100%',
transition: `transform ${motionDurationSlow} ${motionEaseOut},box-shadow ${motionDurationSlow} ${motionEaseOut}`,
[`${componentCls}-content`]: {
2022-03-24 23:33:51 +08:00
width: '100%',
height: '100%',
position: 'relative',
zIndex: 1,
overflow: 'auto',
backgroundColor: token.colorBgElevated,
2022-03-24 23:33:51 +08:00
backgroundClip: `padding-box`,
border: 0,
[`${componentCls}-wrapper-body`]: {
2022-03-24 23:33:51 +08:00
display: 'flex',
flexFlow: 'column nowrap',
width: '100%',
height: '100%',
[`${componentCls}-header`]: {
2022-03-24 23:33:51 +08:00
position: 'relative',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
2022-05-17 20:22:26 +08:00
padding: `${padding}px ${paddingLG}px`,
2022-03-24 23:33:51 +08:00
color: colorText,
background: token.colorBgElevated,
2022-05-17 20:22:26 +08:00
borderBottom: `${lineWidth}px ${lineType} ${colorSplit}`,
borderRadius: `${radiusBase}px ${radiusBase}px 0 0`,
2022-03-24 23:33:51 +08:00
[`${componentCls}-header-title`]: {
2022-03-24 23:33:51 +08:00
display: 'flex',
flex: 1,
alignItems: 'center',
justifyContent: 'space-between',
[`${componentCls}-title`]: {
2022-03-24 23:33:51 +08:00
flex: 1,
margin: 0,
color: colorText,
2022-05-17 20:22:26 +08:00
fontWeight: token.fontWeightStrong,
2022-03-24 23:33:51 +08:00
fontSize: fontSizeLG,
2022-05-17 20:22:26 +08:00
lineHeight: token.lineHeightLG,
2022-03-24 23:33:51 +08:00
},
[`${componentCls}-close`]: {
2022-03-24 23:33:51 +08:00
display: 'inline-block',
2022-05-17 20:22:26 +08:00
marginInlineEnd: token.marginSM,
color: token.colorAction,
fontWeight: token.fontWeightStrong,
2022-03-24 23:33:51 +08:00
fontSize: fontSizeLG,
fontStyle: 'normal',
lineHeight: 1,
textAlign: 'center',
textTransform: 'none',
textDecoration: 'none',
background: 'transparent',
border: 0,
outline: 0,
cursor: 'pointer',
transition: `color ${motionDurationSlow}`,
textRendering: 'auto',
2022-05-17 20:22:26 +08:00
[`&:focus, &:hover`]: {
color: token.colorActionHover,
2022-03-24 23:33:51 +08:00
textDecoration: 'none',
},
},
},
[`${componentCls}-header-close-only`]: {
2022-03-24 23:33:51 +08:00
paddingBottom: 0,
border: 'none',
},
},
[`${componentCls}-body`]: {
2022-03-24 23:33:51 +08:00
flexGrow: 1,
padding: paddingLG,
overflow: 'auto',
fontSize,
lineHeight,
wordWrap: 'break-word',
},
[`${componentCls}-footer`]: {
2022-03-24 23:33:51 +08:00
flexShrink: 0,
2022-05-17 20:22:26 +08:00
padding: `${drawerFooterPaddingVertical}px ${drawerFooterPaddingHorizontal}px`,
borderTop: `${lineWidth}px ${lineType} ${colorSplit}`,
2022-03-24 23:33:51 +08:00
},
},
},
},
[`${componentCls}-mask`]: {
2022-03-24 23:33:51 +08:00
position: 'absolute',
insetBlockStart: 0,
insetInlineStart: 0,
width: '100%',
height: 0,
backgroundColor: token.controlMaskBg,
2022-03-24 23:33:51 +08:00
opacity: 0,
transition: `opacity ${motionDurationSlow} linear, height 0s ease ${motionDurationSlow}`,
pointerEvents: 'none',
},
},
[`${componentCls}${componentCls}-open ${componentCls}-mask`]: {
2022-03-24 23:33:51 +08:00
height: '100%',
opacity: 1,
transition: 'none',
animationName: antdDrawerFadeIn,
animationDuration: token.motionDurationSlow,
animationTimingFunction: motionEaseOut,
2022-03-24 23:33:51 +08:00
pointerEvents: 'auto',
},
};
};
const genDrawerStyle: GenerateStyle<DrawerToken> = (token: DrawerToken) => {
const { componentCls, motionDurationSlow, lineWidth, motionEaseOut } = token;
2022-03-24 23:33:51 +08:00
return {
// =================== left,right ===================
[`${componentCls}-left`]: {
2022-03-24 23:33:51 +08:00
insetInlineStart: 0,
insetBlockStart: 0,
width: 0,
height: '100%',
[`${componentCls}-content-wrapper`]: {
2022-03-24 23:33:51 +08:00
height: '100%',
insetInlineStart: 0,
},
},
[`${componentCls}-left${componentCls}-open`]: {
2022-03-24 23:33:51 +08:00
width: '100%',
transition: `transform ${motionDurationSlow} ${motionEaseOut}`,
[`${componentCls}-content-wrapper`]: {
boxShadow: token.boxShadowDrawerRight,
2022-03-24 23:33:51 +08:00
},
},
[`${componentCls}-right`]: {
2022-03-24 23:33:51 +08:00
insetInlineEnd: 0,
insetBlockStart: 0,
width: 0,
height: '100%',
[`${componentCls}-content-wrapper`]: {
2022-03-24 23:33:51 +08:00
height: '100%',
insetInlineEnd: 0,
},
},
[`${componentCls}-right${componentCls}-open`]: {
2022-03-24 23:33:51 +08:00
width: '100%',
transition: `transform ${motionDurationSlow} ${motionEaseOut}`,
[`${componentCls}-content-wrapper`]: {
boxShadow: token.boxShadowDrawerLeft,
2022-03-24 23:33:51 +08:00
},
},
// https://github.com/ant-design/ant-design/issues/18607, Avoid edge alignment bug.
[`${componentCls}-right${componentCls}-open.no-mask`]: {
2022-03-24 23:33:51 +08:00
insetInlineEnd: lineWidth,
transform: `translateX(${lineWidth})`,
},
// =================== top,bottom ===================
[`${componentCls}-top,${componentCls}-bottom`]: {
2022-03-24 23:33:51 +08:00
insetInlineStart: 0,
width: '100%',
height: 0,
[`${componentCls}-content-wrapper`]: {
2022-03-24 23:33:51 +08:00
width: '100%',
},
},
[`${componentCls}-top${componentCls}-open,${componentCls}-bottom${componentCls}-open`]: {
height: '100%',
transition: `transform ${motionDurationSlow} ${motionEaseOut}`,
},
2022-03-24 23:33:51 +08:00
[`${componentCls}-top`]: {
2022-03-24 23:33:51 +08:00
insetBlockStart: 0,
},
[`${componentCls}-top${componentCls}-open`]: {
[`${componentCls}-content-wrapper`]: {
boxShadow: token.boxShadowDrawerDown,
2022-03-24 23:33:51 +08:00
},
},
[`${componentCls}-bottom`]: {
2022-03-24 23:33:51 +08:00
bottom: 0,
[`${componentCls}-content-wrapper`]: {
2022-03-24 23:33:51 +08:00
bottom: 0,
},
},
[`${componentCls}-bottom${componentCls}-bottom-open`]: {
[`${componentCls}-content-wrapper`]: {
boxShadow: token.boxShadowDrawerUp,
2022-03-24 23:33:51 +08:00
},
},
[`${componentCls}-bottom${componentCls}-bottom-open.no-mask`]: {
2022-03-24 23:33:51 +08:00
insetBlockEnd: lineWidth,
transform: `translateY(${lineWidth})`,
},
};
};
// ============================== Export ==============================
export default genComponentStyleHook('Drawer', token => {
const drawerToken = mergeToken<DrawerToken>(token, {
2022-05-17 20:22:26 +08:00
drawerFooterPaddingVertical: token.paddingXS,
drawerFooterPaddingHorizontal: token.padding,
});
2022-03-24 23:33:51 +08:00
return [genBaseStyle(drawerToken), genDrawerStyle(drawerToken)];
});