UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

182 lines (175 loc) 7.55 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { openBlock, createElementBlock, createElementVNode, defineComponent, ref, onMounted, onBeforeUnmount, createVNode } from 'vue'; import { _ as __unplugin_components_4 } from '../_chunks/dep-cb88bacb.js'; import { _ as __unplugin_components_1 } from '../_chunks/dep-8eef0183.js'; import { _ as __unplugin_components_0$1 } from '../_chunks/dep-b09ff084.js'; import { _ as __unplugin_components_0 } from '../_chunks/dep-2f5ed418.js'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import isString from 'lodash/isString'; import isArray from 'lodash/isArray'; import { on, off, addClass } from '../utils/dom.js'; import props from './props.js'; import { useIcon } from '../hooks/icon.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { useTNodeJSX } from '../hooks/tnode.js'; import { useConfig } from '../config-provider/useConfig.js'; import '../_chunks/dep-3a1cce9f.js'; import 'lodash/isFunction'; import '../utils/easing.js'; import 'lodash/camelCase'; import 'lodash/kebabCase'; import '../utils/render-tnode.js'; import 'lodash/isEmpty'; import 'lodash/isObject'; import 'lodash/cloneDeep'; import '../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/en_US.js'; const _hoisted_1 = { class: "x-icon", viewBox: "0 0 24 24", width: "1.1em", height: "1.1em" }; const _hoisted_2 = /*#__PURE__*/createElementVNode("path", { fill: "currentColor", d: "m12 10.586l4.95-4.95l1.415 1.415l-4.95 4.95l4.95 4.95l-1.415 1.414l-4.95-4.95l-4.95 4.95l-1.413-1.415l4.95-4.95l-4.95-4.95L7.05 5.638l4.95 4.95Z" }, null, -1 /* HOISTED */); const _hoisted_3 = [ _hoisted_2 ]; function render(_ctx, _cache) { return (openBlock(), createElementBlock("svg", _hoisted_1, _hoisted_3)) } var __unplugin_components_5 = { name: 'ri-close-fill', render }; /* vite-plugin-components disabled */ var _Alert = defineComponent({ name: "XAlert", props: props, setup: function setup(props2) { var _useConfig = useConfig("alert"), globalConfig = _useConfig.globalConfig, classPrefix = _useConfig.classPrefix; var COMPONENT_NAME = usePrefixClass("alert"); var renderTNodeJSX = useTNodeJSX(); var renderIconTNode = useIcon(); var alertRef = ref(null); var descriptionRef = ref(null); var descHeight = ref(0); var visible = ref(true); var collapsed = ref(true); var renderIcon = function renderIcon() { var Component = { info: createVNode(__unplugin_components_0, null, null), success: createVNode(__unplugin_components_0$1, null, null), warning: createVNode(__unplugin_components_1, null, null), error: createVNode(__unplugin_components_1, null, null), question: createVNode(__unplugin_components_4, null, null) }; var iconContent = renderIconTNode("icon", Component); return iconContent ? createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__icon") }, [iconContent]) : null; }; var renderClose = function renderClose() { var close = props2.close; var closeContent = null; if (close === true || close === "") { closeContent = createVNode(__unplugin_components_5, null, null); } else if (isString(close)) { closeContent = close; } else { closeContent = renderIconTNode("close"); } return closeContent ? createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__close"), "onClick": handleClose }, [closeContent]) : null; }; var renderTitle = function renderTitle() { var titleContent = renderTNodeJSX("title"); return titleContent ? createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__title") }, [" ", titleContent]) : null; }; var renderMessage = function renderMessage() { var operationContent = renderTNodeJSX("operation"); return createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__message") }, [renderDescription(), operationContent ? createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__operation") }, [operationContent]) : null]); }; var renderDescription = function renderDescription() { var _descriptionRef$value; var messageContent; messageContent = renderTNodeJSX("default"); if (!messageContent) { messageContent = renderTNodeJSX("message"); } var contentLength = isArray(messageContent) ? messageContent.length : 1; var hasCollapse = props2.maxLine > 0 && props2.maxLine < contentLength; var height = (_descriptionRef$value = descriptionRef.value) === null || _descriptionRef$value === void 0 || (_descriptionRef$value = _descriptionRef$value.children[0]) === null || _descriptionRef$value === void 0 ? void 0 : _descriptionRef$value.offsetHeight; if (hasCollapse && collapsed.value) { messageContent = messageContent.slice(0, props2.maxLine); height && (descriptionRef.value.style.height = "".concat(descHeight.value, "px")); } else if (hasCollapse) { height && (descriptionRef.value.style.height = "".concat(height * (contentLength - props2.maxLine) + descHeight.value, "px")); } return createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__description"), "ref": descriptionRef }, [hasCollapse ? messageContent.map(function (content) { return createVNode("div", null, [content]); }) : messageContent, hasCollapse ? createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__collapse"), "onClick": function onClick() { collapsed.value = !collapsed.value; } }, [collapsed.value ? globalConfig.value.expandText : globalConfig.value.collapseText]) : null]); }; var renderContent = function renderContent() { return createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__content") }, [renderTitle(), renderMessage()]); }; var handleClose = function handleClose(e) { var _props2$onClose; (_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 ? void 0 : _props2$onClose.call(props2, { e: e }); addClass(alertRef.value, "".concat(COMPONENT_NAME.value, "--closing")); }; var handleCloseEnd = function handleCloseEnd(e) { var isTransitionTarget = e.target === alertRef.value; if (e.propertyName === "opacity" && isTransitionTarget) { var _props2$onClosed; visible.value = false; (_props2$onClosed = props2.onClosed) === null || _props2$onClosed === void 0 ? void 0 : _props2$onClosed.call(props2, { e: e }); } }; onMounted(function () { on(alertRef.value, "transitionend", handleCloseEnd); descHeight.value = descriptionRef.value.offsetHeight; }); onBeforeUnmount(function () { off(alertRef.value, "transitionend", handleCloseEnd); }); return function () { return createVNode("div", { "ref": alertRef, "class": ["".concat(COMPONENT_NAME.value), "".concat(COMPONENT_NAME.value, "--").concat(props2.theme), _defineProperty({}, "".concat(classPrefix.value, "-is-hidden"), !visible.value)] }, [renderIcon(), renderContent(), renderClose()]); }; } }); export { _Alert as default }; //# sourceMappingURL=alert.js.map