createMuiTheme是否提供缺少属性的默认值?

时间:2019-10-22 20:26:54

标签: reactjs material-ui

我正在使用createMuiTheme()创建主题:

import { createMuiTheme, responsiveFontSizes } from '@material-ui/core/styles';

const theme = responsiveFontSizes(
  createMuiTheme({
    palette: {
      type: 'dark',
      primary: {
        main: '#c5cae9',
        light: '#f8fdff',
        dark: '#9499b7',
        contrastText: '#212121',
      },
      secondary: {
        main: '#5c6bc0',
        light: '#8e99f3',
        dark: '#26418f',
        contrastText: '#ffffff',
      },
    },
    typography: {
      fontFamily: [
        'Roboto',
        'Arial',
        '"Helvetica"',
        'sans-serif',
      ].join(','),
    },
  }),
);

export default theme;

查看default theme时,我缺少许多属性,例如breakpointsdirectionshadowsspacing等。< / p>

即使省略了这些属性,createMuiTheme()是否也提供填充这些字段的默认值?还是我必须自己提供这些价值观。

1 个答案:

答案 0 :(得分:1)

看看createMuiTheme options签名

(Object): Takes an incomplete theme object and adds the missing parts.

是的,您的自定义主题将与MUI的默认主题合并。参见docs here

const options = {palette:{/*such empty*/}}

export const theme = createMuiTheme(options)