Refactor KeyBadge component to return key names directly and update ShortcutItem to use <kbd> for key display

This commit is contained in:
Anwarul Islam
2025-07-18 05:53:42 +06:00
parent c34b402297
commit f5d221feec
@@ -16,7 +16,7 @@ import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
const KeyBadge = ({ keyName }: { keyName: string }) => { const KeyBadge = ({ keyName }: { keyName: string }) => {
// Replace common key names with symbols or friendly names // Replace common key names with symbols or friendly names
const displayKey = keyName return keyName
.replace("Cmd", "⌘") .replace("Cmd", "⌘")
.replace("Shift", "Shift") .replace("Shift", "Shift")
.replace("ArrowLeft", "Arrow Left") .replace("ArrowLeft", "Arrow Left")
@@ -26,12 +26,6 @@ const KeyBadge = ({ keyName }: { keyName: string }) => {
.replace("←", "◀") .replace("←", "◀")
.replace("→", "▶") .replace("→", "▶")
.replace("Space", "Space"); .replace("Space", "Space");
return (
<Badge variant="secondary" className="font-mono text-xs px-1 py-1">
{displayKey}
</Badge>
);
}; };
const ShortcutItem = ({ shortcut }: { shortcut: any }) => { const ShortcutItem = ({ shortcut }: { shortcut: any }) => {
@@ -65,12 +59,9 @@ const ShortcutItem = ({ shortcut }: { shortcut: any }) => {
<div key={index} className="flex items-center gap-1"> <div key={index} className="flex items-center gap-1">
<div className="flex items-center"> <div className="flex items-center">
{key.split("+").map((keyPart: string, partIndex: number) => ( {key.split("+").map((keyPart: string, partIndex: number) => (
<div key={partIndex} className="flex items-center gap-1"> <kbd key={partIndex} className="shortcut-key">
<KeyBadge keyName={keyPart} /> <KeyBadge keyName={keyPart} />
{partIndex < key.split("+").length - 1 && ( </kbd>
<span className="text-xs text-muted-foreground">+</span>
)}
</div>
))} ))}
</div> </div>
{index < displayKeys.length - 1 && ( {index < displayKeys.length - 1 && (