import { Fragment, useState } from 'react'; import { Alert, AlertProps, AlertGroup, AlertActionCloseButton, AlertVariant, Flex, FlexItem } from '@patternfly/react-core'; import buttonStyles from '@patternfly/react-styles/css/components/Button/button'; export const AlertGroupSingularDynamic: React.FunctionComponent = () => { const [alerts, setAlerts] = useState[]>([]); const addAlert = (title: string, variant: AlertProps['variant'], key: React.Key) => { setAlerts((prevAlerts) => [{ title, variant, key }, ...prevAlerts]); }; const removeAlert = (key: React.Key) => { setAlerts((prevAlerts) => [...prevAlerts.filter((alert) => alert.key !== key)]); }; const btnClasses = [buttonStyles.button, buttonStyles.modifiers.secondary].join(' '); const getUniqueId = () => new Date().getTime(); const addSuccessAlert = () => { addAlert('Success alert', 'success', getUniqueId()); }; const addDangerAlert = () => { addAlert('Danger alert', 'danger', getUniqueId()); }; const addInfoAlert = () => { addAlert('Info alert', 'info', getUniqueId()); }; return ( {alerts.map(({ title, variant, key }) => ( removeAlert(key)} /> } /> ))} ); };