From 1a133c5a2acf16159316189b98e86585cf0d6732 Mon Sep 17 00:00:00 2001 From: talksik Date: Mon, 30 May 2022 13:32:48 -0500 Subject: [PATCH] insane nice typechecking here --- .../src/components/KeyboardShortcutLabel.tsx | 7 ++++++- packages/desktop/src/components/Navbar.tsx | 4 ++-- packages/desktop/src/util/keyboard.ts | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/desktop/src/components/KeyboardShortcutLabel.tsx b/packages/desktop/src/components/KeyboardShortcutLabel.tsx index 03979a7..b6fbf25 100644 --- a/packages/desktop/src/components/KeyboardShortcutLabel.tsx +++ b/packages/desktop/src/components/KeyboardShortcutLabel.tsx @@ -1,9 +1,14 @@ import { Box, Paper, Typography } from '@mui/material'; +import { KeyboardShortcuts } from '../util/keyboard'; import React from 'react'; import { blueGrey } from '@mui/material/colors'; -export default function KeyboardShortcutLabel({ label }: { label: string }) { +export default function KeyboardShortcutLabel({ + label, +}: { + label: keyof typeof KeyboardShortcuts; +}) { return ( } - + diff --git a/packages/desktop/src/util/keyboard.ts b/packages/desktop/src/util/keyboard.ts index 87fc7bc..e453595 100644 --- a/packages/desktop/src/util/keyboard.ts +++ b/packages/desktop/src/util/keyboard.ts @@ -1,3 +1,12 @@ -export enum KeyboardShortcuts { - search = '/', -} +type Shortcut = { label: string; shortcutKey: string }; + +export const KeyboardShortcuts: Record = { + search: { + label: '/', + shortcutKey: '/', + }, + escape: { + shortcutKey: 'Escape', + label: 'esc', + }, +};