我们如何扩展material-ui的CssBaseline?

时间:2019-06-14 17:42:27

标签: material-ui

我正在考虑按照以下方式进行操作,但是我不确定是否建议这样做:

import * as React from "react"
import { withStyles, createStyles, Theme } from "@material-ui/core"
import CssBaseline from "@material-ui/core/CssBaseline"

// global styles for a Mapper app
class MyCssBaseline extends React.Component {
  render() {
    return <CssBaseline />
  }
}

export default withStyles(styles)(MapperCssBaseline)

function styles(_theme: Theme) {
  return createStyles({
    "@global": {
      fontSize: 12,
      // ... custom styles here ...
    }
  })
}

这是怎么回事?还是有更推荐的方法?

1 个答案:

答案 0 :(得分:0)

创建主题时,我设法用overrides做到了

export const theme: Theme = createMuiTheme({
  overrides: {
    MuiCssBaseline: {
      '@global': {
        svg: {
          maxWidth: '100%',
          maxHeight: '100%',
        },
      },
    },
  },
})