Skip to content

Commit 5078e34

Browse files
committed
feat: add search dialog
1 parent 4562034 commit 5078e34

File tree

7 files changed

+63
-59
lines changed

7 files changed

+63
-59
lines changed

components/layouts/page-header/command-menu.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client';
2-
import { useState } from 'react';
2+
import { File, Search } from 'lucide-react';
33
import { Button } from '~/components/ui/button';
44
import {
55
Dialog,
@@ -9,30 +9,46 @@ import {
99
DialogTitle,
1010
DialogTrigger,
1111
} from '~/components/ui/dialog';
12+
import { Input } from '~/components/ui/input';
1213

1314
export default function CommandMenu() {
14-
const [, setOpen] = useState(false);
15+
// const list = useSearch(searchQuery);
16+
// console.log(list);
17+
18+
const onSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
19+
console.log(e.target.value);
20+
};
1521

1622
return (
1723
<Dialog>
1824
<DialogTrigger asChild>
1925
<Button
2026
variant="outline"
2127
className="relative h-8 w-full justify-start rounded-[0.5rem] bg-muted/50 text-sm font-normal text-muted-foreground shadow-none sm:pr-12 md:w-32 lg:w-48 xl:w-56"
22-
onClick={() => setOpen(true)}
2328
>
2429
<span className="inline-flex">Try Search</span>
2530
<kbd className="pointer-events-none absolute right-[0.3rem] top-[0.3rem] hidden h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 sm:flex">
2631
<span className="text-xs"></span>K
2732
</kbd>
2833
</Button>
2934
</DialogTrigger>
30-
<DialogContent>
35+
<DialogContent hideCloseIcon className="gap-0 p-0">
36+
{/* Header 仅仅防止报错 */}
3137
<DialogHeader>
32-
<DialogTitle></DialogTitle>
33-
<DialogDescription>功能开发中.....</DialogDescription>
38+
<DialogTitle className="m-0 p-0"></DialogTitle>
39+
<DialogDescription className="m-0 p-0"></DialogDescription>
3440
</DialogHeader>
35-
<div className="h-20"></div>
41+
42+
<div className="flex items-center border-b px-3">
43+
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
44+
<Input className="border-none focus-visible:ring-0" onChange={onSearch} />
45+
</div>
46+
<div className="overflow-hidden px-2 py-1 text-foreground">
47+
<div className="relative flex cursor-default select-none items-center gap-2 rounded-sm px-4 py-3 outline-none hover:bg-accent hover:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0">
48+
<File />
49+
oooooo
50+
</div>
51+
</div>
3652
</DialogContent>
3753
</Dialog>
3854
);

components/ui/dialog.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
3131

3232
const DialogContent = React.forwardRef<
3333
React.ElementRef<typeof DialogPrimitive.Content>,
34-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
35-
>(({ className, children, ...props }, ref) => (
34+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { hideCloseIcon?: boolean }
35+
>(({ className, children, hideCloseIcon, ...props }, ref) => (
3636
<DialogPortal>
3737
<DialogOverlay />
3838
<DialogPrimitive.Content
@@ -44,10 +44,12 @@ const DialogContent = React.forwardRef<
4444
{...props}
4545
>
4646
{children}
47-
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
48-
<X className="h-4 w-4" />
49-
<span className="sr-only">Close</span>
50-
</DialogPrimitive.Close>
47+
{hideCloseIcon ? null : (
48+
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
49+
<X className="h-4 w-4" />
50+
<span className="sr-only">Close</span>
51+
</DialogPrimitive.Close>
52+
)}
5153
</DialogPrimitive.Content>
5254
</DialogPortal>
5355
));

components/ui/input.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
3+
import { cn } from '~/lib/utils';
4+
5+
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<'input'>>(
6+
({ className, type, ...props }, ref) => {
7+
return (
8+
<input
9+
type={type}
10+
className={cn(
11+
'flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
12+
className,
13+
)}
14+
ref={ref}
15+
{...props}
16+
/>
17+
);
18+
},
19+
);
20+
Input.displayName = 'Input';
21+
22+
export { Input };

hooks/useSearch.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@eslint/eslintrc": "^3.2.0",
4545
"@eslint/js": "^9.20.0",
4646
"@tailwindcss/typography": "^0.5.16",
47+
"@types/flexsearch": "^0.7.6",
4748
"@types/node": "^22.13.1",
4849
"@types/react": "^19.0.8",
4950
"@types/react-dom": "^19.0.3",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/content.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const POST_DIR = 'post';
2727
* @property {string} readingTime - 阅读时长
2828
* @property {number} wordCount - 文章字数
2929
* @property {string} content - 文章md内容
30-
* @property {Toc} toc - 目录结构
30+
* @property {Toc[]} toc - 目录结构
3131
*/
3232

3333
/**
@@ -183,7 +183,6 @@ function createMDXData(dir) {
183183
return {
184184
title: frontMatter.title,
185185
publishedAt: frontMatter.date,
186-
order: Number(frontMatter.order) || 0,
187186
url: `/${POST_DIR}/${slug}`,
188187
slug,
189188
readingTime: readingTime(content).text,

0 commit comments

Comments
 (0)