This repository has been archived by the owner on Jul 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.js
114 lines (101 loc) · 3.51 KB
/
index.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
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
import PropTypes from 'prop-types';
import React from 'react';
import nouislider from 'nouislider';
class Nouislider extends React.Component {
componentDidMount() {
if (this.props.disabled) this.sliderContainer.setAttribute('disabled', true);
else this.sliderContainer.removeAttribute('disabled');
this.createSlider();
}
componentDidUpdate() {
if (this.props.disabled) this.sliderContainer.setAttribute('disabled', true);
else this.sliderContainer.removeAttribute('disabled');
this.slider.destroy();
this.createSlider();
}
componentWillUnmount() {
this.slider.destroy();
}
createSlider() {
var slider = (this.slider = nouislider.create(this.sliderContainer, {
...this.props
}));
if (this.props.onUpdate) {
slider.on('update', this.props.onUpdate);
}
if (this.props.onChange) {
slider.on('change', this.props.onChange);
}
if (this.props.onSlide) {
slider.on('slide', this.props.onSlide);
}
if (this.props.onStart) {
slider.on('start', this.props.onStart);
}
if (this.props.onEnd) {
slider.on('end', this.props.onEnd);
}
if (this.props.onSet) {
slider.on('set', this.props.onSet);
}
}
render() {
return (
<div
ref={slider => {
this.sliderContainer = slider;
}}
/>
);
}
}
Nouislider.propTypes = {
// http://refreshless.com/nouislider/slider-options/#section-animate
animate: PropTypes.bool,
// http://refreshless.com/nouislider/behaviour-option/
behaviour: PropTypes.string,
// http://refreshless.com/nouislider/slider-options/#section-Connect
connect: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.bool), PropTypes.bool]),
// http://refreshless.com/nouislider/slider-options/#section-cssPrefix
cssPrefix: PropTypes.string,
// http://refreshless.com/nouislider/slider-options/#section-orientation
direction: PropTypes.oneOf(['ltr', 'rtl']),
// http://refreshless.com/nouislider/more/#section-disable
disabled: PropTypes.bool,
// http://refreshless.com/nouislider/slider-options/#section-limit
limit: PropTypes.number,
// http://refreshless.com/nouislider/slider-options/#section-margin
margin: PropTypes.number,
// http://refreshless.com/nouislider/events-callbacks/#section-change
onChange: PropTypes.func,
// http://refreshless.com/nouislider/events-callbacks/
onEnd: PropTypes.func,
// http://refreshless.com/nouislider/events-callbacks/#section-set
onSet: PropTypes.func,
// http://refreshless.com/nouislider/events-callbacks/#section-slide
onSlide: PropTypes.func,
// http://refreshless.com/nouislider/events-callbacks/
onStart: PropTypes.func,
// http://refreshless.com/nouislider/events-callbacks/#section-update
onUpdate: PropTypes.func,
// http://refreshless.com/nouislider/slider-options/#section-orientation
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
// http://refreshless.com/nouislider/pips/
pips: PropTypes.object,
// http://refreshless.com/nouislider/slider-values/#section-range
range: PropTypes.object.isRequired,
// http://refreshless.com/nouislider/slider-options/#section-start
start: PropTypes.arrayOf(PropTypes.number).isRequired,
// http://refreshless.com/nouislider/slider-options/#section-step
step: PropTypes.number,
// http://refreshless.com/nouislider/slider-options/#section-tooltips
tooltips: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.arrayOf(
PropTypes.shape({
to: PropTypes.func
})
)
])
};
module.exports = Nouislider;