Прошу прощения, если эти вопросы покажутся глупыми. Я пытаюсь перейти к 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>
);
}
с
<Dialog className = {classes.root}
open = {this.state.dialogOpen}
onClose = {this.onDialogClose}
maxWidth = {'md'}
>
Дайте мне знать ваши мысли ... любые советы или предложения о том, как решить эти проблемы, будут очень признательны.
Спасибо!



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Нужна ли вам поддержка Internet Explorer? Если нет, самый простой способ добиться этого — использовать css сетка.
Вот пример:
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;
Живой пример: