24

运行材质界面 1.0.0-beta.24

我正在使用以下方法设置新主题createMuiTheme

import {createMuiTheme} from 'material-ui/styles';

const theme = createMuiTheme({
  typography: {
    fontSize: 16
  }
});

export default theme;

如何在此处直接访问我要覆盖的主题?我想这样做,这是行不通的:

import {createMuiTheme} from 'material-ui/styles';

const theme = createMuiTheme({
  typography: {
    fontSize: theme.typography.fontSize + 2
  }
});

export default theme;
4

2 回答 2

60

您需要创建默认主题的实例并在定义自己的主题时使用它:

import { createMuiTheme } from 'material-ui/styles';

const defaultTheme = createMuiTheme();

const theme = createMuiTheme({
  typography: {
    fontSize: defaultTheme.typography.fontSize + 2
  }
});

export default theme;
于 2017-12-28T13:29:43.187 回答
8

您还可以创建您的主题,然后在创建后添加到它theme

import { createMuiTheme } from 'material-ui/styles';

const theme = createMuiTheme();
theme.typography = {
  ...theme.typography,
  fontSize: theme.typography.fontSize + 2
}

export default theme;
于 2019-07-20T17:25:30.140 回答