-
-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathDot.tsx
More file actions
42 lines (35 loc) · 1.23 KB
/
Dot.tsx
File metadata and controls
42 lines (35 loc) · 1.23 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
import { clsx } from 'clsx';
import * as React from 'react';
import SliderContext from '../context';
import { getDirectionStyle } from '../util';
export interface DotProps {
prefixCls: string;
value: number;
style?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
activeStyle?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
}
const Dot: React.FC<DotProps> = (props) => {
const { prefixCls, value, style, activeStyle } = props;
const { min, max, direction, included, includedStart, includedEnd } =
React.useContext(SliderContext);
const dotClassName = `${prefixCls}-dot`;
const active = included && includedStart <= value && value <= includedEnd;
// ============================ Offset ============================
let mergedStyle: React.CSSProperties = {
...getDirectionStyle(direction, value, min, max),
...(typeof style === 'function' ? style(value) : style),
};
if (active) {
mergedStyle = {
...mergedStyle,
...(typeof activeStyle === 'function' ? activeStyle(value) : activeStyle),
};
}
return (
<span
className={clsx(dotClassName, { [`${dotClassName}-active`]: active })}
style={mergedStyle}
/>
);
};
export default Dot;