@jengaui/alert-dialog
Version:
Jenga UI Alert Dialog component in React
56 lines (53 loc) • 1.57 kB
TypeScript
import { DialogProps, AlertDialogResolveStatus } from './types.js';
import '@react-types/dialog';
import 'react';
import 'tastycss';
import '@jengaui/dialog';
import './AlertDialog.js';
import '@jengaui/button';
interface DialogApi {
open: (dialogProps: DialogProps, params?: DialogApiParams) => Promise<AlertDialogResolveStatus>;
}
interface DialogApiParams {
cancelToken?: AbortSignal;
}
/**
* @internal Do not use it in your code!
*/
declare function AlertDialogApiProvider(props: any): JSX.Element;
/**
* Hook gives the ability to open `<AlertDialog />` imperatively.
*
* ***Important*** it's commonly a bad practice when you open multiple dialogs in a row;
* that means this api will reject all dialogs when there is already open one
*
* @example calling in a side effect
* const alertDialogAPI = useAlertDialogAPI();
*
* useEffect(() => {
* const abortDialog = new AbortController();
* const openedDialog = alertDialogAPI.open({
* title: 'Are you sure?',
* content: <Paragraph>Test content</Paragraph>
* }, {
* cancelToken: abortDialog.signal
* });
*
* openedDialog.then(() => console.log('closed'))
*
* return () => {
* abortDialog.abort();
* }
* }, [])
*
* @example opening dialog on Button click.
* const alertDialogAPI = useAlertDialogAPI();
*
* const onPress = useCallback(() => {
* alertDialogAPI.open({...})
* }, [])
*
* return <Button onPress={onPress}>New issue</Button>
*/
declare function useAlertDialogAPI(): DialogApi;
export { AlertDialogApiProvider, useAlertDialogAPI };