【问题标题】:ReactJS material makeStylesReactJS 材质 makeStyles
【发布时间】:2020-06-01 08:26:26
【问题描述】:

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

【问题讨论】:

    标签: css reactjs material-ui react-material


    【解决方案1】:

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

    使用样式化组件并创建样式化元素 - 我们可以更轻松地更改样式。我们应该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-08-19
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 2019-02-28
      • 2021-03-23
      • 2020-11-25
      • 1970-01-01
      • 2017-09-20
      相关资源
      最近更新 更多