tdesign-vue
Version:
217 lines (213 loc) • 8.26 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, inject, computed } from '@vue/composition-api';
import props from './collapse-panel-props.js';
import FakeArrow from '../common-components/fake-arrow.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { useTNodeJSX, useContent } from '../hooks/tnode.js';
import useCollapseAnimation from '../hooks/useCollapseAnimation.js';
import '../config-provider/config-receiver.js';
import 'vue';
import 'lodash-es';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-ba613a02.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/mixins.js';
import '../config-provider/useConfig.js';
import '../hooks/render-tnode.js';
var _CollapsePanel = defineComponent({
name: "TCollapsePanel",
props: props,
setup: function setup(props2, _ref) {
var slots = _ref.slots;
var _toRefs = toRefs(props2),
value = _toRefs.value,
disabled = _toRefs.disabled;
var componentName = usePrefixClass("collapse-panel");
var disableClass = usePrefixClass("is-disabled");
var clickableClass = usePrefixClass("is-clickable");
var transitionClass = usePrefixClass("slide-down");
var collapseValue = inject("collapseValue");
var updateCollapseValue = inject("updateCollapseValue");
var getUniqId = inject("getUniqId", function () {
return void 0;
}, false);
var _inject = inject("collapseProps"),
defaultExpandAll = _inject.defaultExpandAll,
disableAll = _inject.disabled,
expandIconPlacement = _inject.expandIconPlacement,
expandOnRowClick = _inject.expandOnRowClick;
var renderParentTNode = inject("renderParentTNode");
var innerValue = value.value === void 0 ? getUniqId() : value.value;
if (defaultExpandAll.value) {
updateCollapseValue(innerValue);
}
var isDisabled = computed(function () {
return disabled.value || disableAll.value;
});
var isActive = computed(function () {
return collapseValue.value instanceof Array ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue;
});
var classes = computed(function () {
return [componentName.value, _defineProperty({}, disableClass.value, isDisabled.value)];
});
var panelExpandIcon = computed(function () {
return slots.expandIcon || props2.expandIcon;
});
var renderTNodeJSX = useTNodeJSX();
var renderContent = useContent();
return {
isDisabled: isDisabled,
classes: classes,
isActive: isActive,
updateCollapseValue: updateCollapseValue,
innerValue: innerValue,
expandIconPlacement: expandIconPlacement,
expandOnRowClick: expandOnRowClick,
componentName: componentName,
clickableClass: clickableClass,
transitionClass: transitionClass,
panelExpandIcon: panelExpandIcon,
renderParentTNode: renderParentTNode,
renderTNodeJSX: renderTNodeJSX,
renderContent: renderContent
};
},
methods: {
renderDefaultIcon: function renderDefaultIcon() {
var h = this.$createElement;
var componentName = this.componentName;
return h(FakeArrow, {
"attrs": {
"overlayClassName": "".concat(componentName, "__icon--default")
}
});
},
renderIcon: function renderIcon() {
var h = this.$createElement;
var panelExpandIcon = this.panelExpandIcon,
renderParentTNode = this.renderParentTNode,
componentName = this.componentName,
expandIconPlacement = this.expandIconPlacement,
isActive = this.isActive,
handleClick = this.handleClick,
renderDefaultIcon = this.renderDefaultIcon,
renderTNodeJSX = this.renderTNodeJSX;
var tNodeRender = panelExpandIcon === void 0 ? renderParentTNode : renderTNodeJSX;
return h("div", {
"ref": "iconRef",
"class": "".concat(componentName, "__icon ").concat(componentName, "__icon--").concat(expandIconPlacement, " ").concat(isActive ? "".concat(componentName, "__icon--active") : ""),
"on": {
"click": handleClick
}
}, [tNodeRender("expandIcon", renderDefaultIcon())]);
},
renderHeader: function renderHeader() {
var h = this.$createElement;
var isDisabled = this.isDisabled,
handleClick = this.handleClick,
renderIcon = this.renderIcon,
renderBlank = this.renderBlank;
var cls = ["".concat(this.componentName, "__header"), _defineProperty({}, this.clickableClass, this.expandOnRowClick && !isDisabled)];
return h("div", {
"class": cls,
"on": {
"click": handleClick
}
}, [h("div", {
"class": "".concat(this.componentName, "__header-left")
}, [this.expandIconPlacement === "left" && renderIcon()]), h("div", {
"class": "".concat(this.componentName, "__header-content")
}, [this.renderTNodeJSX("header")]), renderBlank(), h("div", {
"class": "".concat(this.componentName, "__header-right")
}, [h("div", {
"class": "".concat(this.componentName, "__header-right-content"),
"on": {
"click": function click(e) {
return e.stopPropagation();
}
}
}, [this.renderTNodeJSX("headerRightContent")]), this.expandIconPlacement === "right" && renderIcon()])]);
},
renderBlank: function renderBlank() {
var h = this.$createElement;
return h("div", {
"class": "".concat(this.componentName, "__header--blank")
});
},
renderBody: function renderBody() {
return this.destroyOnCollapse ? this.renderBodyDestroyOnCollapse() : this.renderBodyByNormal();
},
renderBodyByNormal: function renderBodyByNormal() {
var h = this.$createElement;
return h("div", {
"directives": [{
name: "show",
value: this.isActive
}],
"class": "".concat(this.componentName, "__body")
}, [h("div", {
"class": "".concat(this.componentName, "__content")
}, [this.renderContent("default", "content")])]);
},
renderBodyDestroyOnCollapse: function renderBodyDestroyOnCollapse() {
var h = this.$createElement;
return this.isActive ? h("div", {
"class": "".concat(this.componentName, "__body")
}, [h("div", {
"class": "".concat(this.componentName, "__content")
}, [this.renderContent("default", "content")])]) : null;
},
handleClick: function handleClick(e) {
var expandOnRowClick = this.expandOnRowClick,
updateCollapseValue = this.updateCollapseValue,
innerValue = this.innerValue,
isDisabled = this.isDisabled;
var canExpand = expandOnRowClick || e.currentTarget === this.$refs.iconRef;
if (canExpand && !isDisabled) {
updateCollapseValue(innerValue);
}
e.stopPropagation();
}
},
render: function render() {
var h = arguments[0];
var _useCollapseAnimation = useCollapseAnimation(),
beforeEnter = _useCollapseAnimation.beforeEnter,
enter = _useCollapseAnimation.enter,
afterEnter = _useCollapseAnimation.afterEnter,
beforeLeave = _useCollapseAnimation.beforeLeave,
leave = _useCollapseAnimation.leave,
afterLeave = _useCollapseAnimation.afterLeave;
var classes = this.classes;
return h("div", {
"class": classes
}, [h("div", {
"class": "".concat(this.componentName, "__wrapper")
}, [this.renderHeader(), h("transition", {
"attrs": {
"name": this.transitionClass
},
"on": {
"beforeEnter": beforeEnter,
"enter": enter,
"afterEnter": afterEnter,
"beforeLeave": beforeLeave,
"leave": leave,
"afterLeave": afterLeave
}
}, [this.renderBody()])])]);
}
});
export { _CollapsePanel as default };
//# sourceMappingURL=collapse-panel.js.map