-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
51 lines (46 loc) · 1.74 KB
/
App.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
import React, { Component } from 'react'
import NumberInput from 'number-input-lib';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
positiveInteger: '',
invalidPositiveInteger: '',
integer: '',
invalidInteger: '',
positiveFloat: '',
invalidPositiveFloat: '',
float: '',
invalidFloat: ''
}
this.handleInputChanges = this.handleInputChanges.bind(this);
}
handleInputChanges(type, value) {
this.setState({[type]: value})
}
getInput(validValue, invalidPositiveIntegerValue, invalidValidValueStateKey, validValueStateKey, type) {
return (
<div className={'input-type'}>
<div>
<div> value: {validValue} </div>
<div> last invalid input: {invalidPositiveIntegerValue} </div>
</div>
<span className={'input-type-and-input-span'}>
{type} :
<NumberInput type={type}
onInvalidInput={(value) => this.handleInputChanges(invalidValidValueStateKey, value)}
onChange={(value) => this.handleInputChanges(validValueStateKey, value)}/>
</span>
</div>)
}
render () {
return (
<div className={'input-examples'}>
{this.getInput(this.state.positiveInteger, this.state.invalidPositiveInteger, 'invalidPositiveInteger', 'positiveInteger', 'positive-integer')}
{this.getInput(this.state.integer, this.state.invalidInteger, 'invalidInteger', 'integer', 'integer')}
{this.getInput(this.state.positiveFloat, this.state.invalidPositiveFloat, 'invalidPositiveFloat', 'positiveFloat', 'positive-float')}
{this.getInput(this.state.Float, this.state.invalidFloat, 'invalidFloat', 'float', 'float')}
</div>
)
}
}