UNPKG

tdesign-vue

Version:
195 lines (191 loc) 9.41 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, getCurrentInstance, inject, toRefs, computed } from '@vue/composition-api'; import { Loading } from '../loading/index.js'; import getRenderAlign from './utils.js'; import TimelineItemProps from './timeline-item-props.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js'; import '../loading/directive.js'; import 'lodash-es'; import '../loading/plugin.js'; import 'vue'; import '../loading/loading.js'; import '../loading/icon/gradient.js'; import '../_common/js/loading/circle-adapter.js'; import '../_common/js/utils/setStyle.js'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../config-provider/config-receiver.js'; 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-c44a474d.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-d639fbd7.js'; import 'dayjs'; import '../_chunks/dep-3c66615e.js'; import '../config-provider/type.js'; import '../_common/js/global-config/t.js'; import '../utils/mixins.js'; import '../utils/dom.js'; import 'raf'; import '../utils/easing.js'; import '../utils/transfer-dom.js'; import '../loading/props.js'; import '@babel/runtime/helpers/readOnlyError'; import '../config.js'; import '../utils/withInstall.js'; import './style/index.js'; import '../loading/type.js'; import '../_common/js/log/index.js'; import '../_common/js/log/log.js'; import '../config-provider/useConfig.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var DEFAULT_THEME = ["primary", "warning", "error", "default"]; var _TimelineItem = defineComponent({ name: "TTimelineItem", components: { TLoading: Loading }, props: _objectSpread({}, TimelineItemProps), setup: function setup(props, context) { var instance = getCurrentInstance(); var classPrefix = usePrefixClass(); var timelineProvider = inject("TTimeline", { layout: "vertical", reverse: false, theme: void 0, labelAlign: "left", mode: "alternate" }); var layout = timelineProvider.layout, reverse = timelineProvider.reverse, theme = timelineProvider.theme, labelAlign = timelineProvider.labelAlign, mode = timelineProvider.mode; var _toRefs = toRefs(props), dotColor = _toRefs.dotColor, itemLabelAlign = _toRefs.labelAlign, loading = _toRefs.loading; var timelineItemAlign = computed(function () { var _itemLabelAlign$value; return (_itemLabelAlign$value = itemLabelAlign.value) !== null && _itemLabelAlign$value !== void 0 ? _itemLabelAlign$value : getRenderAlign(labelAlign === null || labelAlign === void 0 ? void 0 : labelAlign.value, layout === null || layout === void 0 ? void 0 : layout.value); }); var uidArr = computed(function () { var _instance$parent$slot; var defaultSlots = (_instance$parent$slot = instance.parent.slots["default"]) !== null && _instance$parent$slot !== void 0 ? _instance$parent$slot : [null]; return defaultSlots.map(function (item) { var _item$componentInstan; return item === null || item === void 0 || (_item$componentInstan = item.componentInstance) === null || _item$componentInstan === void 0 ? void 0 : _item$componentInstan._uid; }); }); var currentIndex = computed(function () { var index = 0; uidArr.value.forEach(function (item, itemIndex) { if (item === instance.uid) { index = itemIndex; } }); return index; }); var positionClassName = computed(function () { var left = (layout === null || layout === void 0 ? void 0 : layout.value) === "horizontal" ? "top" : "left"; var right = (layout === null || layout === void 0 ? void 0 : layout.value) === "horizontal" ? "bottom" : "right"; if (timelineItemAlign.value === "alternate") { return currentIndex.value % 2 === 0 ? "".concat(classPrefix.value, "-timeline-item-").concat(left) : "".concat(classPrefix.value, "-timeline-item-").concat(right); } if (timelineItemAlign.value === "left" || timelineItemAlign.value === "top") { return "".concat(classPrefix.value, "-timeline-item-").concat(left); } if (timelineItemAlign.value === "right" || timelineItemAlign.value === "bottom") { return "".concat(classPrefix.value, "-timeline-item-").concat(right); } return ""; }); var getItemClassName = computed(function () { var isLastChildren = uidArr.value.length - 1 === currentIndex.value; var lastClassName = isLastChildren ? "".concat(classPrefix.value, "-timeline-item--last") : ""; return "".concat(classPrefix.value, "-timeline-item ").concat(positionClassName.value, " ").concat(lastClassName); }); var tailClassName = computed(function () { var statusClassName = reverse ? "".concat(classPrefix.value, "-timeline-item__tail--status-").concat(dotColor === null || dotColor === void 0 ? void 0 : dotColor.value) : ""; return "".concat(classPrefix.value, "-timeline-item__tail ").concat(classPrefix.value, "-timeline-item__tail--theme-").concat(theme === null || theme === void 0 ? void 0 : theme.value, " ").concat(statusClassName); }); var dotElement = computed(function () { return Boolean(context.slots.dot || props.dot); }); var dotClassName = computed(function () { var dotCustomClassName = !!dotElement.value || !dotElement.value && loading !== null && loading !== void 0 && loading.value ? "".concat(classPrefix.value, "-timeline-item__dot--custom") : ""; var docColorClassName = DEFAULT_THEME.includes(dotColor === null || dotColor === void 0 ? void 0 : dotColor.value) ? "".concat(classPrefix.value, "-timeline-item__dot--").concat(dotColor === null || dotColor === void 0 ? void 0 : dotColor.value) : ""; return "".concat(classPrefix.value, "-timeline-item__dot ").concat(dotCustomClassName, " ").concat(docColorClassName); }); var labelClassName = computed(function () { return "".concat(classPrefix.value, "-timeline-item__label ").concat(classPrefix.value, "-timeline-item__label--").concat(mode === null || mode === void 0 ? void 0 : mode.value); }); return { mode: mode, currentIndex: currentIndex, tailClassName: tailClassName, dotClassName: dotClassName, labelClassName: labelClassName, getItemClassName: getItemClassName, classPrefix: classPrefix }; }, render: function render() { var _dotElement$; var h = arguments[0]; var dotColor = this.dotColor, dotClassName = this.dotClassName, _this$style = this.style, style = _this$style === void 0 ? {} : _this$style, labelClassName = this.labelClassName, mode = this.mode, loading = this.loading, tailClassName = this.tailClassName, getItemClassName = this.getItemClassName, _this$classPrefix = this.classPrefix, classPrefix = _this$classPrefix === void 0 ? "t" : _this$classPrefix; var dotElement = renderTNodeJSX(this, "dot"); var labelNode = renderTNodeJSX(this, "label"); var dotContentClass = "".concat(classPrefix, "-timeline-item__dot-content"); if (Array.isArray(dotElement) && (_dotElement$ = dotElement[0]) !== null && _dotElement$ !== void 0 && _dotElement$.data) { var classes = dotElement[0].data["class"]; dotElement[0].data["class"] = classes ? [classes, dotContentClass].join(" ") : dotContentClass; } return h("li", { "class": getItemClassName, "style": style }, [mode === "alternate" && labelNode && h("div", { "class": labelClassName }, [labelNode]), h("div", { "class": "".concat(classPrefix, "-timeline-item__wrapper") }, [h("div", { "class": dotClassName, "style": { borderColor: !DEFAULT_THEME.includes(dotColor) && dotColor } }, [!dotElement && loading && h(Loading, { "attrs": { "size": "12px" }, "class": dotContentClass }), dotElement]), h("div", { "class": tailClassName })]), h("div", { "class": "".concat(classPrefix, "-timeline-item__content") }, [renderContent(this, "content", "default"), mode === "same" && labelNode && h("div", { "class": labelClassName }, [labelNode])])]); } }); export { _TimelineItem as default }; //# sourceMappingURL=timeline-item.js.map