diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-02 01:34:19 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-02 01:34:19 -0700 |
commit | cd6a3a56b0a9f27dd7250c7641776fe1bd184888 (patch) | |
tree | b26c2731e39c63b748ac3bc76cc977419bae4746 /src/engine/utils | |
parent | 1ec5a8d088f599d094f387abc6014f228607b605 (diff) | |
download | the-abstraction-engine-cd6a3a56b0a9f27dd7250c7641776fe1bd184888.tar.gz the-abstraction-engine-cd6a3a56b0a9f27dd7250c7641776fe1bd184888.zip |
add modal interaction with code
Diffstat (limited to 'src/engine/utils')
-rw-r--r-- | src/engine/utils/index.ts | 1 | ||||
-rw-r--r-- | src/engine/utils/modal.ts | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/engine/utils/index.ts b/src/engine/utils/index.ts index 439e664..78b600e 100644 --- a/src/engine/utils/index.ts +++ b/src/engine/utils/index.ts @@ -1,3 +1,4 @@ export * from "./clamp"; export * from "./dotProduct"; export * from "./rotateVector"; +export * from "./modal"; diff --git a/src/engine/utils/modal.ts b/src/engine/utils/modal.ts new file mode 100644 index 0000000..e7b36b1 --- /dev/null +++ b/src/engine/utils/modal.ts @@ -0,0 +1,38 @@ +import { Miscellaneous } from "../config"; + +let modalOpen = false; + +export const openModal = (content: string, id = Miscellaneous.MODAL_ID) => { + const modal = document.getElementById(id); + if (modal && !modalOpen) { + modal.style.display = "flex"; + modal.style.animation = "fadeIn 0.25s"; + + modal.innerHTML = `<div class="modal-content">${content}</div>`; + const modalContent = document.querySelector<HTMLElement>(".modal-content"); + if (modalContent) { + modalContent.style.animation = "scaleUp 0.25s"; + } + + modalOpen = true; + } +}; + +export const closeModal = (id = Miscellaneous.MODAL_ID) => { + const modal = document.getElementById(id); + if (modal && modalOpen) { + modal.style.animation = "fadeOut 0.25s"; + + const modalContent = document.querySelector<HTMLElement>(".modal-content"); + if (modalContent) { + modalContent.style.animation = "scaleDown 0.25s"; + } + + setTimeout(() => { + modal.innerHTML = ""; + modal.style.display = "none"; + + modalOpen = false; + }, 250); + } +}; |