UNPKG

vuestic-ui

Version:
48 lines (47 loc) 1.38 kB
import { getCurrentInstance } from "vue"; import { c as createModalInstance } from "../modal.mjs"; const useModal = () => { var _a; const appContext = (_a = getCurrentInstance()) == null ? void 0 : _a.appContext; if (!appContext) { throw new Error("useModal can be used only in setup function. You can use app.config.globalProperties.$vaModal outside setup function"); } const init = (options) => { return createModalInstance(options, appContext); }; const confirm = (options) => { if (typeof options === "string") { return new Promise((resolve, reject) => { createModalInstance({ message: options, onOk() { resolve(true); }, onCancel() { resolve(false); } }, appContext); }); } return new Promise((resolve, reject) => { createModalInstance({ ...options, onOk() { var _a2; (_a2 = options == null ? void 0 : options.onOk) == null ? void 0 : _a2.call(options); resolve(true); }, onCancel() { var _a2; (_a2 = options == null ? void 0 : options.onCancel) == null ? void 0 : _a2.call(options); resolve(false); } }, appContext); }); }; return { init, confirm }; }; export { useModal as u }; //# sourceMappingURL=useModal.mjs.map