-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSliderWrapper.jsx
157 lines (149 loc) · 3.45 KB
/
SliderWrapper.jsx
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
import React from 'react';
import Slider from '../components/index';
import styles from './styles.css';
const MAX = 24;
const MIN = 0;
class SliderWrapper extends React.Component {
constructor(props) {
super(props);
this.state = {
val: 0
};
this.onChange = this.onChange.bind(this);
this.onKeydown = this.onKeydown.bind(this);
}
onChange(val) {
this.setState({ val });
}
componentDidMount() {
if (document.addEventListener) {
document.addEventListener('keydown', this.onKeydown, true);
} else {
document.attachEvent('onkeydown', this.onKeydown);
}
}
componentWillUnmount() {
if (document.removeEventListener) {
document.removeEventListener('keydown', this.onKeydown, true);
} else {
document.detachEvent('onkeydown', this.onKeydown);
}
}
onKeydown(e) {
const { val } = this.state;
const { keyCode } = e;
if ((keyCode === 37 || keyCode === 65) && val >= MIN + 1) {
// left
this.onChange(val - 1);
}
if ((keyCode === 39 || keyCode === 68) && val < MAX) {
// right
this.onChange(val + 1);
}
return false;
}
render() {
const { jump, clickable, showTipso = false } = this.props;
const { val } = this.state;
return (
<div id="components-container">
<h4>Default</h4>
<div>
<Slider
id="1"
value={15}
jump={jump}
/>
<br />
<Slider
id="2"
showTipso
value={15}
jump={jump}
/>
<br />
<Slider
jump
id="3"
max={MAX}
min={MIN}
value={val}
updateWhenDrag
showTipso={showTipso}
clickable={clickable}
draggerClass={styles.dragger}
/>
<br/>
<Slider
jump
id="4"
max={MAX}
min={MIN}
value={val}
showTipso
updateWhenDrag
clickable={clickable}
draggerClass={styles.dragger}
/>
</div>
<br />
<h4>Update when dragging</h4>
<div>
<div>{val}</div>
<Slider
id="5"
max={MAX}
min={MIN}
jump={jump}
sectionRange={4}
value={val}
updateWhenDrag
clickable={clickable}
showTipso={showTipso}
onChange={this.onChange}
/>
</div>
<br />
<h4>...with drag section</h4>
<div>
<Slider
jump
id="6"
min={0}
max={24}
clickable
sectionRange={4}
/>
</div>
<br />
<h4>Support given different section range</h4>
<div>
<Slider
jump
id="7"
min={0}
max={24}
clickable
sectionRange={[1, 2, 3, 4]}
/>
</div>
<br />
<h4>Custom (Without tip, curstom dragger style)</h4>
<div>
<Slider
id="8"
min={1}
max={24}
value={24}
jump={jump}
useTipso={false}
clickable={clickable}
showTipso={showTipso}
draggerClass={styles.dragger}
/>
</div>
</div>
);
}
}
export default SliderWrapper;