-
-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy pathDot.tsx
More file actions
49 lines (43 loc) · 1.36 KB
/
Dot.tsx
File metadata and controls
49 lines (43 loc) · 1.36 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
import cls from 'classnames';
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);
}
export default function Dot(props: DotProps) {
const { prefixCls, value, style, activeStyle } = props;
const { min, max, direction, included, includedStart, includedEnd, styles, classNames } =
React.useContext(SliderContext);
const dotClassName = `${prefixCls}-dot`;
const active = included && includedStart <= value && value <= includedEnd;
// ============================ Offset ============================
let mergedStyle = {
...getDirectionStyle(direction, value, min, max),
...(typeof style === 'function' ? style(value) : style),
...styles.dot,
};
if (active) {
mergedStyle = {
...mergedStyle,
...(typeof activeStyle === 'function' ? activeStyle(value) : activeStyle),
...styles.dotActive,
};
}
return (
<span
className={cls(
dotClassName,
{
[`${dotClassName}-active`]: active,
},
active && classNames.dotActive,
classNames.dot,
)}
style={mergedStyle}
/>
);
}