MCPcopy Create free account
hub / github.com/TanStack/devtools / HotkeyConfig

Function HotkeyConfig

packages/devtools/src/tabs/hotkey-config.tsx:24–97  ·  view source on GitHub ↗
(props: HotkeyConfigProps)

Source from the content-addressed store, hash-verified

22
23export const HotkeyConfig = (props: HotkeyConfigProps) => {
24 const styles = createStyles()
25
26 const toggleModifier = (modifier: KeyboardKey) => {
27 if (props.hotkey.includes(modifier)) {
28 props.onHotkeyChange(props.hotkey.filter((key) => key !== modifier))
29 } else {
30 const existingModifiers = props.hotkey.filter((key) =>
31 props.modifiers.includes(key as any),
32 )
33 const otherKeys = props.hotkey.filter(
34 (key) => !props.modifiers.includes(key as any),
35 )
36 props.onHotkeyChange([...existingModifiers, modifier, ...otherKeys])
37 }
38 }
39
40 const getNonModifierValue = () => {
41 return props.hotkey
42 .filter((key) => !props.modifiers.includes(key as any))
43 .join('+')
44 }
45
46 const handleKeyInput = (input: string) => {
47 const makeModifierArray = (key: string) => {
48 if (key.length === 1) return [uppercaseFirstLetter(key)]
49 const modifiersArray: Array<string> = []
50 for (const character of key) {
51 const newLetter = uppercaseFirstLetter(character)
52 if (!modifiersArray.includes(newLetter)) modifiersArray.push(newLetter)
53 }
54 return modifiersArray
55 }
56
57 const hotkeyModifiers = props.hotkey.filter((key) =>
58 props.modifiers.includes(key as any),
59 )
60 const newKeys = input
61 .split('+')
62 .flatMap((key) => makeModifierArray(key))
63 .filter(Boolean)
64 props.onHotkeyChange([...hotkeyModifiers, ...newKeys])
65 }
66
67 const getDisplayHotkey = () => {
68 return props.hotkey.join(' + ')
69 }
70
71 return (
72 <div class={styles().settingsGroup}>
73 {/* `title` names the shortcut, `description` explains it — before, the
74 description was rendered as the heading and `title` went unused. */}
75 <h4 class={styles().hotkeyTitle}>{props.title}</h4>
76 <p class={styles().hotkeyDescription}>{props.description}</p>
77 <div class={styles().settingsModifiers}>
78 <Show keyed when={props.hotkey}>
79 {props.modifiers.map((modifier) => {
80 const enabled = props.hotkey.includes(modifier)
81 return (

Callers

nothing calls this directly

Calls 4

createStylesFunction · 0.90
toggleModifierFunction · 0.85
getNonModifierValueFunction · 0.85
getDisplayHotkeyFunction · 0.85

Tested by

no test coverage detected