Skip to content

Commit dab1824

Browse files
committed
feat: add sidebarAndStepWrapper prop
Gives ability to add a wrapper around the sidebar and the active step. Useful for styling.
1 parent e82abff commit dab1824

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export type WizardProps = {
1919
* ```
2020
*/
2121
wrapper?: React.ReactElement;
22+
/**
23+
* Optional wrapper that is exclusively wrapped around the sidebar and active step component. It is not wrapped around the `header` and `footer`
24+
* @example With `framer-motion` - `<AnimatePresence />`
25+
* ```jsx
26+
* <Wizard wrapper={<AnimatePresence exitBeforeEnter />}>
27+
* ...
28+
* </Wizard>
29+
* ```
30+
*/
31+
sidebarAndStepWrapper?: React.ReactElement;
2232
/** Callback that will be invoked with the new step index when the wizard changes steps */
2333
onStepChange?: (stepIndex: number) => void;
2434
};
@@ -63,9 +73,7 @@ export type WizardValues = {
6373
/** Indicate if the current step is the last step (aka no next step) */
6474
isLastStep: boolean;
6575
/** The labels of each step */
66-
stepNames: ({
67-
name: any;
68-
} | null)[];
76+
stepNames: StepName[];
6977
};
7078

7179
/** Console log levels */

src/wizard.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
1313
onStepChange,
1414
wrapper: Wrapper,
1515
startIndex = 0,
16+
sidebarAndStepWrapper: SidebarAndStepWrapper,
1617
}) => {
1718
const [activeStep, setActiveStep] = React.useState(startIndex);
1819
const [isLoading, setIsLoading] = React.useState(false);
@@ -163,11 +164,33 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
163164
[Wrapper, activeStepContent],
164165
);
165166

167+
const enhancedActiveStepContentWithSidebar = React.useMemo(
168+
() =>
169+
SidebarAndStepWrapper ? (
170+
React.cloneElement(SidebarAndStepWrapper, {
171+
children: (
172+
<>
173+
{sidebar}
174+
{enhancedActiveStepContent}
175+
</>
176+
),
177+
})
178+
) : (
179+
<>
180+
{sidebar}
181+
{enhancedActiveStepContent}
182+
</>
183+
),
184+
[SidebarAndStepWrapper, sidebar, enhancedActiveStepContent],
185+
);
186+
166187
return (
167188
<WizardContext.Provider value={wizardValue}>
168189
{header}
169-
{sidebar}
170-
{enhancedActiveStepContent}
190+
{sidebar
191+
? enhancedActiveStepContentWithSidebar
192+
: enhancedActiveStepContent}
193+
171194
{footer}
172195
</WizardContext.Provider>
173196
);

0 commit comments

Comments
 (0)