Skip to content

Commit 5ecdc23

Browse files
committed
feat: add wrapper prop to wizard
1 parent 761c4b8 commit 5ecdc23

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ export type WizardProps = {
77
footer?: React.ReactNode;
88
/** Optional start index @default 0 */
99
startIndex?: number;
10+
/**
11+
* Optional wrapper that is exclusively wrapped around the active step component. It is not wrapped around the `header` and `footer`
12+
*
13+
* @example With `framer-motion` - `<AnimatePresence />`
14+
* ```jsx
15+
* <Wizard wrapper={<AnimatePresence exitBeforeEnter />}>
16+
* ...
17+
* </Wizard>
18+
* ```
19+
*/
20+
wrapper?: React.ReactElement;
1021
};
1122

1223
export type WizardValues = {

src/wizard.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Handler, WizardProps } from './types';
55
import WizardContext from './wizardContext';
66

77
const Wizard: React.FC<WizardProps> = React.memo(
8-
({ header, footer, children, startIndex = 0 }) => {
8+
({ header, footer, children, wrapper: Wrapper, startIndex = 0 }) => {
99
const [activeStep, setActiveStep] = React.useState(startIndex);
1010
const [isLoading, setIsLoading] = React.useState(false);
1111
const hasNextStep = React.useRef(true);
@@ -111,10 +111,18 @@ const Wizard: React.FC<WizardProps> = React.memo(
111111
return reactChildren[activeStep];
112112
}, [activeStep, children, header, footer]);
113113

114+
const enhancedActiveStepContent = React.useMemo(
115+
() =>
116+
Wrapper
117+
? React.cloneElement(Wrapper, { children: activeStepContent })
118+
: activeStepContent,
119+
[Wrapper, activeStepContent],
120+
);
121+
114122
return (
115123
<WizardContext.Provider value={wizardValue}>
116124
{header}
117-
{activeStepContent}
125+
{enhancedActiveStepContent}
118126
{footer}
119127
</WizardContext.Provider>
120128
);

0 commit comments

Comments
 (0)