Debian Codegraph @

node/@patternfly/react-core/src/demos/examples/Nav/NavGrouped.tsx

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