import React from 'react' import Button from '../Button/Button' import Icon from '../Icons/Icon' import { type IconColorList, type IconStringList } from '../Icons/Icon.models' import { useMediaQuery } from '../../hooks/responsiveHooks' import { type ToastTypes } from './Toast' import styles from './_toast-content.module.scss' import { type ButtonProps } from '../Button/Button.models' export type ToastContentProps = { /** The content displayed inside of the component */ text: React.ReactNode /** Determines the style of the component */ type: ToastTypes /** Optional array of buttons to be added to the right of the main content. The maximum number of buttons is 2. */ buttons?: [ButtonProps, ButtonProps?] /** Optional custom icon to be displayed on the left of the main content. */ customIcon?: IconStringList /** Optional prop to add a test id to the ToastContent for QA testing */ qaTestId?: string } const ToastContent = ({ text, type, buttons, customIcon, qaTestId = 'toast-content', }: ToastContentProps): React.JSX.Element => { const isMobile = useMediaQuery({ type: 'max', breakpoint: 'sm' }) interface IconConfig { icon: IconStringList iconColor: IconColorList } const iconConfigs: Record = { error: { icon: 'flag', iconColor: 'dark-red', }, info: { icon: 'info', iconColor: 'dark-blue', }, warning: { icon: 'info', iconColor: 'dark-yellow', }, success: { icon: 'check', iconColor: 'dark-green', }, } const iconConfig = iconConfigs[type] const { icon, iconColor } = iconConfig return (
{text}
{buttons ? (
{buttons.map((button, index) => button ? (
) : null}
) } export default ToastContent