<html>
<head>
<meta charset="UTF-8" />
<script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
const { useState } = React;
function App() {
const [dialog, setDialog] = useState(false);
const [imageSrc, setImageSrc] = useState(
"https://www.sarkarinaukriexams.com/images/post/1670771584desola-lanre-ologun-IgUR1iX0mqM-unsplash_(1).jpg"
);
const toggleDialog = () => {
setDialog(!dialog);
};
return (
<div className="container">
<h3>React Js Show Image in Popup Modal</h3>
<button className="popup-button" onClick={toggleDialog}>Show Popup Image</button>
{dialog && (
<div className="dialog">
<div className="dialog-content">
<h3>React Js Show Image in Popup Modal </h3>
<button className="close-icon" onClick={toggleDialog}>✕</button>
<img className="popup-image" src={imageSrc} alt="Popup Image" />
</div>
</div>
)}
</div>
);
}
ReactDOM.render(<App />, document.getElementById("app"));
</script>
<style>
/* Style for the container */
.container {
text-align: center;
margin: 0px auto;
}
/* Style for the popup button */
.popup-button {
background-color: #007BFF;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.popup-button:hover {
background-color: #0056b3;
}
/* Style for the dialog container */
.dialog {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 1;
}
/* Style for the dialog content */
.dialog-content {
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
text-align: center;
position: relative;
max-width: 500px;
padding: 0 15px;
}
/* Style for the close icon */
.close-icon {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
border: none;
font-size: 24px;
cursor: pointer;
border: none;
color: #333;
cursor: pointer;
padding: 0;
}
.popup-image {
max-width: 100%;
height: auto;
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
</style>
</body>
</html>