ReactJS材质makeStyles

时间:2020-02-17 11:54:26

标签: css reactjs material-ui react-material

我有自己的主题,我可以很好地主题化。 现在,我有三种不同的样式以及实质性的UI选项卡。这就是为什么我需要使用makeStyles更改样式的原因。

这是我需要更改的选项卡的示例

...

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
    width: "100%",
    backgroundColor: theme.pallete.primary
  },
  tabs: {
  /// some styles
  }
...
}
));

...


<Tabs
 ...someProps
 className={classes.tabs}
>
标签内的

元素具有此类:

 <button class="MuiButtonBase-root MuiTab-root MuiTab-textColorSecondary Mui-selected MuiTab-labelIcon">

我试图以与

相同的方式编辑样式
... = createMuiTHeme ({
overrides: {
...some overrides
}

就我而言:

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
    width: "100%",
    backgroundColor: "#121D42",
   MuiButtonBase: {
    root: {
    ///some styles
    },
   }
  },
...

但不适用于makeStyles

那么如何使用makeStyles()编辑选项卡中的按钮,这可能吗?或请帮助我解决问题

1 个答案:

答案 0 :(得分:0)

我现在已经找到了解决方案。

使用样式化组件并创建样式化元素-我们可以更轻松地更改样式。我们应该 StylesProvider

const NewButton = styled(({styledComponentProp, ...rest}) => (
  <Button classes={{label: 'label'}} {...rest}/>
))`
  .label {
    color: blue;
    font-size: ${props => props.styledComponentProp};
  }  
`



export const BlueButton = styled(props => {
  return (

    <StylesProvider injectFirst>
    <NewButton variant="contained" styledComponentProp="20px"> Red Labeled Button </NewButton>
  </StylesProvider>
  );
})`

`;

但是我们有更好的解决方案吗?