【问题标题】:How to override material ui shadows in the theme如何覆盖主题中的材质ui阴影
【发布时间】:2021-04-23 19:14:56
【问题描述】:
import {
  createMuiTheme, responsiveFontSizes,
} from "@material-ui/core/styles";

let theme = createMuiTheme({
  palette: {
    primary: {
      main: "#000",
    },
    secondary: {
      main: "#ccc",
    },
  },
  typography: {
    fontFamily: "Roboto",
  },
  shadows: [
    "none",
    "0px 15px 60px rgba(0, 0, 0, 0.25)",
    "0px 35px 60px rgba(0, 0, 0, 0.25)",
    "20px 55px 60px rgba(0, 0, 0, 0.25)",
    "10px 15px 60px rgba(0, 0, 0, 0.25)",
  ],
});

theme = responsiveFontSizes(theme);

export default theme;

控制台中有一条警告说: 警告:失败的道具类型:Material-UI:此海拔4 未在组件中实现。 既然是25个元素的数组,应该怎么做呢?

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    shadows 需要所有 25 个 box-shadows,因为 material-ui 默认在组件内部使用许多这些阴影。所以方法是提供所需的阴影,然后完成其余部分,以完成数组中的25 box-shadows 传递none

    shadows: [
        "none",
        "0px 15px 60px rgba(0, 0, 0, 0.25)",
        "0px 35px 60px rgba(0, 0, 0, 0.25)",
        "20px 55px 60px rgba(0, 0, 0, 0.25)",
        "10px 15px 60px rgba(0, 0, 0, 0.25)",
        ...Array(20).fill('none')
      ]
    

    这里提供了 5 个阴影,其余 20 个将是 noneArray(20).fill('none') 将生成一个包含 20 个元素的数组(在这种情况下没有),然后将该数组传播到 shadows 数组中。它将在数组中总计 25 个元素。

    【讨论】:

      猜你喜欢
      • 2020-01-13
      • 2021-04-14
      • 2020-08-05
      • 2018-05-21
      • 2018-08-18
      • 2020-08-19
      • 2019-01-28
      • 2021-09-11
      • 1970-01-01
      相关资源
      最近更新 更多