aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/Select.js
blob: 2a877af3e3ec2bc6e9cc94fdaed920575cc33741 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { Field } from 'mobx-react-form';
import classnames from 'classnames';

@observer
export default class Select extends Component {
  static propTypes = {
    field: PropTypes.instanceOf(Field).isRequired,
    className: PropTypes.string,
    showLabel: PropTypes.bool,
  };

  static defaultProps = {
    className: null,
    focus: false,
    showLabel: true,
  };

  render() {
    const {
      field,
      className,
      showLabel,
    } = this.props;

    return (
      <div
        className={classnames({
          'franz-form__field': true,
          'has-error': field.error,
          [`${className}`]: className,
        })}
      >
        {field.label && showLabel && (
          <label
            className="franz-form__label"
            htmlFor={field.name}
          >
            {field.label}
          </label>
        )}
        <select
          onChange={field.onChange}
          id={field.id}
          defaultValue={field.value}
          className="franz-form__select"
        >
          {field.options.map(type => (
            <option
              key={type.value}
              value={type.value}
              // selected={field.value === }
            >
              {type.label}
            </option>
          ))}
        </select>
        {field.error && (
          <div
            className="franz-form__error"
          >
            {field.error}
          </div>
        )}
      </div>
    );
  }
}