| 1 |
import { useContext, useRef, useState } from 'react'; |
| 2 |
import { |
| 3 |
Button, |
| 4 |
Content, |
| 5 |
Drawer, |
| 6 |
DrawerPanelContent, |
| 7 |
DrawerContent, |
| 8 |
DrawerContentBody, |
| 9 |
DrawerHead, |
| 10 |
DrawerActions, |
| 11 |
DrawerCloseButton, |
| 12 |
JumpLinks, |
| 13 |
JumpLinksItem, |
| 14 |
JumpLinksList, |
| 15 |
PageSection, |
| 16 |
Sidebar, |
| 17 |
SidebarContent, |
| 18 |
SidebarPanel, |
| 19 |
DrawerContext |
| 20 |
} from '@patternfly/react-core'; |
| 21 |
import { DashboardWrapper } from '@patternfly/react-core/dist/js/demos/DashboardWrapper'; |
| 22 |
|
| 23 |
const JumpLinksWrapper = ({ headings }) => { |
| 24 |
const { drawerContentRef } = useContext(DrawerContext); |
| 25 |
|
| 26 |
return ( |
| 27 |
<JumpLinks |
| 28 |
isVertical={true} |
| 29 |
label="Jump to section" |
| 30 |
scrollableRef={drawerContentRef} |
| 31 |
expandable={{ default: 'expandable', md: 'nonExpandable' }} |
| 32 |
> |
| 33 |
{headings.map((heading) => ( |
| 34 |
<JumpLinksItem key={heading} href={`#jump-links-drawer-jump-links-${heading.toLowerCase()}`}> |
| 35 |
{`${heading} section`} |
| 36 |
<JumpLinksList></JumpLinksList> |
| 37 |
</JumpLinksItem> |
| 38 |
))} |
| 39 |
</JumpLinks> |
| 40 |
); |
| 41 |
}; |
| 42 |
|
| 43 |
export const JumpLinksWithDrawer: React.FunctionComponent = () => { |
| 44 |
const headings = ['First', 'Second', 'Third', 'Fourth', 'Fifth']; |
| 45 |
|
| 46 |
const [isExpanded, setIsExpanded] = useState(false); |
| 47 |
const drawerRef = useRef(undefined); |
| 48 |
|
| 49 |
const onCloseClick = () => { |
| 50 |
setIsExpanded(false); |
| 51 |
}; |
| 52 |
|
| 53 |
const onToggleClick = () => { |
| 54 |
setIsExpanded(!isExpanded); |
| 55 |
}; |
| 56 |
|
| 57 |
const panelContent = ( |
| 58 |
<DrawerPanelContent> |
| 59 |
<DrawerHead> |
| 60 |
<span tabIndex={isExpanded ? 0 : -1} ref={drawerRef}> |
| 61 |
drawer-panel |
| 62 |
</span> |
| 63 |
<DrawerActions> |
| 64 |
<DrawerCloseButton onClick={onCloseClick} /> |
| 65 |
</DrawerActions> |
| 66 |
</DrawerHead> |
| 67 |
</DrawerPanelContent> |
| 68 |
); |
| 69 |
|
| 70 |
return ( |
| 71 |
<DashboardWrapper breadcrumb={null} mainContainerId="scrollable-element"> |
| 72 |
<Drawer isExpanded={isExpanded}> |
| 73 |
<DrawerContent panelContent={panelContent}> |
| 74 |
<DrawerContentBody> |
| 75 |
<Sidebar> |
| 76 |
<SidebarPanel variant="sticky"> |
| 77 |
<PageSection> |
| 78 |
<JumpLinksWrapper headings={headings} /> |
| 79 |
</PageSection> |
| 80 |
</SidebarPanel> |
| 81 |
<SidebarContent> |
| 82 |
<PageSection id="drawer-toggle" stickyOnBreakpoint={{ default: 'top' }}> |
| 83 |
<Button onClick={onToggleClick}>Toggle drawer</Button> |
| 84 |
</PageSection> |
| 85 |
<PageSection hasOverflowScroll> |
| 86 |
<Content> |
| 87 |
{headings.map((heading) => ( |
| 88 |
<div key={heading} style={{ maxWidth: '800px', marginBottom: '32px' }}> |
| 89 |
<h2 id={`jump-links-drawer-jump-links-${heading.toLowerCase()}`} tabIndex={-1}> |
| 90 |
{`${heading} section`} |
| 91 |
</h2> |
| 92 |
<p> |
| 93 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed dui ullamcorper, |
| 94 |
dignissim purus eu, mattis leo. Curabitur eleifend turpis ipsum, aliquam pretium risus |
| 95 |
efficitur vel. Etiam eget enim vitae quam facilisis pharetra at eget diam. Suspendisse ut |
| 96 |
vulputate magna. Nunc viverra posuere orci sit amet pulvinar. Quisque dui justo, egestas ac |
| 97 |
accumsan suscipit, tristique eu risus. In aliquet libero ante, ac pulvinar lectus pretium in. |
| 98 |
Ut enim tellus, vulputate et lorem et, hendrerit rutrum diam. Cras pharetra dapibus elit vitae |
| 99 |
ullamcorper. Nulla facilisis euismod diam, at sodales sem laoreet hendrerit. Curabitur |
| 100 |
porttitor ex nulla. Proin ligula leo, egestas ac nibh a, pellentesque mollis augue. Donec nec |
| 101 |
augue vehicula eros pulvinar vehicula eget rutrum neque. Duis sit amet interdum lorem. Vivamus |
| 102 |
porttitor nec quam a accumsan. Nam pretium vitae leo vitae rhoncus. |
| 103 |
</p> |
| 104 |
<p> |
| 105 |
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium |
| 106 |
voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati |
| 107 |
cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est |
| 108 |
laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero |
| 109 |
tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime |
| 110 |
placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus |
| 111 |
autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et |
| 112 |
voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a |
| 113 |
sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis |
| 114 |
doloribus asperiores repellat. |
| 115 |
</p> |
| 116 |
</div> |
| 117 |
))} |
| 118 |
</Content> |
| 119 |
</PageSection> |
| 120 |
</SidebarContent> |
| 121 |
</Sidebar> |
| 122 |
</DrawerContentBody> |
| 123 |
</DrawerContent> |
| 124 |
</Drawer> |
| 125 |
</DashboardWrapper> |
| 126 |
); |
| 127 |
}; |