// @flow strict import * as React from 'react'; import type {AlertSemanticType} from '../../types/common'; import {ALERT_SEMANTIC} from '../../types/common'; 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'; type ClassNames = $ReadOnly<{ wrapper?: string, alertText?: string, actionContainer?: string, icon?: string, }>; 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, iconClassName, }: { semantic: AlertSemanticType, leftIconName: string, leftIconType?: IconType, iconClassName?: string, }) => { 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 && ( )}
)}
)} ); }, );