【问题标题】:Does createMuiTheme provide default values for missing properties?createMuiTheme 是否为缺少的属性提供默认值?
【发布时间】:2019-10-22 20:26:54
【问题描述】:

我正在使用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 等。

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

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    看看createMuiThemeoptions签名

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

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

    const options = {palette:{/*such empty*/}}
    
    export const theme = createMuiTheme(options)
    

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 2019-01-02
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 2015-06-12
      • 2022-11-11
      • 1970-01-01
      相关资源
      最近更新 更多