import classNames from 'classnames' import React, { ReactElement, useState } from 'react' import { useTranslation } from 'react-i18next' import MaterialIcon from './material-icon' type NotificationType = 'info' | 'success' | 'warning' | 'error' type NotificationProps = { action?: React.ReactElement ariaLive?: 'polite' | 'off' | 'assertive' content: React.ReactElement | string customIcon?: React.ReactElement isDismissible?: boolean isActionBelowContent?: boolean onDismiss?: () => void title?: string type: NotificationType } function NotificationIcon({ notificationType, customIcon, }: { notificationType: NotificationType customIcon?: ReactElement }) { let icon = if (customIcon) { icon = customIcon } else if (notificationType === 'success') { icon = } else if (notificationType === 'warning') { icon = } else if (notificationType === 'error') { icon = } return
{icon}
} function Notification({ action, ariaLive, content, customIcon, isActionBelowContent, isDismissible, onDismiss, title, type, }: NotificationProps) { type = type || 'info' const { t } = useTranslation() const [show, setShow] = useState(true) const notificationClassName = classNames( 'notification', `notification-type-${type}`, isActionBelowContent ? 'notification-cta-below-content' : '' ) const handleDismiss = () => { setShow(false) if (onDismiss) onDismiss() } if (!show) { return null } return (
{title && (

{title}

)} {content}
{action &&
{action}
}
{isDismissible && (
)}
) } export default Notification