使用材质ui createStyles

时间:2019-09-10 13:24:44

标签: reactjs typescript less material-ui

我正在尝试将css从较少的文件转换为实质的createStyles,而我无法理解它的工作原理。

我了解createstyle的基础知识,但我的子选择器无法正常工作

我想要的是能够访问CSS类missionStatusLibelle

.missionStatus {
  display: flex;
  align-items: center;
  height: 34px;
  width: 100%;

  .missionStatusLibelle {
    align-items: flex-start;
    justify-content: flex-start;
    margin-left: 10px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
  }

}

喜欢

<div className={styles.missionStatusLibelle}>

并将其转换为类似

const useStyles = makeStyles((theme: Theme) =>
  createStyles({
    missionStatus: {
      display: "flex",
      alignItems: "center",
      height: "34px",
      width: "100%",

      missionStatusLibelle: {
        alignItems: "flex-start",
        justifyContent: "flex-start",
        marginLeft: "10px",
        fontSize: "14px",
        fontWeight: 500,
        lineHeight: "20px"
      }
    }
}));

但是除了使用伪选择器之外,我无法进入MissionStatusLibelle。

const styles = useStyles();
<div className={styles.missionStatusLibelle}>

1 个答案:

答案 0 :(得分:0)

您想要以下内容:

const useStyles = makeStyles((theme: Theme) =>
  createStyles({
    missionStatus: {
      display: "flex",
      alignItems: "center",
      height: "34px",
      width: "100%",

      "& $missionStatusLibelle": {
        alignItems: "flex-start",
        justifyContent: "flex-start",
        marginLeft: "10px",
        fontSize: "14px",
        fontWeight: 500,
        lineHeight: "20px"
      }
    },
    missionStatusLibelle: {}
  }
));

以下是相关文档:https://cssinjs.org/jss-plugin-nested/?v=v10.0.0-alpha.24#use-rulename-to-reference-a-local-rule-within-the-same-style-sheet