You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1013 B
TypeScript
44 lines
1013 B
TypeScript
2 years ago
|
import clsx from "clsx";
|
||
|
import { composeEventHandlers } from "../utils";
|
||
2 years ago
|
import "./Button.scss";
|
||
|
|
||
1 year ago
|
interface ButtonProps
|
||
|
extends React.DetailedHTMLProps<
|
||
|
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||
|
HTMLButtonElement
|
||
|
> {
|
||
2 years ago
|
type?: "button" | "submit" | "reset";
|
||
|
onSelect: () => any;
|
||
2 years ago
|
/** whether button is in active state */
|
||
|
selected?: boolean;
|
||
2 years ago
|
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,
|
||
2 years ago
|
selected,
|
||
2 years ago
|
children,
|
||
|
className = "",
|
||
|
...rest
|
||
|
}: ButtonProps) => {
|
||
|
return (
|
||
|
<button
|
||
2 years ago
|
onClick={composeEventHandlers(rest.onClick, (event) => {
|
||
2 years ago
|
onSelect();
|
||
2 years ago
|
})}
|
||
2 years ago
|
type={type}
|
||
2 years ago
|
className={clsx("excalidraw-button", className, { selected })}
|
||
2 years ago
|
{...rest}
|
||
|
>
|
||
|
{children}
|
||
|
</button>
|
||
|
);
|
||
|
};
|