-
Notifications
You must be signed in to change notification settings - Fork 11
/
InputRange.jsx
95 lines (93 loc) · 2.46 KB
/
InputRange.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
import React, { PureComponent } from 'react';
import autobind from '@lskjs/autobind';
import PropTypes from 'prop-types';
import Numeric from 'react-numeric-input';
import filterProps from '@lskjs/utils/filterProps';
import Input from '../../../components/BaseInput';
// import Input from '@lskjs/ui/Input';
import { elInput, El, Block } from './InputRange.styles';
class InputRange extends PureComponent {
static propTypes = {
value: PropTypes.array,
onChange: PropTypes.func,
validationState: PropTypes.any,
max: PropTypes.number,
min: PropTypes.number,
minProps: PropTypes.object,
maxProps: PropTypes.object,
}
static defaultProps = {
value: [null, null],
minProps: {},
maxProps: {},
onChange: null,
validationState: null,
max: null,
min: null,
}
constructor(props) {
super(props);
this.state = {
value: props.value,
};
}
componentWillReceiveProps(next) {
if (this.props.value[0] !== next.value[0] || this.props.value[1] !== next.value[1]) {
this.setState({ value: next.value });
}
}
@autobind changeFrom(e) {
const { value } = this.state;
this.setState({ value: [e, value[1]] }, this.callback);
}
@autobind changeTo(e) {
const { value } = this.state;
this.setState({ value: [value[0], e] }, this.callback);
}
@autobind callback() {
const { value } = this.state;
const { onChange } = this.props;
if (onChange) onChange(value);
}
render() {
const { value } = this.state;
const {
validationState, min, max, minProps, maxProps,
} = this.props;
const [from, to] = value;
return (
<Block>
<El>
<Input
validationState={validationState}
className={elInput}
componentClass={Numeric}
onChange={this.changeFrom}
placeholder={min}
value={from}
max={to || max}
min={min}
{...filterProps(minProps, Numeric)}
// {...minProps}
/>
</El>
-
<El>
<Input
validationState={validationState}
className={elInput}
componentClass={Numeric}
onChange={this.changeTo}
placeholder={max}
value={to}
max={max}
min={from || min}
{...filterProps(maxProps, Numeric)}
// {...maxProps}
/>
</El>
</Block>
);
}
}
export default InputRange;