diff options
Diffstat (limited to 'app/client/common')
| -rw-r--r-- | app/client/common/index.js | 4 | ||||
| -rw-r--r-- | app/client/common/numberInput.component.js | 49 | ||||
| -rw-r--r-- | app/client/common/textInput.component.js | 7 |
3 files changed, 56 insertions, 4 deletions
diff --git a/app/client/common/index.js b/app/client/common/index.js index 025b56c..eeb8bfc 100644 --- a/app/client/common/index.js +++ b/app/client/common/index.js @@ -8,6 +8,7 @@ import Gallery from './gallery.component' import Group from './group.component' import Header from './header.component' import Loading from './loading.component' +import NumberInput from './numberInput.component' import Param from './param.component' import ParamGroup from './paramGroup.component' import Player from './player.component' @@ -24,6 +25,7 @@ export { FolderList, FileList, FileRow, FileUpload, Gallery, Player, Group, ParamGroup, Param, - TextInput, Slider, Select, SelectGroup, Button, Checkbox, + TextInput, NumberInput, + Slider, Select, SelectGroup, Button, Checkbox, CurrentTask, }
\ No newline at end of file diff --git a/app/client/common/numberInput.component.js b/app/client/common/numberInput.component.js new file mode 100644 index 0000000..c3ad24c --- /dev/null +++ b/app/client/common/numberInput.component.js @@ -0,0 +1,49 @@ +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) + } + 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 diff --git a/app/client/common/textInput.component.js b/app/client/common/textInput.component.js index a3739d4..44e1349 100644 --- a/app/client/common/textInput.component.js +++ b/app/client/common/textInput.component.js @@ -12,7 +12,7 @@ class TextInput extends Component { value: e.target.value, changed: true, }) - this.props.onInput && this.props.onInput(e.target.value) + this.props.onInput && this.props.onInput(e.target.value, e.target.name) } handleKeydown(e){ if (e.keyCode === 13) { @@ -20,7 +20,7 @@ class TextInput extends Component { value: e.target.value, changed: false, }) - this.props.onSave && this.props.onSave(e.target.value) + this.props.onSave && this.props.onSave(e.target.value, e.target.name) } } render() { @@ -29,7 +29,8 @@ class TextInput extends Component { <label> <span>{this.props.title}</span> <input - type='text' + type={this.props.type || 'text'} + name={this.props.name || 'text'} value={this.state.changed ? this.state.value : this.props.value} onInput={this.handleInput} onKeydown={this.handleKeydown} |
