Skip to content

Instantly share code, notes, and snippets.

@4lun
Last active October 14, 2025 11:33
Show Gist options
  • Select an option

  • Save 4lun/5b52a6933ca9b08d19cbe0c381298dc1 to your computer and use it in GitHub Desktop.

Select an option

Save 4lun/5b52a6933ca9b08d19cbe0c381298dc1 to your computer and use it in GitHub Desktop.
Typescript type declarations for "@inertiaui/modal-react" (generated against 1.0.0-beta-4) https://github.com/inertiaui/modal/issues/158
import type {
ComponentPropsWithoutRef,
ComponentType,
ElementType,
ForwardRefExoticComponent,
ReactElement,
ReactNode,
RefAttributes,
} from "react";
import type { AxiosResponse } from "axios";
declare module "@inertiaui/modal-react" {
type AnyRecord = Record<string, unknown>;
export type ModalMaxWidth =
| "sm"
| "md"
| "lg"
| "xl"
| "2xl"
| "3xl"
| "4xl"
| "5xl"
| "6xl"
| "7xl"
| (string & {});
export type ModalResolvedPosition =
| "top"
| "center"
| "bottom"
| "left"
| "right"
| (string & {});
export interface ModalConfigState {
slideover: boolean;
closeButton: boolean;
closeExplicitly: boolean;
maxWidth: ModalMaxWidth;
paddingClasses: string;
panelClasses: string;
position: ModalResolvedPosition;
}
export type ModalConfigInput = Partial<ModalConfigState> & {
[key: string]: unknown;
};
export interface ModalRuntimeConfiguration {
type: "modal" | "slideover";
navigate: boolean;
modal: ModalConfigState;
slideover: ModalConfigState;
[key: string]: unknown;
}
export interface ModalGlobalConfig {
type?: "modal" | "slideover";
navigate?: boolean;
modal?: ModalConfigInput;
slideover?: ModalConfigInput;
[key: string]: unknown;
}
export interface ModalResponseMeta {
deferredProps?: Record<string, string[]>;
[key: string]: unknown;
}
export interface ModalResponse {
id?: string;
component: string;
props: AnyRecord;
url?: string;
version?: string;
baseUrl?: string;
meta?: ModalResponseMeta;
[key: string]: unknown;
}
export interface ModalReloadOptions {
only?: string | string[];
except?: string | string[];
method?: string;
data?: AnyRecord | FormData;
headers?: AnyRecord;
onStart?(...args: unknown[]): void;
onSuccess?(response: AxiosResponse): void;
onError?(error: unknown): void;
onFinish?(): void;
}
export type ModalEventHandler = (...args: unknown[]) => void;
export interface ModalRenderProps {
afterLeave(): void;
close(): void;
config: ModalConfigState;
emit(event: string, ...args: unknown[]): void;
getChildModal(): ModalContext | null;
getParentModal(): ModalContext | null;
id: string;
index: number;
isOpen: boolean;
modalContext: ModalContext;
onTopOfStack: boolean;
reload(options?: ModalReloadOptions): void;
setOpen(open?: boolean): void;
shouldRender: boolean;
}
export interface ModalContext {
id: string;
index: number;
isOpen: boolean;
shouldRender: boolean;
onTopOfStack: boolean;
component: ComponentType<AnyRecord> | null;
config: ModalConfigInput;
props: AnyRecord;
response: ModalResponse;
show(): void;
setOpen(open?: boolean): void;
close(): void;
afterLeave(): void;
emit(event: string, ...args: unknown[]): void;
on(event: string, callback: ModalEventHandler): void;
off(event: string, callback?: ModalEventHandler): void;
reload(options?: ModalReloadOptions): void;
updateProps(props: AnyRecord): void;
getParentModal(): ModalContext | null;
getChildModal(): ModalContext | null;
registerEventListenersFromProps(
events: Record<string, ModalEventHandler | undefined>,
): () => void;
}
export type ModalController = ModalRenderProps;
export interface ModalVisitOptions {
method?: string;
data?: AnyRecord | FormData;
headers?: AnyRecord;
config?: ModalConfigInput;
onClose?: () => void;
onAfterLeave?: () => void;
queryStringArrayFormat?: string;
navigate?: boolean;
onStart?: (...args: unknown[]) => void;
onSuccess?: (...args: unknown[]) => void;
onError?: (...args: unknown[]) => void;
listeners?: Record<string, ModalEventHandler>;
}
export interface ModalStackContextValue {
stack: ModalContext[];
localModals: Record<
string,
{ name: string; callback: (modal: ModalContext) => void }
>;
registerLocalModal(
name: string,
callback: (modal: ModalContext) => void,
): void;
removeLocalModal(name: string): void;
push(
component: ComponentType<AnyRecord> | null,
response: ModalResponse,
config?: ModalConfigInput,
onClose?: (() => void) | null,
afterLeave?: (() => void) | null,
): ModalContext;
pushFromResponseData(
response: ModalResponse,
config?: ModalConfigInput,
onClose?: (() => void) | null,
onAfterLeave?: (() => void) | null,
): Promise<ModalContext>;
visit(
href: string,
method?: string,
data?: AnyRecord | FormData,
headers?: AnyRecord,
config?: ModalConfigInput,
onClose?: (() => void) | null,
onAfterLeave?: (() => void) | null,
queryStringArrayFormat?: string,
navigate?: boolean,
onStart?: (...args: unknown[]) => void,
onSuccess?: (...args: unknown[]) => void,
onError?: (...args: unknown[]) => void,
): Promise<ModalContext>;
visitModal(url: string, options?: ModalVisitOptions): Promise<ModalContext>;
length(): number;
closeAll(): void;
reset(): void;
onModalOnBase(modal: ModalContext): void;
}
export interface DeferredProps {
children: ReactNode;
data: string | string[];
fallback?: ReactNode;
}
export const Deferred: ComponentType<DeferredProps>;
export interface HeadlessModalProps extends ModalConfigInput {
name?: string;
children?: ReactNode | ((props: ModalRenderProps) => ReactNode);
onFocus?: () => void;
onBlur?: () => void;
onClose?: () => void;
onSuccess?: () => void;
[key: string]: unknown;
}
export const HeadlessModal: ForwardRefExoticComponent<
HeadlessModalProps & RefAttributes<ModalController | null>
>;
export interface ModalProps extends HeadlessModalProps {
onAfterLeave?: () => void;
}
export const Modal: ForwardRefExoticComponent<
ModalProps & RefAttributes<ModalController | null>
>;
export interface ModalLinkProps<T extends ElementType = "a">
extends ModalConfigInput {
href: string;
method?: string;
data?: AnyRecord | FormData;
as?: T;
headers?: AnyRecord;
queryStringArrayFormat?: string;
onAfterLeave?: () => void;
onBlur?: () => void;
onClose?: () => void;
onError?: (error: unknown) => void;
onFocus?: () => void;
onStart?: () => void;
onSuccess?: () => void;
navigate?: boolean;
children?: ReactNode | ((state: { loading: boolean }) => ReactNode);
}
export function ModalLink<T extends ElementType = "a">(
props: ModalLinkProps<T> &
Omit<ComponentPropsWithoutRef<T>, "href" | "children" | "onClick"> &
AnyRecord,
): ReactElement | null;
export interface ModalRootProps {
children?: ReactNode;
}
export const ModalRoot: ComponentType<ModalRootProps>;
export interface ModalStackProviderProps {
children?: ReactNode;
}
export const ModalStackProvider: ComponentType<ModalStackProviderProps>;
export function useModalStack(): ModalStackContextValue;
export function useModal(): ModalContext | null;
export function useModalIndex(): number;
export interface WhenVisibleProps {
children: ReactNode;
data?: string | string[];
params?: ModalReloadOptions;
buffer?: number;
as?: ElementType;
always?: boolean;
fallback?: ReactNode;
}
export const WhenVisible: ComponentType<WhenVisibleProps>;
export function getConfig(): ModalRuntimeConfiguration;
export function getConfig<T = unknown>(key: string): T;
export function putConfig(config: ModalGlobalConfig): void;
export function putConfig(path: string, value: unknown): void;
export function resetConfig(): void;
export function initFromPageProps(pageProps: {
initialPage?: { version?: string; [key: string]: unknown };
resolveComponent?: (name: string) => Promise<ComponentType<AnyRecord>>;
[key: string]: unknown;
}): void;
export function renderApp<AppProps extends AnyRecord>(
App: ComponentType<AppProps>,
pageProps: AppProps,
): ReactElement;
export function setPageLayout<T extends ComponentType<AnyRecord>>(
layout: T,
): <Module extends { default: ComponentType<AnyRecord> }>(
module: Module,
) => Module;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment