Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(current-step): passed current step index as prop in wizard compo… #22

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-rats-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'formik-wizard-form': minor
---

Passed current step index to wizard components as prop
7 changes: 6 additions & 1 deletion src/FormkWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const FormikWizard = ({
currentStepIndex,
isPrevDisabled,
isNextDisabled: (validateOnNext && !formikBag.isValid) || false,
renderComponent: () => <StepComponent {...formikBag} />,
renderComponent: () => (
<StepComponent
{...formikBag}
currentStepIndex={currentStepIndex}
/>
),
};

return children({
Expand Down
4 changes: 3 additions & 1 deletion src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export type Step = {
) => Promise<any>;

/** React functional or class component */
component: React.ComponentType<FormikProps<FormikValues>>;
component: React.ComponentType<
FormikProps<FormikValues> & { currentStepIndex: number }
>;
};

export interface RenderProps extends FormikProps<FormikValues> {
Expand Down
4 changes: 3 additions & 1 deletion src/useFormikWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const useFormikWizard = ({
currentStepIndex,
isPrevDisabled,
isNextDisabled: (validateOnNext && !formik.isValid) || false,
renderComponent: () => <StepComponent {...formik} />,
renderComponent: () => (
<StepComponent {...formik} currentStepIndex={currentStepIndex} />
),
};
};

Expand Down