Skip to content

Commit cb21d85

Browse files
committed
feat: add keyboard shortcuts
1 parent f7ea109 commit cb21d85

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

examples/react/basic/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ function App() {
44
return (
55
<div>
66
<h1>TanStack Devtools Basic Example</h1>
7-
<Devtools />
7+
<Devtools options={{
8+
openHotkey: ["Shift", "B"]
9+
}} />
810
</div>
911
)
1012
}

examples/solid/basic/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ function App() {
44
return (
55
<div>
66
<h1>TanStack Devtools Basic Example</h1>
7-
<Devtools />
7+
<Devtools options={{
8+
openHotkey: ["Shift", "B"]
9+
}} />
810
</div>
911
)
1012
}

packages/devtools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
"build": "vite build"
5959
},
6060
"dependencies": {
61+
"@solid-primitives/keyboard": "^1.2.8",
6162
"clsx": "^2.1.1",
6263
"goober": "^2.1.16",
6364
"solid-js": "^1.9.5"
6465
},
6566
"devDependencies": {
6667
"vite-plugin-solid": "^2.11.6"
6768
}
68-
}
69+
}

packages/devtools/src/context/devtools-store.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { DevtoolsPlugin } from './devtools-context'
22

3+
type ModifierKey = 'Alt' | 'Control' | 'Meta' | 'Shift'
4+
type KeyboardKey = ModifierKey | (string & {})
5+
36
type TriggerPosition =
47
| 'top-left'
58
| 'top-right'
@@ -35,7 +38,7 @@ export type DevtoolsStore = {
3538
* The hotkey to open the dev tools
3639
* @default "shift+a"
3740
*/
38-
openHotkey: string
41+
openHotkey: Array<KeyboardKey>
3942
/**
4043
* Whether to require the URL flag to open the dev tools
4144
* @default false
@@ -62,7 +65,7 @@ export const initialState: DevtoolsStore = {
6265
hideUntilHover: false,
6366
position: 'bottom-right',
6467
panelLocation: 'bottom',
65-
openHotkey: 'shift+a',
68+
openHotkey: ['Shift', 'A'],
6669
requireUrlFlag: false,
6770
urlFlag: 'tanstack-devtools',
6871
},

packages/devtools/src/devtools.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createEffect, createSignal } from 'solid-js'
2+
import { createShortcut } from '@solid-primitives/keyboard'
23
import {
34
useDevtoolsSettings,
45
useHeight,
@@ -123,7 +124,9 @@ export default function DevTools() {
123124
el?.style.setProperty('--tsrd-font-size', fontSize)
124125
}
125126
})
126-
127+
createShortcut(settings().openHotkey, () => {
128+
toggleOpen()
129+
})
127130
return (
128131
<div ref={setRootEl} data-testid={TANSTACK_DEVTOOLS}>
129132
<Trigger isOpen={isOpen} setIsOpen={toggleOpen} />

pnpm-lock.yaml

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)