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

Properly align wizard stepper labels #522

Merged
merged 1 commit into from
Jun 4, 2024
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
8 changes: 5 additions & 3 deletions src/components/shared/wizard/WizardStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cn from "classnames";
import { Step, StepButton, StepLabel, Stepper } from "@mui/material";
import {
isSummaryReachable,
useStepLabelStyles,
useStepperStyle,
} from "../../../utils/wizardUtils";
import CustomStepIcon from "./CustomStepIcon";
Expand Down Expand Up @@ -38,7 +39,8 @@ const WizardStepper = ({
const { t } = useTranslation();
const dispatch = useAppDispatch();

const classes = useStepperStyle();
const stepperClasses = useStepperStyle();
const labelClasses = useStepLabelStyles();

const handleOnClick = async (key: number) => {
if (isSummaryReachable(key, steps, completed)) {
Expand Down Expand Up @@ -67,13 +69,13 @@ const WizardStepper = ({
alternativeLabel
// @ts-expect-error TS(2322): Type 'boolean' is not assignable to type 'ReactEle... Remove this comment to see the full error message
connector={false}
className={cn("step-by-step", classes.root)}
className={cn("step-by-step", stepperClasses.root)}
>
{steps.map((label, key) =>
!label.hidden ? (
<Step key={label.translation} completed={completed[key]}>
<StepButton onClick={() => handleOnClick(key)} disabled={disabled}>
<StepLabel StepIconComponent={CustomStepIcon}>
<StepLabel className={labelClasses.root} StepIconComponent={CustomStepIcon}>
{t(label.translation)}
</StepLabel>
</StepButton>
Expand Down
8 changes: 5 additions & 3 deletions src/components/shared/wizard/WizardStepperEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cn from "classnames";
import { Step, StepButton, StepLabel, Stepper } from "@mui/material";
import {
isSummaryReachable,
useStepLabelStyles,
useStepperStyle,
} from "../../../utils/wizardUtils";
import CustomStepIcon from "./CustomStepIcon";
Expand All @@ -30,7 +31,8 @@ const WizardStepperEvent = ({
}) => {
const { t } = useTranslation();

const classes = useStepperStyle();
const stepperClasses = useStepperStyle();
const labelClasses = useStepLabelStyles();

const handleOnClick = async (key: number) => {
if (isSummaryReachable(key, steps, completed)) {
Expand Down Expand Up @@ -60,13 +62,13 @@ const WizardStepperEvent = ({
alternativeLabel
// @ts-expect-error TS(2322): Type 'boolean' is not assignable to type 'ReactEle... Remove this comment to see the full error message
connector={false}
className={cn("step-by-step", classes.root)}
className={cn("step-by-step", stepperClasses.root)}
>
{steps.map((label, key) =>
!label.hidden ? (
<Step key={label.translation} completed={completed[key]}>
<StepButton onClick={() => handleOnClick(key)}>
<StepLabel StepIconComponent={CustomStepIcon}>
<StepLabel className={labelClasses.root} StepIconComponent={CustomStepIcon}>
{t(label.translation)}
</StepLabel>
</StepButton>
Expand Down
7 changes: 7 additions & 0 deletions src/utils/wizardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export const useStepperStyle = makeStyles({
},
});

// Properly align multi-line wizard step labels
export const useStepLabelStyles = makeStyles({
root: {
alignSelf: "flex-start",
},
});

// Style of icons used in Stepper
type stepIconStyleProps = {
active: boolean,
Expand Down
Loading