blob: e5723a81807a5fc64c591e6a7706fb5e20a4b8f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import Components from "discord-types/components";
import { waitFor } from "../webpack";
export let Modal: Components.Modal;
export let modals: any;
waitFor("openModalLazy", m => modals = m);
waitFor("ModalRoot", m => Modal = m);
let modalId = 1337;
/**
* Open a modal
* @param Component The component to render in the modal
* @returns The key of this modal. This can be used to close the modal later with closeModal
*/
export function openModal(Component: React.ComponentType, modalProps: Record<string, any>) {
let key = `Vencord${modalId++}`;
modals.openModal(props =>
<Modal.ModalRoot {...props} {...modalProps}>
<Component />
</Modal.ModalRoot>
, { modalKey: key });
return key;
};
/**
* Close a modal by key. The id you need for this is returned by openModal.
* @param key The key of the modal to close
*/
export function closeModal(key: string) {
modals.closeModal(key);
}
|