Skip to content

Commit 343e67b

Browse files
committed
feat: improve command search items
1 parent a151c04 commit 343e67b

2 files changed

Lines changed: 39 additions & 18 deletions

File tree

apps/website/src/components/docs/search-docs.tsx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import {
1010
CommandInput,
1111
CommandItem,
1212
CommandList,
13+
CommandSeparator,
1314
} from "@/components/ui/command";
1415
import { Button } from "@/components/ui/button";
1516

17+
import { cn } from "@/utils/cn";
1618
import { SearchIcon } from "lucide-react";
1719
import { getDocsByFolder } from "@/utils/docs";
1820

@@ -54,23 +56,42 @@ const SearchDocs = () => {
5456
<CommandInput placeholder="Search" />
5557
<CommandList>
5658
<CommandEmpty>No results found.</CommandEmpty>
57-
{Object.entries(docsByFolder).map(([folder, docs]) => (
58-
<CommandGroup key={folder} heading={folder} className="my-2">
59-
{docs.map((doc) => (
60-
<CommandItem
61-
key={doc._meta.path}
62-
onSelect={() => {
63-
router.push(`/docs/${doc.folder}/${doc._meta.path}`);
64-
setOpen(false);
65-
}}
66-
>
67-
<span className="font-medium">{doc.title}</span>
68-
<span className="max-w-110 truncate text-xs text-neutral-600 dark:text-neutral-400">
69-
{doc.description}
70-
</span>
71-
</CommandItem>
72-
))}
73-
</CommandGroup>
59+
{Object.entries(docsByFolder).map(([folder, docs], index, array) => (
60+
<div key={folder}>
61+
<CommandGroup heading={folder} className="my-1">
62+
{docs.map((doc) => (
63+
<CommandItem
64+
key={doc._meta.path}
65+
onSelect={() => {
66+
router.push(`/docs/${doc.folder}/${doc._meta.path}`);
67+
setOpen(false);
68+
}}
69+
>
70+
<span className="font-medium">{doc.title}</span>
71+
<span className="max-w-110 truncate text-xs text-neutral-600 dark:text-neutral-400">
72+
{doc.description}
73+
</span>
74+
{doc.category && (
75+
<div className="mt-1 flex items-center space-x-1">
76+
{doc.category.map((cat) => (
77+
<span
78+
key={cat}
79+
className={cn(
80+
"bg-neutral-100 dark:bg-neutral-800",
81+
"border border-neutral-300 dark:border-neutral-700",
82+
"rounded-full px-2 py-0.5 text-xs tracking-tight text-neutral-600 dark:text-neutral-300",
83+
)}
84+
>
85+
{cat}
86+
</span>
87+
))}
88+
</div>
89+
)}
90+
</CommandItem>
91+
))}
92+
</CommandGroup>
93+
{index < array.length - 1 && <CommandSeparator />}
94+
</div>
7495
))}
7596
</CommandList>
7697
</CommandDialog>

apps/website/src/components/ui/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function CommandItem({
155155
<CommandPrimitive.Item
156156
data-slot="command-item"
157157
className={cn(
158-
"relative flex cursor-default flex-col items-start justify-start rounded-sm px-4 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-neutral-100 data-[selected=true]:text-neutral-900 dark:data-[selected=true]:bg-neutral-800 dark:data-[selected=true]:text-neutral-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='text-'])]:text-neutral-500 dark:[&_svg:not([class*='text-'])]:text-neutral-400",
158+
"relative flex cursor-default flex-col items-start justify-start rounded-sm px-4 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-neutral-200/70 data-[selected=true]:text-neutral-900 dark:data-[selected=true]:bg-neutral-800/70 dark:data-[selected=true]:text-neutral-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='text-'])]:text-neutral-500 dark:[&_svg:not([class*='text-'])]:text-neutral-400",
159159
className,
160160
)}
161161
{...props}

0 commit comments

Comments
 (0)