Debian Codegraph @

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

raw
1 import { createContext, useContext, useState } from 'react';
2 import { Checkbox, Wizard, WizardStep } from '@patternfly/react-core';
3
4 interface SomeContextProps {
5 isToggleStepChecked: boolean;
6 setIsToggleStepChecked(isHidden: boolean): void;
7 }
8 type SomeContextRenderProps = Pick<SomeContextProps, 'isToggleStepChecked'>;
9 interface SomeContextProviderProps {
10 children: (context: SomeContextRenderProps) => React.ReactElement<any>;
11 }
12
13 const SomeContext: React.Context<SomeContextProps> = createContext({} as SomeContextProps);
14
15 const SomeContextProvider: React.FunctionComponent<SomeContextProviderProps> = ({ children }) => {
16 const [isToggleStepChecked, setIsToggleStepChecked] = useState(false);
17
18 return (
19 <SomeContext.Provider value={{ isToggleStepChecked, setIsToggleStepChecked }}>
20 {children({ isToggleStepChecked })}
21 </SomeContext.Provider>
22 );
23 };
24
25 const StepContentWithAction: React.FunctionComponent = () => {
26 const { isToggleStepChecked, setIsToggleStepChecked } = useContext(SomeContext);
27
28 return (
29 <Checkbox
30 label="Toggle visibility of the next step"
31 isChecked={isToggleStepChecked}
32 onChange={(_event, checked) => setIsToggleStepChecked(checked)}
33 id="toggle-hide-step-checkbox"
34 name="Toggle Hide Step Checkbox"
35 />
36 );
37 };
38
39 export const WizardToggleStepVisibility: React.FunctionComponent = () => (
40 <SomeContextProvider>
41 {({ isToggleStepChecked }) => (
42 <Wizard height={400} title="Toggle step visibility wizard">
43 <WizardStep name="Hidden action step" id="toggle-visible-step-1">
44 <StepContentWithAction />
45 </WizardStep>
46 <WizardStep name="Step 2" id="toggle-visible-step-2" isHidden={isToggleStepChecked}>
47 Step 2 content
48 </WizardStep>
49 <WizardStep name="Review" id="toggle-visible-review-step" footer={{ nextButtonText: 'Finish' }}>
50 Review step content
51 </WizardStep>
52 </Wizard>
53 )}
54 </SomeContextProvider>
55 );