import React from "react"; import { Classes as BlueprintClassNames, Toast2 as BlueprintToast, ToastProps as BlueprintToastProps, } from "@blueprintjs/core"; import { ClassNames as IntentClassNames, IntentTypes } from "../../common/Intent"; import { CLASSPREFIX as eccgui } from "../../configuration/constants"; import { TestableComponent } from "../interfaces"; import { ValidIconName } from "./../Icon/canonicalIconNames"; import Icon, { IconProps } from "./../Icon/Icon"; import { TestIconProps } from "./../Icon/TestIcon"; export interface NotificationProps extends TestableComponent, Omit, React.HTMLAttributes { /** * Extra user action elements */ actions?: React.JSX.Element | React.JSX.Element[]; /** * Notification message that can be used as alternative to children elements. */ message?: React.JSX.Element | string; /** * Intent state of the notification. */ intent?: Extract; /** * Notification uses the the given space more flexible. * Default notification is displayed in min and max limits. * Those limits are removed by setting this property to `true`. */ flexWidth?: boolean; /** * Icon displayed with the notification. * Set it to false if you need to prevent automatically set icon regarding the notification type. */ icon?: false | React.ReactElement | React.ReactElement; /** * If set then a `div` element is used as wrapper. * It uses the attributes given via this property. */ wrapperProps?: React.HTMLAttributes; } /** * Displays a notification message, optionally combined with depiction and further action buttons. * By default it uses colorization of an blueish info alert. */ export const Notification = ({ actions, children, className, message, flexWidth = false, icon, timeout, wrapperProps, "data-test-id": dataTestId, "data-testid": dataTestid, intent = "info", ...otherProps }: NotificationProps) => { const intentClass = intent ? " " + IntentClassNames[intent.toUpperCase()] : ""; const intentIconSymbol = intent !== "neutral" ? `state-${intent}` : false; let notificationIcon = icon !== false ? icon : undefined; if (icon !== false && !notificationIcon && !!intentIconSymbol) { notificationIcon = ; } const content = actions ? (
{message ? message : children}
{actions}
) : message ? ( message ) : ( children ); const notification = ( ); return wrapperProps || dataTestId || dataTestid ? (
{notification}
) : ( <>{notification} ); }; export default Notification;