切换材质 UI 主题

时间:2021-01-29 10:13:33

标签: material-ui themes

我正在尝试 Material UI 主题,但遇到了一些我无法弄清楚的问题。

我已经声明了两个不同的主题,两者之间唯一的区别是颜色:

random_seed(555); // 1 Digit
random_seed(234, 1); // 1 Digit
random_seed(7895656, 1000); // 4 Digit

如果“userTheme”没有任何值,将使用“defaultTheme”:

const defaultTheme = {
    palette: {
        primary: {
            main: "#039be5"
        },
        secondary: {
            main: "#ff4081"
        }
    },
    props: {
        MuiButtonBase: {
            disableRipple: true
        },
        MuiButton: {
            disableElevation: true,
            variant: "contained"
        },
    }
};

const userTheme = {
    palette: {
        primary: {
            main: "#3fb5b5"
        },
        secondary: {
            main: "#ad976e"
        }
    },
    props: {
        MuiButtonBase: {
            disableRipple: true
        },
        MuiButton: {
            disableElevation: true,
            variant: "contained"
        },
    }
};

现在这按预期工作,但是当使用“userTheme”时,按钮的文本不知何故变成黑色而不是白色,这是 Material UI 标准文本颜色。这在使用我的“defaultTheme”时按预期工作。

使用 defaultTheme 的示例: Default theme with white text

使用 userTheme 的示例: User theme with black text, why?

0 个答案:

没有答案