2018-03-26 00:46:45 +05:30
|
|
|
// @flow
|
2018-05-05 12:13:43 +05:30
|
|
|
import type { Color, Skin } from 'components/ui';
|
|
|
|
import type { MessageDescriptor } from 'react-intl';
|
2018-03-26 00:46:45 +05:30
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { SKIN_DARK, COLOR_GREEN } from 'components/ui';
|
|
|
|
import { omit } from 'functions';
|
|
|
|
|
|
|
|
import styles from './form.scss';
|
|
|
|
import FormInputComponent from './FormInputComponent';
|
|
|
|
|
|
|
|
export default class Radio extends FormInputComponent<{
|
|
|
|
color: Color,
|
|
|
|
skin: Skin,
|
|
|
|
label: string | MessageDescriptor,
|
|
|
|
}> {
|
|
|
|
static defaultProps = {
|
|
|
|
color: COLOR_GREEN,
|
|
|
|
skin: SKIN_DARK,
|
|
|
|
};
|
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
elRef = React.createRef<HTMLInputElement>();
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
render() {
|
|
|
|
const { color, skin } = this.props;
|
|
|
|
let { label } = this.props;
|
|
|
|
|
|
|
|
label = this.formatMessage(label);
|
|
|
|
|
|
|
|
const props = omit(this.props, ['color', 'skin', 'label']);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames(styles[`${color}MarkableRow`], styles[`${skin}MarkableRow`])}>
|
|
|
|
<label className={styles.markableContainer}>
|
2019-06-30 19:02:50 +05:30
|
|
|
<input ref={this.elRef}
|
2018-03-26 00:46:45 +05:30
|
|
|
className={styles.markableInput}
|
|
|
|
type="radio"
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
<div className={styles.radio} />
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
{this.renderError()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
2019-06-30 19:02:50 +05:30
|
|
|
const { current: el } = this.elRef;
|
2018-05-05 14:31:25 +05:30
|
|
|
|
|
|
|
return el && el.checked ? 1 : 0;
|
2018-03-26 00:46:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
focus() {
|
2019-06-30 19:02:50 +05:30
|
|
|
const { current: el } = this.elRef;
|
2018-05-05 14:31:25 +05:30
|
|
|
|
|
|
|
el && el.focus();
|
2018-03-26 00:46:45 +05:30
|
|
|
}
|
|
|
|
}
|