hds-web 1.36.3 → 1.36.5

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.
@@ -1,19 +1,28 @@
1
1
  import algoliasearch from "algoliasearch/lite";
2
2
  import React, { useRef, useState, useEffect } from "react";
3
- import { InstantSearch, connectStateResults, Index } from "react-instantsearch-dom";
3
+ import {
4
+ InstantSearch,
5
+ connectStateResults,
6
+ Index,
7
+ } from "react-instantsearch-dom";
4
8
  import SearchBox from "./searchbox";
5
9
  import SearchResults from "./searchresults";
6
10
  import { INDEX_TYPES } from "./constants";
7
11
  import SearchFooter from "./searchfooter";
8
- import { Typography } from '../../foundation/Typography'
9
-
10
-
11
-
12
- const AllResults = ({ allSearchResults, children, indices, searchState, searching }) => {
12
+ import { Typography } from "../../foundation/Typography";
13
+
14
+ const AllResults = ({
15
+ allSearchResults,
16
+ children,
17
+ indices,
18
+ searchState,
19
+ searching,
20
+ }) => {
13
21
  if (!searchState?.query) return null;
14
22
 
15
23
  const hasResults =
16
- allSearchResults && Object.values(allSearchResults).some(results => results.nbHits > 0);
24
+ allSearchResults &&
25
+ Object.values(allSearchResults).some((results) => results.nbHits > 0);
17
26
  return !hasResults ? (
18
27
  <div>
19
28
  <div>
@@ -27,7 +36,7 @@ const AllResults = ({ allSearchResults, children, indices, searchState, searchin
27
36
  </span>
28
37
  )}
29
38
  </div>
30
- {indices.map(index => (
39
+ {indices.map((index) => (
31
40
  <Index indexName={index.name} key={index.name} />
32
41
  ))}
33
42
  <SearchFooter />
@@ -45,57 +54,74 @@ const IndexTypeFilter = ({ activeIndexTypes, setActiveIndexTypes }) => {
45
54
  const handleOnClick = (indexType) => {
46
55
  if (indexType === INDEX_TYPES.All) {
47
56
  showAll = true;
48
- const allFiltersSelected = Object.keys(activeIndexTypes).reduce((acc, key) => {
49
- acc[key] = true;
50
- return acc;
51
- }, {});
57
+ const allFiltersSelected = Object.keys(activeIndexTypes).reduce(
58
+ (acc, key) => {
59
+ acc[key] = true;
60
+ return acc;
61
+ },
62
+ {}
63
+ );
52
64
  setActiveIndexTypes(allFiltersSelected);
53
65
  } else {
54
- showAll = false
55
- const allFiltersSelected = Object.keys(activeIndexTypes).reduce((acc, key) => {
56
- acc[key] = false;
57
- return acc;
58
- }, {});
66
+ showAll = false;
67
+ const allFiltersSelected = Object.keys(activeIndexTypes).reduce(
68
+ (acc, key) => {
69
+ acc[key] = false;
70
+ return acc;
71
+ },
72
+ {}
73
+ );
59
74
  setActiveIndexTypes(allFiltersSelected);
60
75
  setActiveIndexTypes((prevState) => ({
61
76
  ...prevState,
62
77
  [indexType]: !prevState[indexType],
63
78
  }));
64
79
  }
65
- setShowDropdown(false)
80
+ setShowDropdown(false);
66
81
  };
67
82
 
68
83
  return (
69
84
  <div className="relative">
70
- <div className="tb-m:min-w-[182px] static tb-m:sticky top-[116px] self-start">
71
- <ul className="hds-hidden tb-m:block bg-neutral-0 shadow-md p-4 rounded-2xl">
72
- {Object.values(INDEX_TYPES).map((index) => (
73
- <li key={index} className="flex items-center mb-2 last:mb-0 tb-m:mr-0 py-0">
74
- <button
75
- onClick={() => handleOnClick(index)}
76
- className={`capitalize cursor-pointer py-1 px-3 w-full text-left rounded-full text-neutral-500 ${(activeIndexTypes[index] && index === 'All') ? "bg-blue-500 " : ""
77
- } ${(activeIndexTypes[index] && !showAll) ? 'bg-blue-500': ''} `}
85
+ <div className="tb-m:min-w-[182px] static tb-m:sticky top-[116px] self-start">
86
+ <ul className="hds-hidden tb-m:block bg-neutral-0 shadow-md p-4 rounded-2xl">
87
+ {Object.values(INDEX_TYPES).map((index) => (
88
+ <li
89
+ key={index}
90
+ className="flex items-center mb-2 last:mb-0 tb-m:mr-0 py-0"
78
91
  >
79
- <Typography
80
- textStyle="body3c-medium"
81
- className={`${(activeIndexTypes[index] && index === 'All') ? "text-neutral-0 " : ""} ${(activeIndexTypes[index] && !showAll) ? 'text-neutral-0' : ''} `
82
- }
92
+ <button
93
+ onClick={() => handleOnClick(index)}
94
+ className={`capitalize cursor-pointer py-1 px-3 w-full text-left rounded-full text-neutral-500 ${
95
+ activeIndexTypes[index] && index === "All"
96
+ ? "bg-blue-500 "
97
+ : ""
98
+ } ${activeIndexTypes[index] && !showAll ? "bg-blue-500" : ""} `}
83
99
  >
84
- {index}
85
- </Typography>
86
- </button>
87
- </li>
88
- ))}
89
- </ul>
90
-
91
- </div>
100
+ <Typography
101
+ textStyle="body3c-medium"
102
+ className={`${
103
+ activeIndexTypes[index] && index === "All"
104
+ ? "text-neutral-0 "
105
+ : ""
106
+ } ${
107
+ activeIndexTypes[index] && !showAll ? "text-neutral-0" : ""
108
+ } `}
109
+ >
110
+ {index}
111
+ </Typography>
112
+ </button>
113
+ </li>
114
+ ))}
115
+ </ul>
116
+ </div>
92
117
  <div className="relative hds-hidden-tbm">
93
118
  <button
94
119
  onClick={() => setShowDropdown(!showDropdown)}
95
120
  className="capitalize cursor-pointer py-1 px-3 w-full border border-neutral-800 text-left rounded-full text-neutral-800 bg-transparent"
96
121
  >
97
- {Object.values(INDEX_TYPES).find((index) => activeIndexTypes[index]) || "All"}
98
-
122
+ {Object.values(INDEX_TYPES).find(
123
+ (index) => activeIndexTypes[index]
124
+ ) || "All"}
99
125
  </button>
100
126
  {showDropdown && (
101
127
  <ul className="absolute top-full left-0 w-full bg-neutral-0 shadow-md z-[20] p-2 rounded-3xl mt-1">
@@ -103,8 +129,11 @@ const IndexTypeFilter = ({ activeIndexTypes, setActiveIndexTypes }) => {
103
129
  <li
104
130
  key={index}
105
131
  onClick={() => handleOnClick(index)}
106
- className={`capitalize cursor-pointer py-2 px-4 ${activeIndexTypes[index] ? "text-neutral-1000 " : "text-neutral-500"
107
- }`}
132
+ className={`capitalize cursor-pointer py-2 px-4 ${
133
+ activeIndexTypes[index]
134
+ ? "text-neutral-1000 "
135
+ : "text-neutral-500"
136
+ }`}
108
137
  >
109
138
  {index}
110
139
  </li>
@@ -112,21 +141,18 @@ const IndexTypeFilter = ({ activeIndexTypes, setActiveIndexTypes }) => {
112
141
  </ul>
113
142
  )}
114
143
  </div>
115
-
116
144
  </div>
117
145
  );
118
146
  };
119
147
 
120
148
  export default function SearchWrapper({ indices, ...props }) {
121
- let ALGOLIA_APP_ID, ALGOLIA_SEARCH_KEY ;
122
- if (props.ALGOLIA_APP_ID && props.ALGOLIA_SEARCH_KEY){
149
+ let ALGOLIA_APP_ID, ALGOLIA_SEARCH_KEY;
150
+ if (props.ALGOLIA_APP_ID && props.ALGOLIA_SEARCH_KEY) {
123
151
  ALGOLIA_APP_ID = props.ALGOLIA_APP_ID;
124
152
  ALGOLIA_SEARCH_KEY = props.ALGOLIA_SEARCH_KEY;
125
153
  }
126
- const algoliaClient = algoliasearch(
127
- ALGOLIA_APP_ID,
128
- ALGOLIA_SEARCH_KEY
129
- );
154
+
155
+ const algoliaClient = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_SEARCH_KEY);
130
156
 
131
157
  const searchClient = {
132
158
  ...algoliaClient,
@@ -146,13 +172,17 @@ export default function SearchWrapper({ indices, ...props }) {
146
172
  },
147
173
  };
148
174
 
149
-
150
- const defaultIndexTypesState = Object.values(INDEX_TYPES).reduce((acc, index) => {
151
- acc[index] = true;
152
- return acc;
153
- }, {});
175
+ const defaultIndexTypesState = Object.values(INDEX_TYPES).reduce(
176
+ (acc, index) => {
177
+ acc[index] = true;
178
+ return acc;
179
+ },
180
+ {}
181
+ );
154
182
  const wrapperRef = useRef(null);
155
- const [activeIndexTypes, setActiveIndexTypes] = useState(defaultIndexTypesState);
183
+ const [activeIndexTypes, setActiveIndexTypes] = useState(
184
+ defaultIndexTypesState
185
+ );
156
186
  useEffect(() => {
157
187
  setActiveIndexTypes(defaultIndexTypesState);
158
188
  }, []);
@@ -168,8 +198,8 @@ export default function SearchWrapper({ indices, ...props }) {
168
198
  <div className="tb-m:flex gap-10">
169
199
  <div className="hds-hidden tb-m:flex">
170
200
  <IndexTypeFilter
171
- activeIndexTypes={activeIndexTypes}
172
- setActiveIndexTypes={setActiveIndexTypes}
201
+ activeIndexTypes={activeIndexTypes}
202
+ setActiveIndexTypes={setActiveIndexTypes}
173
203
  />
174
204
  </div>
175
205
  <SearchResults
@@ -177,13 +207,14 @@ export default function SearchWrapper({ indices, ...props }) {
177
207
  indices={indices}
178
208
  wrapperRef={wrapperRef}
179
209
  activeIndexTypes={activeIndexTypes}
180
- className="search-results">
181
- <div className="hds-hidden-tbm sticky top-[124px] tb:top-[114px] z-10 bg-neutral-100 pb-3">
182
- <IndexTypeFilter
183
- activeIndexTypes={activeIndexTypes}
184
- setActiveIndexTypes={setActiveIndexTypes}
185
- />
186
- </div>
210
+ className="search-results"
211
+ >
212
+ <div className="hds-hidden-tbm sticky top-[124px] tb:top-[114px] z-10 bg-neutral-100 pb-3">
213
+ <IndexTypeFilter
214
+ activeIndexTypes={activeIndexTypes}
215
+ setActiveIndexTypes={setActiveIndexTypes}
216
+ />
217
+ </div>
187
218
  </SearchResults>
188
219
  </div>
189
220
  </CustomAllResults>