MCPcopy
hub / github.com/react-component/slider / Tracks

Function Tracks

src/Tracks/index.tsx:16–77  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

14}
15
16const Tracks: React.FC<TrackProps> = (props) => {
17 const { prefixCls, style, values, startPoint, onStartMove } = props;
18 const { included, range, min, styles, classNames } = React.useContext(SliderContext);
19
20 // =========================== List ===========================
21 const trackList = React.useMemo(() => {
22 if (!range) {
23 // null value do not have track
24 if (values.length === 0) {
25 return [];
26 }
27
28 const startValue = startPoint ?? min;
29 const endValue = values[0];
30
31 return [{ start: Math.min(startValue, endValue), end: Math.max(startValue, endValue) }];
32 }
33
34 // Multiple
35 const list: { start: number; end: number }[] = [];
36
37 for (let i = 0; i < values.length - 1; i += 1) {
38 list.push({ start: values[i], end: values[i + 1] });
39 }
40
41 return list;
42 }, [values, range, startPoint, min]);
43
44 if (!included) {
45 return null;
46 }
47
48 // ========================== Render ==========================
49 const tracksNode =
50 trackList?.length && (classNames.tracks || styles.tracks) ? (
51 <Track
52 index={null}
53 prefixCls={prefixCls}
54 start={trackList[0].start}
55 end={trackList[trackList.length - 1].end}
56 replaceCls={cls(classNames.tracks, `${prefixCls}-tracks`)}
57 style={styles.tracks}
58 />
59 ) : null;
60
61 return (
62 <>
63 {tracksNode}
64 {trackList.map<React.ReactNode>(({ start, end }, index) => (
65 <Track
66 index={index}
67 prefixCls={prefixCls}
68 style={{ ...getIndex(style, index), ...styles.track }}
69 start={start}
70 end={end}
71 key={index}
72 onStartMove={onStartMove}
73 />

Callers

nothing calls this directly

Calls 1

getIndexFunction · 0.90

Tested by

no test coverage detected