diff --git a/src/action-sheet/index.tsx b/src/action-sheet/index.tsx index 7ae296d37..bd96a3964 100644 --- a/src/action-sheet/index.tsx +++ b/src/action-sheet/index.tsx @@ -5,8 +5,9 @@ import { createNamespace, pick } from '../utils'; // Components import Icon from '../icon'; -import Popup, { popupSharedProps } from '../popup'; +import Popup from '../popup'; import Loading from '../loading'; +import { popupSharedProps, popupSharedPropKeys } from '../popup/shared'; const [createComponent, bem] = createNamespace('action-sheet'); @@ -50,10 +51,6 @@ export default createComponent({ emits: ['select', 'cancel', 'update:show'], setup(props, { slots, emit }) { - const popupPropKeys = Object.keys(popupSharedProps) as Array< - keyof typeof popupSharedProps - >; - const onUpdateShow = (show: boolean) => { emit('update:show', show); }; @@ -161,7 +158,7 @@ export default createComponent({ position="bottom" safeAreaInsetBottom={props.safeAreaInsetBottom} {...{ - ...pick(props, popupPropKeys), + ...pick(props, popupSharedPropKeys), 'onUpdate:show': onUpdateShow, }} > diff --git a/src/dialog/Dialog.tsx b/src/dialog/Dialog.tsx index 65490b28a..8239801f4 100644 --- a/src/dialog/Dialog.tsx +++ b/src/dialog/Dialog.tsx @@ -6,10 +6,11 @@ import { createNamespace, addUnit, pick, UnknownProp } from '../utils'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; // Components -import Popup, { popupSharedProps } from '../popup'; +import Popup from '../popup'; import Button from '../button'; import ActionBar from '../action-bar'; import ActionBarButton from '../action-bar-button'; +import { popupSharedProps, popupSharedPropKeys } from '../popup/shared'; const [createComponent, bem, t] = createNamespace('dialog'); @@ -18,7 +19,7 @@ export type DialogAction = 'confirm' | 'cancel'; export type DialogMessageAlign = 'left' | 'center' | 'right'; const popupKeys = [ - ...(Object.keys(popupSharedProps) as Array), + ...popupSharedPropKeys, 'transition', 'closeOnPopstate', ] as const; diff --git a/src/notify/Notify.tsx b/src/notify/Notify.tsx index 2e8e61786..df129a32d 100644 --- a/src/notify/Notify.tsx +++ b/src/notify/Notify.tsx @@ -1,6 +1,7 @@ import { PropType } from 'vue'; import { createNamespace, UnknownProp } from '../utils'; -import Popup, { popupSharedProps } from '../popup'; +import Popup from '../popup'; +import { popupSharedProps } from '../popup/shared'; const [createComponent, bem] = createNamespace('notify'); diff --git a/src/popup/index.tsx b/src/popup/index.tsx index df51e5291..4bf6bb050 100644 --- a/src/popup/index.tsx +++ b/src/popup/index.tsx @@ -1,4 +1,3 @@ -// Utils import { ref, watch, @@ -9,10 +8,12 @@ import { Transition, onActivated, CSSProperties, - TeleportProps, onDeactivated, } from 'vue'; -import { createNamespace, isDef, UnknownProp } from '../utils'; + +// Utils +import { popupSharedProps } from './shared'; +import { createNamespace, isDef } from '../utils'; // Composition import { useEventListener } from '@vant/use'; @@ -36,43 +37,6 @@ const [createComponent, bem] = createNamespace('popup'); let globalZIndex = 2000; -export const popupSharedProps = { - // whether to show popup - show: Boolean, - // z-index - zIndex: [Number, String], - // transition duration - duration: [Number, String], - // teleport - teleport: [String, Object] as PropType, - // overlay custom style - overlayStyle: Object as PropType, - // overlay custom class name - overlayClass: UnknownProp, - // Initial rendering animation - transitionAppear: Boolean, - // whether to show overlay - overlay: { - type: Boolean, - default: true, - }, - // prevent body scroll - lockScroll: { - type: Boolean, - default: true, - }, - // whether to lazy render - lazyRender: { - type: Boolean, - default: true, - }, - // whether to close popup when overlay is clicked - closeOnClickOverlay: { - type: Boolean, - default: true, - }, -}; - export default createComponent({ inheritAttrs: false, diff --git a/src/popup/shared.ts b/src/popup/shared.ts new file mode 100644 index 000000000..e276c2481 --- /dev/null +++ b/src/popup/shared.ts @@ -0,0 +1,45 @@ +import { PropType, CSSProperties, TeleportProps } from 'vue'; +import { UnknownProp } from '../utils'; + +export const popupSharedProps = { + // whether to show popup + show: Boolean, + // z-index + zIndex: [Number, String], + // transition duration + duration: [Number, String], + // teleport + teleport: [String, Object] as PropType, + // overlay custom style + overlayStyle: Object as PropType, + // overlay custom class name + overlayClass: UnknownProp, + // Initial rendering animation + transitionAppear: Boolean, + // whether to show overlay + overlay: { + type: Boolean, + default: true, + }, + // prevent body scroll + lockScroll: { + type: Boolean, + default: true, + }, + // whether to lazy render + lazyRender: { + type: Boolean, + default: true, + }, + // whether to close popup when overlay is clicked + closeOnClickOverlay: { + type: Boolean, + default: true, + }, +}; + +export type PopupSharedPropKeys = Array; + +export const popupSharedPropKeys = Object.keys( + popupSharedProps +) as PopupSharedPropKeys; diff --git a/src/share-sheet/index.tsx b/src/share-sheet/index.tsx index d6d454556..994d981a3 100644 --- a/src/share-sheet/index.tsx +++ b/src/share-sheet/index.tsx @@ -4,7 +4,8 @@ import { PropType } from 'vue'; import { createNamespace, pick } from '../utils'; // Components -import Popup, { popupSharedProps } from '../popup'; +import Popup from '../popup'; +import { popupSharedProps } from '../popup/shared'; export type ShareSheetOption = { name: string;