2024-03-15 17:36:41 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2024-08-09 14:56:39 +00:00
|
|
|
import CheckIndeterminateSmallIcon from '@/material-icons/400-24px/check_indeterminate_small.svg?react';
|
2024-03-15 17:36:41 +00:00
|
|
|
import DoneIcon from '@/material-icons/400-24px/done.svg?react';
|
|
|
|
|
|
|
|
import { Icon } from './icon';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
value: string;
|
|
|
|
checked: boolean;
|
2024-08-09 14:56:39 +00:00
|
|
|
indeterminate: boolean;
|
2024-03-15 17:36:41 +00:00
|
|
|
name: string;
|
|
|
|
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
|
|
label: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const CheckBox: React.FC<Props> = ({
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
checked,
|
2024-08-09 14:56:39 +00:00
|
|
|
indeterminate,
|
2024-03-15 17:36:41 +00:00
|
|
|
onChange,
|
|
|
|
label,
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<label className='check-box'>
|
|
|
|
<input
|
|
|
|
name={name}
|
|
|
|
type='checkbox'
|
|
|
|
value={value}
|
|
|
|
checked={checked}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
|
2024-08-09 14:56:39 +00:00
|
|
|
<span
|
|
|
|
className={classNames('check-box__input', { checked, indeterminate })}
|
|
|
|
>
|
|
|
|
{indeterminate ? (
|
|
|
|
<Icon id='indeterminate' icon={CheckIndeterminateSmallIcon} />
|
|
|
|
) : (
|
|
|
|
checked && <Icon id='check' icon={DoneIcon} />
|
|
|
|
)}
|
2024-03-15 17:36:41 +00:00
|
|
|
</span>
|
|
|
|
|
|
|
|
<span>{label}</span>
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
};
|