代码之家  ›  专栏  ›  技术社区  ›  Ram kumar

如何全局更改原色?

  •  0
  • Ram kumar  · 技术社区  · 8 年前

    我正在为电子学习项目使用材料用户界面。我在网站范围内更改主/辅助颜色时遇到问题。如何全局设置原色? 我查过这个了 link

    import { createMuiTheme } from '@material-ui/core/styles';
    
    const theme = createMuiTheme({
      palette: {
        primary: {
          // light: will be calculated from palette.primary.main,
          main: '#ff4400',
          // dark: will be calculated from palette.primary.main,
          // contrastText: will be calculated to contrast with palette.primary.main
        },
        secondary: {
          light: '#0066ff',
          main: '#0044ff',
          // dark: will be calculated from palette.secondary.main,
          contrastText: '#ffcc00',
        },
        // error: will use the default color
      },
    });

    它将作为单个组件工作,但我需要在一个地方申请所有组件的更改?

    有什么好主意要实现吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Nadun    8 年前

    你所做的是正确的。 为了让它在全球范围内包裹你的应用程序 MuiThemeProvider 阻碍

    例如:

    import { createMuiTheme } from '@material-ui/core/styles';
    import { MuiThemeProvider } from '@material-ui/core/styles';
    
    const theme = createMuiTheme({
      palette: {
        primary: {
          // light: will be calculated from palette.primary.main,
          main: '#ff4400',
          // dark: will be calculated from palette.primary.main,
          // contrastText: will be calculated to contrast with palette.primary.main
        },
        secondary: {
          light: '#0066ff',
          main: '#0044ff',
          // dark: will be calculated from palette.secondary.main,
          contrastText: '#ffcc00',
        },
        // error: will use the default color
      },
    });
    
    export default class App extends Component {
      render() {
        return (
          <MuiThemeProvider theme={theme}>
            < your application code >
          </MuiThemeProvider>
        );
      }
    

    希望这对你有帮助。