Debian Codegraph @

node/@patternfly/react-core/src/demos/examples/Wizard/InPageWithDrawer.tsx

raw
1 import { Fragment, useRef, useState } from 'react';
2 import {
3 Brand,
4 Breadcrumb,
5 BreadcrumbItem,
6 Button,
7 Content,
8 Drawer,
9 DrawerActions,
10 DrawerCloseButton,
11 DrawerContent,
12 DrawerPanelContent,
13 DrawerHead,
14 Flex,
15 Nav,
16 NavItem,
17 NavList,
18 Page,
19 PageSection,
20 PageSectionTypes,
21 PageSidebar,
22 PageSidebarBody,
23 SkipToContent,
24 Masthead,
25 MastheadMain,
26 MastheadToggle,
27 MastheadBrand,
28 MastheadLogo,
29 PageToggleButton,
30 Wizard,
31 WizardStep
32 } from '@patternfly/react-core';
33 import pfLogo from '@patternfly/react-core/src/demos/assets/PF-HorizontalLogo-Color.svg';
34
35 export const WizardFullPageWithDrawerDemo: React.FunctionComponent = () => {
36 const [isDrawerExpanded, setIsDrawerExpanded] = useState(false);
37 const [activeItem, setActiveItem] = useState(0);
38
39 const drawerRef = useRef<HTMLSpanElement>(null);
40
41 const onExpand = () => {
42 if (drawerRef.current) {
43 drawerRef.current.focus();
44 }
45 };
46
47 const onOpenClick = () => {
48 setIsDrawerExpanded(true);
49 };
50
51 const onCloseClick = () => {
52 setIsDrawerExpanded(false);
53 };
54
55 const onNavSelect = (_event: React.FormEvent<HTMLElement>, result: { itemId: number | string }) => {
56 setActiveItem(result.itemId as number);
57 };
58
59 const PageNav = (
60 <Nav onSelect={onNavSelect} aria-label="Nav">
61 <NavList>
62 <NavItem itemId={0} isActive={activeItem === 0}>
63 System Panel
64 </NavItem>
65 <NavItem itemId={1} isActive={activeItem === 1}>
66 Policy
67 </NavItem>
68 <NavItem itemId={2} isActive={activeItem === 2}>
69 Authentication
70 </NavItem>
71 <NavItem itemId={3} isActive={activeItem === 3}>
72 Network Services
73 </NavItem>
74 <NavItem itemId={4} isActive={activeItem === 4}>
75 Server
76 </NavItem>
77 </NavList>
78 </Nav>
79 );
80
81 const masthead = (
82 <Masthead id="basic">
83 <MastheadMain>
84 <MastheadToggle>
85 <PageToggleButton isHamburgerButton aria-label="Global navigation" />
86 </MastheadToggle>
87 <MastheadBrand>
88 <MastheadLogo>
89 <Brand src={pfLogo} alt="PatternFly" heights={{ default: '36px' }} />
90 </MastheadLogo>
91 </MastheadBrand>
92 </MastheadMain>
93 </Masthead>
94 );
95
96 const Sidebar = (
97 <PageSidebar>
98 <PageSidebarBody>{PageNav}</PageSidebarBody>
99 </PageSidebar>
100 );
101
102 const pageId = 'main-content-page-layout-default-nav';
103
104 const handleClick = (event) => {
105 event.preventDefault();
106
107 const mainContentElement = document.getElementById(pageId);
108 if (mainContentElement) {
109 mainContentElement.focus();
110 }
111 };
112
113 const PageSkipToContent = (
114 <SkipToContent onClick={handleClick} href={`#${pageId}`}>
115 Skip to content
116 </SkipToContent>
117 );
118
119 const PageBreadcrumb = (
120 <Breadcrumb>
121 <BreadcrumbItem>Section home</BreadcrumbItem>
122 <BreadcrumbItem to="#">Section title</BreadcrumbItem>
123 <BreadcrumbItem to="#">Section title</BreadcrumbItem>
124 <BreadcrumbItem to="#" isActive>
125 Section landing
126 </BreadcrumbItem>
127 </Breadcrumb>
128 );
129
130 const createStepContentWithDrawer = (stepName: string) => (
131 <Drawer isInline isExpanded={isDrawerExpanded} onExpand={onExpand}>
132 <DrawerContent
133 panelContent={
134 <DrawerPanelContent widths={{ default: 'width_33' }}>
135 <DrawerHead>
136 <span tabIndex={isDrawerExpanded ? 0 : -1} ref={drawerRef}>
137 Drawer content: {stepName}
138 </span>
139 <DrawerActions>
140 <DrawerCloseButton onClick={onCloseClick} />
141 </DrawerActions>
142 </DrawerHead>
143 </DrawerPanelContent>
144 }
145 >
146 <Flex
147 className="pf-v6-c-wizard__main-body"
148 direction={{ default: 'column' }}
149 spaceItems={{ default: 'spaceItemsLg' }}
150 height="100%"
151 >
152 {!isDrawerExpanded && (
153 <Button isInline variant="link" onClick={onOpenClick}>
154 Open drawer
155 </Button>
156 )}
157 <div>{stepName} content</div>
158 </Flex>
159 </DrawerContent>
160 </Drawer>
161 );
162
163 return (
164 <Fragment>
165 <Page
166 masthead={masthead}
167 sidebar={Sidebar}
168 isManagedSidebar
169 skipToContent={PageSkipToContent}
170 breadcrumb={PageBreadcrumb}
171 mainContainerId={pageId}
172 >
173 <PageSection aria-labelledby="main-title">
174 <Content>
175 <h1 id="main-title">Main title</h1>
176 <p>A demo of a wizard in a page.</p>
177 </Content>
178 </PageSection>
179 <PageSection hasBodyWrapper={false} type={PageSectionTypes.wizard} aria-label="Wizard container">
180 <Wizard>
181 <WizardStep body={{ hasNoPadding: true }} name="Information" id="wizard-step-1">
182 {createStepContentWithDrawer('Information step')}
183 </WizardStep>
184 <WizardStep
185 name="Configuration"
186 id="wizard-step-2"
187 steps={[
188 <WizardStep body={{ hasNoPadding: true }} name="Substep A" id="wizard-step-2a" key="wizard-step-2a">
189 {createStepContentWithDrawer('Configuration substep A')}
190 </WizardStep>,
191 <WizardStep body={{ hasNoPadding: true }} name="Substep B" id="wizard-step-2b" key="wizard-step-2b">
192 {createStepContentWithDrawer('Configuration substep B')}
193 </WizardStep>
194 ]}
195 />
196 <WizardStep body={{ hasNoPadding: true }} name="Additional" id="wizard-step-3">
197 {createStepContentWithDrawer('Additional step')}
198 </WizardStep>
199 <WizardStep
200 body={{ hasNoPadding: true }}
201 name="Review"
202 id="wizard-step-4"
203 footer={{ nextButtonText: 'Finish' }}
204 >
205 {createStepContentWithDrawer('Review step')}
206 </WizardStep>
207 </Wizard>
208 </PageSection>
209 </Page>
210 </Fragment>
211 );
212 };