| 1 |
import { Fragment, useRef, useState } from 'react'; |
| 2 |
import { |
| 3 |
Drawer, |
| 4 |
DrawerPanelContent, |
| 5 |
DrawerContent, |
| 6 |
DrawerContentBody, |
| 7 |
DrawerHead, |
| 8 |
DrawerActions, |
| 9 |
DrawerCloseButton, |
| 10 |
DrawerPanelBody, |
| 11 |
Button, |
| 12 |
Title |
| 13 |
} from '@patternfly/react-core'; |
| 14 |
|
| 15 |
export const DrawerStackedContentBodyElements: React.FunctionComponent = () => { |
| 16 |
const [isExpanded, setIsExpanded] = useState(false); |
| 17 |
const drawerRef = useRef<HTMLDivElement>(undefined); |
| 18 |
|
| 19 |
const onExpand = () => { |
| 20 |
drawerRef.current && drawerRef.current.focus(); |
| 21 |
}; |
| 22 |
|
| 23 |
const onClick = () => { |
| 24 |
setIsExpanded(!isExpanded); |
| 25 |
}; |
| 26 |
|
| 27 |
const onCloseClick = () => { |
| 28 |
setIsExpanded(false); |
| 29 |
}; |
| 30 |
|
| 31 |
const panelContent = ( |
| 32 |
<DrawerPanelContent> |
| 33 |
<DrawerHead> |
| 34 |
<Title headingLevel="h3" size="2xl" tabIndex={isExpanded ? 0 : -1} ref={drawerRef}> |
| 35 |
Drawer panel header in a Title |
| 36 |
</Title> |
| 37 |
<DrawerActions> |
| 38 |
<DrawerCloseButton onClick={onCloseClick} /> |
| 39 |
</DrawerActions> |
| 40 |
</DrawerHead> |
| 41 |
<DrawerPanelBody hasNoPadding>Drawer panel body with no padding</DrawerPanelBody> |
| 42 |
<DrawerPanelBody>Drawer panel body</DrawerPanelBody> |
| 43 |
</DrawerPanelContent> |
| 44 |
); |
| 45 |
|
| 46 |
return ( |
| 47 |
<Fragment> |
| 48 |
<Button aria-expanded={isExpanded} onClick={onClick}> |
| 49 |
Toggle drawer |
| 50 |
</Button> |
| 51 |
<Drawer isExpanded={isExpanded} onExpand={onExpand}> |
| 52 |
<DrawerContent panelContent={panelContent}> |
| 53 |
<DrawerContentBody>content-body</DrawerContentBody> |
| 54 |
<DrawerContentBody hasPadding>content-body with padding</DrawerContentBody> |
| 55 |
<DrawerContentBody>content-body</DrawerContentBody> |
| 56 |
</DrawerContent> |
| 57 |
</Drawer> |
| 58 |
</Fragment> |
| 59 |
); |
| 60 |
}; |