Skip to content

Commit 6acd1f4

Browse files
Migrated Kbd component to a centralized implementation (#2475)
## Description - Updated Kbd component styles and markup - Migrated Kbd component to a centralized implementation
1 parent 3f5ee31 commit 6acd1f4

File tree

7 files changed

+36
-91
lines changed

7 files changed

+36
-91
lines changed

apps/desktop/src/components/main/body/empty/index.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AppWindowIcon, ChevronDown } from "lucide-react";
22
import { useCallback, useState } from "react";
33

4+
import { Kbd } from "@hypr/ui/components/ui/kbd";
45
import { cn } from "@hypr/utils";
56

67
import { type Tab, useTabs } from "../../../../store/zustand/tabs";
@@ -130,22 +131,15 @@ function ActionItem({
130131
>
131132
<span>{label}</span>
132133
{shortcut && shortcut.length > 0 ? (
133-
<kbd
134+
<Kbd
134135
className={cn([
135-
"inline-flex h-5 items-center gap-1",
136-
"rounded border border-neutral-300",
137-
"bg-gradient-to-b from-white to-neutral-100",
138-
"px-1.5 font-mono text-xs font-medium text-neutral-400",
139-
"shadow-[0_1px_0_0_rgba(0,0,0,0.1),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
140-
"select-none transition-all duration-100",
136+
"transition-all duration-100",
141137
"group-hover:-translate-y-0.5 group-hover:shadow-[0_2px_0_0_rgba(0,0,0,0.15),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
142138
"group-active:translate-y-0.5 group-active:shadow-none",
143139
])}
144140
>
145-
{shortcut.map((key, index) => (
146-
<span key={index}>{key}</span>
147-
))}
148-
</kbd>
141+
{shortcut.join(" ")}
142+
</Kbd>
149143
) : (
150144
icon
151145
)}

apps/desktop/src/components/main/body/search.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Loader2Icon, SearchIcon, XIcon } from "lucide-react";
22
import { useEffect, useState } from "react";
33

44
import { Button } from "@hypr/ui/components/ui/button";
5-
import { Kbd, KbdGroup } from "@hypr/ui/components/ui/kbd";
5+
import { Kbd } from "@hypr/ui/components/ui/kbd";
66
import { cn } from "@hypr/utils";
77

88
import { useSearch } from "../../../contexts/search/ui";
@@ -171,10 +171,7 @@ function ExpandedSearch({
171171
)}
172172
{showShortcut && (
173173
<div className="absolute right-2 top-1">
174-
<KbdGroup>
175-
<Kbd className="bg-neutral-200"></Kbd>
176-
<Kbd className="bg-neutral-200">K</Kbd>
177-
</KbdGroup>
174+
<Kbd>⌘ K</Kbd>
178175
</div>
179176
)}
180177
</div>

apps/desktop/src/components/main/body/sessions/note-input/raw.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const RawEditor = forwardRef<
6666
const hasNonEmptyText = useCallback(
6767
(node?: JSONContent): boolean =>
6868
!!node?.text?.trim() ||
69-
!!node?.content?.some((child) => hasNonEmptyText(child)),
69+
!!node?.content?.some((child: JSONContent) => hasNonEmptyText(child)),
7070
[],
7171
);
7272

apps/desktop/src/components/main/body/shared.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { X } from "lucide-react";
22
import { useState } from "react";
33

4-
import { Kbd, KbdGroup } from "@hypr/ui/components/ui/kbd";
4+
import { Kbd } from "@hypr/ui/components/ui/kbd";
55
import { cn } from "@hypr/utils";
66

77
import { useCmdKeyPressed } from "../../../hooks/useCmdKeyPressed";
@@ -149,12 +149,7 @@ export function TabItemBase({
149149
</div>
150150
{showShortcut && (
151151
<div className="absolute top-[3px] right-2 pointer-events-none">
152-
<KbdGroup>
153-
<Kbd className={active ? "bg-red-200" : "bg-neutral-200"}></Kbd>
154-
<Kbd className={active ? "bg-red-200" : "bg-neutral-200"}>
155-
{tabIndex}
156-
</Kbd>
157-
</KbdGroup>
152+
<Kbd>{tabIndex}</Kbd>
158153
</div>
159154
)}
160155
</InteractiveButton>

apps/desktop/src/components/main/sidebar/profile/index.tsx

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AnimatePresence, motion } from "motion/react";
1111
import { useCallback, useEffect, useRef, useState } from "react";
1212
import { useResizeObserver } from "usehooks-ts";
1313

14+
import { Kbd } from "@hypr/ui/components/ui/kbd";
1415
import { cn } from "@hypr/utils";
1516

1617
import { useAuth } from "../../../../auth";
@@ -128,12 +129,7 @@ export function ProfileSection({ onExpandChange }: ProfileSectionProps = {}) {
128129
// }, [openNew, closeMenu]);
129130

130131
const kbdClass = cn([
131-
"inline-flex h-5 items-center gap-1",
132-
"rounded border border-neutral-300",
133-
"bg-gradient-to-b from-white to-neutral-100",
134-
"px-1.5 font-mono text-[10px] font-medium text-neutral-400",
135-
"shadow-[0_1px_0_0_rgba(0,0,0,0.1),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
136-
"select-none transition-all duration-100",
132+
"transition-all duration-100",
137133
"group-hover:-translate-y-0.5 group-hover:shadow-[0_2px_0_0_rgba(0,0,0,0.15),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
138134
"group-active:translate-y-0.5 group-active:shadow-none",
139135
]);
@@ -143,55 +139,31 @@ export function ProfileSection({ onExpandChange }: ProfileSectionProps = {}) {
143139
icon: FolderOpenIcon,
144140
label: "Folders",
145141
onClick: handleClickFolders,
146-
badge: (
147-
<kbd className={kbdClass}>
148-
<span className="text-xs"></span>
149-
<span className="text-xs"></span>D
150-
</kbd>
151-
),
142+
badge: <Kbd className={kbdClass}>⌘ ⇧ D</Kbd>,
152143
},
153144
{
154145
icon: UsersIcon,
155146
label: "Contacts",
156147
onClick: handleClickContacts,
157-
badge: (
158-
<kbd className={kbdClass}>
159-
<span className="text-xs"></span>
160-
<span className="text-xs"></span>O
161-
</kbd>
162-
),
148+
badge: <Kbd className={kbdClass}>⌘ ⇧ O</Kbd>,
163149
},
164150
{
165151
icon: CalendarIcon,
166152
label: "Calendar",
167153
onClick: handleClickCalendar,
168-
badge: (
169-
<kbd className={kbdClass}>
170-
<span className="text-xs"></span>
171-
<span className="text-xs"></span>C
172-
</kbd>
173-
),
154+
badge: <Kbd className={kbdClass}>⌘ ⇧ C</Kbd>,
174155
},
175156
{
176157
icon: SparklesIcon,
177158
label: "AI",
178159
onClick: handleClickAI,
179-
badge: (
180-
<kbd className={kbdClass}>
181-
<span className="text-xs"></span>
182-
<span className="text-xs"></span>A
183-
</kbd>
184-
),
160+
badge: <Kbd className={kbdClass}>⌘ ⇧ A</Kbd>,
185161
},
186162
{
187163
icon: SettingsIcon,
188164
label: "Settings",
189165
onClick: handleClickSettings,
190-
badge: (
191-
<kbd className={kbdClass}>
192-
<span className="text-xs"></span>,
193-
</kbd>
194-
),
166+
badge: <Kbd className={kbdClass}>⌘ ,</Kbd>,
195167
},
196168
];
197169

apps/web/src/components/search.tsx

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
CommandItem,
1919
CommandList,
2020
} from "@hypr/ui/components/ui/command";
21+
import { Kbd } from "@hypr/ui/components/ui/kbd";
2122
import { cn } from "@hypr/utils";
2223

2324
interface SearchResult {
@@ -111,20 +112,16 @@ export function SearchTrigger({
111112
>
112113
<SearchIcon size={16} className="text-neutral-400" />
113114
<span className="flex-1 text-left">Search docs...</span>
114-
<kbd
115+
<Kbd
115116
className={cn([
116-
"hidden sm:inline-flex h-5 items-center gap-1",
117-
"rounded border border-neutral-300",
118-
"bg-linear-to-b from-white to-neutral-100",
119-
"px-1.5 font-mono text-[10px] font-medium text-neutral-400",
120-
"shadow-[0_1px_0_0_rgba(0,0,0,0.1),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
121-
"select-none transition-all duration-100",
117+
"hidden sm:inline-flex",
118+
"transition-all duration-100",
122119
"group-hover:-translate-y-0.5 group-hover:shadow-[0_2px_0_0_rgba(0,0,0,0.15),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
123120
"group-active:translate-y-0.5 group-active:shadow-none",
124121
])}
125122
>
126-
<span className="text-xs"></span>K
127-
</kbd>
123+
K
124+
</Kbd>
128125
</button>
129126
);
130127
}
@@ -160,20 +157,16 @@ export function SearchTrigger({
160157
])}
161158
>
162159
<SearchIcon size={16} />
163-
<kbd
160+
<Kbd
164161
className={cn([
165-
"hidden sm:inline-flex h-5 items-center gap-1",
166-
"rounded border border-neutral-300",
167-
"bg-linear-to-b from-white to-neutral-100",
168-
"px-1.5 font-mono text-[10px] font-medium text-neutral-400",
169-
"shadow-[0_1px_0_0_rgba(0,0,0,0.1),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
170-
"select-none transition-all duration-100",
162+
"hidden sm:inline-flex",
163+
"transition-all duration-100",
171164
"group-hover:-translate-y-0.5 group-hover:shadow-[0_2px_0_0_rgba(0,0,0,0.15),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
172165
"group-active:translate-y-0.5 group-active:shadow-none",
173166
])}
174167
>
175-
<span className="text-sm"></span>K
176-
</kbd>
168+
K
169+
</Kbd>
177170
</button>
178171
);
179172
}
@@ -193,16 +186,7 @@ export function SearchTrigger({
193186
>
194187
<SearchIcon size={14} className="text-neutral-400" />
195188
<span className="hidden lg:inline">Search</span>
196-
<kbd
197-
className={cn([
198-
"hidden lg:inline-flex h-5 items-center gap-1",
199-
"rounded border border-neutral-200 bg-white",
200-
"px-1.5 font-mono text-[10px] font-medium text-neutral-500",
201-
"select-none",
202-
])}
203-
>
204-
<span className="text-xs"></span>K
205-
</kbd>
189+
<Kbd className="hidden lg:inline-flex">⌘ K</Kbd>
206190
</button>
207191
);
208192
}

packages/ui/src/components/ui/kbd.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ function Kbd({ className, ...props }: React.ComponentProps<"kbd">) {
55
<kbd
66
data-slot="kbd"
77
className={cn([
8-
"bg-muted text-muted-foreground pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm px-1 font-sans text-xs font-medium",
8+
"pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded px-1 font-mono text-xs font-medium",
9+
"border border-neutral-300",
10+
"bg-gradient-to-b from-white to-neutral-100",
11+
"text-neutral-400",
12+
"shadow-[0_1px_0_0_rgba(0,0,0,0.1),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
913
"[&_svg:not([class*='size-'])]:size-3",
10-
"[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10",
1114
className,
1215
])}
1316
{...props}
@@ -17,9 +20,9 @@ function Kbd({ className, ...props }: React.ComponentProps<"kbd">) {
1720

1821
function KbdGroup({ className, ...props }: React.ComponentProps<"div">) {
1922
return (
20-
<kbd
23+
<div
2124
data-slot="kbd-group"
22-
className={cn(["inline-flex items-center gap-1", className])}
25+
className={cn(["inline-flex items-center gap-0.5", className])}
2326
{...props}
2427
/>
2528
);

0 commit comments

Comments
 (0)