UNPKG

2.62 kBTypeScriptView Raw
1import * as React from "react";
2import { HotkeysDialog2Props } from "../../components/hotkeys/hotkeysDialog2";
3import { HotkeyConfig } from "../../hooks";
4interface HotkeysContextState {
5 /**
6 * Whether the context instance is being used within a tree which has a <HotkeysProvider>.
7 * It's technically ok if this is false, but not recommended, since that means any hotkeys
8 * bound with that context instance will not show up in the hotkeys help dialog.
9 */
10 hasProvider: boolean;
11 /** List of hotkeys accessible in the current scope, registered by currently mounted components, can be global or local. */
12 hotkeys: HotkeyConfig[];
13 /** Whether the global hotkeys dialog is open. */
14 isDialogOpen: boolean;
15}
16declare type HotkeysAction = {
17 type: "ADD_HOTKEYS" | "REMOVE_HOTKEYS";
18 payload: HotkeyConfig[];
19} | {
20 type: "CLOSE_DIALOG" | "OPEN_DIALOG";
21};
22export declare type HotkeysContextInstance = [HotkeysContextState, React.Dispatch<HotkeysAction>];
23/**
24 * A React context used to register and deregister hotkeys as components are mounted and unmounted in an application.
25 * Users should take care to make sure that only _one_ of these is instantiated and used within an application, especially
26 * if using global hotkeys.
27 *
28 * You will likely not be using this HotkeysContext directly, except in cases where you need to get a direct handle on an
29 * existing context instance for advanced use cases involving nested HotkeysProviders.
30 *
31 * For more information, see the [HotkeysProvider documentation](https://blueprintjs.com/docs/#core/context/hotkeys-provider).
32 */
33export declare const HotkeysContext: React.Context<HotkeysContextInstance>;
34export interface HotkeysProviderProps {
35 /** The component subtree which will have access to this hotkeys context. */
36 children: React.ReactChild;
37 /** Optional props to customize the rendered hotkeys dialog. */
38 dialogProps?: Partial<Omit<HotkeysDialog2Props, "hotkeys">>;
39 /** If provided, this dialog render function will be used in place of the default implementation. */
40 renderDialog?: (state: HotkeysContextState, contextActions: {
41 handleDialogClose: () => void;
42 }) => JSX.Element;
43 /** If provided, we will use this context instance instead of generating our own. */
44 value?: HotkeysContextInstance;
45}
46/**
47 * Hotkeys context provider, necessary for the `useHotkeys` hook.
48 *
49 * @see https://blueprintjs.com/docs/#core/context/hotkeys-provider
50 */
51export declare const HotkeysProvider: ({ children, dialogProps, renderDialog, value }: HotkeysProviderProps) => JSX.Element;
52export {};