| 1 |
import { useEffect, useState } from 'react'; |
| 2 |
import { |
| 3 |
EmptyState, |
| 4 |
EmptyStateFooter, |
| 5 |
EmptyStateBody, |
| 6 |
EmptyStateActions, |
| 7 |
Progress, |
| 8 |
Button |
| 9 |
} from '@patternfly/react-core'; |
| 10 |
import { Wizard as WizardDeprecated } from '@patternfly/react-core/deprecated'; |
| 11 |
// eslint-disable-next-line patternfly-react/import-tokens-icons |
| 12 |
import { CogsIcon } from '@patternfly/react-icons'; |
| 13 |
import layout from '@patternfly/react-styles/css/layouts/Bullseye/bullseye'; |
| 14 |
|
| 15 |
interface finishedProps { |
| 16 |
onClose: () => void; |
| 17 |
} |
| 18 |
|
| 19 |
const FinishedStep: React.FunctionComponent<finishedProps> = (props: finishedProps) => { |
| 20 |
const [percent, setPercent] = useState(0); |
| 21 |
|
| 22 |
const tick = () => { |
| 23 |
setPercent((prevPercent) => { |
| 24 |
if (prevPercent < 100) { |
| 25 |
return prevPercent + 20; |
| 26 |
} else { |
| 27 |
return prevPercent; |
| 28 |
} |
| 29 |
}); |
| 30 |
}; |
| 31 |
|
| 32 |
useEffect(() => { |
| 33 |
const interval = setInterval(() => tick(), 1000); |
| 34 |
|
| 35 |
if (percent >= 100) { |
| 36 |
clearInterval(interval); |
| 37 |
} |
| 38 |
|
| 39 |
return () => clearInterval(interval); |
| 40 |
}, [percent]); |
| 41 |
|
| 42 |
return ( |
| 43 |
<div className={layout.bullseye}> |
| 44 |
<EmptyState |
| 45 |
headingLevel="h4" |
| 46 |
titleText={percent === 100 ? 'Validation complete' : 'Validating credentials'} |
| 47 |
icon={CogsIcon} |
| 48 |
variant="lg" |
| 49 |
> |
| 50 |
<EmptyStateBody> |
| 51 |
<Progress value={percent} measureLocation="outside" aria-label="validation-progress" /> |
| 52 |
</EmptyStateBody> |
| 53 |
<EmptyStateBody> |
| 54 |
Description can be used to further elaborate on the validation step, or give the user a better idea of how |
| 55 |
long the process will take. |
| 56 |
</EmptyStateBody> |
| 57 |
<EmptyStateFooter> |
| 58 |
<EmptyStateActions> |
| 59 |
<Button isDisabled={percent !== 100} onClick={props.onClose}> |
| 60 |
Log to console |
| 61 |
</Button> |
| 62 |
</EmptyStateActions> |
| 63 |
</EmptyStateFooter> |
| 64 |
</EmptyState> |
| 65 |
</div> |
| 66 |
); |
| 67 |
}; |
| 68 |
|
| 69 |
export const WizardFinished: React.FunctionComponent = () => { |
| 70 |
const closeWizard = () => { |
| 71 |
// eslint-disable-next-line no-console |
| 72 |
console.log('close wizard'); |
| 73 |
}; |
| 74 |
|
| 75 |
const steps = [ |
| 76 |
{ name: 'First step', component: <p>Step 1 content</p> }, |
| 77 |
{ name: 'Second step', component: <p>Step 2 content</p> }, |
| 78 |
{ name: 'Third step', component: <p>Step 3 content</p> }, |
| 79 |
{ name: 'Fourth step', component: <p>Step 4 content</p> }, |
| 80 |
{ name: 'Review', component: <p>Review step content</p>, nextButtonText: 'Finish' }, |
| 81 |
{ name: 'Finish', component: <FinishedStep onClose={closeWizard} />, isFinishedStep: true } |
| 82 |
]; |
| 83 |
const title = 'Finished wizard example'; |
| 84 |
return ( |
| 85 |
<WizardDeprecated |
| 86 |
navAriaLabel={`${title} steps`} |
| 87 |
mainAriaLabel={`${title} content`} |
| 88 |
onClose={closeWizard} |
| 89 |
steps={steps} |
| 90 |
height={400} |
| 91 |
/> |
| 92 |
); |
| 93 |
}; |