useIsShortcutEnabled.ts 815 B

1234567891011121314151617181920
  1. import type { ShortcutId } from './registry'
  2. import { useShortcutPreferences } from './state'
  3. /**
  4. * Reactive check for whether a shortcut is currently enabled for the user.
  5. *
  6. * Subscribes the calling component to the shortcut preferences query so it
  7. * re-renders when the user toggles this shortcut in Account → Preferences.
  8. *
  9. * For one-off, non-reactive checks outside render (event handlers, module-level
  10. * code), use the plain `isShortcutEnabled(id)` function from `./state` instead.
  11. *
  12. * @example
  13. * const isEnabled = useIsShortcutEnabled(SHORTCUT_IDS.AI_ASSISTANT_TOGGLE)
  14. * return <Tooltip>{isEnabled && <KeyboardShortcut keys={['Meta', 'I']} />}</Tooltip>
  15. */
  16. export function useIsShortcutEnabled(id: ShortcutId): boolean {
  17. const { disabled } = useShortcutPreferences()
  18. return !disabled[id]
  19. }