@varlet/ui
Version:
A Vue3 component library based on Material Design 2 and 3, supporting mobile and desktop.
255 lines (254 loc) • 8.72 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
import { defineComponent, ref, watch } from "vue";
import { call } from "@varlet/shared";
import VarButton from "../button/index.mjs";
import { t } from "../locale/index.mjs";
import { injectLocaleProvider } from "../locale-provider/provide.mjs";
import VarPopup from "../popup/index.mjs";
import { createNamespace } from "../utils/components.mjs";
import { toSizeUnit } from "../utils/elements.mjs";
import { props } from "./props.mjs";
const { name, n, classes } = createNamespace("dialog");
import { renderSlot as _renderSlot, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, normalizeStyle as _normalizeStyle, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, mergeProps as _mergeProps } from "vue";
function __render__(_ctx, _cache) {
const _component_var_button = _resolveComponent("var-button");
const _component_var_popup = _resolveComponent("var-popup");
return _openBlock(), _createBlock(_component_var_popup, {
class: _normalizeClass(_ctx.n("popup")),
"var-dialog-cover": "",
show: _ctx.popupShow,
overlay: _ctx.overlay,
"overlay-class": _ctx.overlayClass,
"overlay-style": _ctx.overlayStyle,
"lock-scroll": _ctx.lockScroll,
"close-on-click-overlay": _ctx.popupCloseOnClickOverlay,
"close-on-key-escape": false,
teleport: _ctx.teleport,
onOpen: _ctx.onOpen,
onClose: _ctx.onClose,
onClosed: _ctx.onClosed,
onOpened: _ctx.onOpened,
onKeyEscape: _ctx.handleKeyEscape,
onRouteChange: _ctx.onRouteChange,
onClickOverlay: _ctx.handleClickOverlay
}, {
default: _withCtx(() => [
_createElementVNode(
"div",
_mergeProps({
class: _ctx.classes(_ctx.n("$--box"), _ctx.n(), _ctx.dialogClass),
style: __spreadValues({ width: _ctx.toSizeUnit(_ctx.width) }, _ctx.dialogStyle)
}, _ctx.$attrs),
[
_createElementVNode(
"div",
{
class: _normalizeClass(_ctx.n("title"))
},
[
_renderSlot(_ctx.$slots, "title", {}, () => {
var _a;
return [
_createTextVNode(
_toDisplayString((_a = _ctx.title) != null ? _a : (_ctx.pt ? _ctx.pt : _ctx.t)("dialogTitle")),
1
/* TEXT */
)
];
})
],
2
/* CLASS */
),
_createElementVNode(
"div",
{
class: _normalizeClass(_ctx.n("message")),
style: _normalizeStyle({ textAlign: _ctx.messageAlign })
},
[
_renderSlot(_ctx.$slots, "default", {}, () => [
_createTextVNode(
_toDisplayString(_ctx.message),
1
/* TEXT */
)
])
],
6
/* CLASS, STYLE */
),
_renderSlot(_ctx.$slots, "actions", {
slotClass: _ctx.n("actions"),
cancel: _ctx.cancel,
confirm: _ctx.confirm
}, () => [
_createElementVNode(
"div",
{
class: _normalizeClass(_ctx.n("actions"))
},
[
_ctx.cancelButton ? (_openBlock(), _createBlock(_component_var_button, {
key: 0,
class: _normalizeClass(_ctx.classes(_ctx.n("button"), _ctx.n("cancel-button"))),
"var-dialog-cover": "",
text: "",
"text-color": _ctx.cancelButtonTextColor,
color: _ctx.cancelButtonColor,
onClick: _ctx.cancel
}, {
default: _withCtx(() => {
var _a;
return [
_createTextVNode(
_toDisplayString((_a = _ctx.cancelButtonText) != null ? _a : (_ctx.pt ? _ctx.pt : _ctx.t)("dialogCancelButtonText")),
1
/* TEXT */
)
];
}),
_: 1
/* STABLE */
}, 8, ["class", "text-color", "color", "onClick"])) : _createCommentVNode("v-if", true),
_ctx.confirmButton ? (_openBlock(), _createBlock(_component_var_button, {
key: 1,
class: _normalizeClass(_ctx.classes(_ctx.n("button"), _ctx.n("confirm-button"))),
"var-dialog-cover": "",
text: "",
"text-color": _ctx.confirmButtonTextColor,
color: _ctx.confirmButtonColor,
onClick: _ctx.confirm
}, {
default: _withCtx(() => {
var _a;
return [
_createTextVNode(
_toDisplayString((_a = _ctx.confirmButtonText) != null ? _a : (_ctx.pt ? _ctx.pt : _ctx.t)("dialogConfirmButtonText")),
1
/* TEXT */
)
];
}),
_: 1
/* STABLE */
}, 8, ["class", "text-color", "color", "onClick"])) : _createCommentVNode("v-if", true)
],
2
/* CLASS */
)
])
],
16
/* FULL_PROPS */
)
]),
_: 3
/* FORWARDED */
}, 8, ["class", "show", "overlay", "overlay-class", "overlay-style", "lock-scroll", "close-on-click-overlay", "teleport", "onOpen", "onClose", "onClosed", "onOpened", "onKeyEscape", "onRouteChange", "onClickOverlay"]);
}
const __sfc__ = defineComponent({
name,
components: {
VarPopup,
VarButton
},
inheritAttrs: false,
props,
setup(props2) {
const popupShow = ref(false);
const popupCloseOnClickOverlay = ref(false);
const { t: pt } = injectLocaleProvider();
watch(
() => props2.show,
(newValue) => {
popupShow.value = newValue;
},
{ immediate: true }
);
watch(
() => props2.closeOnClickOverlay,
(newValue) => {
if (props2.onBeforeClose != null) {
popupCloseOnClickOverlay.value = false;
return;
}
popupCloseOnClickOverlay.value = newValue;
},
{ immediate: true }
);
function done() {
return call(props2["onUpdate:show"], false);
}
function handleClickOverlay() {
const { closeOnClickOverlay, onClickOverlay, onBeforeClose } = props2;
call(onClickOverlay);
if (!closeOnClickOverlay) {
return;
}
if (onBeforeClose != null) {
call(onBeforeClose, "close", done);
return;
}
call(props2["onUpdate:show"], false);
}
function confirm() {
const { onBeforeClose, onConfirm } = props2;
call(onConfirm);
if (onBeforeClose != null) {
call(onBeforeClose, "confirm", done);
return;
}
call(props2["onUpdate:show"], false);
}
function cancel() {
const { onBeforeClose, onCancel } = props2;
call(onCancel);
if (onBeforeClose != null) {
call(onBeforeClose, "cancel", done);
return;
}
call(props2["onUpdate:show"], false);
}
function handleKeyEscape() {
call(props2.onKeyEscape);
if (!props2.closeOnKeyEscape) {
return;
}
cancel();
}
return {
popupShow,
popupCloseOnClickOverlay,
pt,
t,
n,
classes,
handleClickOverlay,
confirm,
cancel,
toSizeUnit,
handleKeyEscape
};
}
});
__sfc__.render = __render__;
var stdin_default = __sfc__;
export {
stdin_default as default
};