I'm having trouble figuring out how to use Material UI's dialog box to render modals, close them upon button clicking and also make it so that clicking on different things brings up different modals.
This is the dialog component that I took from Material UI
import React from 'react';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
class DialogBox extends React.Component {
render() {
return (
<Dialog
open={this.props.open}
onClose={this.props.handleClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">{"Use Google's location service?"}</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
Let Google help apps determine location. This means sending anonymous location data to
Google, even when no apps are running.
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={this.props.handleClose} color="primary">
Okay
</Button>
</DialogActions>
</Dialog>
);
}
}
export default DialogBox;
This is the page that I am rendering the Dialog Box in, I called it Modal in here. How do I make it so that I can close it when the dialog is open and also so I can click on a different picture and have it open up a dialog with different text?
import React,{Component} from "react";
import home from "./home.png";
import car from "./car.png";
import bed from "./bed.png";
import pet from "./pet.png";
import Dialog from "./Modal.js";
class Scenarios extends Component {
constructor(){
super();
this.state = { open: false };
}
openModal = () =>{
this.setState({ open: true });
}
handleClose = () => {
this.setState({ open: false });
};
render() {
return (
<section className="App-scenarios">
<h2> Quick Tips </h2>
<p>Know What to Do in Different Scenarios during an Earthquake</p>
<div className="scenario-group">
<div className="scenario" onClick={this.openModal}>
<img src={car}/>
</div>
<div className="scenario" onClick={this.openModal}>
<img src={home}/>
<Dialog open={this.state.open} onClose={this.handleClose} title="Home" description="text" />
</div>
<div className="scenario" >
<img src={bed}/>
</div>
<div className="scenario">
<img src={pet}/>
</div>
</div>
</section>
);
}
};
export default Scenarios;