【问题标题】:Error with createMuiTheme when using current and latest versions of material-ui使用当前和最新版本的 material-ui 时 createMuiTheme 出错
【发布时间】:2018-02-14 13:49:10
【问题描述】:

我已经分叉了 material-ui v1-beta 分支,构建了它,将 package.json 中的名称更改为 material-ui-beta 以防止它安装为覆盖当前版本的 material-ui。

这工作正常,直到我想使用来自材料 ui 的 beta 版本的 createMuiTheme 定义一个主题。这会引发以下错误:

TypeError: Cannot read property 'secondary' of undefined
createTypography
node_modules/material-ui-beta/styles/typography.js:52
  49 |   fontFamily: fontFamily,
  50 |   letterSpacing: '-.04em',
  51 |   lineHeight: 1,
> 52 |   color: palette.text.secondary
  53 | },
  54 | display3: {
  55 |   fontSize: 56,

我想知道是否有其他人遇到过这个问题或者可以指出我哪里出错了?

谢谢。

【问题讨论】:

    标签: material-ui


    【解决方案1】:

    我今天遇到了这个问题,它与createMuiTheme 中为palette.text 传递的值有关。我们之前一直路过

    const muiTheme = createMuiTheme({
      palette: {
        primary: colors[customer.colors.primary],
        secondary: colors[customer.colors.secondary],
        text: colors.white,
        type: 'light',
        background: colors.white,
        grey: colors.grey
      },
    });
    

    事实证明,值colors.white 没有secondary 属性(未在colors page 中列出)。因为我们没有对textbackgroundgrey 进行自定义,所以我们决定将它们从选项对象中删除。但是,您似乎可以为 text 值选择文档中列出的任何其他颜色

    【讨论】:

      猜你喜欢
      • 2019-02-06
      • 2021-10-24
      • 2021-01-03
      • 2020-04-06
      • 1970-01-01
      • 2020-05-02
      • 2020-04-25
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多