mirror of
https://github.com/vercel/commerce.git
synced 2025-08-06 08:51:25 +00:00
.github
.vscode
app
components
cart
grid
icons
layout
navbar
index.tsx
mobile-menu.tsx
search.tsx
search
footer.tsx
product-grid-items.tsx
product
carousel.tsx
loading-dots.tsx
price.tsx
prose.tsx
e2e
lib
.env.example
.eslintrc.js
.gitignore
.nvmrc
.prettierignore
README.md
license.md
next.config.js
package.json
playwright.config.ts
pnpm-lock.yaml
postcss.config.js
prettier.config.js
tailwind.config.js
tsconfig.json
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { useRouter, useSearchParams } from 'next/navigation';
|
|
|
|
import SearchIcon from 'components/icons/search';
|
|
|
|
export default function Search() {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
|
|
function onSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault();
|
|
|
|
const val = e.target as HTMLFormElement;
|
|
const search = val.search as HTMLInputElement;
|
|
|
|
if (search.value) {
|
|
router.push(`/search?q=${search.value}`);
|
|
} else {
|
|
router.push(`/search`);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form
|
|
onSubmit={onSubmit}
|
|
className="relative m-0 flex w-full items-center border border-gray-200 bg-transparent p-0 dark:border-gray-500"
|
|
>
|
|
<input
|
|
type="text"
|
|
name="search"
|
|
placeholder="Search for products..."
|
|
autoComplete="off"
|
|
defaultValue={searchParams?.get('q') || ''}
|
|
className="w-full px-4 py-2 text-black dark:bg-black dark:text-gray-100"
|
|
/>
|
|
<div className="absolute right-0 top-0 mr-3 flex h-full items-center">
|
|
<SearchIcon className="h-5" />
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|