-
Notifications
You must be signed in to change notification settings - Fork 80
/
components.tsx
204 lines (193 loc) · 4.64 KB
/
components.tsx
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import * as React from 'react';
import {
GetRailProps,
GetHandleProps,
GetTrackProps,
SliderItem,
} from 'react-compound-slider';
// *******************************************************
// RAIL
// *******************************************************
const railOuterStyle = {
position: 'absolute' as 'absolute',
width: '100%',
height: 42,
transform: 'translate(0%, -50%)',
borderRadius: 7,
cursor: 'pointer',
};
const railInnerStyle = {
position: 'absolute' as 'absolute',
width: '100%',
height: 14,
transform: 'translate(0%, -50%)',
borderRadius: 7,
pointerEvents: 'none' as 'none',
backgroundColor: 'rgb(155,155,155)',
};
interface SliderRailProps {
getRailProps: GetRailProps;
}
export const SliderRail: React.FC<SliderRailProps> = ({ getRailProps }) => {
return (
<>
<div style={railOuterStyle} {...getRailProps()} />
<div style={railInnerStyle} />
</>
);
};
// *******************************************************
// HANDLE COMPONENT
// *******************************************************
interface HandleProps {
domain: number[];
handle: SliderItem;
getHandleProps: GetHandleProps;
disabled?: boolean;
}
export const Handle: React.FC<HandleProps> = ({
domain: [min, max],
handle: { id, value, percent },
disabled = false,
getHandleProps,
}) => {
return (
<>
<div
style={{
left: `${percent}%`,
position: 'absolute',
transform: 'translate(-50%, -50%)',
WebkitTapHighlightColor: 'rgba(0,0,0,0)',
zIndex: 5,
width: 28,
height: 42,
cursor: 'pointer',
backgroundColor: 'none',
}}
{...getHandleProps(id)}
/>
<div
role="slider"
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value}
style={{
left: `${percent}%`,
position: 'absolute',
transform: 'translate(-50%, -50%)',
zIndex: 2,
width: 24,
height: 24,
borderRadius: '50%',
boxShadow: '1px 1px 1px 1px rgba(0, 0, 0, 0.3)',
backgroundColor: disabled ? '#666' : '#9BBFD4',
}}
/>
</>
);
};
// *******************************************************
// KEYBOARD HANDLE COMPONENT
// Uses a button to allow keyboard events
// *******************************************************
export const KeyboardHandle: React.FC<HandleProps> = ({
domain: [min, max],
handle: { id, value, percent },
disabled = false,
getHandleProps,
}) => {
return (
<button
role="slider"
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value}
style={{
left: `${percent}%`,
position: 'absolute',
transform: 'translate(-50%, -50%)',
zIndex: 2,
width: 24,
height: 24,
borderRadius: '50%',
boxShadow: '1px 1px 1px 1px rgba(0, 0, 0, 0.3)',
backgroundColor: disabled ? '#666' : '#9BBFD4',
}}
{...getHandleProps(id)}
/>
);
};
// *******************************************************
// TRACK COMPONENT
// *******************************************************
interface TrackProps {
source: SliderItem;
target: SliderItem;
getTrackProps: GetTrackProps;
disabled?: boolean;
}
export const Track: React.FC<TrackProps> = ({
source,
target,
getTrackProps,
disabled = false,
}) => {
return (
<div
style={{
position: 'absolute',
transform: 'translate(0%, -50%)',
height: 14,
zIndex: 1,
backgroundColor: disabled ? '#999' : '#607E9E',
borderRadius: 7,
cursor: 'pointer',
left: `${source.percent}%`,
width: `${target.percent - source.percent}%`,
}}
{...getTrackProps()}
/>
);
};
// *******************************************************
// TICK COMPONENT
// *******************************************************
interface TickProps {
tick: SliderItem;
count: number;
format?: (val: number) => string;
}
export const Tick: React.FC<TickProps> = ({
tick,
count,
format = (d) => d,
}) => {
return (
<div>
<div
style={{
position: 'absolute',
marginTop: 14,
width: 1,
height: 5,
backgroundColor: 'rgb(200,200,200)',
left: `${tick.percent}%`,
}}
/>
<div
style={{
position: 'absolute',
marginTop: 22,
fontSize: 10,
textAlign: 'center',
marginLeft: `${-(100 / count) / 2}%`,
width: `${100 / count}%`,
left: `${tick.percent}%`,
}}
>
{format(tick.value)}
</div>
</div>
);
};