-
-
Notifications
You must be signed in to change notification settings - Fork 777
Expand file tree
/
Copy pathindex.tsx
More file actions
66 lines (57 loc) · 1.68 KB
/
index.tsx
File metadata and controls
66 lines (57 loc) · 1.68 KB
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
import * as React from 'react';
import type { InternalMarkObj } from '../Marks';
import SliderContext from '../context';
import Dot from './Dot';
import classNames from 'classnames';
export interface StepsProps {
prefixCls: string;
marks: InternalMarkObj[];
dots?: boolean;
style?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
activeStyle?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
}
export default function Steps(props: StepsProps) {
const { prefixCls, marks, dots, style, activeStyle } = props;
const { min, max, step } = React.useContext(SliderContext);
const { stepDots, marksValue } = React.useMemo(() => {
const dotSet = new Set<number>();
// Add marks
marks.forEach((mark) => {
dotSet.add(mark.value);
});
// Set marksValue
const uniqueMarksValue = Array.from(dotSet);
// Fill dots
if (dots && step !== null) {
let current = min;
while (current <= max) {
dotSet.add(current);
current += step;
}
}
return {
marksValue: uniqueMarksValue,
stepDots: Array.from(dotSet),
};
}, [min, max, step, dots, marks]);
return (
<div className={`${prefixCls}-step`}>
{stepDots.map((dotValue) => {
// Check whether it is a marks dot
const isMarksDot = marksValue.indexOf(dotValue) >= 0;
return (
<Dot
prefixCls={prefixCls}
className={classNames({
[`${prefixCls}-marks-dot`]: isMarksDot,
})}
key={dotValue}
value={dotValue}
style={style}
activeStyle={activeStyle}
/>
);
})}
</div>
);
}