aboutsummaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/components/ButtonIcon.tsx
blob: cbbd73df934c54fda1bd8455cff39f2cb72406f5 (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
37
import { forwardRef } from "react";
import type { JSX } from "react";
import clsx from "clsx";

import "./ButtonIcon.scss";

interface ButtonIconProps {
  icon: JSX.Element;
  title: string;
  className?: string;
  testId?: string;
  /** if not supplied, defaults to value identity check */
  active?: boolean;
  /** include standalone style (could interfere with parent styles) */
  standalone?: boolean;
  onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
}

export const ButtonIcon = forwardRef<HTMLButtonElement, ButtonIconProps>(
  (props, ref) => {
    const { title, className, testId, active, standalone, icon, onClick } =
      props;
    return (
      <button
        type="button"
        ref={ref}
        key={title}
        title={title}
        data-testid={testId}
        className={clsx(className, { standalone, active })}
        onClick={onClick}
      >
        {icon}
      </button>
    );
  },
);