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