UNPKG

vuetify3-confirm

Version:
201 lines (200 loc) 5.56 kB
import { resolveComponent as o, openBlock as d, createElementBlock as h, createVNode as u, withKeys as V, withCtx as l, createBlock as b, createTextVNode as g, toDisplayString as y, createCommentVNode as _, createApp as F } from "vue"; import { VCard as w, VCardActions as B, VCardText as S, VDialog as E, VIcon as P, VToolbar as I, VToolbarTitle as L, VSpacer as N, VBtn as A } from "vuetify/components"; const M = (n, e) => { const t = n.__vccOpts || n; for (const [s, a] of e) t[s] = a; return t; }, D = { components: { VCard: w, VCardActions: B, VCardText: S, VDialog: E, VIcon: P, VToolbar: I, VToolbarTitle: L, VSpacer: N, VBtn: A }, props: { buttonTrueText: { type: String, default: "Confirm" }, buttonFalseText: { type: String, default: "Cancel" }, buttonTrueColor: { type: String, default: "primary" }, buttonFalseColor: { type: String, default: "grey" }, buttonFalseFlat: { type: Boolean, default: !0 }, buttonTrueFlat: { type: Boolean, default: !0 }, color: { type: String // default: 'warning' }, icon: { type: String, default() { return "tabler-alert-octagon-filled"; } }, message: { type: String, required: !0 }, persistent: Boolean, title: { type: String }, width: { type: Number, default: 450 }, submitCallback: { type: Function }, cancelCallback: { type: Function } }, data() { return { value: !1 }; }, mounted() { document.addEventListener("keyup", this.onEnterPressed); }, destroyed() { document.removeEventListener("keyup", this.onEnterPressed); }, methods: { onEnterPressed(n) { n.keyCode === 13 && (n.stopPropagation(), this.choose(!0)); }, choose(n) { this.value = n, n ? this.submitCallback() : this.cancelCallback(); }, change(n) { this.cancelCallback(); } } }; function H(n, e, t, s, a, r) { const v = o("v-icon"), c = o("v-toolbar-title"), f = o("v-toolbar"), x = o("v-card-text"), C = o("v-spacer"), m = o("v-btn"), i = o("v-card-actions"), p = o("v-card"), T = o("v-dialog"); return d(), h("div", null, [ u(T, { eager: "", onInput: r.change, "model-value": "true", "max-width": t.width, persistent: t.persistent, onKeydown: e[2] || (e[2] = V((k) => r.choose(!1), ["esc"])) }, { default: l(() => [ u(p, { tile: "" }, { default: l(() => [ t.title ? (d(), b(f, { key: 0, dark: "", color: t.color, dense: "", flat: "" }, { default: l(() => [ t.icon ? (d(), b(v, { key: 0, left: "", style: { "margin-left": "10px" } }, { default: l(() => [ g(y(t.icon), 1) ]), _: 1 })) : _("", !0), u(c, { class: "white--text", textContent: y(t.title) }, null, 8, ["textContent"]) ]), _: 1 }, 8, ["color"])) : _("", !0), u(x, { class: "body-1 text-body-1 py-3", innerHTML: t.message }, null, 8, ["innerHTML"]), u(i, null, { default: l(() => [ u(C), t.buttonFalseText ? (d(), b(m, { key: 0, color: t.buttonFalseColor, text: t.buttonFalseFlat, onClick: e[0] || (e[0] = (k) => r.choose(!1)) }, { default: l(() => [ g(y(t.buttonFalseText), 1) ]), _: 1 }, 8, ["color", "text"])) : _("", !0), t.buttonTrueText ? (d(), b(m, { key: 1, color: t.buttonTrueColor, text: t.buttonTrueFlat, onClick: e[1] || (e[1] = (k) => r.choose(!0)) }, { default: l(() => [ g(y(t.buttonTrueText), 1) ]), _: 1 }, 8, ["color", "text"])) : _("", !0) ]), _: 1 }) ]), _: 1 }) ]), _: 1 }, 8, ["onInput", "max-width", "persistent"]) ]); } const K = /* @__PURE__ */ M(D, [["render", H]]); function O(n, e = {}) { const t = e.property || "$confirm"; delete e.property; const s = e.vuetify; delete e.vuetify, s || console.warn("Module vuetify3-confirm needs vuetify instance. Use Vue.use(Vuetify3Confirm, { vuetify })"); const a = document.createElement("div"); a.setAttribute("class", "confirm-container"), a.setAttribute("id", "confirm-container"), document.body.appendChild(a); function r(v, c = {}) { return c.message = v, new Promise((f, x) => { const C = () => { i.unmount("#confirm-container"), f(!0); }, m = () => { i.unmount("#confirm-container"), f(!1); }; c.submitCallback = C, c.cancelCallback = m; let i = F(K, c); i.use(s), i.mount("#confirm-container"); }); } n.config.globalProperties[t] = r, n.config.globalProperties[t].options = e || {}; } export { O as default };