如何覆盖StepLabel的活动颜色和字体粗细

时间:2018-06-10 05:51:41

标签: javascript reactjs material-ui

我尝试通过添加以下内容来覆盖StepLabel的活动颜色和字体粗细:

const StepLabelStyles = theme => ({
    active: {
    paddingBottom: "19px",
    borderBottom: "#ffffff 3px solid",
    color: "#dddddd"
},

label: {
    paddingBottom: "19px",
    color: "#7b7b7b"
},

iconContainer: {
    paddingBottom: "19px"
}
});
const StepLabelStyled = withStyles(StepLabelStyles)(StepLabel);

并且我的颜色不适用。

2 个答案:

答案 0 :(得分:0)

我的解决方案:

export const MyStepper = withStyles({
    rootClass: {
        color: "blue",                  // default icon color
        "& span": { color: "magenta" }, // default label color
        "& $done": { color: "green" },
        "& $active": { color: "orange", fontWeight: 'bold' },
        "& $fail": { color: "pink" },
    },
    done: {},   // this empty property is necessary
    active: {}, // this empty property is necessary
    fail: {},   // this empty property is necessary
})((props) => {

    const { classes } = props;
    return (
        <Stepper activeStep={ 2 }>
            { [ 'A', 'B', 'C', 'D', 'E' ].map( label => {
                return (
                    <Step key={ label } >
                        <StepLabel
                            error={ label === 'B' }
                            classes={ {         // label colors
                                root: classes.rootClass,
                                completed: classes.done,
                                active: classes.active,
                                error: classes.fail
                            } }

                            StepIconProps={ {    // icon colors
                                classes: {
                                    root: classes.rootClass,
                                    completed: classes.done,
                                    active: classes.active,
                                    error: classes.fail
                                }
                            } }
                        >
                            { label }
                        </StepLabel>
                    </Step>
                );
            })}
        </Stepper>
    );
});

编辑: 或者使用!important规则:

{
    rootClass: {
        color: "blue",                  // default icon color
        "& span": { color: "magenta" }, // default label color
    },
    done: { color: "green !important" },
    active: { color: "orange !important", fontWeight: 'bold' },
    fail: { color: "pink !important" }
}

答案 1 :(得分:0)

在我的主题中,它与!important和StepIconProps配合使用

    const styles = theme => ({
        stepIcon: {color: theme.palette.primary.main,},
        done: { color: theme.palette.secondary.dark+" !important" },
        active: { color: theme.palette.secondary.light+" !important"},
        fail: { color: "red !important" },
    )}

    <StepLabel {...labelProps} 
        StepIconProps={{
            classes: { 
               root: classes.stepIcon,
               completed: classes.done,
               active: classes.active,
               error: classes.fail
            }
        }}
    >