import "./ToolIcon.scss"; import React from "react"; import clsx from "clsx"; import { useExcalidrawContainer } from "./App"; type ToolIconSize = "s" | "m"; type ToolButtonBaseProps = { icon?: React.ReactNode; "aria-label": string; "aria-keyshortcuts"?: string; "data-testid"?: string; label?: string; title?: string; name?: string; id?: string; size?: ToolIconSize; keyBindingLabel?: string; showAriaLabel?: boolean; hidden?: boolean; visible?: boolean; selected?: boolean; className?: string; }; type ToolButtonProps = | (ToolButtonBaseProps & { type: "button"; children?: React.ReactNode; onClick?(): void; }) | (ToolButtonBaseProps & { type: "icon"; children?: React.ReactNode; onClick?(): void; }) | (ToolButtonBaseProps & { type: "radio"; checked: boolean; onChange?(): void; }); const DEFAULT_SIZE: ToolIconSize = "m"; export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => { const { id: excalId } = useExcalidrawContainer(); const innerRef = React.useRef(null); React.useImperativeHandle(ref, () => innerRef.current); const sizeCn = `ToolIcon_size_${props.size || DEFAULT_SIZE}`; if (props.type === "button" || props.type === "icon") { return ( {(props.icon || props.label) && ( {props.icon || props.label} {props.keyBindingLabel && ( {props.keyBindingLabel} )} )} {props.showAriaLabel && ( {props["aria-label"]} )} {props.children} ); } return ( {props.icon} {props.keyBindingLabel && ( {props.keyBindingLabel} )} ); }); ToolButton.defaultProps = { visible: true, className: "", };