2020-08-15 10:17:15 +02:00
|
|
|
import React, { useRef } from 'react';
|
2021-02-16 12:04:00 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2020-08-15 10:17:15 +02:00
|
|
|
import Icon from 'components/common/Icon';
|
|
|
|
import Check from 'assets/check.svg';
|
|
|
|
import styles from './Checkbox.module.css';
|
|
|
|
|
2021-02-16 12:04:00 +01:00
|
|
|
function Checkbox({ name, value, label, onChange }) {
|
2020-08-15 10:17:15 +02:00
|
|
|
const ref = useRef();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.container}>
|
|
|
|
<div className={styles.checkbox} onClick={() => ref.current.click()}>
|
|
|
|
{value && <Icon icon={<Check />} size="small" />}
|
|
|
|
</div>
|
|
|
|
<label className={styles.label} htmlFor={name}>
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={ref}
|
|
|
|
className={styles.input}
|
|
|
|
type="checkbox"
|
|
|
|
name={name}
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-02-16 12:04:00 +01:00
|
|
|
|
|
|
|
Checkbox.propTypes = {
|
|
|
|
name: PropTypes.string,
|
|
|
|
value: PropTypes.any,
|
|
|
|
label: PropTypes.node,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Checkbox;
|