ant-design-vue/components/_util/transition.tsx

86 lines
3.0 KiB
Vue
Raw Normal View History

2020-10-26 10:31:50 +00:00
import { defineComponent, nextTick, Transition as T, TransitionGroup as TG } from 'vue';
2020-10-25 15:06:03 +00:00
import { findDOMNode } from './props-util';
2020-10-22 14:45:21 +00:00
export const getTransitionProps = (transitionName: string, opt: object = {}) => {
2020-10-22 15:27:18 +00:00
if (process.env.NODE_ENV === 'test') {
2020-10-25 15:06:03 +00:00
return opt;
2020-10-22 15:27:18 +00:00
}
2020-10-22 14:45:21 +00: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 15:06:03 +00:00
Transition = (props, { slots }) => {
2020-10-27 15:02:45 +00:00
const child = slots.default?.()[0];
2020-10-25 15:06:03 +00:00
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 14:45:21 +00:00
return slots.default?.();
};
2020-10-27 15:02:45 +00:00
Transition.displayName = 'TransitionForTest';
2020-10-25 15:06:03 +00:00
Transition.inheritAttrs = false;
2020-10-22 14:45:21 +00:00
TransitionGroup = defineComponent({
2020-10-26 10:31:50 +00:00
name: 'TransitionGroupForTest',
2020-10-22 14:51:50 +00:00
inheritAttrs: false,
2020-10-22 14:45:21 +00:00
props: ['tag', 'class'],
setup(props, { slots }) {
return () => {
2020-11-07 14:43:31 +00:00
const { tag: Tag, ...rest } = props;
2020-10-26 10:31:50 +00:00
const children = slots.default?.() || [];
2020-10-27 15:02:45 +00:00
if (Tag) {
return <Tag {...rest}>{children}</Tag>;
2020-10-26 10:31:50 +00:00
} else {
return children;
}
2020-10-22 14:45:21 +00:00
};
},
});
}
export { Transition, TransitionGroup };
export default Transition;