UNPKG

@ctsy/layui-vue

Version:

a component library for Vue 3 base on layui-vue

131 lines (130 loc) 5.07 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; 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; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { defineComponent, useSlots, ref, computed, watch, provide, unref, openBlock, createElementBlock, normalizeClass, createElementVNode, Fragment, renderList, withModifiers, createTextVNode, toDisplayString, createCommentVNode, renderSlot } from "vue"; import { _ as _sfc_main$1 } from "../index9.js"; var index = ""; const _hoisted_1 = ["onClick"]; const _hoisted_2 = ["onClick"]; const _hoisted_3 = { class: "layui-tab-content" }; const __default__ = { name: "LayTab" }; const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__), { props: { type: null, modelValue: null, allowClose: { type: Boolean }, tabPosition: { default: "top" }, beforeClose: null, beforeLeave: null }, emits: ["update:modelValue", "change", "close"], setup(__props, { emit }) { const props = __props; const slot = useSlots(); slot.default && slot.default(); const childrens = ref([]); const slotsChange = ref(true); const setItemInstanceBySlot = function(nodeList) { nodeList == null ? void 0 : nodeList.map((item) => { let component = item.type; if (component.name != _sfc_main$1.name) { setItemInstanceBySlot(item.children); } else { childrens.value.push(item); } }); }; const active = computed({ get() { return props.modelValue; }, set(val) { emit("update:modelValue", val); } }); const change = function(id) { if (props.beforeLeave && props.beforeLeave(id) === false) { return; } emit("update:modelValue", id); emit("change", id); }; const close = function(index2, id) { if (props.beforeClose && props.beforeClose(id) === false) { return; } childrens.value.splice(index2, 1); if (active.value === id) { const nextChildren = childrens.value[index2 === childrens.value.length ? 0 : index2]; change(nextChildren && nextChildren.props ? nextChildren.props.id : ""); } emit("close", id); }; watch(slotsChange, function() { childrens.value = []; setItemInstanceBySlot(slot.default && slot.default()); }); provide("active", active); provide("slotsChange", slotsChange); return (_ctx, _cache) => { return unref(active) ? (openBlock(), createElementBlock("div", { key: 0, class: normalizeClass(["layui-tab", [ __props.type ? "layui-tab-" + __props.type : "", props.tabPosition ? `is-${__props.tabPosition}` : "" ]]) }, [ createElementVNode("div", { class: normalizeClass(["layui-tab-head", props.tabPosition ? `is-${__props.tabPosition}` : ""]) }, [ createElementVNode("ul", { class: normalizeClass([ "layui-tab-title", props.tabPosition ? `is-${__props.tabPosition}` : "" ]) }, [ (openBlock(true), createElementBlock(Fragment, null, renderList(childrens.value, (children, index2) => { return openBlock(), createElementBlock("li", { key: children, class: normalizeClass([children.props.id === unref(active) ? "layui-this" : ""]), onClick: withModifiers(($event) => change(children.props.id), ["stop"]) }, [ createTextVNode(toDisplayString(children.props.title) + " ", 1), __props.allowClose && children.props.closable != false ? (openBlock(), createElementBlock("i", { key: 0, class: "layui-icon layui-icon-close layui-unselect layui-tab-close", onClick: withModifiers(($event) => close(index2, children.props.id), ["stop"]) }, null, 8, _hoisted_2)) : createCommentVNode("", true) ], 10, _hoisted_1); }), 128)) ], 2) ], 2), createElementVNode("div", _hoisted_3, [ renderSlot(_ctx.$slots, "default") ]) ], 2)) : createCommentVNode("", true); }; } })); _sfc_main.install = (app) => { app.component(_sfc_main.name, _sfc_main); }; export { _sfc_main as default };