import { Button } from '@cloud-ru/ds-button'; import { Card, PolymorphicRef } from '@cloud-ru/ds-card'; import { CrossSVG } from '@cloud-ru/ds-icons/interface/system'; import { TruncateString } from '@cloud-ru/ds-truncate-string'; import { Typography } from '@cloud-ru/ds-typography'; import { withInnerRefSupport } from '@cloud-ru/ds-utils'; import cn from 'classnames'; import { ComponentPropsWithoutRef, ElementType, MouseEventHandler, ReactElement, useCallback } from 'react'; import { TEST_IDS } from '../../constants'; import { CardAction } from '../../helperComponents'; import styles from './styles.module.scss'; type BaseCardBannerProps = { /** Заголовок карточки */ title: string; /** Описание */ content: string; /** Текст кнопки действия */ actionLabel: string; /** Изображение */ image: { src: string; alt: string; }; /** Колбэк закрытия. При наличии отображается кнопка «Закрыть» */ onClose?: MouseEventHandler; /** Неактивное состояние */ disabled?: boolean; /** CSS-класс корневого элемента */ className?: string; /** Support prop для тестов */ 'data-test-id'?: string; }; export type CardBannerProps = BaseCardBannerProps & { /** Полиморфный элемент: `'div'`, `'a'`, `{Link}` и т.д. */ as?: T; /** Ref на реальный DOM-элемент / инстанс */ innerRef?: PolymorphicRef; } & Omit, keyof BaseCardBannerProps | 'as' | 'ref'>; export function CardBanner({ title, content, actionLabel, image, onClose, disabled, className, as, innerRef, 'data-test-id': dataTestId, ...rest }: CardBannerProps): ReactElement | null { const handleClose: MouseEventHandler = useCallback( e => { e.stopPropagation(); onClose?.(e); }, [onClose], ); return ( as={as} innerRef={innerRef} disabled={disabled} interactive className={cn(styles.root, className)} data-test-id={dataTestId ?? TEST_IDS.cardBanner} {...(rest as ComponentPropsWithoutRef)} > {onClose && (
)}
{image.alt}
); } withInnerRefSupport(CardBanner);