import React from 'react'; import classnames from 'classnames'; import { IconName, Icon, IconSize, Text } from '..'; import { AlignItems, Display, JustifyContent, TextColor, TextVariant, BorderRadius, BackgroundColor, IconColor, } from '../../../helpers/constants/design-system'; import type { PolymorphicRef } from '../box'; import type { TextProps } from '../text'; import { ButtonBaseProps, ButtonBaseSize, ButtonBaseComponent, } from './button-base.types'; export const ButtonBase: ButtonBaseComponent = React.forwardRef( ( { as, block, children, className = '', href, ellipsis = false, externalLink, size = ButtonBaseSize.Md, startIconName, startIconProps, endIconName, endIconProps, loading, disabled, iconLoadingProps, textProps, color = TextColor.textDefault, iconColor = IconColor.iconDefault, ...props }: ButtonBaseProps, ref?: PolymorphicRef, ) => { const tag = href ? 'a' : as || 'button'; const tagProps = href && tag === 'a' ? { href, ...props } : props; return ( )} > {startIconName && ( )} {/* * If children is a string and doesn't need truncation or loading * prevent html bloat by rendering just the string * otherwise render with wrapper to allow truncation or loading */} {typeof children === 'string' && !ellipsis && !loading ? ( children ) : ( {children} )} {endIconName && ( )} {loading && ( )} ); }, );