Debian Codegraph @

node/@patternfly/react-core/src/demos/examples/Wizard/InPageWithDrawerInformationalStep.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 DrawerHead,
13 DrawerPanelContent,
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 WizardFullPageWithDrawerInfoStepDemo: React.FunctionComponent = () => {
36 const [isDrawerExpanded, setIsDrawerExpanded] = useState(false);
37 const [activeItem, setActiveItem] = useState(0);
38
39 const drawerRef = useRef<HTMLSpanElement | null>(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: any, result: any) => {
56 setActiveItem(result.itemId);
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 <Content>
153 <p>{stepName} content</p>
154 <p>
155 Wizard description goes here. If you need more assistance,{' '}
156 <Button isInline variant="link" onClick={onOpenClick}>
157 see more information
158 </Button>{' '}
159 in the side drawer.{' '}
160 </p>
161 </Content>
162 </Flex>
163 </DrawerContent>
164 </Drawer>
165 );
166
167 return (
168 <Fragment>
169 <Page
170 masthead={masthead}
171 sidebar={Sidebar}
172 isManagedSidebar
173 skipToContent={PageSkipToContent}
174 breadcrumb={PageBreadcrumb}
175 mainContainerId={pageId}
176 >
177 <PageSection aria-labelledby="main-title">
178 <Content>
179 <h1 id="main-title">Main title</h1>
180 <p>A demo of a wizard in a page.</p>
181 </Content>
182 </PageSection>
183 <PageSection hasBodyWrapper={false} type={PageSectionTypes.wizard} ß aria-label="Wizard container">
184 <Wizard>
185 <WizardStep body={{ hasNoPadding: true }} name="Information" id="wizard-step-1">
186 {createStepContentWithDrawer('Information step')}
187 </WizardStep>
188 <WizardStep
189 name="Configuration"
190 id="wizard-step-2"
191 steps={[
192 <WizardStep body={{ hasNoPadding: true }} name="Substep A" id="wizard-step-2a" key="wizard-step-2a">
193 {createStepContentWithDrawer('Configuration substep A')}
194 </WizardStep>,
195 <WizardStep body={{ hasNoPadding: true }} name="Substep B" id="wizard-step-2b" key="wizard-step-2b">
196 {createStepContentWithDrawer('Configuration substep B')}
197 </WizardStep>
198 ]}
199 />
200 <WizardStep body={{ hasNoPadding: true }} name="Additional" id="wizard-step-3">
201 {createStepContentWithDrawer('Additional step')}
202 </WizardStep>
203 <WizardStep
204 body={{ hasNoPadding: true }}
205 name="Review"
206 id="wizard-step-4"
207 footer={{ nextButtonText: 'Finish' }}
208 >
209 {createStepContentWithDrawer('Review step')}
210 </WizardStep>
211 </Wizard>
212 </PageSection>
213 </Page>
214 </Fragment>
215 );
216 };