Skip to content

Commit 2af9d8f

Browse files
committed
feat: support sidebar property
1 parent eacb209 commit 2af9d8f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ export type Handler = (() => Promise<void>) | (() => void) | null;
33
export type WizardProps = {
44
/** Optional header that is shown above the active step */
55
header?: React.ReactNode;
6+
/** Optional sidebar that is shown before the active step */
7+
sidebar?: React.ReactNode;
68
/** Optional footer that is shown below the active step */
79
footer?: React.ReactNode;
810
/** Optional start index @default 0 */
911
startIndex?: number;
1012
/**
11-
* Optional wrapper that is exclusively wrapped around the active step component. It is not wrapped around the `header` and `footer`
13+
* Optional wrapper that is exclusively wrapped around the active step component. It is not wrapped around the `header`, `sidebar` and `footer`
1214
* @example With `framer-motion` - `<AnimatePresence />`
1315
* ```jsx
1416
* <Wizard wrapper={<AnimatePresence exitBeforeEnter />}>

src/wizard.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import WizardContext from './wizardContext';
77
const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
88
({
99
header,
10+
sidebar,
1011
footer,
1112
children,
1213
onStepChange,
@@ -126,14 +127,19 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
126127
if (header && !React.isValidElement(header)) {
127128
logger.log('error', 'Invalid header passed to <Wizard>');
128129
}
130+
// Invalid sidebar element
131+
if (sidebar && !React.isValidElement(sidebar)) {
132+
logger.log('error', 'Invalid sidebar passed to <Wizard>');
133+
}
134+
129135
// Invalid footer element
130136
if (footer && !React.isValidElement(footer)) {
131137
logger.log('error', 'Invalid footer passed to <Wizard>');
132138
}
133139
}
134140

135141
return reactChildren[activeStep];
136-
}, [activeStep, children, header, footer]);
142+
}, [activeStep, children, header, sidebar, footer]);
137143

138144
const enhancedActiveStepContent = React.useMemo(
139145
() =>
@@ -146,6 +152,7 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
146152
return (
147153
<WizardContext.Provider value={wizardValue}>
148154
{header}
155+
{sidebar}
149156
{enhancedActiveStepContent}
150157
{footer}
151158
</WizardContext.Provider>

0 commit comments

Comments
 (0)