/
Checkbox.tsx
36 lines (33 loc) · 915 Bytes
/
Checkbox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ReactElement, CSSProperties, ChangeEvent } from 'react';
export interface CheckboxProps {
checked: boolean;
indeterminate?: boolean;
className?: string;
style?: CSSProperties;
disabled?: boolean;
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
}
const Checkbox = ({ checked, indeterminate = false, className = '', style = {}, disabled = false, onChange }: CheckboxProps): ReactElement => {
return (
<input
type="checkbox"
className={className}
style={style}
ref={input => {
/* istanbul ignore else */
if (input) {
input.checked = checked;
input.indeterminate = indeterminate as boolean;
input.disabled = disabled as boolean;
}
}}
onChange={e => {
/* istanbul ignore else */
if (onChange) {
onChange(e);
}
}}
/>
);
};
export default Checkbox;