import { Fragment, useState } from 'react'; import { Alert, AlertGroup, AlertVariant, Flex, FlexItem } from '@patternfly/react-core'; import buttonStyles from '@patternfly/react-styles/css/components/Button/button'; interface AlertInfo { title: string; variant: AlertVariant; key: number; } export const DynamicLiveRegionAlert: React.FunctionComponent = () => { const [alerts, setAlerts] = useState([]); const getUniqueId: () => number = () => new Date().getTime(); const btnClasses = [buttonStyles.button, buttonStyles.modifiers.secondary].join(' '); const addAlert = (alertInfo: AlertInfo) => { setAlerts((prevAlertInfo) => [alertInfo, ...prevAlertInfo]); }; const addSuccessAlert = () => { addAlert({ title: 'Single success alert', variant: AlertVariant.success, key: getUniqueId() }); }; const addInfoAlert = () => { addAlert({ title: 'Single info alert', variant: AlertVariant.info, key: getUniqueId() }); }; const addDangerAlert = () => { addAlert({ title: 'Single danger alert', variant: AlertVariant.danger, key: getUniqueId() }); }; return ( {alerts.map(({ title, variant, key }) => ( ))} ); };