diff options
author | Vendicated <vendicated@riseup.net> | 2022-09-08 21:47:53 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-09-08 21:47:53 +0200 |
commit | e52225304e47d92bf1b84f5a2c8e97ab57bd85a4 (patch) | |
tree | 77fecc6a6480487746ed2008275067e01b168753 /src/utils | |
parent | 4f531b36344390365adc2ddbf0bffec90b8303b7 (diff) | |
download | Vencord-e52225304e47d92bf1b84f5a2c8e97ab57bd85a4.tar.gz Vencord-e52225304e47d92bf1b84f5a2c8e97ab57bd85a4.tar.bz2 Vencord-e52225304e47d92bf1b84f5a2c8e97ab57bd85a4.zip |
Add modal api
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/modal.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx new file mode 100644 index 0000000..5628ebe --- /dev/null +++ b/src/utils/modal.tsx @@ -0,0 +1,34 @@ +import Components from "discord-types/components"; +import { waitFor } from "../webpack"; + +let Modal: Components.Modal; +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) { + let key = `Vencord${modalId++}`; + modals.openModal(props => + <Modal.ModalRoot {...props}> + <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); +}
\ No newline at end of file |