-
Notifications
You must be signed in to change notification settings - Fork 2
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
New Stepper Component #388
Conversation
jay-deshmukh
commented
Sep 27, 2024
✅ Deploy Preview for nifty-johnson-6002dd ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lib version is not incremented in package.json. Otherwise LGTM.
if (currentStep < steps.length - 1) { | ||
const nextStep = currentStep + 1; | ||
setCurrentStep(nextStep); | ||
onStepChange(steps[nextStep]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this onStepChange, should accept a parameter a function (or a function should be one of the optiosn). If this function evaluates to true, then the step is changed. This way it will allow me in the code to write some validation, and then the step to change. @ifrim wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I would await
on the response of the onStepChange
call. This way you can make sync or async validations in the function. And then go ahead and increment the step only if the awaited value is truthy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I see it is that the problem that needs to be solved is that the user interacts with the component and then a decision needs to be made if the step is changed or not (in which case an error may or may not be displayed).
The simplest API I can think of for this is using a callback called at the moment of the user interaction and doing stuff based on the response.
The validations need to happen at the moment the user requested the step change. In order to do this with the props based approach then the parent component will need to know the next step and the moment the user interacted with the component requesting the step change. It will also need to keep track of the current step and transition the value of allowNextStep
when the step changes and while the validations are running. This is boilerplate code that will need to be replicated every time you would use the component. I would rather have this encapsulated inside the component. It will also be easier to do future changes if everything that is not specific to a use case is inside the component instead of the outside.
Having said that not sure if I completely understand the use cases for this component so whatever you think is best.
Quality Gate passedIssues Measures |