1 | import React, {PureComponent} from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import classNames from 'classnames';
|
4 | import checkmarkIcon from '@jetbrains/icons/checkmark.svg';
|
5 |
|
6 | import Icon from '../icon/icon';
|
7 |
|
8 | import styles from './checkbox.css';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export default class Checkbox extends PureComponent {
|
14 |
|
15 | static propTypes = {
|
16 | name: PropTypes.string,
|
17 | label: PropTypes.string,
|
18 | className: PropTypes.string,
|
19 | defaultChecked: PropTypes.bool,
|
20 | checked: PropTypes.bool,
|
21 | disabled: PropTypes.bool,
|
22 | onChange: PropTypes.func,
|
23 | children: PropTypes.node
|
24 | };
|
25 |
|
26 | inputRef = el => {
|
27 | this.input = el;
|
28 | };
|
29 |
|
30 | render() {
|
31 | const {children, label, ...restProps} = this.props;
|
32 |
|
33 | const classes = classNames(
|
34 | styles.input,
|
35 | this.props.className
|
36 | );
|
37 |
|
38 | return (
|
39 | <label
|
40 | className={styles.checkbox}
|
41 | data-test="ring-checkbox"
|
42 | >
|
43 | <input
|
44 | {...restProps}
|
45 | ref={this.inputRef}
|
46 | type="checkbox"
|
47 | className={classes}
|
48 | />
|
49 | <span className={styles.cell}>
|
50 | <Icon
|
51 | glyph={checkmarkIcon}
|
52 | className={styles.icon}
|
53 | />
|
54 | </span>
|
55 | <span className={styles.label}>{label || children}</span>
|
56 | </label>
|
57 | );
|
58 | }
|
59 | }
|