import { ChevronEnd } from '@transferwise/icons'; import { clsx } from 'clsx'; import { forwardRef } from 'react'; import CardContainer from '../CardContainer'; import { Typography } from '../common'; import Link from '../Link'; import Title from '../Title'; import type { CardWidgetHeader, CardWidgetProps } from './CardWidget.types'; import CardWidgetAction, { isCardWidgetActionButton, type CardWidgetActionSlot, } from './CardWidgetAction'; const renderAction = (action: CardWidgetHeader['action'], slot: CardWidgetActionSlot) => isCardWidgetActionButton(action) ? : action; const CardWidgetHeaderComponent = ({ title, as = 'h3', titleAction, action, actionSecondary, }: CardWidgetHeader) => (
{titleAction ? ( <Link href={titleAction.href} target={titleAction.target} className="wds-card-widget__title-link" onClick={titleAction.onClick} > {title} {/* The word joiner keeps the chevron on the title's last line instead of wrapping alone. */} <span className="wds-card-widget__title-chevron" aria-hidden> {'\u2060'} <ChevronEnd size={16} /> </span> </Link> ) : ( title )} {(action || actionSecondary) && (
{actionSecondary && renderAction(actionSecondary, 'actionSecondary')} {action && renderAction(action, 'action')}
)}
); /** * A `CardContainer` with an optional header — a title, a title link and up to two actions — above * its content. The card shows as hovered or pressed while the title link is, and as hovered while * the link has keyboard focus. Hovering or pressing the rest of the card, or its actions, leaves it * at rest. */ const CardWidget = forwardRef( ({ header, children, className, ...props }, ref) => ( {header && } {children != null &&
{children}
}
), ); CardWidget.displayName = 'CardWidget'; export default CardWidget;