58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
"use client"
|
|
|
|
import Image from "next/image"
|
|
import type { Hit as HitType } from "instantsearch.js"
|
|
|
|
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
|
import { ImageIcon } from "lucide-react"
|
|
|
|
export type ProductHit = HitType<{
|
|
title: string | null
|
|
handle: string | null
|
|
thumbnail: string | null
|
|
}>
|
|
|
|
type SearchHitProps = {
|
|
hit: ProductHit
|
|
onNavigate?: () => void
|
|
}
|
|
|
|
const SearchHit = ({ hit, onNavigate }: SearchHitProps) => {
|
|
if (!hit.handle) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<li>
|
|
<LocalizedClientLink
|
|
href={`/products/${hit.handle}`}
|
|
onClick={onNavigate}
|
|
className="flex items-center gap-3.5 px-3 py-2.5 rounded-lg hover:bg-accent transition-colors"
|
|
data-testid="search-hit-link"
|
|
>
|
|
<div className="relative h-14 w-14 shrink-0 overflow-hidden rounded-md border border-border bg-muted/30">
|
|
{hit.thumbnail ? (
|
|
<Image
|
|
src={hit.thumbnail}
|
|
alt={hit.title ?? ""}
|
|
fill
|
|
sizes="56px"
|
|
className="object-contain p-1"
|
|
draggable={false}
|
|
/>
|
|
) : (
|
|
<div className="flex h-full w-full items-center justify-center text-muted-foreground/60">
|
|
<ImageIcon className="h-5 w-5" />
|
|
</div>
|
|
)}
|
|
</div>
|
|
<span className="text-sm font-medium text-foreground line-clamp-2">
|
|
{hit.title}
|
|
</span>
|
|
</LocalizedClientLink>
|
|
</li>
|
|
)
|
|
}
|
|
|
|
export default SearchHit
|