- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果这些问题听起来很愚蠢,我深表歉意。我正在尝试进入 React 和 Material-UI,但没有导师可以向我提问或指导我。当我使用文档和教程等时,有点像在黑暗中拍摄。我有很多问题。(事实上,是否有更好的地方可以提出这些一次性的快速问题?也许是初学者聊天论坛?Slack 小组?不确定 Stack 是否是最好的地方..)
我正在为客户构建一个表单。其中一个问题是四象限图,用户在其中选择一个组合 4 个不同向量的选项。这很难解释,而且我不确定这种类型的图表的技术术语是什么,所以我画了一个图表来清楚地表明我想要实现的目标:
我开始在 React 中构建一个组件来处理这个选择图表,但我已经有点迷失了..这是我到目前为止所拥有的......
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardActionArea from '@material-ui/core/CardActionArea';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import Grid from '@material-ui/core/Grid';
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
},
h2: { //<-- is there a better way to do this? Or do I need to target each h2 with a className classes.h2 ?
color: "#f00",
},
paper: {
padding: theme.spacing(1),
textAlign: 'center',
color: theme.palette.text.secondary,
},
card: {
maxWidth: 345,
},
media: {
height: 140,
},
}));
export default function ProjectMap() {
const classes = useStyles();
function Slow_Expensive() {
return (
<Card className={classes.card}>
<CardActionArea>
<CardContent>
<Typography variant="body2" color="textSecondary" component="p">
Selection box slow but expensive.
</Typography>
</CardContent>
</CardActionArea>
</Card>
);
}
function TopRow() {
return (
<React.Fragment>
<Grid item xs={4}></Grid>
<Grid item xs={4}>
<h2>Expensive</h2>
</Grid>
<Grid item xs={4}></Grid>
</React.Fragment>
);
}
function MidRow() {
return (
<React.Fragment>
<Grid item xs={4}>
<h2 className={classes.h2}>Slow</h2> {/*Do I need to set a className on all of my h2's or is there a better way to target all of them within this component. */}
</Grid>
<Grid item xs={4}>
<h2>The Four Quadrants go here.. maybe cards assembled into maybe another grid?? a table??</h2>
</Grid>
<Grid item xs={4}>
<h2>Fast</h2>
</Grid>
</React.Fragment>
);
}
function BotRow() {
return (
<React.Fragment>
<Grid item xs={4}></Grid>
<Grid item xs={4}>
Cheap
</Grid>
<Grid item xs={4}></Grid>
</React.Fragment>
);
}
return (
<div className={classes.root}>
<h2>Choose one of hte options:</h2>
<Grid container spacing={1}> {/*is grid the best way to layout this component? Should I use a table instead?*/}
<Grid container justify="center" item xs={12} spacing={2}>{/* Justify is not working.. I don't know why?*/}
<TopRow />
</Grid>
<Grid container justify="center" item xs={12} spacing={2}>
<MidRow />
</Grid>
<Grid container justify="center" item xs={12} spacing={2}>
<BotRow />
</Grid>
</Grid>
</div>
);
}
s
<Dialog className={classes.root}
open={this.state.dialogOpen}
onClose={this.onDialogClose}
maxWidth = {'md'}
>
让我知道您的想法...任何有关如何解决这些问题的提示或建议将不胜感激。
谢谢!
最佳答案
您需要支持 Internet Explorer 吗?如果没有,实现此目的的最简单方法是使用 css grid .
这是一个例子:
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import Typography from "@material-ui/core/Typography";
import Paper from "@material-ui/core/Paper";
const useStyles = makeStyles({
paper: {
display: "grid",
gridTemplateColumns: "3rem 250px 250px 3rem",
gridTemplateRows: "3rem 250px 250px 3rem",
gridGap: "1rem",
justifyItems: "center",
alignItems: "center",
justifyContent: "center"
},
top: {
gridRow: "1 / 2",
gridColumn: "1 / 5"
},
bottom: {
gridRow: "4 / 5",
gridColumn: "1 / 5"
},
left: {
gridRow: "2 / 4",
gridColumn: "1 / 2"
},
right: {
gridRow: "2 / 4",
gridColumn: "4 / 5"
},
card: {
width: "100%",
height: "100%"
}
});
function MyCard({ title }) {
const classes = useStyles();
return (
<Card className={classes.card}>
<CardContent>
<Typography>{title}</Typography>
</CardContent>
</Card>
);
}
function Quadrants() {
return (
<React.Fragment>
<MyCard title="Slow but expensive" />
<MyCard title="Fast but expensive" />
<MyCard title="Slow but Cheap" />
<MyCard title="Slow but Fast" />
</React.Fragment>
);
}
function FourQuadrants() {
const classes = useStyles();
return (
<Paper className={classes.paper}>
<Typography className={classes.top}>Expensive</Typography>
<Typography className={classes.bottom}>Cheap</Typography>
<Typography className={classes.left}>Slow</Typography>
<Typography className={classes.right}>Fast</Typography>
<Quadrants />
</Paper>
);
}
export default FourQuadrants;
实例:
关于javascript - 初学者困惑: Four Quadrant Selection Grid in a Pop-Up Form Using Material UI & React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57116195/
我正在开发一个 iOS 应用程序,其中我需要显示散点图,但我需要限制沿 x 轴的滚动,也只能在正象限中。 我有工作图。我正在使用 core-plot 1.3。 任何帮助将不胜感激。 问候,伊山 最佳答
你们知道我可以用来创建 Gartner's Magic Quadrant 的 ASP.Net 图表控件吗?风格的图表? 我还希望气泡大小能够反射(reflect)每个数据点的市场交易量。 由于时间紧迫
如果这些问题听起来很愚蠢,我深表歉意。我正在尝试进入 React 和 Material-UI,但没有导师可以向我提问或指导我。当我使用文档和教程等时,有点像在黑暗中拍摄。我有很多问题。(事实上,是
我是一名优秀的程序员,十分优秀!