import React from "react"; import { CLASSPREFIX as eccgui } from "../../configuration/constants"; import Button, { ButtonProps } from "../Button/Button"; import { TestableComponent } from "../interfaces"; import { ValidIconName } from "./canonicalIconNames"; import Icon, { IconProps } from "./Icon"; import { TestIconProps } from "./TestIcon"; interface ExtendedButtonProps extends Omit, TestableComponent { /** * Canonical icon name, or an array of strings. * In case of the array the first valid icon name is used. */ name: ValidIconName | string[] | React.ReactElement; /** * Button text, will be displayed as tooltip. */ text?: string; /** * If `text` should be set as HTML `title` attribute instead of attaching it as tooltip. * If true then `tooltipProps` is ignored. */ tooltipAsTitle?: boolean; /** * Description for icon as accessibility fallback. * If not set then `text` is used. */ description?: string; /** * Button is displayed with minimal styles (no borders, no background color). */ minimal?: boolean; } export type IconButtonProps = ExtendedButtonProps; /** A button with an icon instead of text. */ export const IconButton = ({ className = "", name = "undefined", text, tooltipProps, description, tooltipAsTitle = false, minimal = true, ...restProps }: IconButtonProps) => { const defaultIconTooltipProps = { hoverOpenDelay: 1000, openOnTargetFocus: restProps.disabled || (restProps.tabIndex ?? 0) < 0 ? false : undefined, swapPlaceholderDelay: 10, }; const iconProps = { small: restProps.small || restProps["size"] === "small", large: restProps.large || restProps["size"] === "large", tooltipText: tooltipAsTitle ? undefined : text, tooltipProps: tooltipProps ? { ...defaultIconTooltipProps, ...tooltipProps, } : defaultIconTooltipProps, description: description ? description : text, }; return (