| 1 |
import { Fragment, useState } from 'react'; |
| 2 |
import { Alert, AlertActionLink, AlertGroup, Button } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const AlertTimeout: React.FunctionComponent = () => { |
| 5 |
const [alerts, setAlerts] = useState<React.ReactNode[]>([]); |
| 6 |
const [newAlertKey, setNewAlertKey] = useState<number>(0); |
| 7 |
|
| 8 |
const onClick = () => { |
| 9 |
const timeout = 8000; |
| 10 |
setNewAlertKey((key) => key + 1); |
| 11 |
setAlerts((prevAlerts) => [ |
| 12 |
<Alert |
| 13 |
title="Default timeout Alert" |
| 14 |
timeout={timeout} |
| 15 |
actionLinks={ |
| 16 |
<Fragment> |
| 17 |
<AlertActionLink component="a" href="#"> |
| 18 |
View details |
| 19 |
</AlertActionLink> |
| 20 |
<AlertActionLink // eslint-disable-next-line no-console |
| 21 |
onClick={() => console.log('Clicked on Ignore')} |
| 22 |
> |
| 23 |
Ignore |
| 24 |
</AlertActionLink> |
| 25 |
</Fragment> |
| 26 |
} |
| 27 |
key={newAlertKey} |
| 28 |
> |
| 29 |
This alert will dismiss after {`${timeout / 1000} seconds`} |
| 30 |
</Alert>, |
| 31 |
...prevAlerts |
| 32 |
]); |
| 33 |
}; |
| 34 |
|
| 35 |
return ( |
| 36 |
<Fragment> |
| 37 |
<Button variant="secondary" onClick={onClick}> |
| 38 |
Add alert |
| 39 |
</Button> |
| 40 |
<AlertGroup hasAnimations isLiveRegion> |
| 41 |
{alerts} |
| 42 |
</AlertGroup> |
| 43 |
</Fragment> |
| 44 |
); |
| 45 |
}; |