Skip to content

Commit

Permalink
Merge pull request #22 from mjangir/curr-step-in-component
Browse files Browse the repository at this point in the history
feat(current-step): passed current step index as prop in wizard compo…
  • Loading branch information
mjangir authored Mar 28, 2022
2 parents c4190b3 + aed5c6f commit ece0aef
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
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

0 comments on commit ece0aef

Please sign in to comment.