about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components/radio_button.jsx
blob: 0496fa2868ac7bfdfa294206cda3572362f163e8 (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
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

export default class RadioButton extends React.PureComponent {

  static propTypes = {
    value: PropTypes.string.isRequired,
    checked: PropTypes.bool,
    name: PropTypes.string.isRequired,
    onChange: PropTypes.func.isRequired,
    label: PropTypes.node.isRequired,
  };

  render () {
    const { name, value, checked, onChange, label } = this.props;

    return (
      <label className='radio-button'>
        <input
          name={name}
          type='radio'
          value={value}
          checked={checked}
          onChange={onChange}
        />

        <span className={classNames('radio-button__input', { checked })} />

        <span>{label}</span>
      </label>
    );
  }

}