在createMuiTheme中访问以前的主题变量

问题描述 投票:6回答:1

运行材料UI 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;
reactjs material-ui theming jss
1个回答
17
投票

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

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

const defaultTheme = createMuiTheme();

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

export default theme;
© www.soinside.com 2019 - 2024. All rights reserved.