-
Notifications
You must be signed in to change notification settings - Fork 3
/
Checkbox.jsx
85 lines (81 loc) · 1.67 KB
/
Checkbox.jsx
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as React from "react";
import {
FormControlLabel,
FormGroup,
Checkbox as MuiCheckbox
} from "@mui/material";
import PropTypes from "prop-types";
/**
* Checkbox component
*/
export default function Checkbox({
checked,
defaultChecked,
disabled = false,
label = "",
name,
onChange = () => {},
size = "medium",
style = {}
}) {
// return components
return (
<FormGroup>
<FormControlLabel
control={
<MuiCheckbox
sx={{ ...style, pointerEvents: "auto" }}
checked={checked}
defaultChecked={defaultChecked}
disabled={disabled}
name={name}
onChange={onChange}
size={size}
/>
}
label={label}
sx={{ pointerEvents: "none" }}
/>
</FormGroup>
);
}
Checkbox.propTypes = {
/*
* If true, the component is checked.
*/
checked: PropTypes.bool,
/**
* The default value of the input.
*/
defaultChecked: PropTypes.bool,
/**
* If true, the component is disabled.
*/
disabled: PropTypes.bool,
/**
* Text to be used alongside checkbox.
*/
label: PropTypes.string,
/**
* The name of the input.
*/
name: PropTypes.string,
/**
* Callback fired when the state is changed.
*
* **Signature**
* ```
* function(event: object) => void
* ```
* _event_: The event source of the callback. You can pull out the new checked state by accessing event.target.checked (boolean).
*/
onChange: PropTypes.func,
/**
* The size of the component.
*/
size: PropTypes.oneOf(["small", "medium"]),
/*
* Custom style to apply to the checkbox.
*/
style: PropTypes.object
};