import { forwardRef, isValidElement } from "react"; import { StyledIconButton } from "./icon-button.styled"; import type { IconProps } from "../icons/withSharedIconProps"; import type { ColorKey } from "../../theme"; import type { WithTestId } from "../../types"; interface IconButtonProps extends WithTestId> { /** * Icon to display */ Icon: React.FC | React.ReactElement; } /** * Icon button component */ export const IconButton = forwardRef((props, ref) => { const { Icon, variant = "primary", type, ...rest } = props; const darkColor = variant === "primary" || variant === "ghost-dark"; const iconColor: ColorKey = darkColor ? "$light-chromia-dark" : "$light-off-white"; return ( {/* @ts-expect-error ts unable to correctly type narrow else branch */} {isValidElement(Icon) ? Icon : } ); }); IconButton.displayName = "IconButton";