/
Radio.jsx
45 lines (39 loc) · 1.15 KB
/
Radio.jsx
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
import React from 'react'
import PropTypes from 'prop-types'
import { createField, fieldPresets } from 'react-advanced-form'
class Radio extends React.Component {
static propTypes = {
/* General */
id: PropTypes.string,
className: PropTypes.string,
label: PropTypes.string,
/* Inherited */
fieldProps: PropTypes.object.isRequired,
fieldState: PropTypes.object.isRequired,
}
render() {
const { fieldProps, fieldState, id, className, label } = this.props
const { touched, pristine, valid, invalid } = fieldState
const inputClassNames = [
'custom-control-input',
touched && 'is-touched',
pristine && 'is-pristine',
valid && 'is-valid',
invalid && 'is-invalid',
className,
]
.filter(Boolean)
.join(' ')
return (
<div className="form-group">
<div className="custom-control custom-radio">
<input id={id} className={inputClassNames} {...fieldProps} />
<label className="custom-control-label" htmlFor={id}>
{label}
</label>
</div>
</div>
)
}
}
export default createField(fieldPresets.radio)(Radio)