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:
33
src/views/contexts/DialogContext.ts
Normal file
33
src/views/contexts/DialogContext.ts
Normal 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);
|
||||
Reference in New Issue
Block a user