import { ActionIcon as MantineActionIcon, Button as MantineButton, Stack as MantineStack, Text as MantineText, Tooltip as MantineTooltip, } from "@mantine/core"; import { assertEmpty, isSafari } from "@blocknote/core"; import { ComponentProps } from "@blocknote/react"; import { forwardRef } from "react"; export const TooltipContent = (props: { mainTooltip: string; secondaryTooltip?: string; }) => ( {props.mainTooltip} {props.secondaryTooltip && ( {props.secondaryTooltip} )} ); type ToolbarButtonProps = ComponentProps["FormattingToolbar"]["Button"] & ComponentProps["LinkToolbar"]["Button"]; /** * Helper for basic buttons that show in the formatting toolbar. */ export const ToolbarButton = forwardRef( (props, ref) => { const { className, children, mainTooltip, secondaryTooltip, icon, isSelected, isDisabled, onClick, label, ...rest } = props; // false, because rest props can be added by mantine when button is used as a trigger // assertEmpty in this case is only used at typescript level, not runtime level assertEmpty(rest, false); return ( }> {/*Creates an ActionIcon instead of a Button if only an icon is provided as content.*/} {children ? ( { if (isSafari()) { (e.currentTarget as HTMLButtonElement).focus(); } }} onClick={onClick} aria-pressed={isSelected} data-selected={isSelected || undefined} data-test={ mainTooltip.slice(0, 1).toLowerCase() + mainTooltip.replace(/\s+/g, "").slice(1) } size={"xs"} disabled={isDisabled || false} ref={ref} {...rest}> {children} ) : ( { if (isSafari()) { (e.currentTarget as HTMLButtonElement).focus(); } }} onClick={onClick} aria-pressed={isSelected} data-selected={isSelected || undefined} data-test={ mainTooltip.slice(0, 1).toLowerCase() + mainTooltip.replace(/\s+/g, "").slice(1) } size={30} disabled={isDisabled || false} ref={ref} {...rest}> {icon} )} ); } );