| 1 |
import { Fragment, useState } from 'react'; |
| 2 |
import { |
| 3 |
Card, |
| 4 |
CardBody, |
| 5 |
Content, |
| 6 |
Gallery, |
| 7 |
GalleryItem, |
| 8 |
Nav, |
| 9 |
NavExpandable, |
| 10 |
NavItem, |
| 11 |
NavList, |
| 12 |
Page, |
| 13 |
PageSection, |
| 14 |
PageSidebar, |
| 15 |
PageSidebarBody, |
| 16 |
SkipToContent |
| 17 |
} from '@patternfly/react-core'; |
| 18 |
import { DashboardBreadcrumb } from '@patternfly/react-core/dist/js/demos/DashboardWrapper'; |
| 19 |
import { DashboardHeader } from '@patternfly/react-core/dist/js/demos/DashboardHeader'; |
| 20 |
|
| 21 |
export const NavExpandableDemo: React.FunctionComponent = () => { |
| 22 |
const [activeGroup, setActiveGroup] = useState<string | number>('grp-1'); |
| 23 |
const [activeItem, setActiveItem] = useState<string | number>('grp-1_itm-1'); |
| 24 |
|
| 25 |
const onNavSelect = ( |
| 26 |
_event: React.FormEvent<HTMLInputElement>, |
| 27 |
selectedItem: { |
| 28 |
groupId: number | string; |
| 29 |
itemId: number | string; |
| 30 |
to: string; |
| 31 |
} |
| 32 |
) => { |
| 33 |
setActiveItem(selectedItem.itemId); |
| 34 |
setActiveGroup(selectedItem.groupId); |
| 35 |
}; |
| 36 |
|
| 37 |
const PageNav = ( |
| 38 |
<Nav onSelect={onNavSelect} aria-label="Nav"> |
| 39 |
<NavList> |
| 40 |
<NavExpandable title="System Panel" groupId="grp-1" isActive={activeGroup === 'grp-1'} isExpanded> |
| 41 |
{/* Preventing default click behavior on each NavItem for demo purposes only */} |
| 42 |
<NavItem preventDefault groupId="grp-1" itemId="grp-1_itm-1" isActive={activeItem === 'grp-1_itm-1'} to="#"> |
| 43 |
Overview |
| 44 |
</NavItem> |
| 45 |
<NavItem preventDefault groupId="grp-1" itemId="grp-1_itm-2" isActive={activeItem === 'grp-1_itm-2'} to="#"> |
| 46 |
Resource usage |
| 47 |
</NavItem> |
| 48 |
<NavItem preventDefault groupId="grp-1" itemId="grp-1_itm-3" isActive={activeItem === 'grp-1_itm-3'} to="#"> |
| 49 |
Hypervisors |
| 50 |
</NavItem> |
| 51 |
<NavItem preventDefault groupId="grp-1" itemId="grp-1_itm-4" isActive={activeItem === 'grp-1_itm-4'} to="#"> |
| 52 |
Instances |
| 53 |
</NavItem> |
| 54 |
<NavItem preventDefault groupId="grp-1" itemId="grp-1_itm-5" isActive={activeItem === 'grp-1_itm-5'} to="#"> |
| 55 |
Volumes |
| 56 |
</NavItem> |
| 57 |
<NavItem preventDefault groupId="grp-1" itemId="grp-1_itm-6" isActive={activeItem === 'grp-1_itm-6'} to="#"> |
| 58 |
Network |
| 59 |
</NavItem> |
| 60 |
</NavExpandable> |
| 61 |
<NavExpandable title="Policy" groupId="grp-2" isActive={activeGroup === 'grp-2'}> |
| 62 |
<NavItem preventDefault groupId="grp-2" itemId="grp-2_itm-1" isActive={activeItem === 'grp-2_itm-1'} to="#"> |
| 63 |
Subnav link 1 |
| 64 |
</NavItem> |
| 65 |
<NavItem preventDefault groupId="grp-2" itemId="grp-2_itm-2" isActive={activeItem === 'grp-2_itm-2'} to="#"> |
| 66 |
Subnav link 2 |
| 67 |
</NavItem> |
| 68 |
</NavExpandable> |
| 69 |
<NavExpandable title="Authentication" groupId="grp-3" isActive={activeGroup === 'grp-3'}> |
| 70 |
<NavItem preventDefault groupId="grp-3" itemId="grp-3_itm-1" isActive={activeItem === 'grp-3_itm-1'} to="#"> |
| 71 |
Subnav link 1 |
| 72 |
</NavItem> |
| 73 |
<NavItem preventDefault groupId="grp-3" itemId="grp-3_itm-2" isActive={activeItem === 'grp-3_itm-2'} to="#"> |
| 74 |
Subnav link 2 |
| 75 |
</NavItem> |
| 76 |
</NavExpandable> |
| 77 |
</NavList> |
| 78 |
</Nav> |
| 79 |
); |
| 80 |
|
| 81 |
const Sidebar = ( |
| 82 |
<PageSidebar> |
| 83 |
<PageSidebarBody>{PageNav}</PageSidebarBody> |
| 84 |
</PageSidebar> |
| 85 |
); |
| 86 |
const pageId = 'main-content-page-layout-expandable-nav'; |
| 87 |
|
| 88 |
const handleClick = (event) => { |
| 89 |
event.preventDefault(); |
| 90 |
|
| 91 |
const mainContentElement = document.getElementById(pageId); |
| 92 |
if (mainContentElement) { |
| 93 |
mainContentElement.focus(); |
| 94 |
} |
| 95 |
}; |
| 96 |
|
| 97 |
const PageSkipToContent = ( |
| 98 |
<SkipToContent onClick={handleClick} href={`#${pageId}`}> |
| 99 |
Skip to content |
| 100 |
</SkipToContent> |
| 101 |
); |
| 102 |
|
| 103 |
return ( |
| 104 |
<Fragment> |
| 105 |
<Page |
| 106 |
masthead={<DashboardHeader />} |
| 107 |
sidebar={Sidebar} |
| 108 |
isManagedSidebar |
| 109 |
skipToContent={PageSkipToContent} |
| 110 |
breadcrumb={DashboardBreadcrumb} |
| 111 |
mainContainerId={pageId} |
| 112 |
> |
| 113 |
<PageSection aria-labelledby="main-title"> |
| 114 |
<Content> |
| 115 |
<h1 id="main-title">Main title</h1> |
| 116 |
<p> |
| 117 |
Body text should be Red Hat Text at 1rem(16px). It should have leading of 1.5rem(24px) because <br /> |
| 118 |
of its relative line height of 1.5. |
| 119 |
</p> |
| 120 |
</Content> |
| 121 |
</PageSection> |
| 122 |
<PageSection aria-label="Card gallery"> |
| 123 |
<Gallery hasGutter> |
| 124 |
{Array.from({ length: 10 }).map((_value, index) => ( |
| 125 |
<GalleryItem key={index}> |
| 126 |
<Card> |
| 127 |
<CardBody>This is a card</CardBody> |
| 128 |
</Card> |
| 129 |
</GalleryItem> |
| 130 |
))} |
| 131 |
</Gallery> |
| 132 |
</PageSection> |
| 133 |
</Page> |
| 134 |
</Fragment> |
| 135 |
); |
| 136 |
}; |