Debian Codegraph @

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

raw
1 import { useRef, useState } from 'react';
2 import {
3 Button,
4 Drawer,
5 DrawerContent,
6 DrawerPanelContent,
7 DrawerHead,
8 DrawerActions,
9 DrawerCloseButton,
10 Flex,
11 Modal,
12 ModalVariant,
13 Wizard,
14 WizardHeader,
15 WizardStep
16 } from '@patternfly/react-core';
17
18 export const WizardModalWithDrawerDemo: React.FunctionComponent = () => {
19 const [isDrawerExpanded, setIsDrawerExpanded] = useState(false);
20 const drawerRef = useRef<HTMLSpanElement | null>(null);
21
22 const onExpand = () => {
23 if (drawerRef.current) {
24 drawerRef.current.focus();
25 }
26 };
27
28 const onOpenClick = () => {
29 setIsDrawerExpanded(true);
30 };
31
32 const onCloseClick = () => {
33 setIsDrawerExpanded(false);
34 };
35
36 const createStepContentWithDrawer = (stepName: string) => (
37 <Drawer isInline isExpanded={isDrawerExpanded} onExpand={onExpand}>
38 <DrawerContent
39 panelContent={
40 <DrawerPanelContent widths={{ default: 'width_33' }}>
41 <DrawerHead>
42 <span tabIndex={isDrawerExpanded ? 0 : -1} ref={drawerRef}>
43 Drawer content: {stepName}
44 </span>
45 <DrawerActions>
46 <DrawerCloseButton onClick={onCloseClick} />
47 </DrawerActions>
48 </DrawerHead>
49 </DrawerPanelContent>
50 }
51 >
52 <Flex
53 className="pf-v6-c-wizard__main-body"
54 direction={{ default: 'column' }}
55 spaceItems={{ default: 'spaceItemsLg' }}
56 height="100%"
57 >
58 {!isDrawerExpanded && (
59 <Button isInline variant="link" onClick={onOpenClick}>
60 Open drawer
61 </Button>
62 )}
63 <div>{stepName} content</div>
64 </Flex>
65 </DrawerContent>
66 </Drawer>
67 );
68
69 return (
70 <Modal
71 isOpen
72 variant={ModalVariant.large}
73 showClose={false}
74 hasNoBodyWrapper
75 aria-describedby="wiz-modal-demo-description"
76 aria-labelledby="wiz-modal-demo-title"
77 >
78 <Wizard
79 header={
80 <WizardHeader
81 closeButtonAriaLabel="Close wizard"
82 title="Wizard in modal with drawer"
83 titleId="wiz-modal-demo-title"
84 description="Simple wizard description"
85 descriptionId="wiz-modal-demo-description"
86 />
87 }
88 >
89 <WizardStep body={{ hasNoPadding: true }} name="Information" id="wizard-step-1">
90 {createStepContentWithDrawer('Information step')}
91 </WizardStep>
92 <WizardStep
93 name="Configuration"
94 id="wizard-step-2"
95 steps={[
96 <WizardStep body={{ hasNoPadding: true }} name="Substep A" id="wizard-step-2a" key="wizard-step-2a">
97 {createStepContentWithDrawer('Configuration substep A')}
98 </WizardStep>,
99 <WizardStep body={{ hasNoPadding: true }} name="Substep B" id="wizard-step-2b" key="wizard-step-2b">
100 {createStepContentWithDrawer('Configuration substep B')}
101 </WizardStep>
102 ]}
103 />
104 <WizardStep body={{ hasNoPadding: true }} name="Additional" id="wizard-step-3">
105 {createStepContentWithDrawer('Additional step')}
106 </WizardStep>
107 <WizardStep
108 body={{ hasNoPadding: true }}
109 name="Review"
110 id="wizard-step-4"
111 footer={{ nextButtonText: 'Finish' }}
112 >
113 {createStepContentWithDrawer('Review step')}
114 </WizardStep>
115 </Wizard>
116 </Modal>
117 );
118 };