UNPKG

@bigfishtv/cockpit

Version:

51 lines (45 loc) 1.21 kB
import PropTypes from 'prop-types' import React, { Component } from 'react' import classnames from 'classnames' let refCount = 0 export default class RadioGroup extends Component { static propTypes = { value: PropTypes.any, options: PropTypes.array, onChange: PropTypes.func, inline: PropTypes.bool, id: PropTypes.string, } static defaultProps = { options: [], onChange: () => {}, inline: false, disabled: false, readOnly: false, } constructor() { super() this._internalId = refCount++ } render() { return ( <div className={this.props.className}> {this.props.options.map((option, i) => ( <label key={option.value} className={classnames('control radio', { 'control-inline': this.props.inline })}> <input type="radio" name={this.props.id || `_radio-group-${this._internalId}_`} checked={this.props.value == option.value} onClick={() => this.props.onChange(option.value)} onChange={() => {}} disabled={this.props.disabled} readOnly={this.props.readOnly} /> <span className="control-indicator" /> <span className="control-label">{option.text}</span> </label> ))} </div> ) } }