-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathCheckbox.component.tsx
34 lines (31 loc) · 998 Bytes
/
Checkbox.component.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
import { ChangeEvent } from 'react';
interface ICheckboxProps {
id: string;
label: string;
checked: boolean;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
}
/**
* A reusable checkbox component with a label
* @function Checkbox
* @param {string} id - Unique identifier for the checkbox
* @param {string} label - Label text to display next to the checkbox
* @param {boolean} checked - Whether the checkbox is checked
* @param {function} onChange - Handler for when the checkbox state changes
* @returns {JSX.Element} - Rendered component
*/
const Checkbox = ({ id, label, checked, onChange }: ICheckboxProps) => {
return (
<label htmlFor={id} className="flex items-center py-2 cursor-pointer">
<input
id={id}
type="checkbox"
className="form-checkbox h-5 w-5 cursor-pointer"
checked={checked}
onChange={onChange}
/>
<span className="ml-3 text-base">{label}</span>
</label>
);
};
export default Checkbox;