mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 21:05:06 +03:00
* feat(preferences): allow disable hotkeys Add a section in /account/me for disabling hotkeys. Only added one hotkey for now (Cmd + E for toggling editor side panel) but we can add more with the same pattern. * refactor: remove default export on ProjectLayout * feat(hotkeys): allow toggling of command menu and ai assistant hotkeys * Nit * PRettier lint --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
26 lines
604 B
TypeScript
26 lines
604 B
TypeScript
import { useEffect } from 'react'
|
|
|
|
export function useHotKey(
|
|
callback: (e: KeyboardEvent) => void,
|
|
key: string,
|
|
dependencies: any[] = [],
|
|
options?: { enabled?: boolean }
|
|
): void {
|
|
const enabled = options?.enabled ?? true
|
|
|
|
useEffect(() => {
|
|
if (!enabled) return
|
|
|
|
function handler(e: KeyboardEvent) {
|
|
if ((e.metaKey || e.ctrlKey) && e.key === key && !e.altKey && !e.shiftKey) {
|
|
callback(e)
|
|
}
|
|
}
|
|
|
|
window.addEventListener('keydown', handler)
|
|
return () => {
|
|
window.removeEventListener('keydown', handler)
|
|
}
|
|
}, [key, enabled, ...dependencies])
|
|
}
|