import { type FC, type ReactNode, type HTMLAttributes, type MouseEvent, } from 'react'; import cn from 'classnames'; import InformationIcon from '../svg/information.svg'; import WarningTriangleIcon from '../svg/warning-triangle.svg'; import ErrorIcon from '../svg/error.svg'; import SuccessIcon from '../svg/success.svg'; import CloseIcon from '../svg/times.svg'; import '../styles/components/message.scss'; const iconSize = '1.125em'; type Props = { /** * The message level: 'warning', 'failure', 'success', 'info' (default) */ level?: 'warning' | 'failure' | 'success' | 'info'; /** * The title of the message */ heading?: ReactNode; /** * The content to appear underneath of the main message */ subtitle?: ReactNode; /** * Whether the message can be closed or not */ onDismiss?: (event: MouseEvent) => void; /** * To hide the default message icon */ noIcon?: boolean; /** * To hide the default box shadow */ noShadow?: boolean; }; const Message: FC> = ({ children, level = 'info', heading, subtitle, onDismiss, noIcon, noShadow, className, ...props }) => { let maybeIcon = null; const iconAlign = heading ? 'message--icon-align-center' : 'message--icon-align-top'; if (!noIcon) { maybeIcon = ( ); if (level === 'warning') { maybeIcon = ( ); } else if (level === 'failure') { maybeIcon = ( ); } else if (level === 'success') { maybeIcon = ( ); } } return (
{maybeIcon} {heading ? ( <>
{heading}
{children}
) : (
{children}
)} {onDismiss && ( )} {subtitle &&
{subtitle}
}
); }; export default Message;