UNPKG

element-plus

Version:

A Component Library for Vue 3

152 lines (147 loc) 5.28 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); require('../../../utils/index.js'); var index = require('../../collapse-transition/index.js'); var index$1 = require('../../icon/index.js'); var iconsVue = require('@element-plus/icons-vue'); require('../../../hooks/index.js'); var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js'); var rand = require('../../../utils/rand.js'); var index$2 = require('../../../hooks/use-namespace/index.js'); const _sfc_main = vue.defineComponent({ name: "ElCollapseItem", components: { ElCollapseTransition: index["default"], ElIcon: index$1.ElIcon, ArrowRight: iconsVue.ArrowRight }, props: { title: { type: String, default: "" }, name: { type: [String, Number], default: () => { return rand.generateId(); } }, disabled: Boolean }, setup(props) { const collapse = vue.inject("collapse"); const ns = index$2.useNamespace("collapse"); const contentWrapStyle = vue.ref({ height: "auto", display: "block" }); const contentHeight = vue.ref(0); const focusing = vue.ref(false); const isClick = vue.ref(false); const id = vue.ref(rand.generateId()); const isActive = vue.computed(() => { return (collapse == null ? void 0 : collapse.activeNames.value.indexOf(props.name)) > -1; }); const handleFocus = () => { setTimeout(() => { if (!isClick.value) { focusing.value = true; } else { isClick.value = false; } }, 50); }; const handleHeaderClick = () => { if (props.disabled) return; collapse == null ? void 0 : collapse.handleItemClick(props.name); focusing.value = false; isClick.value = true; }; const handleEnterClick = () => { collapse == null ? void 0 : collapse.handleItemClick(props.name); }; return { isActive, contentWrapStyle, contentHeight, focusing, isClick, id, ns, handleFocus, handleHeaderClick, handleEnterClick, collapse }; } }); const _hoisted_1 = ["aria-expanded", "aria-controls", "aria-describedby"]; const _hoisted_2 = ["id", "tabindex"]; const _hoisted_3 = ["id", "aria-hidden", "aria-labelledby"]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_arrow_right = vue.resolveComponent("arrow-right"); const _component_el_icon = vue.resolveComponent("el-icon"); const _component_el_collapse_transition = vue.resolveComponent("el-collapse-transition"); return vue.openBlock(), vue.createElementBlock("div", { class: vue.normalizeClass([ _ctx.ns.b("item"), _ctx.ns.is("active", _ctx.isActive), _ctx.ns.is("disabled", _ctx.disabled) ]) }, [ vue.createElementVNode("div", { role: "tab", "aria-expanded": _ctx.isActive, "aria-controls": _ctx.ns.b(`content-${_ctx.id}`), "aria-describedby": _ctx.ns.b(`content-${_ctx.id}`) }, [ vue.createElementVNode("div", { id: _ctx.ns.b(`head-${_ctx.id}`), class: vue.normalizeClass([ _ctx.ns.be("item", "header"), _ctx.ns.is("active", _ctx.isActive), { focusing: _ctx.focusing } ]), role: "button", tabindex: _ctx.disabled ? -1 : 0, onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleHeaderClick && _ctx.handleHeaderClick(...args)), onKeyup: _cache[1] || (_cache[1] = vue.withKeys(vue.withModifiers((...args) => _ctx.handleEnterClick && _ctx.handleEnterClick(...args), ["stop"]), ["space", "enter"])), onFocus: _cache[2] || (_cache[2] = (...args) => _ctx.handleFocus && _ctx.handleFocus(...args)), onBlur: _cache[3] || (_cache[3] = ($event) => _ctx.focusing = false) }, [ vue.renderSlot(_ctx.$slots, "title", {}, () => [ vue.createTextVNode(vue.toDisplayString(_ctx.title), 1) ]), vue.createVNode(_component_el_icon, { class: vue.normalizeClass([_ctx.ns.be("item", "arrow"), _ctx.ns.is("active", _ctx.isActive)]) }, { default: vue.withCtx(() => [ vue.createVNode(_component_arrow_right) ]), _: 1 }, 8, ["class"]) ], 42, _hoisted_2) ], 8, _hoisted_1), vue.createVNode(_component_el_collapse_transition, null, { default: vue.withCtx(() => [ vue.withDirectives(vue.createElementVNode("div", { id: _ctx.ns.b(`content-${_ctx.id}`), class: vue.normalizeClass(_ctx.ns.be("item", "wrap")), role: "tabpanel", "aria-hidden": !_ctx.isActive, "aria-labelledby": _ctx.ns.b(`head-${_ctx.id}`) }, [ vue.createElementVNode("div", { class: vue.normalizeClass(_ctx.ns.be("item", "content")) }, [ vue.renderSlot(_ctx.$slots, "default") ], 2) ], 10, _hoisted_3), [ [vue.vShow, _ctx.isActive] ]) ]), _: 3 }) ], 2); } var CollapseItem = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render]]); exports["default"] = CollapseItem; //# sourceMappingURL=collapse-item.js.map