antd
Version:
An enterprise-class UI design language and React components implementation
63 lines (62 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const getMoveTranslate = direction => {
const value = '100%';
return {
left: `translateX(-${value})`,
right: `translateX(${value})`,
top: `translateY(-${value})`,
bottom: `translateY(${value})`
}[direction];
};
const getEnterLeaveStyle = (startStyle, endStyle) => ({
'&-enter, &-appear': {
...startStyle,
'&-active': endStyle
},
'&-leave': {
...endStyle,
'&-active': startStyle
}
});
const getFadeStyle = (from, duration) => ({
'&-enter, &-appear, &-leave': {
'&-start': {
transition: 'none'
},
'&-active': {
transition: `all ${duration}`
}
},
...getEnterLeaveStyle({
opacity: from
}, {
opacity: 1
})
});
const getPanelMotionStyles = (direction, duration) => [getFadeStyle(0.7, duration), getEnterLeaveStyle({
transform: getMoveTranslate(direction)
}, {
transform: 'none'
})];
const genMotionStyle = 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) => ({
...obj,
[`&-${direction}`]: getPanelMotionStyles(direction, motionDurationSlow)
}), {})
}
};
};
var _default = exports.default = genMotionStyle;