Как добавить элементы в столбец с помощью Flexbox и Material UI - PullRequest
0 голосов
/ 29 мая 2019

Я ищу какой-то совет, так как я не могу разместить эти предметы на модале.Я хочу добавить счетчик предметов в виде текста и звездочек внизу.С неназначенным текстом внизу.Я перепробовал много макетов.Пока это мой код:

 const styles = theme => ({
  root: {
    flexGrow: 1,
    overflow: 'hidden',
    padding: theme.spacing(0, 3),
  },
  paper: {
    maxWidth: 800,
    margin: `${theme.spacing(2)}px auto`,
    padding: theme.spacing(2),
  },
  textField: {
    marginLeft: theme.spacing(1),
    marginRight: theme.spacing(1),
    width: 200,
  },
    playButton: {
      display: "flex",
      flexDirection: "column",
      justifyContent: "center",
      alignItems: "center",
      "& .rating": {
        flex: 1
    },
  }
});

function Tasks(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <Paper className={classes.paper}>
        <Grid container spacing={2}>
          <Grid item xs={12} sm container>
            <Grid item xs container direction="column" spacing={2}>
              <Grid item xs>
              <div className="name-label">
              Name
              </div>
              <Typography variant="h6">
              Order cofee beans
              </Typography>
              <div className="form-divider"></div>
                <Typography variant="body2" color="textSecondary">
                  Process of Description
                </Typography>
              </Grid>
            </Grid>
            <Grid item classes={{ root: props.classes.playButton}}>
      <Grid item xs={3} className="playButton">
        <i class="far fa-play-circle fa-2x"></i>
      </Grid>
      <div className="workers-assigned-label">
      Workers Assigned
    </div>
    <div>
      count / total
    </div>
    <div className="rating">
      Stars go here
    </div>
    <div>
      unassigned
    </div>
    </Grid>
          </Grid>
        </Grid>
      </Paper>
    </div>
  );
}

export default withStyles(styles)(Tasks);

Я добавил изображение скриншота дизайна, чтобы было понятно, чего я пытаюсь достичь.

Изображение: введите описание изображения здесь

1 Ответ

0 голосов
/ 29 мая 2019

Вы захотите что-то вроде этого, где flex: 1 - это то, что вы хотите растянуть и занять дополнительное пространство.

const styles = theme => ({
  playButton: {
    display: "flex",
    flexDirection: "column",
    justifyContent: "center",
    alignItems: "center",
    position: "relative",
    "& .playButton": {
      position: "absolute",
      top: "80%",
      left: "-55px",
      transform: "translateY(-50%)",
    },
    "& .rating": {
      flex: 1
    }
  }
});

const YourComponent = props => (
  {...}
  <Grid item classes={{ root: props.classes.playButton}}>
    <Grid item xs={3} className="playButton">
      <i class="far fa-play-circle fa-2x"></i>
    </Grid>
    <div className="workers-assigned-label">
      Workers Assigned
    </div>
    <div>
      count / total
    </div>
    <div className="rating">
      stars go here
    </div>
    <div>
      unassigned
    </div>
  </Grid>
  {...}
);

Я предлагаю вам оформить заказ на этом ресурсе , чтобы узнать, что вы можете сделать с помощью flex.

...