2017-08-22 21:49:50 +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, Color, Skin } from 'app/components/ui';
|
|
|
|
import { omit } from 'app/functions';
|
2016-05-30 07:40:59 +03:00
|
|
|
|
2016-05-02 10:15:42 +03:00
|
|
|
import styles from './form.scss';
|
2016-05-02 12:20:50 +03:00
|
|
|
import FormInputComponent from './FormInputComponent';
|
2016-05-02 10:15:42 +03:00
|
|
|
|
2019-12-07 23:53:22 +02:00
|
|
|
export default class Checkbox extends FormInputComponent<
|
|
|
|
React.InputHTMLAttributes<HTMLInputElement> & {
|
|
|
|
color: Color;
|
|
|
|
skin: Skin;
|
|
|
|
label: string | MessageDescriptor | React.ReactElement;
|
|
|
|
}
|
|
|
|
> {
|
2019-11-27 11:03:32 +02:00
|
|
|
static defaultProps = {
|
|
|
|
color: COLOR_GREEN,
|
|
|
|
skin: SKIN_DARK,
|
|
|
|
};
|
|
|
|
|
|
|
|
elRef = React.createRef<HTMLInputElement>();
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { color, skin } = this.props;
|
|
|
|
let { label } = this.props;
|
|
|
|
|
2019-12-07 23:53:22 +02:00
|
|
|
label = React.isValidElement(label) ? label : this.formatMessage(label);
|
2019-11-27 11:03:32 +02:00
|
|
|
|
|
|
|
const props = omit(this.props, ['color', 'skin', 'label']);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2019-12-07 21:43:08 +02:00
|
|
|
className={clsx(
|
2019-11-27 11:03:32 +02:00
|
|
|
styles[`${color}MarkableRow`],
|
|
|
|
styles[`${skin}MarkableRow`],
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<label className={styles.markableContainer}>
|
|
|
|
<input
|
|
|
|
ref={this.elRef}
|
|
|
|
className={styles.markableInput}
|
|
|
|
type="checkbox"
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
<div className={styles.checkbox} />
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
{this.renderError()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
const { current: el } = this.elRef;
|
|
|
|
|
|
|
|
return el && el.checked ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
const { current: el } = this.elRef;
|
|
|
|
|
|
|
|
el && el.focus();
|
|
|
|
}
|
2016-05-02 10:15:42 +03:00
|
|
|
}
|