Skip to content

Commit 2468984

Browse files
committed
add section for Hooks and address some other feedback
1 parent 6e00aff commit 2468984

10 files changed

Lines changed: 74 additions & 47 deletions

File tree

packages/react-core/src/components/Wizard/Wizard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
6868
onClose?: () => void;
6969
/** Callback function when a step in the nav is clicked */
7070
onGoToStep?: WizardStepFunctionType;
71-
/** Additional classes spread to the Wizard */
71+
/** Additional classes spread to the wizard */
7272
className?: string;
7373
/** The wizard steps configuration object */
7474
steps: WizardStep[];
@@ -88,9 +88,9 @@ export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
8888
footer?: React.ReactNode;
8989
/** (Unused if footer is controlled) Callback function to save at the end of the wizard, if not specified uses onClose */
9090
onSave?: () => void;
91-
/** (Unused if footer is controlled) Callback function after Next button is clicked */
91+
/** (Unused if footer is controlled) Callback function after next button is clicked */
9292
onNext?: WizardStepFunctionType;
93-
/** (Unused if footer is controlled) Callback function after Back button is clicked */
93+
/** (Unused if footer is controlled) Callback function after back button is clicked */
9494
onBack?: WizardStepFunctionType;
9595
/** (Unused if footer is controlled) The Next button text */
9696
nextButtonText?: React.ReactNode;

packages/react-core/src/components/Wizard/examples/Wizard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SlackHashIcon from '@patternfly/react-icons/dist/esm/icons/slack-hash-ico
1313
import FinishedStep from './FinishedStep';
1414
import SampleForm from './SampleForm';
1515

16-
If you seek a Wizard solution that allows for more composition, see the [React next](/components/wizard/react-next) tab.
16+
If you seek a wizard solution that allows for more composition, see the [React next](/components/wizard/react-next) tab.
1717

1818
## Examples
1919

packages/react-core/src/next/components/Wizard/Wizard.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { WizardToggle } from './WizardToggle';
1919

2020
/**
2121
* Wrapper for all steps and hosts state, including navigation helpers, within context.
22-
* The WizardContext provided by default gives any child of Wizard access to those resources.
22+
* The WizardContext provided by default gives any child of wizard access to those resources.
2323
*/
2424

2525
export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
@@ -41,9 +41,9 @@ export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
4141
height?: number | string;
4242
/** Callback function when a step in the nav is clicked */
4343
onNavByIndex?: WizardNavStepFunction;
44-
/** Callback function after Next button is clicked */
44+
/** Callback function after next button is clicked */
4545
onNext?: WizardNavStepFunction;
46-
/** Callback function after Back button is clicked */
46+
/** Callback function after back button is clicked */
4747
onBack?: WizardNavStepFunction;
4848
/** Callback function to save at the end of the wizard, if not specified uses onClose */
4949
onSave?(): void;
@@ -80,20 +80,20 @@ export const Wizard = (props: WizardProps) => {
8080
}
8181

8282
return onClose?.();
83-
} else {
84-
let currStep = steps[currentStepIndex];
85-
let newStepIndex = currentStepIndex + 1;
86-
const prevStep = steps[currentStepIndex - 1];
83+
}
8784

88-
// Skip parent step and focus on the first sub-step if they exist
89-
if (isWizardParentStep(currStep)) {
90-
newStepIndex += 1;
91-
currStep = steps[currentStepIndex + 1];
92-
}
85+
let currStep = steps[currentStepIndex];
86+
let newStepIndex = currentStepIndex + 1;
87+
const prevStep = steps[currentStepIndex - 1];
9388

94-
setCurrentStepIndex(newStepIndex);
95-
return onNext?.(normalizeNavStep(currStep), normalizeNavStep(prevStep));
89+
// Skip parent step and focus on the first sub-step if they exist
90+
if (isWizardParentStep(currStep)) {
91+
newStepIndex += 1;
92+
currStep = steps[currentStepIndex + 1];
9693
}
94+
95+
setCurrentStepIndex(newStepIndex);
96+
return onNext?.(normalizeNavStep(currStep), normalizeNavStep(prevStep));
9797
};
9898

9999
const goToPrevStep = () => {

packages/react-core/src/next/components/Wizard/WizardContext.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@ import { Step, SubStep } from './types';
33
import { getActiveStep } from './utils';
44

55
export interface WizardContextProps {
6+
/** List of steps */
67
steps: (Step | SubStep)[];
8+
/** Active step */
79
activeStep: Step | SubStep;
10+
/** Footer element */
811
footer: React.ReactElement;
12+
/** Navigate to the next step */
913
onNext(): void;
14+
/** Navigate to the previous step */
1015
onBack(): void;
16+
/** Close the wizard */
1117
onClose(): void;
18+
/** Navigate to step by ID */
1219
goToStepById(id: number | string): void;
20+
/** Navigate to step by name */
1321
goToStepByName(name: string): void;
22+
/** Navigate to step by index */
1423
goToStepByIndex(index: number): void;
24+
/** Update the footer with any react element */
1525
setFooter(footer: React.ReactElement): void;
1626
}
1727

@@ -91,5 +101,4 @@ export const WizardContextProvider: React.FunctionComponent<WizardContextProvide
91101
);
92102
};
93103

94-
export const WizardContextConsumer = WizardContext.Consumer;
95104
export const useWizardContext = () => React.useContext(WizardContext);

