summaryrefslogtreecommitdiff
path: root/app/client/common/numberInput.component.js
diff options
context:
space:
mode:
authorjules@lens <julescarbon@gmail.com>2018-09-05 12:00:28 +0200
committerjules@lens <julescarbon@gmail.com>2018-09-05 12:00:28 +0200
commit9abfa16dc059d042c21f1636ecc8797ef29a030d (patch)
treed0583cb5dae01de1abc57ed8f7587d23242ed6f0 /app/client/common/numberInput.component.js
parent0a3c6743543dd3dfcb876f5ce735b72d050e981d (diff)
parent15eb6806b6e216255f33abcb885f6cdbc38a7663 (diff)
Merge branch 'master' of asdf.us:live-cortex
Diffstat (limited to 'app/client/common/numberInput.component.js')
-rw-r--r--app/client/common/numberInput.component.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/client/common/numberInput.component.js b/app/client/common/numberInput.component.js
new file mode 100644
index 0000000..43f9878
--- /dev/null
+++ b/app/client/common/numberInput.component.js
@@ -0,0 +1,50 @@
+import { h, Component } from 'preact'
+
+class NumberInput extends Component {
+ constructor(props){
+ super(props)
+ this.state = { value: null, changed: false }
+ this.handleInput = this.handleInput.bind(this)
+ this.handleKeydown = this.handleKeydown.bind(this)
+ }
+ handleInput(e){
+ this.setState({
+ value: e.target.value,
+ changed: true,
+ })
+ this.props.onInput && this.props.onInput(e.target.value, e.target.name)
+ this.props.onChange && this.props.onInput(e.target.name, e.target.value)
+ }
+ handleKeydown(e){
+ if (e.keyCode === 13) {
+ this.setState({
+ value: e.target.value,
+ changed: false,
+ })
+ this.props.onSave && this.props.onSave(e.target.value, e.target.name)
+ }
+ }
+ render() {
+ return (
+ <div className='numberInput param'>
+ <label>
+ <span>{this.props.title}</span>
+ <input
+ type={'number'}
+ name={this.props.name || 'number'}
+ value={this.state.changed ? this.state.value : this.props.value}
+ onInput={this.handleInput}
+ onKeydown={this.handleKeydown}
+ placeholder={this.props.placeholder}
+ autofocus={this.props.autofocus}
+ min={this.props.min}
+ max={this.props.max}
+ step={this.props.step || this.props.type === 'int' ? 1 : 0.01}
+ />
+ </label>
+ </div>
+ )
+ }
+}
+
+export default NumberInput