1 | const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export default {
|
8 | |
9 |
|
10 |
|
11 | modals: () => modals,
|
12 |
|
13 | |
14 |
|
15 |
|
16 | add: (newModal: HTMLDivElement, blockScroll: boolean) => {
|
17 | if (modals.findIndex((modal) => modal.element === newModal) === -1) {
|
18 | modals.push({ element: newModal, blockScroll });
|
19 | }
|
20 | },
|
21 |
|
22 | |
23 |
|
24 |
|
25 | remove: (oldModal: HTMLDivElement) => {
|
26 | const index = modals.findIndex((modal) => modal.element === oldModal);
|
27 | if (index !== -1) {
|
28 | modals.splice(index, 1);
|
29 | }
|
30 | },
|
31 |
|
32 | |
33 |
|
34 |
|
35 | isTopModal: (modal: HTMLDivElement) =>
|
36 | !!modals.length && modals[modals.length - 1]?.element === modal,
|
37 | };
|