import React from 'react'; import { Alert, AlertProps, AlertGroup, AlertActionCloseButton, AlertVariant, InputGroup, InputGroupItem, useInterval } from '@breakaway/preact-core'; export const AlertGroupAsync: React.FunctionComponent = () => { const [alerts, setAlerts] = React.useState[]>([]); const [isRunning, setIsRunning] = React.useState(false); const btnClasses = ['pf-v5-c-button', 'pf-m-secondary'].join(' '); const getUniqueId = () => new Date().getTime(); const addAlert = () => { setAlerts((prevAlerts) => [ ...prevAlerts, { title: `Async notification ${prevAlerts.length + 1} was added to the queue.`, variant: 'danger', key: getUniqueId() } ]); }; const removeAlert = (key: React.Key) => { setAlerts((prevAlerts) => [...prevAlerts.filter((alert) => alert.key !== key)]); }; const startAsyncAlerts = () => { setIsRunning(true); }; const stopAsyncAlerts = () => { setIsRunning(false); }; useInterval(addAlert, isRunning ? 4500 : null); return ( {alerts.map(({ title, variant, key }) => ( removeAlert(key)} /> } /> ))} ); };