This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathSlider.react.js
147 lines (126 loc) · 3.65 KB
/
Slider.react.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
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
import React, {Component} from 'react';
import ReactSlider from 'rc-slider';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
/**
* A slider component with a single handle.
*/
export default class Slider extends Component {
constructor(props) {
super(props);
this.state = {value: props.value};
}
componentWillReceiveProps(newProps) {
this.setState({value: newProps.value});
}
render() {
const {setProps, fireEvent, updatemode} = this.props;
const {value} = this.state;
return (
<ReactSlider
onChange={value => {
this.setState({value});
if (updatemode === 'drag') {
if (setProps) setProps({value});
if (fireEvent) fireEvent('change');
}
}}
onAfterChange={value => {
if (updatemode === 'mouseup') {
if (setProps) setProps({value});
if (fireEvent) fireEvent('change');
}
}}
value={value}
{...omit(['fireEvent', 'setProps', 'updatemode', 'value'], this.props)}
/>
);
}
}
Slider.propTypes = {
id: PropTypes.string,
/**
* Marks on the slider.
* The key determines the position,
* and the value determines what will show.
* If you want to set the style of a specific mark point,
* the value should be an object which
* contains style and label properties.
*/
marks: PropTypes.shape({
number: PropTypes.oneOfType([
/**
* The label of the mark
*/
PropTypes.string,
/**
* The style and label of the mark
*/
PropTypes.shape({
style: PropTypes.object,
label: PropTypes.string
})
])
}),
/**
* The value of the input
*/
value: PropTypes.number,
/**
* Additional CSS class for the root DOM node
*/
className: PropTypes.string,
/**
* If true, the handles can't be moved.
*/
disabled: PropTypes.bool,
/**
* When the step value is greater than 1,
* you can set the dots to true if you want to
* render the slider with dots.
*/
dots: PropTypes.bool,
/**
* If the value is true, it means a continuous
* value is included. Otherwise, it is an independent value.
*/
included: PropTypes.bool,
/**
* Minimum allowed value of the slider
*/
min: PropTypes.number,
/**
* Maximum allowed value of the slider
*/
max: PropTypes.number,
/**
* Value by which increments or decrements are made
*/
step: PropTypes.number,
/**
* If true, the slider will be vertical
*/
vertical: PropTypes.bool,
/**
* Determines when the component should update
* its value. If `mouseup`, then the slider
* will only trigger its value when the user has
* finished dragging the slider. If `drag`, then
* the slider will update its value continuously
* as it is being dragged.
* Only use `drag` if your updates are fast.
*/
updatemode: PropTypes.oneOf(['mouseup', 'drag']),
/**
* Dash-assigned callback that gets fired when the checkbox item gets selected.
*/
fireEvent: PropTypes.func,
/**
* Dash-assigned callback that gets fired when the value changes.
*/
setProps: PropTypes.func,
dashEvents: PropTypes.oneOf(['change'])
};
Slider.defaultProps = {
updatemode: 'mouseup'
};