2023-05-04 19:33:31 +02:00
|
|
|
import clsx from "clsx";
|
|
|
|
import { composeEventHandlers } from "../utils";
|
2023-01-12 13:06:00 +01:00
|
|
|
import "./Button.scss";
|
|
|
|
|
|
|
|
interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
|
|
|
|
type?: "button" | "submit" | "reset";
|
|
|
|
onSelect: () => any;
|
2023-05-04 19:33:31 +02:00
|
|
|
/** whether button is in active state */
|
|
|
|
selected?: boolean;
|
2023-01-12 13:06:00 +01:00
|
|
|
children: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A generic button component that follows Excalidraw's design system.
|
|
|
|
* Style can be customised using `className` or `style` prop.
|
|
|
|
* Accepts all props that a regular `button` element accepts.
|
|
|
|
*/
|
|
|
|
export const Button = ({
|
|
|
|
type = "button",
|
|
|
|
onSelect,
|
2023-05-04 19:33:31 +02:00
|
|
|
selected,
|
2023-01-12 13:06:00 +01:00
|
|
|
children,
|
|
|
|
className = "",
|
|
|
|
...rest
|
|
|
|
}: ButtonProps) => {
|
|
|
|
return (
|
|
|
|
<button
|
2023-05-04 19:33:31 +02:00
|
|
|
onClick={composeEventHandlers(rest.onClick, (event) => {
|
2023-01-12 13:06:00 +01:00
|
|
|
onSelect();
|
2023-05-04 19:33:31 +02:00
|
|
|
})}
|
2023-01-12 13:06:00 +01:00
|
|
|
type={type}
|
2023-05-04 19:33:31 +02:00
|
|
|
className={clsx("excalidraw-button", className, { selected })}
|
2023-01-12 13:06:00 +01:00
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
};
|