Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing previous theme variables in createMuiTheme

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;
like image 903
Romainpetit Avatar asked Dec 26 '17 11:12

Romainpetit


2 Answers

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; 
like image 105
Ken Gregory Avatar answered Sep 24 '22 00:09

Ken Gregory


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 = {
  ...theme.typography,
  fontSize: theme.typography.fontSize + 2
}

export default theme;
like image 27
zeckdude Avatar answered Sep 26 '22 00:09

zeckdude