Debian Codegraph @

node/@patternfly/react-core/src/components/Modal/examples/ModalWithWizard.tsx

raw
1 import { Fragment, useState } from 'react';
2 import { Button, Modal, ModalVariant, Wizard, WizardHeader, WizardStep } from '@patternfly/react-core';
3
4 export const ModalWithWizard: React.FunctionComponent = () => {
5 const [isModalOpen, setIsModalOpen] = useState(false);
6
7 const handleModalToggle = (_event: KeyboardEvent | React.MouseEvent) => {
8 setIsModalOpen((prevIsModalOpen) => !prevIsModalOpen);
9 };
10
11 const handleWizardToggle = () => {
12 setIsModalOpen((prevIsModalOpen) => !prevIsModalOpen);
13 };
14
15 const numberedSteps = [1, 2, 3, 4].map((stepNumber) => (
16 <WizardStep name={`Step ${stepNumber}`} key={`Step ${stepNumber}`} id={`with-wizard-step-${stepNumber}`}>
17 {`Step ${stepNumber}`}
18 </WizardStep>
19 ));
20
21 return (
22 <Fragment>
23 <Button variant="primary" onClick={handleModalToggle}>
24 Show wizard modal
25 </Button>
26 <Modal
27 variant={ModalVariant.large}
28 isOpen={isModalOpen}
29 aria-labelledby="modal-wizard-label"
30 aria-describedby="modal-wizard-description"
31 >
32 <Wizard
33 height={400}
34 header={
35 <WizardHeader
36 title="Wizard modal"
37 titleId="modal-wizard-label"
38 description="This is a wizard inside of a modal."
39 descriptionId="modal-wizard-description"
40 onClose={handleWizardToggle}
41 closeButtonAriaLabel="Close wizard"
42 />
43 }
44 onClose={handleWizardToggle}
45 >
46 {numberedSteps}
47 <WizardStep
48 name="Review"
49 id="with-wizard-review-step"
50 footer={{ nextButtonText: 'Finish', onNext: handleWizardToggle }}
51 >
52 Review step
53 </WizardStep>
54 </Wizard>
55 </Modal>
56 </Fragment>
57 );
58 };