material-ui createMuiTheme调色板类型为dark不会将textcolor更改为light

时间:2018-08-28 23:45:44

标签: reactjs material-ui material-ui-next

Screenshot

我已经设置了调色板类型:createMuiTheme中为dark,它将背景颜色更改为Dark,这很好。但是文字颜色保持黑色。它不应该适应较浅的颜色吗?

CodeSandbox链接:https://codesandbox.io/s/j22rvq4w2v

Sonarqube version is Version 6.7 (build 33306).

该应用程序组件仅包含一个AppBar和简单文本。

更新 :我拥有的Material-ui版本,我之前提到的v1版本不正确。抱歉,错误信息是3.10.10

3 个答案:

答案 0 :(得分:4)

您只是误解了 CssBaseline 的用途。该组件是某种CSS重置器,不会添加任何视觉样式-只是布局和框大小设置。

您真正想要的是Typography component

请参见updated and working CodeSandbox

答案 1 :(得分:0)

您需要导入正确的颜色,然后:

import React from "react";
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";
import blueGrey from "@material-ui/core/colors/blueGrey";
import lightGreen from "@material-ui/core/colors/lightGreen";
import Reset from "@material-ui/core/CssBaseline";

const theme = createMuiTheme({
  palette: {
    primary: {
      light: lightGreen[300],
      main: lightGreen[500],
      dark: lightGreen[700]
    },
    secondary: {
      light: blueGrey[300],
      main: blueGrey[500],
      dark: blueGrey[700]
    }
  }
});

PD:也许会更新material-u v.3 希望对您有帮助

答案 2 :(得分:0)

只需将@material-ui/core升级到 v3.0.1 。它应该像魅力一样工作。