import React from 'react'; import { Alert, AlertProps, AlertGroup, AlertActionCloseButton, AlertVariant, InputGroup, InputGroupItem } from '@breakaway/preact-core'; export const AlertGroupMultipleDynamic: React.FunctionComponent = () => { const [alerts, setAlerts] = React.useState[]>([]); const addAlerts = (incomingAlerts: Partial[]) => { setAlerts((prevAlerts) => [...prevAlerts, ...incomingAlerts]); }; const removeAlert = (key: React.Key) => { setAlerts((prevAlerts) => [...prevAlerts.filter((alert) => alert.key !== key)]); }; const btnClasses = ['pf-v5-c-button', 'pf-m-secondary'].join(' '); const getUniqueId = () => String.fromCharCode(65 + Math.floor(Math.random() * 26)) + Date.now(); const addAlertCollection = () => { addAlerts([ { title: 'First alert notification.', variant: 'success', key: getUniqueId() }, { title: 'Second alert notification.', variant: 'warning', key: getUniqueId() }, { title: 'Third alert notification.', variant: 'danger', key: getUniqueId() } ]); }; return ( {alerts.map(({ title, variant, key }) => ( removeAlert(key)} /> } /> ))} ); };