UNPKG

@tanstack/react-hotkeys

Version:

React adapter for TanStack Hotkeys

61 lines • 2.16 kB
import { CustomHotkeyActions, CustomHotkeys, RegisteredAppHotkeyListItem, RegisteredAppHotkeys } from "@tanstack/hotkeys"; /** * Returns the effective app hotkeys from `HotkeysProvider`, typed by * `Register`: each declaration with the user's custom hotkey applied. * Pass an entry to `useHotkey` or `useHotkeys` to register it. * * @example * ```tsx * const appHotkeys = useAppHotkeys() * useHotkey(appHotkeys['doc.save'], () => save()) * ``` */ export declare function useAppHotkeys(): RegisteredAppHotkeys; /** * Lists every app hotkey with its live status, in declaration order, for * cheat sheets and settings screens. App hotkeys whose components have not * mounted are `'inactive'`; those without a hotkey are `'unbound'`. * * @example * ```tsx * function CheatSheet() { * const items = useAppHotkeyList() * const formatForDisplay = useFormatForDisplay() * * return ( * <ul> * {items.map(({ appHotkey, status }) => ( * <li key={appHotkey.id} data-status={status}> * {appHotkey.meta?.name}:{' '} * {appHotkey.hotkey ? formatForDisplay(appHotkey.hotkey) : 'Unassigned'} * </li> * ))} * </ul> * ) * } * ``` */ export declare function useAppHotkeyList(): Array<RegisteredAppHotkeyListItem>; /** Custom hotkey state and actions returned by `useCustomHotkeys`. */ export interface UseCustomHotkeysResult extends CustomHotkeyActions { /** The user's hotkeys that differ from the defaults. */ customHotkeys: CustomHotkeys; } /** * Reads and changes the user's custom hotkeys. Changes apply to every * registered app hotkey immediately and are passed to the provider's * `onCustomHotkeysChange`, ready to save. * * @example * ```tsx * const { setCustomHotkey, findConflicts } = useCustomHotkeys() * const recorder = useHotkeyRecorder({ * maxSteps: Infinity, * validate: (hotkey, context) => * findConflicts('doc.save', hotkey, context).length === 0 || * 'Already in use', * onRecord: (hotkey, context) => setCustomHotkey('doc.save', hotkey, context), * }) * ``` */ export declare function useCustomHotkeys(): UseCustomHotkeysResult;