// @flow strict import * as React from 'react'; import {classify} from '../../utils/classify'; import {CircularLoader} from '../CircularLoader'; import type {IconType} from '../Icon'; import {Icon} from '../Icon'; import {Truncate} from '../Truncate'; import css from './Button.module.css'; type ClassNames = $ReadOnly<{wrapper?: string, icon?: string}>; export const BUTTON_TYPES = Object.freeze({ primary: 'primary', secondary: 'secondary', tertiary: 'tertiary', ghost: 'ghost', danger: 'danger', }); export const BUTTON_ACTION_TYPE = Object.freeze({ button: 'button', submit: 'submit', reset: 'reset', }); export type ButtonType = $Values; export type ButtonActionType = $Values; export type BaseButtonProps = { children?: React.Node, disabled?: mixed, actionType?: ButtonActionType, onClick?: ?(SyntheticEvent) => mixed, ariaLabel?: string, tabIndex?: number, isLoading?: boolean, ... }; export type UnstyledButtonProps = { ...BaseButtonProps, className?: string, ... }; export type ButtonProps = { ...BaseButtonProps, classNames?: ClassNames, iconLeftName?: string, iconLeftType?: IconType, iconRightName?: string, iconRightType?: IconType, type?: ButtonType, isFluid?: boolean, size?: 'medium' | 'small', ... }; const ButtonTypeToIconColorMap = { primary: 'inversePrimary', secondary: 'clickable', tertiary: 'primary', ghost: 'primary', danger: 'inversePrimary', }; const ButtonTypeToLoaderColorMap = { primary: 'colorTextInversePrimary', secondary: 'colorTextClickable', tertiary: 'colorTextPrimary', ghost: 'colorTextPrimary', danger: 'colorTextInversePrimary', }; export const UnstyledButton: React$AbstractComponent< UnstyledButtonProps, HTMLButtonElement, > = React.forwardRef( ( { disabled, onClick, className, ariaLabel, actionType, tabIndex = 0, isLoading, ...props }: UnstyledButtonProps, ref, ) => (