| 1 |
import { useState } from 'react'; |
| 2 |
import { Popover, Button } from '@patternfly/react-core'; |
| 3 |
import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon'; |
| 4 |
import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon'; |
| 5 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 6 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 7 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 8 |
|
| 9 |
export const AlertPopover: React.FunctionComponent = () => { |
| 10 |
const [alertSeverityVariant, setAlertSeverityVariant] = useState('default'); |
| 11 |
|
| 12 |
const alertIcons = { |
| 13 |
custom: <RhUiNotificationFillIcon />, |
| 14 |
info: <RhUiInformationFillIcon />, |
| 15 |
success: <RhUiCheckCircleFillIcon />, |
| 16 |
warning: <RhUiWarningFillIcon />, |
| 17 |
danger: <RhUiErrorFillIcon /> |
| 18 |
}; |
| 19 |
|
| 20 |
return ( |
| 21 |
<> |
| 22 |
<div> |
| 23 |
<span style={{ paddingRight: '10px' }}>Alert variant:</span> |
| 24 |
<select aria-label="Popover alert type" onChange={(event) => setAlertSeverityVariant(event.target.value)}> |
| 25 |
<option value="custom">custom</option> |
| 26 |
<option value="info">info</option> |
| 27 |
<option value="success">success</option> |
| 28 |
<option value="warning">warning</option> |
| 29 |
<option value="danger">danger</option> |
| 30 |
</select> |
| 31 |
</div> |
| 32 |
<div style={{ margin: '50px' }}> |
| 33 |
<Popover |
| 34 |
aria-label="Alert popover" |
| 35 |
alertSeverityVariant={alertSeverityVariant as 'custom' | 'info' | 'warning' | 'success' | 'danger'} |
| 36 |
headerContent="Default popover title" |
| 37 |
headerIcon={alertIcons[alertSeverityVariant]} |
| 38 |
headerComponent="h1" |
| 39 |
bodyContent={<div>Popovers are triggered by click rather than hover.</div>} |
| 40 |
footerContent="Popover footer" |
| 41 |
appendTo={() => document.body} |
| 42 |
> |
| 43 |
<Button>Toggle popover</Button> |
| 44 |
</Popover> |
| 45 |
</div> |
| 46 |
</> |
| 47 |
); |
| 48 |
}; |