Debian Codegraph @

node/@patternfly/react-core/src/components/Wizard/examples/WizardWithCustomFooter.tsx

raw
1 import { useState } from 'react';
2 import {
3 ActionList,
4 ActionListGroup,
5 ActionListItem,
6 Button,
7 Flex,
8 FlexItem,
9 Spinner,
10 useWizardContext,
11 Wizard,
12 WizardFooter,
13 WizardFooterWrapper,
14 WizardStep
15 } from '@patternfly/react-core';
16
17 const CustomWizardFooter = () => {
18 const { activeStep, goToNextStep, goToPrevStep, close } = useWizardContext();
19
20 return (
21 <WizardFooter
22 activeStep={activeStep}
23 onNext={goToNextStep}
24 onBack={goToPrevStep}
25 onClose={close}
26 isBackDisabled={activeStep.index === 1}
27 />
28 );
29 };
30
31 const CustomStepTwoFooter = () => {
32 const { goToNextStep, goToPrevStep, close } = useWizardContext();
33 const [isLoading, setIsLoading] = useState(false);
34
35 async function onNext() {
36 setIsLoading(true);
37 await new Promise((resolve) => setTimeout(resolve, 2000));
38 setIsLoading(false);
39
40 goToNextStep();
41 }
42
43 return (
44 <WizardFooterWrapper>
45 <ActionList>
46 <ActionListGroup>
47 <ActionListItem>
48 <Button variant="secondary" onClick={goToPrevStep} isDisabled={isLoading}>
49 Back
50 </Button>
51 </ActionListItem>
52 <ActionListItem>
53 <Button variant="primary" onClick={onNext} isLoading={isLoading} isDisabled={isLoading}>
54 Async Next
55 </Button>
56 </ActionListItem>
57 </ActionListGroup>
58 <ActionListGroup>
59 <ActionListItem>
60 <Button variant="link" onClick={close} isDisabled={isLoading}>
61 Cancel
62 </Button>
63 </ActionListItem>
64 </ActionListGroup>
65 </ActionList>
66 </WizardFooterWrapper>
67 );
68 };
69
70 interface ReviewStepContentProps {
71 isSubmitting: boolean | undefined;
72 }
73
74 const ReviewStepContent: React.FunctionComponent<ReviewStepContentProps> = ({ isSubmitting }) => {
75 if (isSubmitting === undefined) {
76 return <FlexItem alignSelf={{ default: 'alignSelfFlexStart' }}>Review step content</FlexItem>;
77 }
78
79 if (isSubmitting) {
80 return (
81 <>
82 <div>Calculating wizard score...</div>
83 <Spinner />
84 </>
85 );
86 }
87
88 return <>50 points to Gryffindor!</>;
89 };
90
91 export const WizardWithCustomFooter: React.FunctionComponent = () => {
92 const [isSubmitting, setIsSubmitting] = useState<boolean>();
93
94 async function onSubmit(): Promise<void> {
95 setIsSubmitting(true);
96
97 await new Promise((resolve) => setTimeout(resolve, 5000));
98
99 setIsSubmitting(false);
100 }
101
102 return (
103 <Wizard height={400} title="Custom footer wizard" footer={<CustomWizardFooter />}>
104 <WizardStep name="Step 1" id="custom-footer-first-step">
105 Step 1 content
106 </WizardStep>
107 <WizardStep id="custom-footer-second-step" name="Step 2" footer={<CustomStepTwoFooter />}>
108 Step 2 content with a custom async footer
109 </WizardStep>
110 <WizardStep
111 id="custom-footer-review-step"
112 name="Review"
113 footer={{
114 nextButtonText: 'Submit',
115 onNext: onSubmit,
116 isNextDisabled: isSubmitting,
117 isBackDisabled: isSubmitting
118 }}
119 >
120 <Flex
121 direction={{ default: 'column' }}
122 alignItems={{ default: 'alignItemsCenter' }}
123 spaceItems={{ default: 'spaceItemsLg' }}
124 >
125 <ReviewStepContent isSubmitting={isSubmitting} />
126 </Flex>
127 </WizardStep>
128 </Wizard>
129 );
130 };