refactor: menu
parent
8dd74a9977
commit
0d318a324a
|
@ -108,9 +108,15 @@ const getCurrentHeight: MotionEventHandler = node => ({ height: node.offsetHeigh
|
||||||
// const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
|
// const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
|
||||||
// (event as TransitionEvent).propertyName === 'height';
|
// (event as TransitionEvent).propertyName === 'height';
|
||||||
|
|
||||||
const collapseMotion: BaseTransitionProps<HTMLElement> = {
|
export interface CSSMotionProps extends Partial<BaseTransitionProps<HTMLElement>> {
|
||||||
// motionName: 'ant-motion-collapse',
|
name?: string;
|
||||||
|
css?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const collapseMotion: CSSMotionProps = {
|
||||||
|
name: 'ant-motion-collapse',
|
||||||
appear: true,
|
appear: true,
|
||||||
|
css: false,
|
||||||
// onAppearStart: getCollapsedHeight,
|
// onAppearStart: getCollapsedHeight,
|
||||||
onBeforeEnter: getCollapsedHeight,
|
onBeforeEnter: getCollapsedHeight,
|
||||||
onEnter: getRealHeight,
|
onEnter: getRealHeight,
|
||||||
|
|
|
@ -9,13 +9,14 @@ import {
|
||||||
watchEffect,
|
watchEffect,
|
||||||
watch,
|
watch,
|
||||||
reactive,
|
reactive,
|
||||||
|
onMounted,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import shallowEqual from '../../_util/shallowequal';
|
import shallowEqual from '../../_util/shallowequal';
|
||||||
import useProvideMenu, { StoreMenuInfo, useProvideFirstLevel } from './hooks/useMenuContext';
|
import useProvideMenu, { StoreMenuInfo, useProvideFirstLevel } from './hooks/useMenuContext';
|
||||||
import useConfigInject from '../../_util/hooks/useConfigInject';
|
import useConfigInject from '../../_util/hooks/useConfigInject';
|
||||||
import { MenuTheme, MenuMode, BuiltinPlacements, TriggerSubMenuAction } from './interface';
|
import { MenuTheme, MenuMode, BuiltinPlacements, TriggerSubMenuAction } from './interface';
|
||||||
import devWarning from 'ant-design-vue/es/vc-util/devWarning';
|
import devWarning from 'ant-design-vue/es/vc-util/devWarning';
|
||||||
import { collapseMotion } from 'ant-design-vue/es/_util/transition';
|
import { collapseMotion, CSSMotionProps } from 'ant-design-vue/es/_util/transition';
|
||||||
|
|
||||||
export const menuProps = {
|
export const menuProps = {
|
||||||
prefixCls: String,
|
prefixCls: String,
|
||||||
|
@ -24,6 +25,8 @@ export const menuProps = {
|
||||||
overflowDisabled: Boolean,
|
overflowDisabled: Boolean,
|
||||||
openKeys: Array,
|
openKeys: Array,
|
||||||
|
|
||||||
|
motion: Object as PropType<CSSMotionProps>,
|
||||||
|
|
||||||
theme: { type: String as PropType<MenuTheme>, default: 'light' },
|
theme: { type: String as PropType<MenuTheme>, default: 'light' },
|
||||||
mode: { type: String as PropType<MenuMode>, default: 'vertical' },
|
mode: { type: String as PropType<MenuMode>, default: 'vertical' },
|
||||||
|
|
||||||
|
@ -59,6 +62,10 @@ export default defineComponent({
|
||||||
return inlineCollapsed;
|
return inlineCollapsed;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isMounted = ref(false);
|
||||||
|
onMounted(() => {
|
||||||
|
isMounted.value = true;
|
||||||
|
});
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
devWarning(
|
devWarning(
|
||||||
!('inlineCollapsed' in props && props.mode !== 'inline'),
|
!('inlineCollapsed' in props && props.mode !== 'inline'),
|
||||||
|
@ -115,9 +122,9 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultMotions = {
|
const defaultMotions = {
|
||||||
horizontal: { motionName: `ant-slide-up` },
|
horizontal: { name: `ant-slide-up` },
|
||||||
inline: collapseMotion,
|
inline: collapseMotion,
|
||||||
other: { motionName: `ant-zoom-big` },
|
other: { name: `ant-zoom-big` },
|
||||||
};
|
};
|
||||||
|
|
||||||
useProvideFirstLevel(true);
|
useProvideFirstLevel(true);
|
||||||
|
@ -176,7 +183,8 @@ export default defineComponent({
|
||||||
inlineCollapsed: mergedInlineCollapsed,
|
inlineCollapsed: mergedInlineCollapsed,
|
||||||
antdMenuTheme: computed(() => props.theme),
|
antdMenuTheme: computed(() => props.theme),
|
||||||
siderCollapsed,
|
siderCollapsed,
|
||||||
defaultMotions,
|
defaultMotions: computed(() => (isMounted.value ? defaultMotions : null)),
|
||||||
|
motion: computed(() => (isMounted.value ? props.motion : null)),
|
||||||
overflowDisabled: computed(() => props.overflowDisabled),
|
overflowDisabled: computed(() => props.overflowDisabled),
|
||||||
onOpenChange: onInternalOpenChange,
|
onOpenChange: onInternalOpenChange,
|
||||||
registerMenuInfo,
|
registerMenuInfo,
|
||||||
|
|
|
@ -182,14 +182,6 @@ export default defineComponent({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const className = computed(() =>
|
|
||||||
classNames(
|
|
||||||
prefixCls.value,
|
|
||||||
`${prefixCls.value}-sub`,
|
|
||||||
`${prefixCls.value}-${mode.value === 'inline' ? 'inline' : 'vertical'}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Cache mode if it change to `inline` which do not have popup motion
|
// Cache mode if it change to `inline` which do not have popup motion
|
||||||
const triggerModeRef = computed(() => {
|
const triggerModeRef = computed(() => {
|
||||||
return mode.value !== 'inline' && keysPath.value.length > 1 ? 'vertical' : mode.value;
|
return mode.value !== 'inline' && keysPath.value.length > 1 ? 'vertical' : mode.value;
|
||||||
|
@ -266,7 +258,6 @@ export default defineComponent({
|
||||||
class={classNames(
|
class={classNames(
|
||||||
subMenuPrefixClsValue,
|
subMenuPrefixClsValue,
|
||||||
`${subMenuPrefixClsValue}-${mode.value}`,
|
`${subMenuPrefixClsValue}-${mode.value}`,
|
||||||
className.value,
|
|
||||||
attrs.class,
|
attrs.class,
|
||||||
{
|
{
|
||||||
[`${subMenuPrefixClsValue}-open`]: open.value,
|
[`${subMenuPrefixClsValue}-open`]: open.value,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Key } from '../../../_util/type';
|
import { Key } from '../../../_util/type';
|
||||||
import { ComputedRef, defineComponent, inject, InjectionKey, provide, Ref, UnwrapRef } from 'vue';
|
import { ComputedRef, defineComponent, inject, InjectionKey, provide, Ref, UnwrapRef } from 'vue';
|
||||||
import { BuiltinPlacements, MenuMode, MenuTheme, TriggerSubMenuAction } from '../interface';
|
import { BuiltinPlacements, MenuMode, MenuTheme, TriggerSubMenuAction } from '../interface';
|
||||||
|
import { CSSMotionProps } from '../../../_util/transition';
|
||||||
|
|
||||||
export interface StoreMenuInfo {
|
export interface StoreMenuInfo {
|
||||||
eventKey: string;
|
eventKey: string;
|
||||||
|
@ -46,8 +47,8 @@ export interface MenuContextProps {
|
||||||
inlineIndent: ComputedRef<number>;
|
inlineIndent: ComputedRef<number>;
|
||||||
|
|
||||||
// // Motion
|
// // Motion
|
||||||
motion?: any;
|
motion?: ComputedRef<CSSMotionProps | null>;
|
||||||
defaultMotions?: Partial<{ [key in MenuMode | 'other']: any }>;
|
defaultMotions?: ComputedRef<Partial<{ [key in MenuMode | 'other']: CSSMotionProps }> | null>;
|
||||||
|
|
||||||
// // Popup
|
// // Popup
|
||||||
subMenuOpenDelay: ComputedRef<number>;
|
subMenuOpenDelay: ComputedRef<number>;
|
||||||
|
|
2
v2-doc
2
v2-doc
|
@ -1 +1 @@
|
||||||
Subproject commit a7013ae87f69dcbcf547f4b023255b8a7a775557
|
Subproject commit d197053285b81e77718621c0b5b94cb3b21831a2
|
Loading…
Reference in New Issue