Debian Codegraph @

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

raw
1 import { useCallback, useEffect, useState } from 'react';
2 import {
3 EmptyState,
4 EmptyStateFooter,
5 EmptyStateBody,
6 EmptyStateActions,
7 Progress,
8 Button,
9 Wizard,
10 WizardStep
11 } from '@patternfly/react-core';
12 import CogsIcon from '@patternfly/react-icons/dist/esm/icons/cogs-icon';
13 import layout from '@patternfly/react-styles/css/layouts/Bullseye/bullseye';
14
15 interface ValidationProgressProps {
16 onClose(): void;
17 }
18
19 const ValidationProgress: React.FunctionComponent<ValidationProgressProps> = ({ onClose }) => {
20 const [percentValidated, setPercentValidated] = useState(0);
21
22 const tick = useCallback(() => {
23 if (percentValidated < 100) {
24 setPercentValidated((prevValue) => prevValue + 20);
25 }
26 }, [percentValidated]);
27
28 useEffect(() => {
29 const interval = setInterval(() => tick(), 1000);
30
31 return () => {
32 clearInterval(interval);
33 };
34 }, [tick]);
35
36 return (
37 <div className={layout.bullseye}>
38 <EmptyState
39 headingLevel="h4"
40 titleText={percentValidated === 100 ? 'Validation complete' : 'Validating credentials'}
41 icon={CogsIcon}
42 variant="lg"
43 >
44 <EmptyStateBody>
45 <Progress value={percentValidated} measureLocation="outside" aria-label="Wizard validation progress" />
46 </EmptyStateBody>
47 <EmptyStateBody>
48 Description can be used to further elaborate on the validation step, or give the user a better idea of how
49 long the process will take.
50 </EmptyStateBody>
51 <EmptyStateFooter>
52 <EmptyStateActions>
53 <Button isDisabled={percentValidated !== 100} onClick={onClose}>
54 Log to console
55 </Button>
56 </EmptyStateActions>
57 </EmptyStateFooter>
58 </EmptyState>
59 </div>
60 );
61 };
62
63 export const WizardWithSubmitProgress: React.FunctionComponent = () => {
64 const [isSubmitted, setIsSubmitted] = useState(false);
65
66 // eslint-disable-next-line no-console
67 const onClose = () => console.log('Some close action occurs here.');
68
69 if (isSubmitted) {
70 return <ValidationProgress onClose={onClose} />;
71 }
72
73 return (
74 <Wizard height={400} title="Submit progress wizard" onClose={onClose}>
75 <WizardStep name="Step 1" id="submit-progress-step-1">
76 Step 1 content
77 </WizardStep>
78 <WizardStep name="Step 2" id="submit-progress-step-2">
79 Step 2 content
80 </WizardStep>
81 <WizardStep
82 name="Review"
83 id="submit-progress-review"
84 footer={{ nextButtonText: 'Finish', onNext: () => setIsSubmitted(true) }}
85 >
86 Review step content
87 </WizardStep>
88 </Wizard>
89 );
90 };