comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
144 lines (143 loc) • 6.2 kB
JavaScript
import { defineComponent, ref, computed, onMounted, openBlock, createBlock, unref, withCtx, createVNode, Transition, createElementBlock, normalizeClass, createElementVNode, resolveDynamicComponent, createCommentVNode, createTextVNode, toDisplayString, Fragment } from "vue";
import { onKeyStroke } from "@vueuse/core";
import "../../style/message-box.css";
import { CuMode } from "../../../mode/index.mjs";
import "../../../../utils/config.mjs";
import { isVueComponent, isString } from "../../../../utils/typescript.mjs";
import { usePopup } from "../../../../hooks/popup.mjs";
import { CuButton } from "../../../button/index.mjs";
import { confirmProps } from "./main.props.mjs";
import "../../../../icons/index.mjs";
import { Close, Tips, Info, Success, Caution, WarningFilled } from "../../../../icons/components/components.mjs";
const _hoisted_1 = { class: "cu-popup__head" };
const _hoisted_2 = { class: "cu-popup__title" };
const _hoisted_3 = { class: "cu-popup__content" };
const _hoisted_4 = ["innerHTML"];
const _hoisted_5 = { class: "cu-popup__footer" };
const _sfc_main = /* @__PURE__ */ defineComponent({
...{
name: "CuConfirm"
},
__name: "main",
props: confirmProps,
setup(__props) {
const typeList = {
primary: Tips,
info: Info,
success: Success,
warning: Caution,
error: WarningFilled
};
const props = __props;
const { visible, showMode, onAfterEnter, close, onAfterLeave } = usePopup(props);
const TYPE = ref("cancel");
const headIcon = computed(() => {
if (!props.showIcon) return null;
if (isVueComponent(props.icon)) return props.icon;
return props.type ? typeList[props.type] : null;
});
function handleModeClose() {
if (!props.modeClose) return;
cancel("cancel");
}
function cancel(val) {
TYPE.value = val;
close();
}
function confirm() {
close();
TYPE.value = "confirm";
}
onMounted(() => {
showMode.value = true;
if (props.escClose) {
onKeyStroke("Escape", (e) => {
e.preventDefault();
cancel(props.distinguishCloseAndCancel ? "esc" : "cancel");
});
}
});
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(CuMode), {
show: unref(showMode),
"custom-class": ["cu-mode__flex", _ctx.modeClass],
"lock-scroll": _ctx.lockScroll,
onClose: _cache[2] || (_cache[2] = ($event) => _ctx.destroy(TYPE.value)),
onOpen: unref(onAfterEnter),
onModeClick: _cache[3] || (_cache[3] = ($event) => handleModeClose())
}, {
default: withCtx(() => [
createVNode(Transition, {
name: "cu-fade-top",
onAfterLeave: unref(onAfterLeave)
}, {
default: withCtx(() => [
unref(visible) ? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass(["cu-popup", [_ctx.type ? "cu-popup--" + _ctx.type : void 0, { "is-center": _ctx.center }, _ctx.customClass]])
}, [
createElementVNode("div", _hoisted_1, [
createElementVNode("span", _hoisted_2, [
headIcon.value ? (openBlock(), createBlock(resolveDynamicComponent(headIcon.value), {
key: 0,
class: "cu-popup__head--icon",
color: _ctx.color
}, null, 8, ["color"])) : createCommentVNode("", true),
createTextVNode(toDisplayString(_ctx.title), 1)
]),
_ctx.showClose ? (openBlock(), createBlock(unref(Close), {
key: 0,
class: "close-icon",
onClick: _cache[0] || (_cache[0] = ($event) => cancel(_ctx.distinguishCloseAndCancel ? "close" : "cancel"))
})) : createCommentVNode("", true)
]),
createElementVNode("div", _hoisted_3, [
_ctx.isVNode ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
unref(isString)(_ctx.content) ? (openBlock(), createElementBlock("div", {
key: 0,
innerHTML: _ctx.content
}, null, 8, _hoisted_4)) : (openBlock(), createBlock(resolveDynamicComponent(_ctx.content), { key: 1 }))
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
createTextVNode(toDisplayString(_ctx.content), 1)
], 64))
]),
createElementVNode("div", _hoisted_5, [
_ctx.showCancelButton ? (openBlock(), createBlock(unref(CuButton), {
key: 0,
size: "small",
plain: "",
color: _ctx.color,
type: _ctx.color ? void 0 : _ctx.type === "error" ? "danger" : _ctx.type || void 0,
onClick: _cache[1] || (_cache[1] = ($event) => cancel("cancel"))
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(_ctx.cancelButtonText), 1)
]),
_: 1
}, 8, ["color", "type"])) : createCommentVNode("", true),
_ctx.showConfirmButton ? (openBlock(), createBlock(unref(CuButton), {
key: 1,
size: "small",
type: _ctx.color ? void 0 : _ctx.type === "error" ? "danger" : _ctx.type || "primary",
color: _ctx.color,
onClick: confirm
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(_ctx.confirmButtonText), 1)
]),
_: 1
}, 8, ["type", "color"])) : createCommentVNode("", true)
])
], 2)) : createCommentVNode("", true)
]),
_: 1
}, 8, ["onAfterLeave"])
]),
_: 1
}, 8, ["show", "custom-class", "lock-scroll", "onOpen"]);
};
}
});
export {
_sfc_main as default
};