import React from 'react'; import { EmptyState, EmptyStateHeader, EmptyStateFooter, EmptyStateBody, EmptyStateActions, Form, FormGroup, TextInput, Progress, Button, Alert, EmptyStateIcon } from '@breakaway/preact-core'; import { Wizard as WizardDeprecated, WizardFooter as WizardFooterDeprecated, WizardContextConsumer as WizardContextConsumerDeprecated } from '@breakaway/preact-core/deprecated'; // eslint-disable-next-line patternfly-react/import-tokens-icons import { CogsIcon } from '@patternfly/react-icons'; interface finishedProps { onClose: () => void; } const FinishedStep: React.FunctionComponent = (props: finishedProps) => { const [percent, setPercent] = React.useState(0); const tick = () => { setPercent((prevPercent) => { if (prevPercent < 100) { return prevPercent + 20; } else { return prevPercent; } }); }; React.useEffect(() => { const interval = setInterval(() => tick(), 1000); if (percent >= 100) { clearInterval(interval); } return () => clearInterval(interval); }, [percent]); return (
} /> Description can be used to further elaborate on the validation step, or give the user a better idea of how long the process will take.
); }; interface sampleFormProps { formValue: string; isFormValid: boolean; onChange?: (isValid: boolean, value: string) => void; } const SampleForm: React.FunctionComponent = (props: sampleFormProps) => { const [value, setValue] = React.useState(props.formValue); const [isValid, setIsValid] = React.useState(props.isFormValid); const handleTextInputChange = (_event, value: string) => { const valid = /^\d+$/.test(value); setValue(value); setIsValid(valid); props.onChange && props.onChange(valid, value); }; const validated = isValid ? 'default' : 'error'; return (
); }; export const WizardValidateButtonPress: React.FunctionComponent = () => { const [isFormValid, setIsFormValid] = React.useState(false); const [formValue, setFormValue] = React.useState('Validating on button press'); const [stepsValid, setStepsValid] = React.useState(0); const [errorText, setErrorText] = React.useState(false); const closeWizard = () => { // eslint-disable-next-line no-console console.log('close wizard'); }; const onFormChange = (isValid: boolean, value: string) => { setIsFormValid(isValid); setFormValue(value); }; const validateLastStep: (onNext: () => void) => void = (onNext) => { if (stepsValid !== 1 && !isFormValid) { setErrorText(true); } else { setStepsValid(1); setErrorText(false); onNext(); } }; const steps = [ { name: 'First step', component:

Step 1 content

}, { name: 'Second step', component:

Step 2 content

}, { name: 'Final Step', component: ( <> {errorText && (
)} ) }, { name: 'Finish', component: , isFinishedStep: true } ]; const CustomFooter = ( {({ activeStep, goToStepByName, onNext, onBack, onClose }) => { if (activeStep.name !== 'Final Step') { return ( <> ); } // Final step buttons return ( <> ); }} ); const title = 'Validate on button press wizard example'; return ( ); };