From 58cda9cc7fb79ca9df6746de7f9662bc08dc156a Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 13 Oct 2017 12:29:40 +0200 Subject: initial commit --- src/components/ui/Radio.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/components/ui/Radio.js (limited to 'src/components/ui/Radio.js') diff --git a/src/components/ui/Radio.js b/src/components/ui/Radio.js new file mode 100644 index 000000000..b54cfc820 --- /dev/null +++ b/src/components/ui/Radio.js @@ -0,0 +1,89 @@ +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 Radio extends Component { + static propTypes = { + field: PropTypes.instanceOf(Field).isRequired, + className: PropTypes.string, + focus: PropTypes.bool, + showLabel: PropTypes.bool, + }; + + static defaultProps = { + className: null, + focus: false, + showLabel: true, + }; + + componentDidMount() { + if (this.props.focus) { + this.focus(); + } + } + + focus() { + this.inputElement.focus(); + } + + inputElement = null; + + render() { + const { + field, + className, + showLabel, + } = this.props; + + return ( +
+ {field.label && showLabel && ( + + )} +
+ {field.options.map(type => ( + + ))} +
+ {field.error && ( +
+ {field.error} +
+ )} +
+ ); + } +} -- cgit v1.2.3-70-g09d2