Nextjs Modal
-Bootstrap modals are lightweight and multi-purpose popups that are built with HTML, CSS, and JavaScript. The three primary sections of a Bootstrap modal are header, body, and footer. Modals are positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead. Use Bootstrap’s JavaScript modal plugin to add dialogues to your site for lightboxes, user notifications, or completely custom content.
Style
You will find the styles for this component in
assets/jss/nextjs-material-dashboard-pro/modalStyle.js
.
Example
For more examples, please check our live preview here.
import React from 'react';
// material-ui components
import { makeStyles } from "@material-ui/core/styles";
import Slide from "@material-ui/core/Slide";
import Dialog from "@material-ui/core/Dialog";
import DialogTitle from "@material-ui/core/DialogTitle";
import DialogContent from "@material-ui/core/DialogContent";
import DialogActions from "@material-ui/core/DialogActions";
// @material-ui/icons
import Close from "@material-ui/icons/Close";
// core components
import Button from "components/CustomButtons/Button.js";
import styles from "assets/jss/nextjs-material-dashboard-pro/modalStyle.js";
const useStyles = makeStyles(styles);
const Transition = React.forwardRef(function Transition(props, ref) {
return <Slide direction="down" ref={ref} {...props} />;
});
export default function Modal() {
const [modal, setModal] = React.useState(false);
const classes = useStyles();
const dialogClasses = {
root: classes.center,
paper: classes.modal
};
return (
<div>
<Button color="rose" round onClick={() => setModal(true)}>
Modal
</Button>
<Dialog
classes={dialogClasses}
open={modal}
transition={Transition}
keepMounted
onClose={() => setModal(false)}
aria-labelledby="modal-slide-title"
aria-describedby="modal-slide-description"
>
<DialogTitle
id="classic-modal-slide-title"
disableTypography
className={classes.modalHeader}
>
<Button
justIcon
className={classes.modalCloseButton}
key="close"
aria-label="Close"
color="transparent"
onClick={() => setModal(false)}
>
<Close className={classes.modalClose} />
</Button>
<h4 className={classes.modalTitle}>Modal title</h4>
</DialogTitle>
<DialogContent
id="modal-slide-description"
className={classes.modalBody}
>
<h5>Are you sure you want to do this?</h5>
</DialogContent>
<DialogActions
className={classes.modalFooter + " " + classes.modalFooterCenter}
>
<Button onClick={() => setModal(false)}>Never Mind</Button>
<Button onClick={() => setModal(false)} color="success">
Yes
</Button>
</DialogActions>
</Dialog>
</div>
);
}
Props
You should also check the following props from the base Material-UI components: