JSFiddle - React, Tailwind, and code Playground
HTML
<div id="Body">
<button type="button" onclick="_Show_Modal('SomeModal');">
Show Modal
</button>
<button type="button" onclick="_Show_Popup('SomeModal');">
Show Popup
</button>
<button type="button" onclick="_Show_Modal('SomeBigModal');">
Show Big Modal
</button>
</div>
<div id="ModalHolder">
<div id="SomeModal" class="Modal">
<div class="Modal_Mask">
</div>
<div class="Modal_Content">
<div class="Modal_Content_Header">
<label>Some Title</label>
<button type="button" onclick="_Modal_ShowHide('SomeModal');">
Close
</button>
</div>
<div class="Modal_Content_Body">
Some Body
<div>
<input type="checkbox" onclick="_SaveStuff();" />
</div>
</div>
<div class="Modal_Content_Footer">
<div class="Modal_Content_Footer_Notification">
<label>Saved!</label>
</div>
</div>
</div>
</div>
<div id="SomeBigModal" class="Modal">
<div class="Modal_Mask">
</div>
<div class="Modal_Content">
<div class="Modal_Content_Header">
<label>Some Big Modal Title</label>
<button type="button" onclick="_Modal_ShowHide('SomeBigModal');">
Close
</button>
</div>
<div class="Modal_Content_Body">
Some Body
<div>
<input type="checkbox" onclick="_SaveStuff();" />
<div style="background-color: gray; height: 600px; width: 1000px;">
</div>
</div>
</div>
<div class="Modal_Content_Footer">
<div class="Modal_Content_Footer_Notification">
<label>Saved!</label>
</div>
</div>
</div>
</div>
</div>
CSS
.Modal
{
display: none;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
overflow: visible;
max-height: 90vh;
max-width: 90vw;
}
.Modal[IsVisible="1"]
{
display: flex;
}
.Modal[NoMask="1"] > .Modal_Mask
{
display: none;
}
.Modal_Mask
{
width: 100vw;
height: 100vh;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: black;
opacity: 0.2;
z-index: -1;
}
.Modal_Content
{
display: flex;
flex-direction: column;
min-width: 0;
gap: 2px;
background-color: white;
box-shadow: 0 13px 17px rgba(0, 0, 0, 0.4);
border-radius: 5px;
}
.Modal_Content_Header
{
display: grid;
grid-template-columns: auto min-content;
grid-template-rows: min-content;
background-color: #4287f5;
padding: 3px;
border-radius: 5px 5px 0px 0px;
}
.Modal_Content_Body
{
padding: 3px;
overflow: auto;
}
.Modal_Content_Footer
{
border-top: 1px solid silver;
padding: 3px;
border-radius: 0px 0px 5px 5px;
}
.Modal_Content_Footer_Notification
{
min-height: 20px;
text-align: right;
}
.Modal_Content_Footer_Notification > label
{
opacity: 0;
}
.Modal_Content_Footer_Notification[IsSaved="1"] > label
{
animation: fadeOut ease 1000ms;
animation-fill-mode: forwards;
}
@keyframes fadeOut
{
0%
{
opacity: 1;
}
100%
{
opacity: 0;
}
}
JavaScript
function _Show_Modal(P_ModalId)
{
$("#" + P_ModalId).attr("NoMask", "0");
_Modal_ShowHide(P_ModalId);
}
function _Show_Popup(P_ModalId)
{
$("#" + P_ModalId).attr("NoMask", "1");
_Modal_ShowHide(P_ModalId);
}
function _Modal_ShowHide(P_ModalId)
{
var $Modal = $("#" + P_ModalId);
if($("#" + P_ModalId).attr("IsVisible") == "1")
{
$("#" + P_ModalId).attr("IsVisible", "0");
}
else
{
$("#" + P_ModalId).attr("IsVisible", "1");
}
}
function _SaveStuff()
{
$(".Modal_Content_Footer_Notification").attr("IsSaved", "1");
setTimeout(function()
{
$(".Modal_Content_Footer_Notification").attr("IsSaved", "0");
}, 1100);
}