import { noop } from 'lodash'; import { forwardRefWithAs, PropsWithAs } from '@reach/utils'; import { Ref } from 'react'; import { useTheme } from 'styled-components'; import { Box, BoxStylingProps } from './Box'; import { Text } from './Text'; import { ButtonLinkVariantName, TextVariantName } from './theme'; type ButtonLinkSize = 'large' | 'medium' | 'small'; export type NonSemanticButtonLinkProps = Pick & { /** We need to define the `disabled` prop as it's not an HTML attribute for an anchor tag */ disabled?: boolean; size?: ButtonLinkSize; textVariant?: TextVariantName | TextVariantName[]; variant?: ButtonLinkVariantName; }; export interface ButtonLinkProps extends PropsWithAs<'button', NonSemanticButtonLinkProps> {} const LINK_BUTTON_TEXT_SIZE_MAP: { [key in ButtonLinkSize]: TextVariantName } = { large: 'text-ui-16', medium: 'text-ui-14', small: 'text-ui-12', }; export const ButtonLink = forwardRefWithAs( ( { as = 'button', children, disabled = false, onClick, size = 'medium', textVariant, tx, variant = 'button-link-blue', ...restOfProps }: ButtonLinkProps, ref: Ref, ) => { const theme = useTheme(); const buttonProps = as === 'button' ? { disabled } : {}; return ( {children} ); }, );