Modal
The Modal component is a dialog box that overlays the main content and requires the user’s attention or interaction. The Modal component can have different parts, such as a title, a body, and a footer. The Modal component can also have different size and behaviors, such as closing when the user clicks in the close button.
You can find the Modals component in the src/views/Modals.jsx
file.
Examples
Add dialogs to your site for lightboxes, user notifications, or completely custom content. Modal Preview
Result
- Small
- Medium
- Large
- Without Animation
Small
import { useState } from "react";
import { Button, Modal } from "react-bootstrap";
function SmallModal() {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<>
<Button variant="secondary" onClick={handleShow}>
Small
</Button>
<Modal show={show} onHide={handleClose} backdrop="static" keyboard={false} size="sm">
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
I will not close if you click outside me. Do not even try to press escape key.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary">Understood</Button>
</Modal.Footer>
</Modal>
</>
);
}
export default SmallModal;
Medium
import { useState } from "react";
import { Button, Modal } from "react-bootstrap";
function MediumModal() {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<>
<Button variant="secondary" onClick={handleShow}>
Medium
</Button>
<Modal show={show} onHide={handleClose} backdrop="static" keyboard={false} size="md">
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
I will not close if you click outside me. Do not even try to press escape key.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary">Understood</Button>
</Modal.Footer>
</Modal>
</>
);
}
export default MediumModal;
Large
import { useState } from "react";
import { Button, Modal } from "react-bootstrap";
function LargeModal() {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<>
<Button variant="secondary" onClick={handleShow}>
Large
</Button>
<Modal show={show} onHide={handleClose} backdrop="static" keyboard={false} size="lg">
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
I will not close if you click outside me. Do not even try to press escape key.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary">Understood</Button>
</Modal.Footer>
</Modal>
</>
);
}
export default LargeModal;
Modals
import { useState } from "react";
import { Button, Modal } from "react-bootstrap";
function WithoutAnimatedModal() {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<>
<Button variant="secondary" onClick={handleShow}>
Without Animated
</Button>
<Modal
show={show}
onHide={handleClose}
backdrop="static"
keyboard={false}
animation={false}>
<Modal.Header closeButton>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
I will not close if you click outside me. Do not even try to press escape key.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary">Understood</Button>
</Modal.Footer>
</Modal>
</>
);
}
export default WithoutAnimatedModal;
Props
For more information or variant please visit to react-bootstrap