@@ -13,6 +13,7 @@ import { UseHotkeysExample } from 'dev/components/examples/use-hotkeys/use-hotke
13
13
import { UseHoverExample } from 'dev/components/examples/use-hover/use-hover.example' ;
14
14
import { UseIdExample } from 'dev/components/examples/use-id/use-id.example' ;
15
15
import { UseIdleExample } from 'dev/components/examples/use-idle/use-idle.example' ;
16
+ import { UseKeyboardExample } from 'dev/components/examples/use-keyboard/use-keyboard.example' ;
16
17
import { UseLocalStorageExample } from 'dev/components/examples/use-local-storage/use-local-storage.example' ;
17
18
import { UseMediaQueryExample } from 'dev/components/examples/use-media-query/use-media-query.example' ;
18
19
import { UseMountedExample } from 'dev/components/examples/use-mounted/use-mounted.example' ;
@@ -22,13 +23,17 @@ import { UseOrientationExample } from 'dev/components/examples/use-orientation/u
22
23
import { UseOsExample } from 'dev/components/examples/use-os/use-os.example' ;
23
24
import { UseResizeObserverExample } from 'dev/components/examples/use-resize-observer/use-resize-observer.example' ;
24
25
import { UseToggleExample } from 'dev/components/examples/use-toggle/use-toggle.example' ;
26
+ import { Kbd } from 'dev/components/kbd' ;
25
27
import { IconCheck , IconCopy , IconGithub , IconLogo } from 'dev/icons' ;
26
28
import { createMemo , createSignal , For , Show } from 'solid-js' ;
27
- import { useHotkeys , useLocalStorage } from 'src' ;
29
+ import { createStore } from 'solid-js/store' ;
30
+ import { getHotkeyHandler , useHotkeys , useKeyboard , useLocalStorage } from 'src' ;
28
31
29
32
export default function HomePage ( ) {
30
33
const [ searchInput , setSearchInput ] = createSignal ( '' ) ;
31
34
35
+ const [ kbdActiveStore , setKbdActiveStore ] = createStore ( { cmd : false , K : false } ) ;
36
+
32
37
const LIST = [
33
38
{
34
39
title : 'useCounter' ,
@@ -46,6 +51,10 @@ export default function HomePage() {
46
51
title : 'useHotkeys' ,
47
52
example : < UseHotkeysExample /> ,
48
53
} ,
54
+ {
55
+ title : 'useKeyboard' ,
56
+ example : < UseKeyboardExample /> ,
57
+ } ,
49
58
{
50
59
title : 'useHover' ,
51
60
example : < UseHoverExample /> ,
@@ -143,6 +152,7 @@ export default function HomePage() {
143
152
} ) ;
144
153
145
154
let searchInputRef ! : HTMLInputElement ;
155
+
146
156
useHotkeys ( [
147
157
[
148
158
'mod+k' ,
@@ -151,6 +161,30 @@ export default function HomePage() {
151
161
} ,
152
162
] ,
153
163
] ) ;
164
+
165
+ useKeyboard ( {
166
+ onKeyDown : event => {
167
+ if ( event . key === 'k' ) {
168
+ setKbdActiveStore ( 'K' , true ) ;
169
+ }
170
+ if ( event . metaKey ) {
171
+ setKbdActiveStore ( 'cmd' , true ) ;
172
+ }
173
+ } ,
174
+ onKeyUp ( event ) {
175
+ if ( event . key === 'k' ) {
176
+ setKbdActiveStore ( 'K' , false ) ;
177
+ }
178
+ if ( event . key === 'Meta' ) {
179
+ setKbdActiveStore ( 'cmd' , false ) ;
180
+
181
+ if ( kbdActiveStore . K ) {
182
+ setKbdActiveStore ( 'K' , false ) ;
183
+ }
184
+ }
185
+ } ,
186
+ } ) ;
187
+
154
188
return (
155
189
< div class = "relative flex flex-col items-start gap-y-5" >
156
190
< a
@@ -205,14 +239,29 @@ export default function HomePage() {
205
239
</ button >
206
240
</ div >
207
241
208
- < input
209
- ref = { searchInputRef }
210
- class = "mx-auto w-full max-w-md rounded-md p-2.5 px-4"
211
- onInput = { e => {
212
- setSearchInput ( e . currentTarget . value ) ;
213
- } }
214
- placeholder = "Cmd + K to search"
215
- />
242
+ < div class = "relative mx-auto flex h-max w-full max-w-md items-center" >
243
+ < input
244
+ ref = { searchInputRef }
245
+ value = { searchInput ( ) }
246
+ class = "relative w-full rounded-md p-2.5 px-4"
247
+ onInput = { e => {
248
+ setSearchInput ( e . currentTarget . value ) ;
249
+ } }
250
+ placeholder = "Quicksearch..."
251
+ onKeyDown = { getHotkeyHandler ( [
252
+ [
253
+ 'Escape' ,
254
+ ( ) => {
255
+ searchInputRef . blur ( ) ;
256
+ } ,
257
+ ] ,
258
+ ] ) }
259
+ />
260
+ < div class = "absolute right-0 top-2.5 flex items-center gap-x-1 px-2 opacity-80" >
261
+ < Kbd activated = { kbdActiveStore . cmd } > Cmd</ Kbd >
262
+ < Kbd activated = { kbdActiveStore . K } > K</ Kbd >
263
+ </ div >
264
+ </ div >
216
265
</ div >
217
266
218
267
< div class = "max-w-8xl mx-auto grid w-full grid-cols-1 gap-3 px-5 md:grid-cols-2 xl:grid-cols-3" >
0 commit comments