forked from carbon-app/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlider.js
87 lines (77 loc) · 2.04 KB
/
Slider.js
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
import React from 'react'
import { COLORS } from '../lib/constants'
class Slider extends React.Component {
static defaultProps = {
onMouseDown: () => {},
onMouseUp: () => {},
unit: 'px',
}
handleChange = e => {
this.props.onChange(`${e.target.value}${this.props.unit}`)
}
render() {
const minValue = this.props.minValue || 0
const maxValue = this.props.maxValue || 100
const step = 'step' in this.props ? this.props.step : 1
return (
<div className="slider settings-row">
<div
className="slider-bg"
style={{
transform: `translate3d(${
(((parseFloat(this.props.value) - minValue) * 1.0) / (maxValue - minValue)) * 100
}%, 0px, 0px)`,
}}
/>
<label>{this.props.label}</label>
<input
type="range"
defaultValue={this.props.value}
onChange={this.handleChange}
onMouseDown={this.props.onMouseDown}
onMouseUp={this.props.onMouseUp}
min={minValue}
max={maxValue}
step={step}
/>
<style jsx>
{`
.slider {
position: relative;
height: 33px;
overflow: hidden;
user-select: none;
}
.slider:last-of-type {
border-bottom: 0;
}
label {
position: absolute;
left: 8px;
height: 33px;
line-height: 33px;
}
input {
opacity: 0;
cursor: ew-resize;
position: relative;
height: 100%;
width: 100%;
margin: 0;
}
.slider-bg {
position: absolute;
top: 0;
bottom: 0;
pointer-events: none;
height: 33px;
width: 100%;
background: ${COLORS.DARK_GRAY};
}
`}
</style>
</div>
)
}
}
export default Slider