hds-web 1.16.0 → 1.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import algoliasearch from "algoliasearch/lite";
2
+ import React, { useRef, useState } from "react";
3
+ import { InstantSearch, connectStateResults, Index } from "react-instantsearch-dom";
4
+ import SearchBox from "./searchbox";
5
+ import SearchResults from "./searchresults";
6
+ import { INDEX_TYPES } from "./constants";
7
+ import SearchFooter from "./searchfooter";
8
+ import { Typography } from '../../foundation/Typography'
9
+
10
+
11
+ const algoliaClient = algoliasearch(
12
+ process.env.ALGOLIA_APP_ID,
13
+ process.env.ALGOLIA_SEARCH_KEY
14
+ );
15
+
16
+ const searchClient = {
17
+ ...algoliaClient,
18
+ search(requests) {
19
+ if (requests.every(({ params }) => !params.query)) {
20
+ return Promise.resolve({
21
+ results: requests.map(() => ({
22
+ hits: [],
23
+ nbHits: 0,
24
+ nbPages: 0,
25
+ processingTimeMS: 0,
26
+ })),
27
+ });
28
+ }
29
+
30
+ return algoliaClient.search(requests);
31
+ },
32
+ };
33
+
34
+ const AllResults = ({ allSearchResults, children, indices, searchState, searching }) => {
35
+ if (!searchState?.query) return null;
36
+
37
+ const hasResults =
38
+ allSearchResults && Object.values(allSearchResults).some(results => results.nbHits > 0);
39
+ return !hasResults ? (
40
+ <div>
41
+ <div>
42
+ {searching ? (
43
+ <span>
44
+ Searching for "<em>{searchState?.query}</em>"
45
+ </span>
46
+ ) : (
47
+ <span>
48
+ No results for "<em>{searchState?.query}</em>"
49
+ </span>
50
+ )}
51
+ </div>
52
+ {indices.map(index => (
53
+ <Index indexName={index.name} key={index.name} />
54
+ ))}
55
+ <SearchFooter />
56
+ </div>
57
+ ) : (
58
+ children
59
+ );
60
+ };
61
+
62
+ const CustomAllResults = connectStateResults(AllResults);
63
+
64
+ const IndexTypeFilter = ({ activeIndexTypes, setActiveIndexTypes }) => {
65
+ const handleOnChange = indexType => ({ target }) => {
66
+ setActiveIndexTypes(prevState => ({
67
+ ...prevState,
68
+ [indexType]: target.checked,
69
+ }));
70
+ };
71
+
72
+ return (
73
+ <div className="tb-m:min-w-[150px] static tb-m:sticky top-[96px] self-start">
74
+ <Typography textStyle="h6" as="h6" className="text-neutral-700 uppercase">Filter</Typography>
75
+ <ul className="flex tb-m:block">
76
+ {Object.values(INDEX_TYPES).map(index => (
77
+ <li key={index} className="flex items-center py-3 mr-4 tb-m:mr-0">
78
+ <input
79
+ type="checkbox"
80
+ id={"algolia_index_type_" + index}
81
+ name={"algolia_index_type_" + index}
82
+ value={index}
83
+ checked={activeIndexTypes[index]}
84
+ onChange={handleOnChange(index)}
85
+ className="mr-2 focus:outline-none"
86
+ />
87
+ <label htmlFor={"algolia_index_type_" + index}>{index}</label>
88
+ </li>
89
+ ))}
90
+ </ul>
91
+ </div>
92
+ );
93
+ };
94
+
95
+ export default function SearchWrapper({ indices }) {
96
+ const defaultIndexTypesState = Object.values(INDEX_TYPES).reduce((a, c) => {
97
+ a[c] = true;
98
+ return a;
99
+ }, {});
100
+ const wrapperRef = useRef(null);
101
+ const [activeIndexTypes, setActiveIndexTypes] = useState(defaultIndexTypesState);
102
+ return (
103
+ <InstantSearch
104
+ searchClient={searchClient}
105
+ indexName={indices[0].name}
106
+ onSearchStateChange={() => setActiveIndexTypes(defaultIndexTypesState)}
107
+ >
108
+ <SearchBox />
109
+ <CustomAllResults indices={indices}>
110
+ <div className="tb-m:flex">
111
+ <IndexTypeFilter
112
+ activeIndexTypes={activeIndexTypes}
113
+ setActiveIndexTypes={setActiveIndexTypes}
114
+ />
115
+ <SearchResults
116
+ id="search-results"
117
+ indices={indices}
118
+ wrapperRef={wrapperRef}
119
+ activeIndexTypes={activeIndexTypes}
120
+ className="search-results"
121
+ />
122
+ </div>
123
+ </CustomAllResults>
124
+ </InstantSearch>
125
+ );
126
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './Translations';
2
2
  export * from './Media';
3
3
  export * from './Effects';
4
+ export * from './AlgoliaSearch';
package/src/index.css CHANGED
@@ -4,6 +4,58 @@
4
4
  @tailwind utilities;
5
5
  /* Typography classes */
6
6
 
7
+ .hds-hidden{
8
+ display: none;
9
+
10
+ }
11
+ @media (min-width: 905px) {
12
+ .hds-hidden-tbl {
13
+ display: none;
14
+ }
15
+ }
16
+
17
+ .search-results {
18
+ width: calc(100% - 150px);
19
+ }
20
+
21
+ .search-results .ais-Hits .ais-Hits-list,
22
+ .search-results .Hits .ais-Hits-list {
23
+ display: grid;
24
+ grid-template-columns: repeat(3, 1fr);
25
+ grid-gap: 40px;
26
+ }
27
+
28
+ .search-results .ais-Hits .ais-Hits-list .ais-Hits-item,
29
+ .search-results .Hits .ais-Hits-list .ais-Hits-item {
30
+ border-bottom: 1px solid transparent;
31
+ }
32
+
33
+ .search-results .ais-Hits .ais-Hits-list .ais-Hits-item:hover,
34
+ .search-results .Hits .ais-Hits-list .ais-Hits-item:hover {
35
+ border-bottom: 1px solid #e5e7eb;
36
+ }
37
+
38
+ .search-results .ais-Hits .ais-Hits-list .ais-Hits-item .hit-slug,
39
+ .search-results .Hits .ais-Hits-list .ais-Hits-item .hit-slug {
40
+ word-break: break-word;
41
+ }
42
+
43
+ @media (max-width: 799px) {
44
+
45
+ .search-results .ais-Hits .ais-Hits-list,
46
+ .search-results .Hits .ais-Hits-list {
47
+ grid-template-columns: 1fr;
48
+ }
49
+ }
50
+
51
+ @media (min-width: 800px) and (max-width: 905px) {
52
+
53
+ .search-results .ais-Hits .ais-Hits-list,
54
+ .search-results .Hits .ais-Hits-list {
55
+ grid-template-columns: 1fr 1fr;
56
+ }
57
+ }
58
+
7
59
  .card {
8
60
  max-width: 920px;
9
61
  background-size: cover;