2017-08-23 00:19:50 +05:30
|
|
|
import React from 'react';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { MessageDescriptor } from 'react-intl';
|
2019-12-08 01:13:08 +05:30
|
|
|
import clsx from 'clsx';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { SKIN_DARK, COLOR_GREEN, Color, Skin } from 'app/components/ui';
|
|
|
|
import { omit } from 'app/functions';
|
2016-05-30 10:10:59 +05:30
|
|
|
|
2016-05-02 12:45:42 +05:30
|
|
|
import styles from './form.scss';
|
2016-05-02 14:50:50 +05:30
|
|
|
import FormInputComponent from './FormInputComponent';
|
2016-05-02 12:45:42 +05:30
|
|
|
|
2019-12-08 03:23:22 +05:30
|
|
|
export default class Checkbox extends FormInputComponent<
|
|
|
|
React.InputHTMLAttributes<HTMLInputElement> & {
|
|
|
|
color: Color;
|
|
|
|
skin: Skin;
|
|
|
|
label: string | MessageDescriptor | React.ReactElement;
|
|
|
|
}
|
|
|
|
> {
|
2019-11-27 14:33:32 +05:30
|
|
|
static defaultProps = {
|
|
|
|
color: COLOR_GREEN,
|
|
|
|
skin: SKIN_DARK,
|
|
|
|
};
|
|
|
|
|
|
|
|
elRef = React.createRef<HTMLInputElement>();
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { color, skin } = this.props;
|
|
|
|
let { label } = this.props;
|
|
|
|
|
2019-12-08 03:23:22 +05:30
|
|
|
label = React.isValidElement(label) ? label : this.formatMessage(label);
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
const props = omit(this.props, ['color', 'skin', 'label']);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2019-12-08 01:13:08 +05:30
|
|
|
className={clsx(
|
2019-11-27 14:33:32 +05:30
|
|
|
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 12:45:42 +05:30
|
|
|
}
|