如何在Material UI Stepper Step中自定义颜色?

时间:2018-09-03 16:58:37

标签: javascript css reactjs material-ui

我正在尝试自定义Material UI Steppers上禁用的Step颜色

默认颜色为蓝色(启用)+灰色(禁用)。但我希望将其更改为类似的内容:

enter image description here

但是我似乎无法找到Icon的{​​{1}}部分的任何钩子。我已经尝试过将CSS应用于StepLabel,但是特异性还不够。

我的代码在此处可用:https://codesandbox.io/s/0102v4z1op

TIA!

2 个答案:

答案 0 :(得分:2)

<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>

应用于completed的{​​{1}}中classes的符号您可以应用以下内容来覆盖不同的状态。 https://material-ui.com/api/step/#css-api

完整的示例代码段https://codesandbox.io/s/vn8m2rqol3

答案 1 :(得分:0)

我是这样做的:

        <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>

然后在类中,我将它们定义如下:

  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
    }
  },