UNPKG

react-keyhub

Version:

A lightweight, scalable keyboard shortcut manager for React applications with TypeScript support

28 lines (27 loc) 1.17 kB
import { useKeyHubShortcuts } from './KeyHubContext'; import { ShortcutCallback, ShortcutSettings } from './types'; /** * Type helper to get the available shortcuts from the current provider */ export type ProviderShortcuts = ReturnType<typeof useKeyHubShortcuts>; /** * Type for available shortcut keys in the current provider */ export type AvailableShortcuts = keyof ProviderShortcuts; /** * Enhanced hook to subscribe to a keyboard shortcut with type suggestions * @param shortcutId The ID of the shortcut to subscribe to (with autocomplete) * @param callback The callback to execute when the shortcut is triggered * @returns A boolean indicating if the shortcut is registered * @example * // Will suggest all registered shortcuts like 'save', 'undo', etc. * const isSaveRegistered = useShortcut('save', (e) => { * // Handle save shortcut * }); */ export declare function useShortcut<T extends AvailableShortcuts>(shortcutId: T, callback: ShortcutCallback): boolean; /** * Helper function to get all registered shortcuts * @returns All registered shortcuts from the provider */ export declare function getRegisteredShortcuts(): ShortcutSettings;