summaryrefslogtreecommitdiffstats
path: root/src/components/atoms/forms/checkbox.tsx
blob: aec97f00d71293be38fda4f463c3e05c38828565 (plain)
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
import { FC, SetStateAction } from 'react';

export type CheckboxProps = {
  /**
   * One or more ids that refers to the checkbox name.
   */
  'aria-labelledby'?: string;
  /**
   * Add classnames to the checkbox.
   */
  className?: string;
  /**
   * Checkbox id attribute.
   */
  id: string;
  /**
   * Checkbox name attribute.
   */
  name: string;
  /**
   * Callback function to set checkbox value.
   */
  setValue: (value: SetStateAction<boolean>) => void;
  /**
   * Checkbox value.
   */
  value: boolean;
};

/**
 * Checkbox component
 *
 * Render a checkbox type input.
 */
const Checkbox: FC<CheckboxProps> = ({ value, setValue, ...props }) => {
  return (
    <input
      type="checkbox"
      checked={value}
      onChange={() => setValue(!value)}
      {...props}
    />
  );
};

export default Checkbox;