Skip to content

Commit a4854d5

Browse files
refactor(search): replace Kbd with custom SearchKbd component (#2501)
1 parent c89589a commit a4854d5

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

apps/web/src/components/search.tsx

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@ import {
1818
CommandItem,
1919
CommandList,
2020
} from "@hypr/ui/components/ui/command";
21-
import { Kbd } from "@hypr/ui/components/ui/kbd";
2221
import { cn } from "@hypr/utils";
2322

23+
function SearchKbd({ children }: { children: React.ReactNode }) {
24+
return (
25+
<kbd
26+
className={cn([
27+
"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",
28+
"border border-neutral-300",
29+
"bg-linear-to-b from-white to-neutral-100",
30+
"text-neutral-400",
31+
"shadow-[0_1px_0_0_rgba(0,0,0,0.1),inset_0_1px_0_0_rgba(255,255,255,0.8)]",
32+
])}
33+
>
34+
{children}
35+
</kbd>
36+
);
37+
}
38+
2439
interface SearchResult {
2540
url: string;
2641
meta: {
@@ -46,7 +61,6 @@ interface PagefindInstance {
4661
search: (query: string) => Promise<{ results: PagefindSearchResult[] }>;
4762
}
4863

49-
// Context for shared search palette state
5064
const SearchPaletteContext = createContext<{
5165
open: boolean;
5266
setOpen: (open: boolean) => void;
@@ -67,7 +81,6 @@ export function SearchPaletteProvider({
6781
}) {
6882
const [open, setOpen] = useState(false);
6983

70-
// Single global Cmd+K handler
7184
useEffect(() => {
7285
const down = (e: KeyboardEvent) => {
7386
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
@@ -112,16 +125,7 @@ export function SearchTrigger({
112125
>
113126
<SearchIcon size={16} className="text-neutral-400" />
114127
<span className="flex-1 text-left">Search docs...</span>
115-
<Kbd
116-
className={cn([
117-
"hidden sm:inline-flex",
118-
"transition-all duration-100",
119-
"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)]",
120-
"group-active:translate-y-0.5 group-active:shadow-none",
121-
])}
122-
>
123-
⌘ K
124-
</Kbd>
128+
<SearchKbd>⌘ K</SearchKbd>
125129
</button>
126130
);
127131
}
@@ -157,16 +161,7 @@ export function SearchTrigger({
157161
])}
158162
>
159163
<SearchIcon size={16} />
160-
<Kbd
161-
className={cn([
162-
"hidden sm:inline-flex",
163-
"transition-all duration-100",
164-
"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)]",
165-
"group-active:translate-y-0.5 group-active:shadow-none",
166-
])}
167-
>
168-
⌘ K
169-
</Kbd>
164+
<SearchKbd>⌘ K</SearchKbd>
170165
</button>
171166
);
172167
}
@@ -186,7 +181,7 @@ export function SearchTrigger({
186181
>
187182
<SearchIcon size={14} className="text-neutral-400" />
188183
<span className="hidden lg:inline">Search</span>
189-
<Kbd className="hidden lg:inline-flex">⌘ K</Kbd>
184+
<SearchKbd>⌘ K</SearchKbd>
190185
</button>
191186
);
192187
}
@@ -307,7 +302,7 @@ function SearchCommandPalette({
307302

308303
return createPortal(
309304
<div
310-
className="fixed inset-x-0 top-[69px] bottom-0 z-9999 backdrop-blur-sm"
305+
className="fixed inset-x-0 top-17.25 bottom-0 z-9999 backdrop-blur-sm"
311306
onClick={() => onOpenChange(false)}
312307
>
313308
<div className="absolute left-1/2 top-[10%] -translate-x-1/2 w-full max-w-xl px-4">
@@ -326,7 +321,7 @@ function SearchCommandPalette({
326321
onValueChange={setQuery}
327322
/>
328323
<div className="border-t border-neutral-100" />
329-
<CommandList className="max-h-[400px] px-1">
324+
<CommandList className="max-h-100 px-1">
330325
{isLoading && (
331326
<div className="py-6 text-center text-sm text-neutral-500">
332327
Searching...

0 commit comments

Comments
 (0)