forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteps.tsx
69 lines (63 loc) · 2.07 KB
/
Steps.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { ExtractPropTypes, PropType } from 'vue';
import { computed, defineComponent } from 'vue';
import type { VueNode } from '../_util/type';
import PropTypes from '../_util/vue-types';
import type { ProgressSize } from './props';
import { progressProps } from './props';
import { getSize } from './utils';
export const stepsProps = () => ({
...progressProps(),
steps: Number,
size: {
type: String as PropType<ProgressSize>,
},
strokeColor: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
trailColor: String,
});
export type StepsProps = Partial<ExtractPropTypes<ReturnType<typeof stepsProps>>>;
export default defineComponent({
compatConfig: { MODE: 3 },
name: 'Steps',
props: stepsProps(),
setup(props, { slots }) {
const current = computed(() => Math.round(props.steps * ((props.percent || 0) / 100)));
const mergedSize = computed(
() => props.size ?? [props.size === 'small' ? 2 : 14, props.strokeWidth || 8],
);
const sizeRef = computed(() =>
getSize(mergedSize.value as ProgressSize, 'step', {
steps: props.steps,
strokeWidth: props.strokeWidth || 8,
}),
);
const styledSteps = computed(() => {
const { steps, strokeColor, trailColor, prefixCls } = props;
const temp: VueNode[] = [];
for (let i = 0; i < steps; i += 1) {
const color = Array.isArray(strokeColor) ? strokeColor[i] : strokeColor;
const cls = {
[`${prefixCls}-steps-item`]: true,
[`${prefixCls}-steps-item-active`]: i <= current.value - 1,
};
temp.push(
<div
key={i}
class={cls}
style={{
backgroundColor: i <= current.value - 1 ? color : trailColor,
width: `${sizeRef.value.width / steps}px`,
height: `${sizeRef.value.height}px`,
}}
/>,
);
}
return temp;
});
return () => (
<div class={`${props.prefixCls}-steps-outer`}>
{styledSteps.value}
{slots.default?.()}
</div>
);
},
});