Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize colors in Material UI Stepper Step?

I am trying to customize the disabled Step color on Material UI Steppers

The default color is Blue (Enabled) + Grey (Disabled). But I am looking to change this to something like so:

enter image description here

But I don't seem to able to find any hook into the Icon section of the StepLabel. I already tried applying the CSS to the IconContainer, but the specificity is not sufficient.

My code is available here: https://codesandbox.io/s/0102v4z1op

TIA!

like image 524
nikjohn Avatar asked Sep 03 '18 16:09

nikjohn


People also ask

How do I change the material color on my UI stepper?

The color of the stepper bullets can't be changed using any props directly. We can change it by using a theme.

How do I change the stepper color on my flutter?

Wrap your stepper in a Theme Widget. It will change the index color of the stepper as well as the CONTINUE button color to orange(Set the color as per your own requirement). Save this answer.


2 Answers

<Stepper
      activeStep={activeStep}
      orientation="vertical"
      connector={false}
    >
      {steps.map((label, index) => {
        return (
          <Step key={label} className={classes.step} classes={{ completed: classes.completed }}>
            <StepButton icon={<DeleteIcon className={classes.xiconRoot}/>} completed={index === 2}>
              <StepLabel
                classes={{
                  iconContainer: classes.iconContainer
                }}
              >
                {label}
              </StepLabel>
            </StepButton>
          </Step>
        );
      })}
</Stepper>

Similary to completed in classes applied to Step You can apply the following to override different states. https://material-ui.com/api/step/#css-api

Complete example snippet https://codesandbox.io/s/vn8m2rqol3

like image 159
Adeel Imran Avatar answered Sep 28 '22 05:09

Adeel Imran


I did it like this:

        <StepLabel
          classes={{
            alternativeLabel: classes.alternativeLabel,
            labelContainer: classes.labelContainer
          }}
          StepIconProps={{
            classes: {
              root: classes.step,
              completed: classes.completed,
              active: classes.active,
              disabled: classes.disabled
            }
          }}
        >
          {this.state.labels[label - 1]}
        </StepLabel>

And then in the classes I've defined them as follows:

  step: {
    "&$completed": {
      color: "lightgreen"
    },
    "&$active": {
      color: "pink"
    },
    "&$disabled: {
      color: "red"
    },
  },
  alternativeLabel: {},
  active: {}, //needed so that the &$active tag works
  completed: {},
  disabled: {},
  labelContainer: {
    "&$alternativeLabel": {
      marginTop: 0
    },
  },
like image 34
Ally Haire Avatar answered Sep 28 '22 05:09

Ally Haire