| 1 |
import { useState } from 'react'; |
| 2 |
import { Popover, Button } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const PopoverCloseControlled: React.FunctionComponent = () => { |
| 5 |
const [isVisible, setIsVisible] = useState(false); |
| 6 |
|
| 7 |
return ( |
| 8 |
<div style={{ margin: '50px' }}> |
| 9 |
<Popover |
| 10 |
aria-label="Popover with button in the body that can close it" |
| 11 |
isVisible={isVisible} |
| 12 |
shouldOpen={(_event, _fn) => setIsVisible(true)} |
| 13 |
shouldClose={(_event, _fn) => setIsVisible(false)} |
| 14 |
headerContent={<div>Popover header</div>} |
| 15 |
bodyContent={ |
| 16 |
<div> |
| 17 |
<div>A controlled popover can be closed by updating its isVisible state after some user interaction.</div> |
| 18 |
<div> |
| 19 |
<button onClick={() => setIsVisible(false)}>Close popover</button> |
| 20 |
</div> |
| 21 |
</div> |
| 22 |
} |
| 23 |
footerContent="Popover footer" |
| 24 |
> |
| 25 |
<Button>Toggle popover</Button> |
| 26 |
</Popover> |
| 27 |
</div> |
| 28 |
); |
| 29 |
}; |