| 1 | "use client"; |
| 2 | |
| 3 | import { useRouter } from "next/navigation"; |
| 4 | import { useState } from "react"; |
| 5 | import { clsx } from "@/lib/cx"; |
| 6 | |
| 7 | |
| 8 | export function SearchBox({ initialValue }: { initialValue: string }) { |
| 9 | const router = useRouter(); |
| 10 | const [value, setValue] = useState(initialValue); |
| 11 | |
| 12 | return ( |
| 13 | <form |
| 14 | role="search" |
| 15 | action="/search" |
| 16 | method="get" |
| 17 | onSubmit={(e) => { |
| 18 | e.preventDefault(); |
| 19 | const q = value.trim(); |
| 20 | router.push(q ? `/search?q=${encodeURIComponent(q)}` : "/search"); |
| 21 | }} |
| 22 | > |
| 23 | <label htmlFor="docket-search" className="label mb-2 block"> |
| 24 | Look up my state, my representative, or a topic |
| 25 | </label> |
| 26 | <div className="flex flex-col gap-2 sm:flex-row"> |
| 27 | <input |
| 28 | id="docket-search" |
| 29 | type="search" |
| 30 | name="q" |
| 31 | value={value} |
| 32 | onChange={(e) => setValue(e.target.value)} |
| 33 | placeholder="e.g. CA, H.R. 25, Cantwell, tax, appropriations" |
| 34 | autoComplete="off" |
| 35 | aria-label="Search the record" |
| 36 | className={clsx( |
| 37 | "focus-ring min-h-[52px] w-full rounded-[2px] border border-line bg-ink px-4", |
| 38 | "font-mono text-[18px] text-paper placeholder:text-ash-2" |
| 39 | )} |
| 40 | /> |
| 41 | <button |
| 42 | type="submit" |
| 43 | className={clsx( |
| 44 | "focus-ring label inline-flex min-h-[52px] min-w-[120px] items-center justify-center rounded-[2px]", |
| 45 | "border border-line bg-surface px-6 text-paper underline-offset-4 transition-colors", |
| 46 | "hover:bg-graphite" |
| 47 | )} |
| 48 | > |
| 49 | Search |
| 50 | </button> |
| 51 | </div> |
| 52 | </form> |
| 53 | ); |
| 54 | } |