2018-03-25 22:16:45 +03:00
|
|
|
import React from 'react';
|
2019-12-07 13:28:52 +02:00
|
|
|
import { MessageDescriptor } from 'react-intl';
|
2019-12-07 21:43:08 +02:00
|
|
|
import clsx from 'clsx';
|
2019-12-07 21:02:00 +02:00
|
|
|
import { SKIN_DARK, COLOR_GREEN } from 'app/components/ui';
|
|
|
|
import { omit } from 'app/functions';
|
|
|
|
import { Color, Skin } from 'app/components/ui';
|
2018-03-25 22:16:45 +03:00
|
|
|
|
|
|
|
import styles from './form.scss';
|
|
|
|
import FormInputComponent from './FormInputComponent';
|
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
export default class Radio extends FormInputComponent<
|
2020-05-24 02:08:24 +03:00
|
|
|
{
|
|
|
|
color: Color;
|
|
|
|
skin: Skin;
|
|
|
|
label: string | MessageDescriptor;
|
|
|
|
} & React.InputHTMLAttributes<HTMLInputElement>
|
2019-12-07 13:28:52 +02:00
|
|
|
> {
|
2020-05-24 02:08:24 +03:00
|
|
|
static defaultProps = {
|
|
|
|
color: COLOR_GREEN,
|
|
|
|
skin: SKIN_DARK,
|
|
|
|
};
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
elRef = React.createRef<HTMLInputElement>();
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
render() {
|
|
|
|
const { color, skin } = this.props;
|
|
|
|
let { label } = this.props;
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
label = this.formatMessage(label);
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
const props = omit(this.props, ['color', 'skin', 'label']);
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
|
|
|
<div className={clsx(styles[`${color}MarkableRow`], styles[`${skin}MarkableRow`])}>
|
|
|
|
<label className={styles.markableContainer}>
|
|
|
|
<input ref={this.elRef} className={styles.markableInput} type="radio" {...props} />
|
|
|
|
<div className={styles.radio} />
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
{this.renderError()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
getValue() {
|
|
|
|
const { current: el } = this.elRef;
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
return el && el.checked ? 1 : 0;
|
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
focus() {
|
|
|
|
const { current: el } = this.elRef;
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
el && el.focus();
|
|
|
|
}
|
2018-03-25 22:16:45 +03:00
|
|
|
}
|