summaryrefslogtreecommitdiff
path: root/app/client/common/textInput.component.js
blob: 1e2ca01d37886cc1116d6e46dc64e9178d777fb2 (plain)
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
import { h, Component } from 'preact'

class TextInput extends Component {
  constructor(props){
    super(props)
    this.handleInput = this.handleInput.bind(this)
    this.handleKeydown = this.handleKeydown.bind(this)
  }
  handleInput(e){
    this.props.onInput && this.props.onInput(e.target.value)
  }
  handleKeydown(e){
    if (e.keyCode === 13) {
      this.props.onSave && this.props.onSave(e.target.value)
    }
  }
  render() {
    return (
      <div className='textInput param'>
        <label>
          <span>{this.props.title}</span>
          <input
            type='text'
            value={this.props.value}
            onInput={this.handleInput}
            onKeydown={this.handleKeydown}
            placeholder={this.props.placeholder}
            autofocus={this.props.autofocus}
          />
        </label>
      </div>
    )
  }
}

export default TextInput