Skip to content

Commit

Permalink
feat(Wizard): allow disabled and loading state through the wizard con…
Browse files Browse the repository at this point in the history
…text. (#4085)

* fix: prevent wizard tab change if no return from handleBeforeNext
* feat: allow user to define disable and loading state through the wizard context
  • Loading branch information
rubenbarroshv committed Mar 19, 2024
1 parent 2720fee commit 9f3f231
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/lab/src/Wizard/WizardActions/WizardActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ export const HvWizardActions = ({
<HvButton
variant="secondaryGhost"
className={cx(classes.buttonWidth, classes.buttonSpacing)}
onClick={() => handleBeforeNext?.() || setTab((t) => t + 1)}
onClick={() => {
if (handleBeforeNext) {
handleBeforeNext();
} else {
setTab((t) => t + 1);
}
}}
disabled={!skippable && !context?.[tab]?.valid}
endIcon={<Forwards />}
>
Expand Down
2 changes: 2 additions & 0 deletions packages/lab/src/Wizard/WizardContext/WizardContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type HvWizardTab = {
touched?: boolean;
form?: any;
children?: React.ReactNode;
disabled?: boolean;
loading?: boolean;
[other: string]: any;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/lab/src/Wizard/WizardTitle/WizardTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export interface HvWizardTitleProps extends HvBaseProps {
}

const switchTabState = (state, currentTab, index) => {
if (state.loading) return "Pending";
if (index === currentTab) return "Current";
if (state.valid) return "Completed";
if (state.disabled) return "Disabled";
if (state.valid === null) return "Enabled";
if (state.touched && state.valid === false) return "Failed";
// "Disabled"
// "Pending"
return "Enabled";
};

Expand Down

0 comments on commit 9f3f231

Please sign in to comment.