Files
spacedrive/interface/hooks/useKeyBind.ts
nikec 99ccb8f8c7 [ENG-972] quick view improvements (#1233)
* quick preview improvements

* fix ts

* improvements

* fix merge

* non-indexed support

* Update index.tsx

* Update pnpm-lock.yaml

* update quick preview

* sidebar icon weight

* fix thumb

* ts

* fix focus

* remove usePortal

* quick preview store

* Update index.tsx

* Update index.tsx

* cleanup

* add tooltip to name

* hide nav buttons and match explorer nav buttons

---------

Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com>
2023-09-08 11:45:37 +00:00

36 lines
956 B
TypeScript

import { DependencyList } from 'react';
import { HotkeyCallback, Options, useHotkeys } from 'react-hotkeys-hook';
interface UseKeyBindOptions extends Options {
repeatable?: boolean;
}
type UseKeyBindOptionsOrDependencyArray = UseKeyBindOptions | DependencyList;
export const useKeyBind = (
keys: string | string[] | string[][],
callback: HotkeyCallback,
options?: UseKeyBindOptionsOrDependencyArray,
dependencies?: UseKeyBindOptionsOrDependencyArray
) => {
const keyCombination = Array.isArray(keys)
? Array.isArray(keys[0])
? keys.map((k) => (k as string[]).join('+'))
: keys.join('+')
: keys;
const repeatable =
typeof options === 'object' && 'repeatable' in options
? options.repeatable
: typeof dependencies === 'object' && 'repeatable' in dependencies
? dependencies.repeatable
: false;
return useHotkeys(
keyCombination,
(e, k) => (repeatable || !e.repeat) && callback(e, k),
options,
dependencies
);
};