diff --git a/packages/mixins/popup/manager.js b/packages/mixins/popup/manager.js index befa10ff7..b731d5ae2 100644 --- a/packages/mixins/popup/manager.js +++ b/packages/mixins/popup/manager.js @@ -1,6 +1,6 @@ -import Vue from 'vue'; import context from './context'; import Overlay from '../../overlay'; +import { mount } from '../../utils/functional'; const defaultConfig = { className: '', @@ -35,10 +35,11 @@ export default { let { modal } = context; if (!modal) { - modal = new (Vue.extend(Overlay))({ - el: document.createElement('div') + modal = mount(Overlay, { + on: { + click: this.onClick + } }); - modal.$on('click', this.onClick); context.modal = modal; } diff --git a/packages/overlay/index.js b/packages/overlay/index.js deleted file mode 100644 index 076624205..000000000 --- a/packages/overlay/index.js +++ /dev/null @@ -1,36 +0,0 @@ -import { use } from '../utils'; - -const [sfc, bem] = use('overlay'); - -export default sfc({ - props: { - zIndex: Number, - className: null, - visible: Boolean, - customStyle: Object - }, - - render(h) { - const style = { - zIndex: this.zIndex, - ...this.customStyle - }; - - return ( - -
{ - event.preventDefault(); - event.stopPropagation(); - }} - onClick={event => { - this.$emit('click', event); - }} - /> - - ); - } -}); diff --git a/packages/overlay/index.tsx b/packages/overlay/index.tsx new file mode 100644 index 000000000..dae07e1a2 --- /dev/null +++ b/packages/overlay/index.tsx @@ -0,0 +1,58 @@ +import { use } from '../utils'; +import { emit, inherit } from '../utils/functional'; + +// Types +import { CreateElement, RenderContext } from 'vue/types'; +import { DefaultSlots } from '../utils/use/sfc'; + +export type OverlayProps = { + zIndex?: number; + className?: any; + visible?: boolean; + customStyle?: object; +}; + +export type OverlayEvents = { + click(event: Event): void; +}; + +const [sfc, bem] = use('overlay'); + +function Overlay( + h: CreateElement, + props: OverlayProps, + slots: DefaultSlots, + ctx: RenderContext +) { + const style = { + zIndex: props.zIndex, + ...props.customStyle + }; + + return ( + +
{ + event.preventDefault(); + event.stopPropagation(); + }} + onClick={(event: Event) => { + emit(ctx, 'click', event); + }} + {...inherit(ctx, true)} + /> + + ); +} + +Overlay.props = { + zIndex: Number, + className: null as any, + visible: Boolean, + customStyle: Object +}; + +export default sfc(Overlay); diff --git a/packages/utils/functional.ts b/packages/utils/functional.ts index 7d121ee94..9493ca676 100644 --- a/packages/utils/functional.ts +++ b/packages/utils/functional.ts @@ -58,12 +58,15 @@ export function emit(context: Context, eventName: string, ...args: any[]) { } // mount functional component -export function mount(Component: any) { +export function mount(Component: any, data?: VNodeData) { const instance = new Vue({ el: document.createElement('div'), props: Component.props, render(h) { - return h(Component, { props: this.$props }); + return h(Component, { + props: this.$props, + ...data + }); } });