Accessing previous theme variables in createMuiTheme

谁说我不能喝 提交于 2019-12-08 16:12:06

问题


Running Material UI 1.0.0-beta.24

I'm setting a new theme using createMuiTheme:

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

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

export default theme;

How can I access the theme I'm overriding directly here ? I'd like to do this, which is not working :

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

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

export default theme;

回答1:


You'd need to create an instance of the default theme and use it when defining your own:

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

const defaultTheme = createMuiTheme();

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

export default theme;



回答2:


You can also create your theme and then add on to it after theme is created.

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

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

export default theme;


来源:https://stackoverflow.com/questions/47977618/accessing-previous-theme-variables-in-createmuitheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!