summit-kit
Version:
A React component library for building modern web applications with with an earthy and outdoorsy flair.
25 lines (24 loc) • 936 B
TypeScript
/**
* Custom React hook that listens for specified keyboard shortcuts and triggers associated actions.
*
* @param shortcuts - An array of shortcut objects, each containing:
* - `shortcutKey`: A string representing the key or key combination (e.g., "Control+S", "Shift+Alt+X").
* - `action` (optional): A callback function to execute when the shortcut is pressed.
*
* @remarks
* - Supports combination shortcuts using "Shift", "Control", "Meta", and "Alt" modifiers.
* - The hook attaches a `keydown` event listener to the window and cleans up on unmount.
* - Only combination shortcuts (with "+") are currently handled.
*
* @example
* ```tsx
* useKeyPress([
* { shortcutKey: "Control+S", action: handleSave },
* { shortcutKey: "Shift+Alt+X", action: handleSpecialAction }
* ]);<|cursor|>
* ```
*/
export declare const useKeyPress: (shortcuts: {
shortcutKey: string;
action?: () => void;
}[]) => void;