材质UI响应卡

格里格

我正在测试Material-UI。我已经使用Bootstrap很长时间了,但是对将某些React项目适应Material-UI感兴趣。我一直试图弄清楚的是如何在Material-UI中创建响应卡。过去,我非常依赖Bootstraps响应式容器,所以我不明白为什么我的卡会随页面扩展而不会因窗口浓缩而收缩...如果我们打算为该脚本编写自定义CSS这个我很酷,只需要指出正确的方向即可。

问题:

  1. Material-UI中的响应卡是不是很重要?

  2. 还是我们要编写CSS来使显卡响应?

  3. 如果是这样,我在哪里可以学到呢?(过去大量依赖于Bootstrap)

在此先感谢您的帮助!

...
useStyles = () => makeStyles(theme => ({
    root: {
      flexGrow: 1,
    },
    paper: {
      padding: theme.spacing.unit,
      textAlign: "center",
      color: theme.palette.text.secondary,
      marginBottom: theme.spacing.unit
    },
  }));

  render() {
    const {baseData} = this.state;
    const {hfcMetrics} = this.state;
    const {stateMember} = this.state;
    const {stateName} = this.state;
    const {states} = this.state;
    const {lineVizData} = this.state;
    const classes = this.useStyles();

    return (this.state.doneLoading === false ? (
      <div className={classes.root}>
        <Grid container>
          <Grid item xs={12}>
            <ReactLoading type={"spinningBubbles"} color={"black"} height={'10%'}
                          width={'10%'} id='spinner'/>
          </Grid>
        </Grid>
      </div>
        ) 
        :
        (stateMember === true ?
      <div className={classes.root}>
        <Grid container spacing={3}>
          <Grid item xs={12}>
            <Card>  
              <CardHeader
                title="Options" 
              />
              <CardContent style={{ width: '100%', height: 300 }}>
                <LineViz 
                  data={lineVizData}
                  state={stateName}
                  source='compareTool'
                  states={states}
                  vizKey={this.state.vizKey}
                  /> 
              </CardContent>
              <CardActions>
                <Button size="small" color="primary">
                  Share
                </Button>
                <Button size="small" color="primary">
                  Learn More
                </Button>
              </CardActions>
            </Card>
          </Grid>
          <Grid item xs={6}>
            <Card ref={this.elRef}>  
              <CardHeader
                title="Comparison Analysis" 
                action={
                  <ButtonGroup variant="text" color="primary" aria-label="text primary button group">
                    <YearDropDown2 
                      year={this.state.year}
                      handleChange={this.toggleYear}
                    /> 
                    <IconButton color='default' component="span"
                      onClick={() => this.resetStateToggle()}><AutorenewRoundedIcon/></IconButton>
                  </ButtonGroup>
                }
              />
              <CardContent style={{padding: 0}}>
                <DataCompareTable
                  data={this.state.compareData} 
                  metric={this.state.metric}
                  stateName={this.state.stateName}
                  compareCount={this.state.compareCount}
                  handleChange={this.toggleStateName}
                  toggleOne={this.state.toggleOne}
                  toggleTwo={this.state.toggleTwo}
                  toggleThree={this.state.toggleThree}
                />
              </CardContent>
            </Card>
          </Grid>
          <Grid item xs={6}>
            <Paper className={classes.paper}>xs=6</Paper>
          </Grid>
        </Grid>
      </div>
      : '' 
      )
    )
  }
}

export default CompareTool

nadim95

谢谢你的问题

要回答您的问题:1)我不了解2)否,您不必编写很多CSS,但是,是的usestyles中有一些CSS 3)下面我详细解释了您必须在代码中编写的CSS。您正在同时使用内联样式和useStyles,请尝试将所有样式放入usestyle hook API中,并使其具有响应能力。希望这有助于让我知道是否需要更清楚地说明。谢谢

据我所知,您可以使用“ useMediaQuery”挂钩使您的设计具有响应能力。

这是材料UI Card组件页面中的组件,我只添加了useTheme和useMediaQuery导入,并在class.root下的useStyle内添加了一个中间断点。这是“ useMediaQuery”上的有用链接https://material-ui.com / components / use-media-query /#usemediaquery

import { useTheme } from "@material-ui/styles";
import useMediaQuery from "@material-ui/core/useMediaQuery";

const useStyles = makeStyles(theme => ({
  root: {
    maxWidth: 345,
    [theme.breakpoints.down("md")] : {
    maxWidth: 200
    }
  },
  media: {
    height: 140
  }
}));
const Card = () =>  {
  const classes = useStyles();
  const theme = useTheme();

  const matches = useMediaQuery(theme.breakpoints.up("sm"));
  return (

    <Card className={classes.root}>
      <CardActionArea>
        <CardMedia
          className={classes.media}

          title="Contemplative Reptile"
        />
        <CardContent>
          <Typography gutterBottom variant="h5" component="h2">
            Lizard
          </Typography>
          <Typography variant="body2" color="textSecondary" component="p">
            Lizards are a widespread group of squamate reptiles, with over 6,000
            species, ranging across all continents except Antarctica
          </Typography>
        </CardContent>
      </CardActionArea>
      <CardActions>
        <Button size="small" color="primary">
          Share
        </Button>
        <Button size="small" color="primary">
          Learn More
        </Button>
      </CardActions>
    </Card>
  );
}

希望这可以帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章