-
-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy pathMark.tsx
More file actions
51 lines (46 loc) · 1.29 KB
/
Mark.tsx
File metadata and controls
51 lines (46 loc) · 1.29 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
import cls from 'classnames';
import * as React from 'react';
import SliderContext from '../context';
import { getDirectionStyle } from '../util';
export interface MarkProps {
prefixCls: string;
children?: React.ReactNode;
style?: React.CSSProperties;
value: number;
onClick: (value: number) => void;
}
export default function Mark(props: MarkProps) {
const { prefixCls, style, children, value, onClick } = props;
const { min, max, direction, includedStart, includedEnd, included, styles, classNames } =
React.useContext(SliderContext);
const textCls = `${prefixCls}-text`;
const active = included && includedStart <= value && value <= includedEnd;
// ============================ Offset ============================
const positionStyle = getDirectionStyle(direction, value, min, max);
return (
<span
className={cls(
textCls,
{
[`${textCls}-active`]: active,
},
active && classNames.markActive,
classNames.mark,
)}
style={{
...positionStyle,
...style,
...(active ? styles.markActive : {}),
...styles.mark,
}}
onMouseDown={(e) => {
e.stopPropagation();
}}
onClick={() => {
onClick(value);
}}
>
{children}
</span>
);
}