Files
UT-Registration-Plus/src/views/contexts/DialogContext.ts
2024-05-20 16:18:34 -05:00

33 lines
719 B
TypeScript

import { createContext, useContext } from 'react';
/**
* Close wrapper
*/
export type CloseWrapper<T> = (close: () => void) => T;
/**
* Information about a dialog.
*/
export interface DialogInfo {
title?: JSX.Element;
description?: JSX.Element;
className?: string;
buttons?: JSX.Element | CloseWrapper<JSX.Element>;
onClose?: () => void;
}
/**
* Function to show a dialog.
*/
export type ShowDialogFn = (info: DialogInfo | CloseWrapper<DialogInfo>) => void;
/**
* Context for the dialog provider.
*/
export const DialogContext = createContext<ShowDialogFn>(() => {});
/**
* @returns The dialog context for showing dialogs.
*/
export const useDialog = () => useContext(DialogContext);