@@ -13,6 +13,7 @@ import { UseHotkeysExample } from 'dev/components/examples/use-hotkeys/use-hotke
1313import { UseHoverExample } from 'dev/components/examples/use-hover/use-hover.example' ;
1414import { UseIdExample } from 'dev/components/examples/use-id/use-id.example' ;
1515import { UseIdleExample } from 'dev/components/examples/use-idle/use-idle.example' ;
16+ import { UseKeyboardExample } from 'dev/components/examples/use-keyboard/use-keyboard.example' ;
1617import { UseLocalStorageExample } from 'dev/components/examples/use-local-storage/use-local-storage.example' ;
1718import { UseMediaQueryExample } from 'dev/components/examples/use-media-query/use-media-query.example' ;
1819import { UseMountedExample } from 'dev/components/examples/use-mounted/use-mounted.example' ;
@@ -22,13 +23,17 @@ import { UseOrientationExample } from 'dev/components/examples/use-orientation/u
2223import { UseOsExample } from 'dev/components/examples/use-os/use-os.example' ;
2324import { UseResizeObserverExample } from 'dev/components/examples/use-resize-observer/use-resize-observer.example' ;
2425import { UseToggleExample } from 'dev/components/examples/use-toggle/use-toggle.example' ;
26+ import { Kbd } from 'dev/components/kbd' ;
2527import { IconCheck , IconCopy , IconGithub , IconLogo } from 'dev/icons' ;
2628import { 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' ;
2831
2932export default function HomePage ( ) {
3033 const [ searchInput , setSearchInput ] = createSignal ( '' ) ;
3134
35+ const [ kbdActiveStore , setKbdActiveStore ] = createStore ( { cmd : false , K : false } ) ;
36+
3237 const LIST = [
3338 {
3439 title : 'useCounter' ,
@@ -46,6 +51,10 @@ export default function HomePage() {
4651 title : 'useHotkeys' ,
4752 example : < UseHotkeysExample /> ,
4853 } ,
54+ {
55+ title : 'useKeyboard' ,
56+ example : < UseKeyboardExample /> ,
57+ } ,
4958 {
5059 title : 'useHover' ,
5160 example : < UseHoverExample /> ,
@@ -143,6 +152,7 @@ export default function HomePage() {
143152 } ) ;
144153
145154 let searchInputRef ! : HTMLInputElement ;
155+
146156 useHotkeys ( [
147157 [
148158 'mod+k' ,
@@ -151,6 +161,30 @@ export default function HomePage() {
151161 } ,
152162 ] ,
153163 ] ) ;
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+
154188 return (
155189 < div class = "relative flex flex-col items-start gap-y-5" >
156190 < a
@@ -205,14 +239,29 @@ export default function HomePage() {
205239 </ button >
206240 </ div >
207241
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 >
216265 </ div >
217266
218267 < 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