xonecas.io
556
Bn

bees-nest / files

bees-nest / src / components / search-form.tsx

1.4 KB
1"use client";
2
3import { Search01Icon } from "@hugeicons/core-free-icons";
4import { HugeiconsIcon } from "@hugeicons/react";
5import * as React from "react";
6
7import { Button } from "@/components/ui/button";
8import { Input } from "@/components/ui/input";
9import { cn } from "@/lib/utils";
10
11interface SearchFormProps extends React.ComponentProps<"form"> {
12  onSearch: (query: string) => void;
13  initialQuery?: string;
14}
15
16export function SearchForm({
17  className,
18  onSearch,
19  initialQuery = "",
20  ...props
21}: SearchFormProps) {
22  const [query, setQuery] = React.useState(initialQuery);
23
24  const handleSubmit = (e: React.FormEvent) => {
25    e.preventDefault();
26    if (query.trim()) {
27      onSearch(query);
28    }
29  };
30
31  return (
32    <form
33      onSubmit={handleSubmit}
34      className={cn("flex w-full max-w-2xl items-center gap-2", className)}
35      {...props}
36    >
37      <div className="relative flex-1">
38        <HugeiconsIcon
39          icon={Search01Icon}
40          strokeWidth={2}
41          className="text-muted-foreground absolute left-3 top-1/2 size-4 -translate-y-1/2"
42        />
43        <Input
44          type="search"
45          placeholder="Search for documentation, issues, or notes..."
46          className="pl-9"
47          value={query}
48          onChange={(e) => setQuery(e.target.value)}
49        />
50      </div>
51      <Button type="submit">Search</Button>
52    </form>
53  );
54}