import React, { MouseEvent, HTMLAttributes, EventHandler, FC } from 'react'; import classnames from 'classnames'; import { Button } from './Button'; import { Icon, IconSize } from './Icon'; const NOTIFICATION_TYPES = ['alert', 'toast'] as const; const NOTIFICATION_LEVELS = ['info', 'success', 'warning', 'error'] as const; export type NotificationType = (typeof NOTIFICATION_TYPES)[number]; export type NotificationLevel = (typeof NOTIFICATION_LEVELS)[number]; export type NotificationProps = { type?: NotificationType; level?: NotificationLevel; alt?: string; icon?: string; iconSize?: IconSize; onClose?: EventHandler>; } & HTMLAttributes; export const Notification: FC = (props) => { const { className, type, level, alt, icon, iconSize = 'small', onClose, children, ...pprops } = props; const typeClassName = type && NOTIFICATION_TYPES.indexOf(type) >= 0 ? `slds-notify_${type}` : null; const levelClassName = level && NOTIFICATION_LEVELS.indexOf(level) >= 0 ? `slds-theme_${level}` : null; const alertClassNames = classnames( className, 'slds-notify', typeClassName, levelClassName, { [`slds-alert_${level}`]: type === 'alert' && level && level !== 'info', } ); const iconEl = icon ? ( ) : undefined; return ( {alt ? {alt} : undefined} {onClose ? ( ) : undefined} {iconEl} {type === 'toast' ? ( {children} ) : ( {children} )} ); }; export type AlertProps = Omit; export const Alert: FC = (props) => ( ); export type ToastProps = Omit; export const Toast: FC = (props) => ( );