From f19504f8282702bc6945a3d97acbee1a1fbe1b8d Mon Sep 17 00:00:00 2001 From: Ven Date: Wed, 25 Jan 2023 03:25:29 +0100 Subject: split up webpack commons into categories & type everything (#455) --- src/utils/modal.tsx | 76 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 16 deletions(-) (limited to 'src/utils/modal.tsx') diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index 73dd009..3174cac 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -17,6 +17,9 @@ */ import { filters, mapMangledModuleLazy } from "@webpack"; +import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react"; + +import { LazyComponent } from "./misc"; export enum ModalSize { SMALL = "small", @@ -44,16 +47,7 @@ export interface ModalOptions { onCloseCallback?: (() => void); } -interface ModalRootProps { - transitionState: ModalTransitionState; - children: React.ReactNode; - size?: ModalSize; - role?: "alertdialog" | "dialog"; - className?: string; - onAnimationEnd?(): string; -} - -type RenderFunction = (props: ModalProps) => React.ReactNode; +type RenderFunction = (props: ModalProps) => ReactNode; export const Modals = mapMangledModuleLazy(".closeWithCircleBackground", { ModalRoot: filters.byCode(".root"), @@ -61,13 +55,63 @@ export const Modals = mapMangledModuleLazy(".closeWithCircleBackground", { ModalContent: filters.byCode(".content"), ModalFooter: filters.byCode(".footerSeparator"), ModalCloseButton: filters.byCode(".closeWithCircleBackground"), -}); +}) as { + ModalRoot: ComponentType>; + ModalHeader: ComponentType>; + /** This also accepts Scroller props but good luck with that */ + ModalContent: ComponentType; + [prop: string]: any; + }>>; + ModalFooter: ComponentType>; + ModalCloseButton: ComponentType<{ + focusProps?: any; + onClick(): void; + withCircleBackground?: boolean; + hideOnFullscreen?: boolean; + className?: string; + }>; +}; -export const ModalRoot = (props: ModalRootProps) => ; -export const ModalHeader = (props: any) => ; -export const ModalContent = (props: any) => ; -export const ModalFooter = (props: any) => ; -export const ModalCloseButton = (props: any) => ; +export const ModalRoot = LazyComponent(() => Modals.ModalRoot); +export const ModalHeader = LazyComponent(() => Modals.ModalHeader); +export const ModalContent = LazyComponent(() => Modals.ModalContent); +export const ModalFooter = LazyComponent(() => Modals.ModalFooter); +export const ModalCloseButton = LazyComponent(() => Modals.ModalCloseButton); const ModalAPI = mapMangledModuleLazy("onCloseRequest:null!=", { openModal: filters.byCode("onCloseRequest:null!="), -- cgit