Skip to content

Commit

Permalink
refactor: menu (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou authored May 23, 2021
1 parent ea8ff66 commit 67952ab
Show file tree
Hide file tree
Showing 38 changed files with 2,141 additions and 952 deletions.
69 changes: 67 additions & 2 deletions components/_util/transition.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { defineComponent, nextTick, Transition as T, TransitionGroup as TG } from 'vue';
import {
BaseTransitionProps,
CSSProperties,
defineComponent,
nextTick,
Ref,
Transition as T,
TransitionGroup as TG,
} from 'vue';
import { findDOMNode } from './props-util';

export const getTransitionProps = (transitionName: string, opt: object = {}) => {
Expand Down Expand Up @@ -80,6 +88,63 @@ if (process.env.NODE_ENV === 'test') {
});
}

export { Transition, TransitionGroup };
export declare type MotionEvent = (TransitionEvent | AnimationEvent) & {
deadline?: boolean;
};

export declare type MotionEventHandler = (element: Element, done?: () => void) => CSSProperties;

export declare type MotionEndEventHandler = (element: Element, done?: () => void) => boolean | void;

// ================== Collapse Motion ==================
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
const getRealHeight: MotionEventHandler = node => ({
height: `${node.scrollHeight}px`,
opacity: 1,
});
const getCurrentHeight: MotionEventHandler = (node: any) => ({ height: `${node.offsetHeight}px` });
// const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
// (event as TransitionEvent).propertyName === 'height';

export interface CSSMotionProps extends Partial<BaseTransitionProps<Element>> {
name?: string;
css?: boolean;
}

const collapseMotion = (style: Ref<CSSProperties>, className: Ref<string>): CSSMotionProps => {
return {
name: 'ant-motion-collapse',
appear: true,
css: true,
onBeforeEnter: node => {
className.value = 'ant-motion-collapse';
style.value = getCollapsedHeight(node);
},
onEnter: node => {
nextTick(() => {
style.value = getRealHeight(node);
});
},
onAfterEnter: () => {
className.value = '';
style.value = {};
},
onBeforeLeave: node => {
className.value = 'ant-motion-collapse';
style.value = getCurrentHeight(node);
},
onLeave: node => {
window.setTimeout(() => {
style.value = getCollapsedHeight(node);
});
},
onAfterLeave: () => {
className.value = '';
style.value = {};
},
};
};

export { Transition, TransitionGroup, collapseMotion };

export default Transition;
66 changes: 0 additions & 66 deletions components/menu/MenuItem.tsx

This file was deleted.

42 changes: 0 additions & 42 deletions components/menu/SubMenu.tsx

This file was deleted.

Loading

0 comments on commit 67952ab

Please sign in to comment.