// @flow strict import * as React from 'react'; import {TEXT_COLORS} from '../../types/typography'; import {classify} from '../../utils/classify'; import type {IconType} from '../Icon'; import {ClickableIcon, Icon} from '../Icon'; import {Link} from '../Link'; import {SubTitleExtraSmall} from '../Text'; import {Truncate} from '../Truncate'; import css from './InContextAlert.module.css'; export const ALERT_SEMANTIC = Object.freeze({ neutral: 'neutral', success: 'success', information: 'information', warning: 'warning', danger: 'danger', }); type ClassNames = $ReadOnly<{ wrapper?: string, alertText?: string, actionContainer?: string, }>; export type AlertSemanticType = $Values; type InContextAlertBaseProps = { classNames?: ClassNames, ... | { dismissable: true, onCloseClick?: ?(SyntheticEvent) => mixed, selfDismiss?: boolean, } | {dismissable?: false}, children?: string, actionText?: string, onAction?: ?(SyntheticEvent) => mixed, }; export type InContextAlertProps = { ...InContextAlertBaseProps, semantic?: AlertSemanticType, leftIconName?: string, leftIconType?: IconType, }; const AlertIcon = ({ semantic, leftIconName, leftIconType, }: { semantic: AlertSemanticType, leftIconName: string, leftIconType?: IconType, }) => { switch (semantic) { case ALERT_SEMANTIC.neutral: return ( ); case ALERT_SEMANTIC.success: return ( ); case ALERT_SEMANTIC.information: return ( ); case ALERT_SEMANTIC.warning: return ( ); case ALERT_SEMANTIC.danger: return ( ); default: return ( ); } }; export const InContextAlert: React$AbstractComponent< InContextAlertProps, HTMLDivElement, > = React.forwardRef( (props: InContextAlertProps, ref): React.Node => { const { classNames, semantic = ALERT_SEMANTIC.neutral, dismissable, children, selfDismiss = false, leftIconName = '', onCloseClick, actionText = '', onAction, leftIconType, } = props; const [dismissed, setDismissed] = React.useState(false); const closeClickHandler = (e) => { onCloseClick && onCloseClick(e); selfDismiss && setDismissed(true); }; return ( <> {!dismissed && (
{React.Children.count(children) > 0 && ( {children} )} {!!(actionText || dismissable) && (
{!!actionText && ( {actionText} )} {!!dismissable && ( )}
)}
)} ); }, );