import { forwardRef, MouseEventHandler, useCallback, useState } from 'react'; import { clsx } from 'clsx'; import { Tooltip, UnStyledButton } from '../ui'; import './button.css'; type ToolbarButtonProps = { label: string; }; export const ToolbarButton = forwardRef< HTMLButtonElement, ToolbarButtonProps & JSX.IntrinsicElements['button'] >(({ label, onClick, ...props }, ref) => { const [error, setError] = useState(null); const handleClick: MouseEventHandler = useCallback( event => { try { onClick?.(event); setError(null); } catch (err) { setError( err instanceof Error ? err : new Error(`Toolbar button click failed: ${err}`), ); } }, [onClick], ); return ( ); }); ToolbarButton.displayName = 'ToolbarButton';