1
1
import React from 'react' ;
2
2
3
+ import type { HotkeysGroup } from '@gravity-ui/navigation' ;
3
4
import { HotkeysPanel as UIKitHotkeysPanel } from '@gravity-ui/navigation' ;
4
5
import { Hotkey } from '@gravity-ui/uikit' ;
5
6
import hotkeys from 'hotkeys-js' ;
@@ -13,7 +14,7 @@ export const isMac = () => navigator.platform.toUpperCase().includes('MAC');
13
14
14
15
export const SHORTCUTS_HOTKEY = isMac ( ) ? 'cmd+K' : 'ctrl+K' ;
15
16
16
- export const HOTKEYS = [
17
+ export const DEFAULT_HOTKEY_GROUPS : HotkeysGroup [ ] = [
17
18
{
18
19
title : 'Query Editor' ,
19
20
items : [
@@ -48,6 +49,7 @@ export const HOTKEYS = [
48
49
export interface HotkeysPanelProps {
49
50
visible : boolean ;
50
51
closePanel : ( ) => void ;
52
+ hotkeyGroups ?: HotkeysGroup [ ] ;
51
53
}
52
54
53
55
/**
@@ -60,7 +62,11 @@ export interface HotkeysPanelProps {
60
62
* This wrapper ensures the component mounts first, then sets visible=true in a subsequent render cycle
61
63
* to make transition actually happen.
62
64
*/
63
- export const HotkeysPanelWrapper = ( { visible : propsVisible , closePanel} : HotkeysPanelProps ) => {
65
+ export const HotkeysPanelWrapper = ( {
66
+ visible : propsVisible ,
67
+ closePanel,
68
+ hotkeyGroups = DEFAULT_HOTKEY_GROUPS ,
69
+ } : HotkeysPanelProps ) => {
64
70
const [ visible , setVisible ] = React . useState ( false ) ;
65
71
66
72
React . useEffect ( ( ) => {
@@ -70,7 +76,7 @@ export const HotkeysPanelWrapper = ({visible: propsVisible, closePanel}: Hotkeys
70
76
return (
71
77
< UIKitHotkeysPanel
72
78
visible = { visible }
73
- hotkeys = { HOTKEYS }
79
+ hotkeys = { hotkeyGroups }
74
80
className = { b ( 'hotkeys-panel' ) }
75
81
title = {
76
82
< div className = { b ( 'hotkeys-panel-title' ) } >
@@ -87,9 +93,15 @@ interface UseHotkeysPanel {
87
93
isPanelVisible : boolean ;
88
94
openPanel : ( ) => void ;
89
95
closePanel : ( ) => void ;
96
+ hotkeyGroups ?: HotkeysGroup [ ] ;
90
97
}
91
98
92
- export const useHotkeysPanel = ( { isPanelVisible, openPanel, closePanel} : UseHotkeysPanel ) => {
99
+ export const useHotkeysPanel = ( {
100
+ isPanelVisible,
101
+ openPanel,
102
+ closePanel,
103
+ hotkeyGroups = DEFAULT_HOTKEY_GROUPS ,
104
+ } : UseHotkeysPanel ) => {
93
105
React . useEffect ( ( ) => {
94
106
hotkeys ( SHORTCUTS_HOTKEY , openPanel ) ;
95
107
@@ -102,8 +114,14 @@ export const useHotkeysPanel = ({isPanelVisible, openPanel, closePanel}: UseHotk
102
114
} , [ openPanel ] ) ;
103
115
104
116
const renderPanel = React . useCallback (
105
- ( ) => < HotkeysPanelWrapper visible = { isPanelVisible } closePanel = { closePanel } /> ,
106
- [ isPanelVisible , closePanel ] ,
117
+ ( ) => (
118
+ < HotkeysPanelWrapper
119
+ visible = { isPanelVisible }
120
+ closePanel = { closePanel }
121
+ hotkeyGroups = { hotkeyGroups }
122
+ />
123
+ ) ,
124
+ [ isPanelVisible , closePanel , hotkeyGroups ] ,
107
125
) ;
108
126
109
127
return {
0 commit comments