use-kbd 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -36
- package/dist/index.cjs +2145 -409
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +646 -76
- package/dist/index.d.ts +646 -76
- package/dist/index.js +2108 -405
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/src/styles.css +302 -67
package/README.md
CHANGED
|
@@ -2,49 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/use-kbd)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Keyboard shortcuts, navigation, omnibar for React apps.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
2. **Minimal-boilerplate action registration** via `useAction` hook, colocated with handlers
|
|
9
|
-
3. **CSS variables** for easy theming customization
|
|
7
|
+
**[📖 Documentation & Demos →][kbd.rbw.sh]**
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
- [ctbk.dev]
|
|
13
|
-
- [awair.runsascoded.com]
|
|
14
|
-
|
|
15
|
-
## Inspiration
|
|
16
|
-
- macOS (⌘-/) and GDrive (⌥-/) menu search
|
|
17
|
-
- [Superhuman] omnibar
|
|
18
|
-
- Android searchable settings
|
|
19
|
-
- [Vimium] keyboard-driven browsing.
|
|
9
|
+
Also in production at [ctbk.dev] and [awair.runsascoded.com].
|
|
20
10
|
|
|
11
|
+
[kbd.rbw.sh]: https://kbd.rbw.sh
|
|
21
12
|
[ctbk.dev]: https://ctbk.dev
|
|
22
13
|
[awair.runsascoded.com]: https://awair.runsascoded.com
|
|
23
|
-
[Superhuman]: https://superhuman.com
|
|
24
|
-
[Vimium]: https://github.com/philc/vimium
|
|
25
14
|
|
|
26
15
|
## Quick Start
|
|
27
16
|
|
|
17
|
+
```bash
|
|
18
|
+
npm install use-kbd # or: pnpm add use-kbd
|
|
19
|
+
```
|
|
20
|
+
|
|
28
21
|
```tsx
|
|
29
|
-
import { HotkeysProvider, ShortcutsModal, Omnibar, SequenceModal, useAction } from 'use-kbd'
|
|
22
|
+
import { HotkeysProvider, ShortcutsModal, Omnibar, LookupModal, SequenceModal, useAction } from 'use-kbd'
|
|
30
23
|
import 'use-kbd/styles.css'
|
|
31
24
|
|
|
32
25
|
function App() {
|
|
33
26
|
return (
|
|
34
27
|
<HotkeysProvider>
|
|
35
|
-
{/* Your app content */}
|
|
36
28
|
<Dashboard />
|
|
37
|
-
{/*
|
|
38
|
-
<
|
|
39
|
-
<
|
|
40
|
-
<SequenceModal />
|
|
29
|
+
<ShortcutsModal /> {/* "?" modal: view/edit key-bindings */}
|
|
30
|
+
<Omnibar /> {/* "⌘K" omnibar: search and select actions */}
|
|
31
|
+
<LookupModal /> {/* "⌘⇧K": look up actions by key-binding */}
|
|
32
|
+
<SequenceModal /> {/* Inline display for key-sequences in progress */}
|
|
41
33
|
</HotkeysProvider>
|
|
42
34
|
)
|
|
43
35
|
}
|
|
44
36
|
|
|
45
37
|
function Dashboard() {
|
|
46
|
-
const { save
|
|
38
|
+
const { save } = useDocument() // Function to expose via hotkeys / omnibar
|
|
47
39
|
|
|
40
|
+
// Wrap function as "action", with keybinding(s) and omnibar keywords
|
|
48
41
|
useAction('doc:save', {
|
|
49
42
|
label: 'Save document',
|
|
50
43
|
group: 'Document',
|
|
@@ -52,24 +45,20 @@ function Dashboard() {
|
|
|
52
45
|
handler: save,
|
|
53
46
|
})
|
|
54
47
|
|
|
55
|
-
useAction('doc:export', {
|
|
56
|
-
label: 'Export data',
|
|
57
|
-
group: 'Document',
|
|
58
|
-
defaultBindings: ['meta+e'],
|
|
59
|
-
handler: exportData,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
48
|
return <Editor />
|
|
63
49
|
}
|
|
64
50
|
```
|
|
65
51
|
|
|
66
|
-
|
|
52
|
+
### Basic steps
|
|
67
53
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
1. **Drop-in UI components**:
|
|
55
|
+
- `ShortcutsModal`: view/edit key-bindings
|
|
56
|
+
- `Omnibar`: search and select actions
|
|
57
|
+
- `LookupModal`: look up actions by key-binding
|
|
58
|
+
- `SequenceModal`: autocomplete multi-key sequences
|
|
59
|
+
- `ActionLink`: register links as actions
|
|
60
|
+
2. **Register functions as "actions"** with `useAction`
|
|
61
|
+
3. **Easy theming** with CSS variables
|
|
73
62
|
|
|
74
63
|
## Core Concepts
|
|
75
64
|
|
|
@@ -118,7 +107,7 @@ Wrap your app to enable the hotkeys system:
|
|
|
118
107
|
storageKey: 'use-kbd', // localStorage key for user overrides (default)
|
|
119
108
|
modalTrigger: '?', // Open shortcuts modal (default; false to disable)
|
|
120
109
|
omnibarTrigger: 'meta+k', // Open omnibar (default; false to disable)
|
|
121
|
-
sequenceTimeout:
|
|
110
|
+
sequenceTimeout: Infinity, // ms before sequence times out (default: no timeout)
|
|
122
111
|
}}>
|
|
123
112
|
{children}
|
|
124
113
|
</HotkeysProvider>
|
|
@@ -211,6 +200,16 @@ const { isRecording, startRecording, display } = useRecordHotkey({
|
|
|
211
200
|
|
|
212
201
|
Wraps `useHotkeys` with localStorage persistence and conflict detection.
|
|
213
202
|
|
|
203
|
+
## Inspiration
|
|
204
|
+
|
|
205
|
+
- macOS and GDrive menu search
|
|
206
|
+
- [Superhuman] omnibar
|
|
207
|
+
- [Vimium] keyboard-driven browsing
|
|
208
|
+
- Android searchable settings
|
|
209
|
+
|
|
210
|
+
[Superhuman]: https://superhuman.com
|
|
211
|
+
[Vimium]: https://github.com/philc/vimium
|
|
212
|
+
|
|
214
213
|
## License
|
|
215
214
|
|
|
216
215
|
MIT
|