Archived
popups create their own containers in HTML
This commit is contained in:
1 parent
6bb536e51c
commit
182fdbf158
2 files changed
+6
-9
No files matched your search
@@ -15,6 +15,5 @@
|
|||||||
<img src="%PUBLIC_URL%/leaf.svg" alt="eco-meet logo" style="width: 15%; height: 15%" />
|
<img src="%PUBLIC_URL%/leaf.svg" alt="eco-meet logo" style="width: 15%; height: 15%" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="popup-container" style="display: none; overflow: hidden; width: 100vw; height: 100vh; z-index: 20; position: fixed; top: 0; left: 0"></div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -3,11 +3,13 @@ import { Window } from "../../components/Window";
|
|||||||
import { window as windowClass } from "../../components/Window/index.module.scss";
|
import { window as windowClass } from "../../components/Window/index.module.scss";
|
||||||
|
|
||||||
export const spawnPopup = async (elements, windowStyles) => {
|
export const spawnPopup = async (elements, windowStyles) => {
|
||||||
const container = document.getElementById("popup-container");
|
const container = document.createElement("div");
|
||||||
const backgroundColor = "rgba(0,0,0,0.75)";
|
const backgroundColor = "rgba(0,0,0,0.75)";
|
||||||
const animationDuration = 300;
|
const animationDuration = 300;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
container.style = "display: block; overflow: hidden; width: 100vw; height: 100vh; z-index: 20; position: fixed; top: 0; left: 0";
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
const closeWindow = (value) => {
|
const closeWindow = (value) => {
|
||||||
container.animate([{ backgroundColor: backgroundColor }, { backgroundColor: "rgba(0,0,0,0)" }], {
|
container.animate([{ backgroundColor: backgroundColor }, { backgroundColor: "rgba(0,0,0,0)" }], {
|
||||||
easing: "ease",
|
easing: "ease",
|
||||||
@@ -26,16 +28,12 @@ export const spawnPopup = async (elements, windowStyles) => {
|
|||||||
);
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ReactDOM.unmountComponentAtNode(container);
|
ReactDOM.unmountComponentAtNode(container);
|
||||||
container.style.display = "none";
|
container.remove();
|
||||||
resolve(value ?? null);
|
resolve(value ?? null);
|
||||||
}, animationDuration);
|
}, animationDuration);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (container.innerHTML !== "") {
|
document.body.appendChild(container);
|
||||||
reject("Another popup is active");
|
|
||||||
}
|
|
||||||
|
|
||||||
container.style.display = "block";
|
|
||||||
ReactDOM.render(<Window style={windowStyles ?? {}}>{elements(closeWindow)}</Window>, container);
|
ReactDOM.render(<Window style={windowStyles ?? {}}>{elements(closeWindow)}</Window>, container);
|
||||||
const window = document.getElementsByClassName(windowClass)[0];
|
const window = document.getElementsByClassName(windowClass)[0];
|
||||||
container.animate([{ backgroundColor: "rgba(0,0,0,0)" }, { backgroundColor: backgroundColor }], {
|
container.animate([{ backgroundColor: "rgba(0,0,0,0)" }, { backgroundColor: backgroundColor }], {
|
||||||
|
|||||||
Reference in new issue
Block a user