packages/react-core/src/next/components/Wizard/examples/Wizard.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: Wizard
33
section: components
44
cssPrefix: pf-c-wizard
5-
propComponents: ['Wizard', 'WizardFooter', 'WizardToggle', 'WizardStep', 'WizardBody']
5+
propComponents: ['Wizard', 'WizardStep', 'WizardFooter', 'WizardToggle', 'WizardStep', 'WizardBody', 'WizardContextProps', 'Step', 'SubStep']
66
beta: true
77
---
88

@@ -34,25 +34,7 @@ import {
3434
import { css } from '@patternfly/react-styles';
3535
import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
3636

37-
PatternFly has two implementations of a `Wizard`.
38-
39-
This newer `Wizard` takes a more explicit and declarative approach compared to the older implementation, which can be found under the [React](/components/wizard/react) tab.
40-
41-
## Composable structure
42-
43-
The standard sub-component relationships are arranged as follows:
44-
45-
```noLive
46-
<Wizard>
47-
<WizardStep />
48-
<WizardStep
49-
steps={[
50-
<WizardStep />,
51-
<WizardStep />
52-
]}
53-
/>
54-
</Wizard>
55-
```
37+
PatternFly has two implementations of a `Wizard`. This newer `Wizard` takes a more explicit and declarative approach compared to the older implementation, which can be found under the [React](/components/wizard/react) tab.
5638

5739
## Examples
5840

@@ -61,14 +43,42 @@ The standard sub-component relationships are arranged as follows:
6143
```ts file="./WizardBasic.tsx"
6244
```
6345

64-
### Custom Nav
46+
### Custom navigation
6547

6648
```ts file="./WizardCustomNav.tsx"
6749
```
6850

69-
### Kitchen Sink
51+
### Kitchen sink
7052

7153
Includes a header, custom footer, sub-steps, step content with a drawer, custom nav item, and nav prevention until step visitation.
7254

7355
```ts file="./WizardKitchenSink.tsx"
7456
```
57+
58+
## Hooks
59+
60+
### useWizardFooter
61+
62+
Used to set a unique footer for the wizard on any given step. See step 3 of [Kitchen sink](#kitchen-sink) for a live example.
63+
64+
```noLive
65+
import { useWizardFooter } from '@patternfly/react-core/next';
66+
67+
const StepContent = () => {
68+
useWizardFooter(<>Some footer</>);
69+
return <>Step content</>;
70+
}
71+
```
72+
73+
### useWizardContext
74+
75+
Used to access any property of [WizardContext](#wizardcontextprops):
76+
77+
```noLive
78+
import { useWizardContext } from '@patternfly/react-core/next';
79+
80+
const StepContent = () => {
81+
const { activeStep } = useWizardContext();
82+
return <>This is the active step: {activeStep}</>;
83+
}
84+
```

packages/react-core/src/next/components/Wizard/examples/WizardCustomNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { WizardNav, WizardNavItem } from '@patternfly/react-core';
3-
import { Step, SubStep, Wizard, WizardStep } from '@patternfly/react-core/next';
3+
import { Wizard, WizardStep, Step, SubStep } from '@patternfly/react-core/next';
44

55
export const WizardCustomNav: React.FunctionComponent = () => {
66
const nav = (

packages/react-core/src/next/components/Wizard/examples/WizardKitchenSink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const StepWithCustomFooter = () => {
123123
return <>Step 3 content w/ custom async footer</>;
124124
};
125125

126-
const CustomStepFour = (props: WizardStepProps) => <div {...props} />;
126+
const CustomStepFour = (props: WizardStepProps) => <div {...props} id={props.id.toString()} />;
127127

128128
export const WizardKitchenSink: React.FunctionComponent = () => (
129129
<Wizard
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useWizardFooter } from './useWizardFooter';
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export * from './Wizard';
2-
export * from './WizardContext';
32
export * from './WizardBody';
43
export * from './WizardFooter';
54
export * from './WizardToggle';
65
export * from './WizardStep';
7-
export { useWizardFooter } from './hooks/useWizardFooter';
8-
export * from './types';
6+
export * from './hooks';
7+
export { useWizardContext } from './WizardContext';
8+
9+
import * as Types from './types';
10+
export type Step = Types.Step;
11+
export type SubStep = Types.SubStep;

packages/react-core/src/next/components/Wizard/types.ts renamed to packages/react-core/src/next/components/Wizard/types.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from 'react';
22
import { WizardNavItemProps, WizardNavProps } from '../../../components/Wizard';
33

4+
/** Initially inferred from WizardStep components, these properties represent what is controllable from within WizardContext for a given step. */
5+
46
export interface Step {
57
/** Name of the step's nav item */
68
name: React.ReactNode;
79
/** Unique identifier */
8-
id: string;
10+
id: string | number;
911
/** Flag to disable the step's nav item */
1012
isDisabled?: boolean;
1113
/** Flag to represent whether the step has been visited (navigated to) */
@@ -26,6 +28,8 @@ export interface Step {
2628
hideBackButton?: boolean;
2729
}
2830

31+
/** With the same purpose as Step, SubStep inherits all properties of Step with the exception of subStepIds. */
32+
2933
export interface SubStep extends Omit<Step, 'subStepIds'> {
3034
/** Unique identifier of the parent step */
3135
parentId?: string | number;

0 commit comments

Comments
 (0)