Skip to content

Commit

Permalink
stepper: group stepnumber and stepProps
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed Nov 21, 2023
1 parent 7546d6b commit 86172fa
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/lib/components/steppers/Stepper.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,27 @@ export const Stepper = <T extends any[]>({
}: {
steps: readonly [...Steps<T>];
}) => {
const [currentStep, setCurrentStep] = useState<number>(0);
const [stepProps, setStepProps] = useState<Record<string, unknown>>({});
// const [currentStep, setCurrentStep] = useState<number>(0);
const [stepProps, setStepProps] = useState<{
step: number;
props: Record<string, unknown>;
}>({ step: 0, props: {} });

const next = (props: Record<string, unknown>) => {
setCurrentStep(currentStep + 1);
setStepProps(props);
setStepProps({ step: stepProps.step + 1, props });
};

const prev = (props: Record<string, unknown>) => {
setCurrentStep(currentStep - 1);
setStepProps(props);
setStepProps({ step: stepProps.step - 1, props });
};

const { Component } = steps[currentStep];
const { Component } = steps[stepProps.step];

return (
<window.StepperContext.Provider value={{ next, prev }}>
<Box display={'flex'} gap={32} padding={16} flex={1}>
<Steppers
activeStep={currentStep}
activeStep={stepProps.step}
steps={steps.map((step) => {
return {
title: step.label,
Expand Down

0 comments on commit 86172fa

Please sign in to comment.