-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSearchHits.jsx
More file actions
38 lines (33 loc) · 1.28 KB
/
SearchHits.jsx
File metadata and controls
38 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import { connectSearchBox, connectHits } from 'react-instantsearch-dom';
import './SearchHits.scss';
const SearchBox = ({ currentRefinement, refine }) => (
<div className="ais-SearchBox">
<form noValidate action="" role="search" className="ais-SearchBox-form">
<input
className="ais-SearchBox-input"
type="search"
value={currentRefinement}
onChange={(event) => refine(event.currentTarget.value)}
/>
</form>
</div>
);
export const CustomSearchBox = connectSearchBox(SearchBox);
// on page load do not display
/* eslint-disable react/no-danger */
const Hits = ({ hits }) => (
<ul className="style">
{hits.length < 1 ? <li className='px-5 py-3 rounded-lg text-center'>No search results found</li> : ''}
{hits.map((hit) => (
<li key={hit.title}>
<a href={hit?.slug}>
<span className="search-title" dangerouslySetInnerHTML={{ __html: hit._highlightResult.title.value }} />
<p dangerouslySetInnerHTML={{ __html: hit._snippetResult.excerpt.value }} />
</a>
</li>
))}
</ul>
);
/* eslint-enable */
export const SearchHits = connectHits(Hits);