Skip to content

Commit 04e3819

Browse files
committed
perf: timeline
1 parent 587c1ca commit 04e3819

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

components/timeline/TimelineItem.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ExtractPropTypes } from 'vue';
2-
import { defineComponent } from 'vue';
3-
import classNames from '../_util/classNames';
2+
import { computed, defineComponent } from 'vue';
43
import PropTypes from '../_util/vue-types';
54
import initDefaultProps from '../_util/props-util/initDefaultProps';
65
import { tuple, booleanType } from '../_util/type';
@@ -27,24 +26,28 @@ export default defineComponent({
2726
slots: ['dot', 'label'],
2827
setup(props, { slots }) {
2928
const { prefixCls } = useConfigInject('timeline', props);
30-
return () => {
31-
const { color = '', pending, label = slots.label?.(), dot = slots.dot?.() } = props;
32-
const itemClassName = classNames({
33-
[`${prefixCls.value}-item`]: true,
34-
[`${prefixCls.value}-item-pending`]: pending,
35-
});
29+
const itemClassName = computed(() => ({
30+
[`${prefixCls.value}-item`]: true,
31+
[`${prefixCls.value}-item-pending`]: props.pending,
32+
}));
3633

37-
const dotClassName = classNames({
38-
[`${prefixCls.value}-item-head`]: true,
39-
[`${prefixCls.value}-item-head-custom`]: dot,
40-
[`${prefixCls.value}-item-head-${color}`]: true,
41-
});
42-
const customColor = /blue|red|green|gray/.test(color || '') ? undefined : color;
34+
const customColor = computed(() =>
35+
/blue|red|green|gray/.test(props.color || '') ? undefined : props.color || 'blue',
36+
);
37+
const dotClassName = computed(() => ({
38+
[`${prefixCls.value}-item-head`]: true,
39+
[`${prefixCls.value}-item-head-${props.color || 'blue'}`]: !customColor.value,
40+
}));
41+
return () => {
42+
const { label = slots.label?.(), dot = slots.dot?.() } = props;
4343
return (
44-
<li class={itemClassName}>
44+
<li class={itemClassName.value}>
4545
{label && <div class={`${prefixCls.value}-item-label`}>{label}</div>}
4646
<div class={`${prefixCls.value}-item-tail`} />
47-
<div class={dotClassName} style={{ borderColor: customColor, color: customColor }}>
47+
<div
48+
class={[dotClassName.value, !!dot && `${prefixCls.value}-item-head-custom`]}
49+
style={{ borderColor: customColor.value, color: customColor.value }}
50+
>
4851
{dot}
4952
</div>
5053
<div class={`${prefixCls.value}-item-content`}>{slots.default?.()}</div>

0 commit comments

Comments
 (0)