-
Notifications
You must be signed in to change notification settings - Fork 480
/
IntegerTextbox.jsx
45 lines (40 loc) · 1.09 KB
/
IntegerTextbox.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
/** @file Textbox that only allows positive integer values, used in crypto widget */
import React, {PropTypes} from 'react';
import color from "../util/color";
const IntegerTextbox = React.createClass({
propTypes: {
className: PropTypes.string,
value: PropTypes.number,
disabled: PropTypes.bool,
color: PropTypes.string,
onChange: PropTypes.func.isRequired
},
onChange(event) {
const value = parseInt(event.target.value, 10);
this.props.onChange(Number.isInteger(value) ? value : null);
},
render() {
let {className, value, disabled, color: backgroundColor} = this.props;
if (!Number.isInteger(value)) {
value = '';
}
const style = {
width: 75,
paddingLeft: 8,
margin: '0 5px',
backgroundColor: backgroundColor || 'white',
borderColor: color.light_gray,
borderStyle: 'solid',
borderWidth: 1
};
return (
<input
className={className}
style={style}
value={value}
disabled={disabled}
onChange={this.onChange}
/>);
}
});
export default IntegerTextbox;