2020-10-25 23:06:03 +08:00
|
|
|
import { defineComponent, Fragment, nextTick, Transition as T, TransitionGroup as TG } from 'vue';
|
|
|
|
import { findDOMNode } from './props-util';
|
2020-10-22 22:45:21 +08:00
|
|
|
|
|
|
|
export const getTransitionProps = (transitionName: string, opt: object = {}) => {
|
2020-10-22 23:27:18 +08:00
|
|
|
if (process.env.NODE_ENV === 'test') {
|
2020-10-25 23:06:03 +08:00
|
|
|
return opt;
|
2020-10-22 23:27:18 +08:00
|
|
|
}
|
2020-10-22 22:45:21 +08:00
|
|
|
const transitionProps = transitionName
|
|
|
|
? {
|
|
|
|
appear: true,
|
|
|
|
appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
|
|
|
|
// appearActiveClass: `antdv-base-transtion`,
|
|
|
|
appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
|
|
|
|
enterFromClass: `${transitionName}-enter ${transitionName}-enter-prepare`,
|
|
|
|
// enterActiveClass: `antdv-base-transtion`,
|
|
|
|
enterToClass: `${transitionName}-enter ${transitionName}-enter-active`,
|
|
|
|
leaveFromClass: ` ${transitionName}-leave`,
|
|
|
|
leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`,
|
|
|
|
leaveToClass: `${transitionName}-leave ${transitionName}-leave-active`,
|
|
|
|
...opt,
|
|
|
|
}
|
|
|
|
: { css: false, ...opt };
|
|
|
|
return transitionProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getTransitionGroupProps = (transitionName: string, opt: object = {}) => {
|
|
|
|
const transitionProps = transitionName
|
|
|
|
? {
|
|
|
|
appear: true,
|
|
|
|
appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
|
|
|
|
appearActiveClass: `${transitionName}`,
|
|
|
|
appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
|
|
|
|
enterFromClass: `${transitionName}-appear ${transitionName}-enter ${transitionName}-appear-prepare ${transitionName}-enter-prepare`,
|
|
|
|
enterActiveClass: `${transitionName}`,
|
|
|
|
enterToClass: `${transitionName}-enter ${transitionName}-appear ${transitionName}-appear-active ${transitionName}-enter-active`,
|
|
|
|
leaveActiveClass: `${transitionName} ${transitionName}-leave`,
|
|
|
|
leaveToClass: `${transitionName}-leave-active`,
|
|
|
|
...opt,
|
|
|
|
}
|
|
|
|
: { css: false, ...opt };
|
|
|
|
return transitionProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
let Transition = T;
|
|
|
|
let TransitionGroup = TG;
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'test') {
|
2020-10-25 23:06:03 +08:00
|
|
|
Transition = (props, { slots }) => {
|
|
|
|
let child = slots.default?.()[0];
|
|
|
|
if (child && child.dirs && child.dirs[0]) {
|
|
|
|
const value = child.dirs[0].value;
|
|
|
|
const oldValue = child.dirs[0].oldValue;
|
|
|
|
if (!value && value !== oldValue) {
|
|
|
|
nextTick(() => {
|
|
|
|
if (props.onAfterLeave) {
|
|
|
|
props.onAfterLeave(findDOMNode(this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-10-22 22:45:21 +08:00
|
|
|
return slots.default?.();
|
|
|
|
};
|
2020-10-25 23:06:03 +08:00
|
|
|
Transition.inheritAttrs = false;
|
2020-10-22 22:45:21 +08:00
|
|
|
TransitionGroup = defineComponent({
|
2020-10-22 22:51:50 +08:00
|
|
|
inheritAttrs: false,
|
2020-10-22 22:45:21 +08:00
|
|
|
props: ['tag', 'class'],
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const { tag: Tag = Fragment, ...rest } = props;
|
|
|
|
return () => {
|
|
|
|
return <Tag {...rest}>{slots.default?.()}</Tag>;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export { Transition, TransitionGroup };
|
|
|
|
|
|
|
|
export default Transition;
|