-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.tsx
72 lines (60 loc) · 1.88 KB
/
index.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
import { CSSObject } from '@emotion/core';
import { Theme } from '../../../themes';
import styled from '../../../';
const track = (theme: Theme, percentFilled?: number) => ({
width: '100%',
height: 9,
cursor: 'pointer',
background:
percentFilled != null
? `linear-gradient(to right, ${theme.colors.purple} ${percentFilled}%, ${theme.colors.purple} ${percentFilled}%, ${theme.colors.lightGray} ${percentFilled}%)`
: theme.colors.lightGray,
borderRadius: theme.borderRadius.small,
});
const thumb = (theme: Theme): CSSObject => ({
boxSizing: 'border-box',
border: '4px solid #fff',
width: 36,
height: 36,
borderRadius: '100%',
background: theme.colors.purple,
cursor: 'pointer',
WebkitAppearance: 'none',
marginTop: -14,
});
const percentFilled = (value: number, min: number, max: number) => ((value - min) / (max - min)) * 100;
interface SliderProps {
min: number;
max: number;
value: number;
}
export const Slider = styled.input<SliderProps>(({ min, max, value, theme }) => ({
WebkitAppearance: 'none',
width: '100%',
height: 36,
margin: 0,
'&:focus': {
outline: 'none',
},
'&::-webkit-slider-runnable-track': track(theme, percentFilled(value, min, max)),
'&::-webkit-slider-thumb': thumb(theme),
'&::-moz-range-track': track(theme, percentFilled(value, min, max)),
'&::-moz-range-thumb': thumb(theme),
'&::-ms-track': {
...track(theme, percentFilled(value, min, max)),
background: 'transparent',
borderColor: 'transparent',
color: 'transparent',
},
'&::-ms-fill-lower': {
background: theme.colors.purple,
},
'&::-ms-fill-upper': {
background: theme.colors.lightGray,
},
'&::-ms-thumb': {
...thumb(theme),
marginTop: 0,
},
}));
Slider.displayName = 'Collector.Slider';