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 pathRangeSlider.react.js
122 lines (111 loc) · 3.86 KB
/
RangeSlider.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
import React, {Component} from 'react';
import {assoc, omit, pickBy} from 'ramda';
import {Range, createSliderWithTooltip} from 'rc-slider';
import computeSliderStyle from '../utils/computeSliderStyle';
import 'rc-slider/assets/index.css';
import {propTypes, defaultProps} from '../components/RangeSlider.react';
export default class RangeSlider extends Component {
constructor(props) {
super(props);
this.propsToState = this.propsToState.bind(this);
this.DashSlider = props.tooltip
? createSliderWithTooltip(Range)
: Range;
this._computeStyle = computeSliderStyle();
this.state = {
value: props.value,
drag_value: props.value,
};
this.props.setProps({drag_value: props.value});
}
propsToState(newProps) {
if (newProps.value !== this.props.value) {
this.setState({value: newProps.value, drag_value: newProps.value});
}
}
UNSAFE_componentWillReceiveProps(newProps) {
if (newProps.tooltip !== this.props.tooltip) {
this.DashSlider = newProps.tooltip
? createSliderWithTooltip(Range)
: Range;
}
this.propsToState(newProps);
}
UNSAFE_componentWillMount() {
this.propsToState(this.props);
}
render() {
const {
className,
id,
loading_state,
setProps,
tooltip,
updatemode,
vertical,
verticalHeight,
} = this.props;
const value = this.state.value;
let tipProps;
if (tooltip && tooltip.always_visible) {
/**
* clone `tooltip` but with renamed key `always_visible` -> `visible`
* the rc-tooltip API uses `visible`, but `always_visible is more semantic
* assigns the new (renamed) key to the old key and deletes the old key
*/
tipProps = assoc('visible', tooltip.always_visible, tooltip);
delete tipProps.always_visible;
} else {
tipProps = tooltip;
}
const truncatedMarks =
this.props.marks &&
pickBy(
(k, mark) => mark >= this.props.min && mark <= this.props.max,
this.props.marks
);
return (
<div
id={id}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
className={className}
style={this._computeStyle(vertical, verticalHeight, tooltip)}
>
<this.DashSlider
onChange={value => {
if (updatemode === 'drag') {
setProps({value: value, drag_value: value});
} else {
this.setState({value: value});
setProps({drag_value: value});
}
}}
onAfterChange={value => {
if (updatemode === 'mouseup') {
setProps({value});
}
}}
tipProps={tipProps}
value={value}
marks={truncatedMarks}
{...omit(
[
'className',
'value',
'drag_value',
'setProps',
'marks',
'updatemode',
'verticalHeight',
],
this.props
)}
/>
</div>
);
}
}
RangeSlider.propTypes = propTypes;
RangeSlider.defaultProps = defaultProps;