summaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/components/CheckboxItem.tsx
blob: 21c5cfafd28a93b062d7ab542e3633b85633f9a1 (plain) (blame)
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 React from "react";
import clsx from "clsx";
import { checkIcon } from "./icons";

import "./CheckboxItem.scss";

export const CheckboxItem: React.FC<{
  checked: boolean;
  onChange: (checked: boolean, event: React.MouseEvent) => void;
  className?: string;
  children?: React.ReactNode;
}> = ({ children, checked, onChange, className }) => {
  return (
    <div
      className={clsx("Checkbox", className, { "is-checked": checked })}
      onClick={(event) => {
        onChange(!checked, event);
        (
          (event.currentTarget as HTMLDivElement).querySelector(
            ".Checkbox-box",
          ) as HTMLButtonElement
        ).focus();
      }}
    >
      <button
        type="button"
        className="Checkbox-box"
        role="checkbox"
        aria-checked={checked}
      >
        {checkIcon}
      </button>
      <div className="Checkbox-label">{children}</div>
    </div>
  );
};