// @flow strict import * as React from 'react'; import {TEXT_COLORS} from '../../types/typography'; import {classify} from '../../utils/classify'; import type {IconType} from '../Icon'; import {Icon} from '../Icon'; import {SubTitleSmall} from '../Text'; import css from './Notification.module.css'; export const NOTIFICATION_SEMANTIC = Object.freeze({ success: 'success', information: 'information', danger: 'danger', }); type ClassNames = $ReadOnly<{wrapper?: string, text?: string}>; export type NotificationSemanticType = $Values; type BaseNotificationProps = { classNames?: ClassNames, semantic: NotificationSemanticType, iconLeftName?: string, iconLeftType?: IconType, dismissable?: boolean, children?: string, onCloseClick?: ?(SyntheticEvent) => mixed, }; type NotificationBaseProps = { ...BaseNotificationProps, classNames?: ClassNames, ... | { dismissable: true, onCloseClick?: ?(SyntheticEvent) => mixed, selfDismiss?: boolean, } | {dismissable?: false}, }; export type NotificationProps = { ...NotificationBaseProps, semantic: NotificationSemanticType, }; // Base Notification will not have any state. const BaseNotification: React$AbstractComponent< BaseNotificationProps, HTMLDivElement, > = React.forwardRef( (props: BaseNotificationProps, ref): React.Node => { const { classNames, semantic = NOTIFICATION_SEMANTIC.success, iconLeftName, iconLeftType = 'regular', dismissable, children, onCloseClick, } = props; return (
{iconLeftName ? ( ) : null} {children} {dismissable && ( )}
); }, ); export const Notification: React$AbstractComponent< NotificationProps, HTMLDivElement, > = React.forwardRef( (props: NotificationProps, ref): React.Node => { const { classNames, semantic = NOTIFICATION_SEMANTIC.success, iconLeftName, iconLeftType, dismissable, children, selfDismiss = false, onCloseClick, } = props; const [dismissed, setDismissed] = React.useState(false); const closeClickHandler = (e) => { onCloseClick && onCloseClick(e); selfDismiss && setDismissed(true); }; return ( <> {!dismissed && ( {children} )} ); }, );