@@ -45,6 +45,7 @@ const querySuggestionsPlugin = createQuerySuggestionsPlugin({
4545 'exact_matches' ,
4646 'categories' ,
4747 ] ,
48+ categoriesPerItem : 2 ,
4849} ) ;
4950const categoriesPlugin = createCategoriesPlugin ( { searchClient } ) ;
5051
@@ -82,6 +83,16 @@ autocomplete({
8283 } ,
8384 } ,
8485 ] ,
86+ } ) . then ( ( [ hits ] ) => {
87+ return hits . map ( ( hit ) => ( {
88+ ...hit ,
89+ comments : hit . popularity % 100 ,
90+ sale : hit . free_shipping ,
91+ // eslint-disable-next-line @typescript-eslint/camelcase
92+ sale_price : hit . free_shipping
93+ ? ( hit . price - hit . price / 10 ) . toFixed ( 2 )
94+ : hit . price ,
95+ } ) ) ;
8596 } ) ;
8697 } ,
8798 templates : {
@@ -122,24 +133,159 @@ type ProductItemProps = {
122133function ProductItem ( { hit, insights, components } : ProductItemProps ) {
123134 return (
124135 < Fragment >
125- < div className = "aa-ItemIcon aa-ItemIcon--align-top" >
126- < img src = { hit . image } alt = { hit . name } width = "40" height = "40" />
127- </ div >
128136 < div className = "aa-ItemContent" >
129- < div className = "aa-ItemContentTitle " >
130- < components . Snippet hit = { hit } attribute = "name " />
137+ < div className = "aa-ItemVisual aa-ItemIcon aa-ItemIcon--alignTop " >
138+ < img src = { hit . image } alt = { hit . name } width = "40" height = "40 " />
131139 </ div >
132- < div className = "aa-ItemContentDescription" >
133- < components . Snippet hit = { hit } attribute = "description" />
140+
141+ < div className = "aa-ItemContentBody" >
142+ < div className = "aa-ItemContentTitle" >
143+ < components . Snippet hit = { hit } attribute = "name" />
144+ </ div >
145+ < div className = "aa-ItemContentDescription" >
146+ By < strong > { hit . brand } </ strong > in{ ' ' }
147+ < strong > { hit . categories [ 0 ] } </ strong >
148+ </ div >
149+
150+ < div
151+ className = "aa-ItemContentDescription"
152+ style = { {
153+ display : 'grid' ,
154+ gridAutoFlow : 'column' ,
155+ justifyContent : 'start' ,
156+ alignItems : 'center' ,
157+ gap : 8 ,
158+ } }
159+ >
160+ { hit . rating > 0 && (
161+ < div className = "aa-ItemContentDescription" >
162+ < div
163+ style = { {
164+ color : 'rgba(var(--aa-muted-color-rgb), 0.5)' ,
165+ } }
166+ >
167+ { Array . from ( { length : 5 } , ( _value , index ) => {
168+ const isFilled = hit . rating >= index + 1 ;
169+
170+ return (
171+ < svg
172+ key = { index }
173+ width = "16"
174+ height = "16"
175+ viewBox = "0 0 24 24"
176+ fill = { isFilled ? 'currentColor' : 'none' }
177+ stroke = "currentColor"
178+ strokeWidth = "1"
179+ strokeLinecap = "round"
180+ strokeLinejoin = "round"
181+ >
182+ < polygon points = "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
183+ </ svg >
184+ ) ;
185+ } ) }
186+ </ div >
187+ </ div >
188+ ) }
189+ < div
190+ style = { {
191+ display : 'grid' ,
192+ gridAutoFlow : 'column' ,
193+ justifyContent : 'start' ,
194+ alignItems : 'center' ,
195+ gap : 4 ,
196+ } }
197+ >
198+ < svg
199+ width = "16"
200+ height = "16"
201+ viewBox = "0 0 24 24"
202+ fill = "none"
203+ stroke = "currentColor"
204+ strokeWidth = "2"
205+ strokeLinecap = "round"
206+ strokeLinejoin = "round"
207+ style = { {
208+ position : 'relative' ,
209+ top : '1px' ,
210+ } }
211+ >
212+ < path d = "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" > </ path >
213+ </ svg >
214+ < span > { hit . comments . toLocaleString ( ) } </ span >
215+ </ div >
216+ </ div >
217+
218+ < div
219+ style = { {
220+ display : 'flex' ,
221+ alignItems : 'center' ,
222+ gap : 8 ,
223+ } }
224+ >
225+ < div
226+ style = { {
227+ display : 'grid' ,
228+ gridAutoFlow : 'column' ,
229+ justifyContent : 'start' ,
230+ alignItems : 'center' ,
231+ gap : 4 ,
232+ } }
233+ >
234+ < div >
235+ < span
236+ style = { {
237+ color : '#000' ,
238+ fontSize : '0.9em' ,
239+ fontWeight : 'bold' ,
240+ } }
241+ >
242+ ${ hit . sale_price . toLocaleString ( ) }
243+ </ span > { ' ' }
244+ { hit . sale && (
245+ < span
246+ style = { {
247+ color : 'rgb(var(--aa-muted-color-rgb))' ,
248+ fontSize : '0.9em' ,
249+ textDecoration : 'line-through' ,
250+ } }
251+ >
252+ ${ hit . price . toLocaleString ( ) }
253+ </ span >
254+ ) }
255+ </ div >
256+ { hit . sale && (
257+ < span
258+ style = { {
259+ textTransform : 'uppercase' ,
260+ fontSize : '0.64em' ,
261+ background : '#539753' ,
262+ color : '#fff' ,
263+ fontWeight : 600 ,
264+ borderRadius : 9999 ,
265+ padding : '2px 6px' ,
266+ display : 'inline-block' ,
267+ lineHeight : '1.25em' ,
268+ } }
269+ >
270+ On sale
271+ </ span >
272+ ) }
273+ </ div >
274+ </ div >
134275 </ div >
135276 </ div >
277+
136278 < div className = "aa-ItemActions" >
137279 < button
138280 className = "aa-ItemActionButton aa-TouchOnly aa-ActiveOnly"
139281 type = "button"
140282 title = "Select"
283+ disabled = { true }
284+ style = { {
285+ pointerEvents : 'none' ,
286+ } }
141287 >
142- < svg viewBox = "0 0 24 24" width = "20" height = "20" fill = "currentColor" >
288+ < svg viewBox = "0 0 24 24" fill = "currentColor" >
143289 < path d = "M18.984 6.984h2.016v6h-15.188l3.609 3.609-1.406 1.406-6-6 6-6 1.406 1.406-3.609 3.609h13.172v-4.031z" />
144290 </ svg >
145291 </ button >
@@ -159,7 +305,7 @@ function ProductItem({ hit, insights, components }: ProductItemProps) {
159305 } ) ;
160306 } }
161307 >
162- < svg viewBox = "0 0 24 24" width = "18" height = "18" fill = "currentColor" >
308+ < svg viewBox = "0 0 24 24" fill = "currentColor" >
163309 < path d = "M19 5h-14l1.5-2h11zM21.794 5.392l-2.994-3.992c-0.196-0.261-0.494-0.399-0.8-0.4h-12c-0.326 0-0.616 0.156-0.8 0.4l-2.994 3.992c-0.043 0.056-0.081 0.117-0.111 0.182-0.065 0.137-0.096 0.283-0.095 0.426v14c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h14c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-14c0-0.219-0.071-0.422-0.189-0.585-0.004-0.005-0.007-0.010-0.011-0.015zM4 7h16v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-14c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707zM15 10c0 0.829-0.335 1.577-0.879 2.121s-1.292 0.879-2.121 0.879-1.577-0.335-2.121-0.879-0.879-1.292-0.879-2.121c0-0.552-0.448-1-1-1s-1 0.448-1 1c0 1.38 0.561 2.632 1.464 3.536s2.156 1.464 3.536 1.464 2.632-0.561 3.536-1.464 1.464-2.156 1.464-3.536c0-0.552-0.448-1-1-1s-1 0.448-1 1z" />
164310 </ svg >
165311 </ button >
0 commit comments