UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

118 lines (117 loc) 4.35 kB
import { defineComponent, onMounted, onUpdated, onUnmounted, resolveComponent, openBlock, createElementBlock, normalizeClass, renderSlot, createBlock, createCommentVNode, createElementVNode, createVNode } from "vue"; import { getPrefixCls } from "../_utils/global-config.js"; import { MESSAGE_TYPES } from "../_utils/constant.js"; import IconClose from "../icon/icon-close/index.js"; import IconInfoCircleFill from "../icon/icon-info-circle-fill/index.js"; import IconCheckCircleFill from "../icon/icon-check-circle-fill/index.js"; import IconExclamationCircleFill from "../icon/icon-exclamation-circle-fill/index.js"; import IconCloseCircleFill from "../icon/icon-close-circle-fill/index.js"; import IconLoading from "../icon/icon-loading/index.js"; import _export_sfc from "../_virtual/plugin-vue_export-helper"; const _sfc_main = defineComponent({ name: "Message", components: { IconInfoCircleFill, IconCheckCircleFill, IconExclamationCircleFill, IconCloseCircleFill, IconClose, IconLoading }, props: { type: { type: String, default: "info", validator: (value) => { return MESSAGE_TYPES.includes(value); } }, closable: { type: Boolean, default: false }, showIcon: { type: Boolean, default: true }, duration: { type: Number, default: 3e3 }, resetOnUpdate: { type: Boolean, default: false } }, emits: ["close"], setup(props, { emit }) { const prefixCls = getPrefixCls("message"); let timer = 0; const handleClose = () => { emit("close"); }; onMounted(() => { if (props.duration > 0) { timer = window.setTimeout(handleClose, props.duration); } }); onUpdated(() => { if (props.resetOnUpdate) { if (timer) { window.clearTimeout(timer); timer = 0; } if (props.duration > 0) { timer = window.setTimeout(handleClose, props.duration); } } }); onUnmounted(() => { if (timer) { window.clearTimeout(timer); } }); return { prefixCls, handleClose }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_icon_info_circle_fill = resolveComponent("icon-info-circle-fill"); const _component_icon_check_circle_fill = resolveComponent("icon-check-circle-fill"); const _component_icon_exclamation_circle_fill = resolveComponent("icon-exclamation-circle-fill"); const _component_icon_close_circle_fill = resolveComponent("icon-close-circle-fill"); const _component_icon_loading = resolveComponent("icon-loading"); const _component_icon_close = resolveComponent("icon-close"); return openBlock(), createElementBlock("li", { class: normalizeClass([ _ctx.prefixCls, `${_ctx.prefixCls}-${_ctx.type}`, { [`${_ctx.prefixCls}-closable`]: _ctx.closable } ]) }, [ _ctx.showIcon ? (openBlock(), createElementBlock("span", { key: 0, class: normalizeClass(`${_ctx.prefixCls}-icon`) }, [ renderSlot(_ctx.$slots, "icon", {}, () => [ _ctx.type === "info" ? (openBlock(), createBlock(_component_icon_info_circle_fill, { key: 0 })) : _ctx.type === "success" ? (openBlock(), createBlock(_component_icon_check_circle_fill, { key: 1 })) : _ctx.type === "warning" ? (openBlock(), createBlock(_component_icon_exclamation_circle_fill, { key: 2 })) : _ctx.type === "error" ? (openBlock(), createBlock(_component_icon_close_circle_fill, { key: 3 })) : _ctx.type === "loading" ? (openBlock(), createBlock(_component_icon_loading, { key: 4 })) : createCommentVNode("v-if", true) ]) ], 2)) : createCommentVNode("v-if", true), createElementVNode("span", { class: normalizeClass(`${_ctx.prefixCls}-content`) }, [ renderSlot(_ctx.$slots, "default") ], 2), _ctx.closable ? (openBlock(), createElementBlock("span", { key: 1, class: normalizeClass(`${_ctx.prefixCls}-close-btn`), onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClose && _ctx.handleClose(...args)) }, [ createVNode(_component_icon_close) ], 2)) : createCommentVNode("v-if", true) ], 2); } var Message = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { Message as default };