0

我有自己的主题,我可以很好地主题化。现在我有三种不同风格的材质 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() 编辑选项卡内的按钮,这可能吗?或者请帮我解决

4

1 回答 1

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>
  );
})`

`;

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

于 2020-02-18T09:09:19.670 回答