mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 17:19:11 +08:00
8eab5139ad
* refactor: rewrite drawer motion style code * style: improve Drawer motion * refactor: simpify style code * test: fix test coverage * test: fix test coverage * chore: remove !important * chore: revert refactor code * refactor: simpify style code * refactor: simpify style code * refactor: simpify style code * refactor: simpify style code * revert: move distance to 100%
79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
import type { DrawerToken } from '.';
|
|
import type { GenerateStyle } from '../../theme/internal';
|
|
|
|
type Direction = 'left' | 'right' | 'top' | 'bottom';
|
|
|
|
const getMoveTranslate = (direction: Direction) => {
|
|
const value = '100%';
|
|
return {
|
|
left: `translateX(-${value})`,
|
|
right: `translateX(${value})`,
|
|
top: `translateY(-${value})`,
|
|
bottom: `translateY(${value})`,
|
|
}[direction];
|
|
};
|
|
|
|
const getEnterLeaveStyle = (startStyle: React.CSSProperties, endStyle: React.CSSProperties) => ({
|
|
'&-enter, &-appear': {
|
|
...startStyle,
|
|
'&-active': endStyle,
|
|
},
|
|
'&-leave': {
|
|
...endStyle,
|
|
'&-active': startStyle,
|
|
},
|
|
});
|
|
|
|
const getFadeStyle = (from: number, duration: string) => ({
|
|
'&-enter, &-appear, &-leave': {
|
|
'&-start': {
|
|
transition: 'none',
|
|
},
|
|
'&-active': {
|
|
transition: `all ${duration}`,
|
|
},
|
|
},
|
|
...getEnterLeaveStyle(
|
|
{
|
|
opacity: from,
|
|
},
|
|
{
|
|
opacity: 1,
|
|
},
|
|
),
|
|
});
|
|
|
|
const getPanelMotionStyles = (direction: Direction, duration: string) => [
|
|
getFadeStyle(0.7, duration),
|
|
getEnterLeaveStyle(
|
|
{
|
|
transform: getMoveTranslate(direction),
|
|
},
|
|
{
|
|
transform: 'none',
|
|
},
|
|
),
|
|
];
|
|
|
|
const genMotionStyle: GenerateStyle<DrawerToken> = (token) => {
|
|
const { componentCls, motionDurationSlow } = token;
|
|
|
|
return {
|
|
[componentCls]: {
|
|
// ======================== Mask ========================
|
|
[`${componentCls}-mask-motion`]: getFadeStyle(0, motionDurationSlow),
|
|
|
|
// ======================= Panel ========================
|
|
[`${componentCls}-panel-motion`]: ['left', 'right', 'top', 'bottom'].reduce(
|
|
(obj, direction: Direction) => ({
|
|
...obj,
|
|
[`&-${direction}`]: getPanelMotionStyles(direction, motionDurationSlow),
|
|
}),
|
|
{},
|
|
),
|
|
},
|
|
};
|
|
};
|
|
|
|
export default genMotionStyle;
|