refactor: update usePopupState

This commit is contained in:
chenjiahan
2020-09-01 09:47:59 +08:00
parent c4921da290
commit 6e6cfe5c65
6 changed files with 37 additions and 51 deletions

View File

@@ -1,4 +1,4 @@
import { createApp, reactive, Component } from 'vue';
import { createApp, reactive, Component, nextTick } from 'vue';
import { usePublicApi } from '../composition/use-public-api';
export function usePopupState() {
@@ -10,17 +10,22 @@ export function usePopupState() {
state.show = show;
};
const open = (props: Record<string, any>) => {
Object.assign(state, props);
nextTick(() => {
toggle(true);
});
};
const close = () => {
toggle(false);
};
const setState = (props: Record<string, any>) => {
Object.assign(state, props);
};
usePublicApi({ close, toggle, setState });
usePublicApi({ open, close, toggle });
return {
open,
state,
toggle,
};