Skip to content

Commit 5745716

Browse files
authored
Merge pull request #1101 from EpicenterHQ/kbd-migration
refactor: migrate keyboard shortcuts to Kbd component
2 parents 6eeff67 + 9db6ae3 commit 5745716

File tree

6 files changed

+17
-40
lines changed

6 files changed

+17
-40
lines changed

apps/whispering/src/lib/constants/keyboard/display-labels.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ const BROWSER_KEY_DISPLAY_LABELS: Partial<
8585
* Gets display label for a full shortcut string.
8686
*
8787
* @param shortcut - The shortcut string (e.g., "control+shift+ ", "a")
88-
* @returns Human-readable display (e.g., "Ctrl+Shift+Space", "A")
88+
* @returns Human-readable display (e.g., "Ctrl + Shift + Space", "A")
8989
*
9090
* @example
9191
* getShortcutDisplayLabel(' ') // 'Space'
92-
* getShortcutDisplayLabel('control+a') // 'Ctrl+A'
92+
* getShortcutDisplayLabel('control+a') // 'Ctrl + A'
9393
* getShortcutDisplayLabel(null) // ''
9494
*/
9595
export function getShortcutDisplayLabel(shortcut: string | null): string {
@@ -98,7 +98,7 @@ export function getShortcutDisplayLabel(shortcut: string | null): string {
9898
return shortcut
9999
.split('+')
100100
.map((key) => formatKeyForDisplay(key.toLowerCase()))
101-
.join('+');
101+
.join(' + ');
102102
}
103103

104104
/**

apps/whispering/src/lib/constants/keyboard/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ export {
1616
KEYBOARD_EVENT_SUPPORTED_KEYS,
1717
type KeyboardEventSupportedKey,
1818
} from './browser/supported-keys';
19-
19+
export { getShortcutDisplayLabel } from './display-labels';
2020
export {
2121
normalizeOptionKeyCharacter,
2222
OPTION_DEAD_KEYS,
2323
} from './macos-option-key-map';
24-
2524
export { CommandOrAlt, CommandOrControl } from './modifiers';
26-
27-
export { getShortcutDisplayLabel } from './display-labels';

apps/whispering/src/routes/(app)/(config)/install-ffmpeg/+page.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { Button, buttonVariants } from '@epicenter/ui/button';
3+
import * as Kbd from '@epicenter/ui/kbd';
34
import { Link } from '@epicenter/ui/link';
45
import * as Card from '@epicenter/ui/card';
56
import * as Alert from '@epicenter/ui/alert';
@@ -230,10 +231,8 @@
230231
<li class="flex gap-3">
231232
<span class="shrink-0">a.</span>
232233
<span
233-
>Press <kbd
234-
class="bg-muted px-2 py-1 rounded font-mono text-xs"
235-
>Windows + X</kbd
236-
> and select "System"</span
234+
>Press <Kbd.Root>Windows + X</Kbd.Root> and select
235+
"System"</span
237236
>
238237
</li>
239238
<li class="flex gap-3">

apps/whispering/src/routes/(app)/(config)/settings/shortcuts/keyboard-shortcut-recorder/KeyboardShortcutRecorder.svelte

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import * as Alert from '@epicenter/ui/alert';
3-
import { Badge } from '@epicenter/ui/badge';
43
import { Button } from '@epicenter/ui/button';
4+
import * as Kbd from '@epicenter/ui/kbd';
55
import { Input } from '@epicenter/ui/input';
66
import * as Popover from '@epicenter/ui/popover';
77
import {
@@ -41,9 +41,7 @@
4141

4242
<div class="flex items-center justify-end gap-2">
4343
{#if rawKeyCombination}
44-
<Badge variant="secondary" class="font-mono text-xs">
45-
{getShortcutDisplayLabel(rawKeyCombination)}
46-
</Badge>
44+
<Kbd.Root>{getShortcutDisplayLabel(rawKeyCombination)}</Kbd.Root>
4745
<Button
4846
variant="ghost"
4947
size="icon"
@@ -137,9 +135,7 @@
137135
class="flex grow items-center gap-1.5 overflow-x-auto pr-2 scrollbar-none"
138136
>
139137
{#if rawKeyCombination && !keyRecorder.isListening}
140-
<Badge variant="secondary" class="font-mono text-xs">
141-
{getShortcutDisplayLabel(rawKeyCombination)}
142-
</Badge>
138+
<Kbd.Root>{getShortcutDisplayLabel(rawKeyCombination)}</Kbd.Root>
143139
{:else if !keyRecorder.isListening}
144140
<span class="truncate text-muted-foreground"
145141
>{placeholder}</span

apps/whispering/src/routes/(app)/(config)/settings/shortcuts/keyboard-shortcut-recorder/ShortcutFormatHelp.svelte

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import * as Alert from '@epicenter/ui/alert';
3-
import { Badge } from '@epicenter/ui/badge';
43
import { Button } from '@epicenter/ui/button';
4+
import * as Kbd from '@epicenter/ui/kbd';
55
import * as Dialog from '@epicenter/ui/dialog';
66
import {
77
ACCELERATOR_SECTIONS,
@@ -90,9 +90,7 @@
9090
<p class="text-xs text-muted-foreground mb-2">Hold with other keys</p>
9191
<div class="flex flex-wrap sm:flex-col gap-1">
9292
{#each (isLocal ? KEYBOARD_EVENT_SUPPORTED_KEY_SECTIONS.at(0) : ACCELERATOR_SECTIONS.at(0)).keys as modifier}
93-
<Badge variant="outline" class="font-mono text-sm justify-start">
94-
{modifier}
95-
</Badge>
93+
<Kbd.Root>{modifier}</Kbd.Root>
9694
{/each}
9795
</div>
9896
</div>
@@ -108,9 +106,7 @@
108106
</p>
109107
<div class="flex flex-wrap gap-1">
110108
{#each section.keys as key}
111-
<Badge variant="secondary" class="font-mono text-xs">
112-
{key}
113-
</Badge>
109+
<Kbd.Root>{key}</Kbd.Root>
114110
{/each}
115111
</div>
116112
</div>
@@ -140,9 +136,7 @@
140136
</p>
141137
<div class="flex flex-wrap gap-1 my-2">
142138
{#each OPTION_DEAD_KEYS as key}
143-
<Badge variant="outline" class="font-mono text-xs">
144-
Option+{key.toUpperCase()}
145-
</Badge>
139+
<Kbd.Root>Option + {key.toUpperCase()}</Kbd.Root>
146140
{/each}
147141
</div>
148142
<p class="font-medium">Workarounds:</p>

apps/whispering/src/routes/(app)/+page.svelte

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import NavItems from '$lib/components/NavItems.svelte';
44
import CopyToClipboardButton from '$lib/components/copyable/CopyToClipboardButton.svelte';
55
import { Button } from '@epicenter/ui/button';
6+
import * as Kbd from '@epicenter/ui/kbd';
67
import { Link } from '@epicenter/ui/link';
78
import { ClipboardIcon } from '$lib/components/icons';
89
import {
@@ -365,13 +366,7 @@
365366
tooltip="Go to local shortcut in settings"
366367
href="/settings/shortcuts/local"
367368
>
368-
<kbd
369-
class="bg-muted relative rounded px-[0.3rem] py-[0.15rem] font-mono text-sm font-semibold"
370-
>
371-
{getShortcutDisplayLabel(
372-
settings.value['shortcuts.local.toggleManualRecording'],
373-
)}
374-
</kbd>
369+
<Kbd.Root>{getShortcutDisplayLabel(settings.value['shortcuts.local.toggleManualRecording'])}</Kbd.Root>
375370
</Link>{' '}
376371
to start recording here.
377372
</p>
@@ -382,11 +377,7 @@
382377
tooltip="Go to global shortcut in settings"
383378
href="/settings/shortcuts/global"
384379
>
385-
<kbd
386-
class="bg-muted relative rounded px-[0.3rem] py-[0.15rem] font-mono text-sm font-semibold"
387-
>
388-
{settings.value['shortcuts.global.toggleManualRecording']}
389-
</kbd>
380+
<Kbd.Root>{getShortcutDisplayLabel(settings.value['shortcuts.global.toggleManualRecording'])}</Kbd.Root>
390381
</Link>{' '}
391382
to start recording anywhere.
392383
</p>

0 commit comments

Comments
 (0)