feat: DialogProvider component (#198)

* feat: somewhat working DialogProvider

* feat: handle multiple dialogs properly, initial focus

let's just ignore that showFocus=true doesn't work with "nested" dialogs

Co-authored-by: Razboy20 <Razboy20@users.noreply.github.com>

* feat: rework code

* feat: add default styles to prompts

* refactor: fix stylings

---------

Co-authored-by: Razboy20 <Razboy20@users.noreply.github.com>
Co-authored-by: Razboy20 <razboy20@gmail.com>
This commit is contained in:
Samuel Gunter
2024-05-20 13:00:00 -07:00
committed by GitHub
parent bcb5a8c469
commit d1b921a5b0
5 changed files with 331 additions and 4 deletions

View File

@@ -0,0 +1,33 @@
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>;
initialFocusHidden?: boolean;
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);