mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 15:05:35 +00:00
31 lines
693 B
TypeScript
31 lines
693 B
TypeScript
import KEYS from '#constants/keys';
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
|
|
|
type ShortcutOptions = {
|
|
enabled?: boolean;
|
|
disableGlobalCheck?: boolean;
|
|
};
|
|
|
|
export default function useShortcut(
|
|
key: keyof typeof KEYS,
|
|
cb: () => void,
|
|
{ enabled, disableGlobalCheck }: ShortcutOptions = {
|
|
enabled: true,
|
|
disableGlobalCheck: false,
|
|
}
|
|
) {
|
|
const { globalHotkeysEnabled } = useGlobalHotkeysStore();
|
|
return useHotkeys(
|
|
KEYS[key],
|
|
(event) => {
|
|
event.preventDefault();
|
|
cb();
|
|
},
|
|
{
|
|
enabled: disableGlobalCheck ? enabled : enabled && globalHotkeysEnabled,
|
|
enableOnFormTags: ['INPUT'],
|
|
}
|
|
);
|
|
}
|