aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/form/KeymapsForm.jsx
blob: 01acf61c9bf88720d8892606d32068b762e8913c (plain) (blame)
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 './KeymapsForm.scss';
import React from 'react';
import PropTypes from 'prop-types';
import Input from '../ui/Input';
import keymaps from '../../keymaps';

class KeymapsForm extends React.Component {

  render() {
    return <div className='form-keymaps-form'>
      {
        keymaps.fields.map((group, index) => {
          return <div key={index} className='form-keymaps-form-field-group'>
            {
              group.map((field) => {
                let name = field[0];
                let label = field[1];
                let value = this.props.value[name] || '';
                return <Input
                  type='text' id={name} name={name} key={name}
                  label={label} value={value}
                  onChange={this.bindValue.bind(this)}
                  onBlur={this.props.onBlur}
                />;
              })
            }
          </div>;
        })
      }
    </div>;
  }

  bindValue(e) {
    let next = { ...this.props.value };
    next[e.target.name] = e.target.value;

    this.props.onChange(next);
  }
}

KeymapsForm.propTypes = {
  value: PropTypes.objectOf(PropTypes.string),
  onChange: PropTypes.func,
};

KeymapsForm.defaultProps = {
  value: {},
  onChange: () => {},
};

export default KeymapsForm;