import * as React from 'react'; import * as ButtonBase from '@tesseract-design/web-base-button'; type LinkButtonElement = HTMLAnchorElement | HTMLSpanElement; export type LinkButtonProps = Omit, 'size' | 'style'> & { /** * Size of the component. */ size?: ButtonBase.ButtonSize, /** * Variant of the component. */ variant?: ButtonBase.ButtonVariant, /** * Should the component display a border? */ border?: boolean, /** * Should the component occupy the whole width of its parent? */ block?: boolean, /** * Does the component need to conserve space? */ compact?: boolean, /** * Complementary content of the component. */ subtext?: React.ReactNode, /** * Short complementary content displayed at the edge of the component. */ badge?: React.ReactNode, /** * Is this component part of a menu? */ menuItem?: boolean, }; /** * Component for performing an action upon activation (e.g. when clicked). * * This component functions as a hyperlink. */ export const LinkButton = React.forwardRef( ( { size = ButtonBase.ButtonSize.MEDIUM, variant = ButtonBase.ButtonVariant.OUTLINE, border = false, children, block = false, disabled = false, onClick, href, target, rel, compact = false, subtext, badge, menuItem = false, className: _className, as: _as, ...etcProps }: LinkButtonProps, ref, ) => { const styleProps = React.useMemo(() => ({ size, block, variant, border, disabled, compact, menuItem, }), [size, block, variant, border, disabled, compact, menuItem]); const commonChildren = ( <> {children} { subtext && ( <> {' '} {subtext} ) } { badge && ( <> {' '} {badge} ) } { menuItem && ( <> {' '} ) } ); if (disabled) { return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events } onClick={undefined} > {commonChildren} ); } return ( } href={href} target={target} rel={rel} onClick={onClick} > {commonChildren} ); }, ); LinkButton.displayName = 'LinkButton';