@searchstax-inc/searchstudio-ux-react 0.0.1
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.
- package/README.md +303 -0
- package/index.html +24 -0
- package/package.json +44 -0
- package/public/vite.svg +1 -0
- package/src/App.scss +1 -0
- package/src/App.tsx +234 -0
- package/src/assets/react.svg +1 -0
- package/src/components/SearchstaxInputWidget.tsx +83 -0
- package/src/components/SearchstaxResultWidget.tsx +202 -0
- package/src/components/SearchstaxWrapper.tsx +34 -0
- package/src/index.css +0 -0
- package/src/main.js +4 -0
- package/src/main.tsx +5 -0
- package/src/stores/searchstaxStore.js +5 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +24 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.ts +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# searchstudio-ux-react
|
|
2
|
+
|
|
3
|
+
Library to build searchstudio search page
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
npm install following packages
|
|
7
|
+
`npm install --save @searchstax-inc/searchstudio-ux-react`
|
|
8
|
+
`npm install --save @searchstax-inc/searchstudio-ux-js`
|
|
9
|
+
|
|
10
|
+
Add following code to `<head>`
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
<script type="text/javascript">
|
|
14
|
+
var _msq = _msq || []; //declare object
|
|
15
|
+
var analyticsBaseUrl = 'https://analytics-us-east.searchstax.co';
|
|
16
|
+
(function () {
|
|
17
|
+
var ms = document.createElement('script');
|
|
18
|
+
ms.type = 'text/javascript';
|
|
19
|
+
ms.src = 'https://static.searchstax.co/studio-js/v3/js/studio-analytics.js';
|
|
20
|
+
var s = document.getElementsByTagName('script')[0];
|
|
21
|
+
s.parentNode.insertBefore(ms, s);
|
|
22
|
+
})();
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## imports
|
|
27
|
+
types can be imported from
|
|
28
|
+
|
|
29
|
+
`import type { ISearchstaxParsedResult, ISearchstaxSearchProps, ISearchstaxSuggestProps, ISearchstaxSuggestResponse, Searchstax } from '@searchstax-inc/searchstudio-ux-js'`
|
|
30
|
+
|
|
31
|
+
component import
|
|
32
|
+
|
|
33
|
+
`import {SearchstaxWrapper, SearchstaxInputWidget, SearchstaxResultWidget} from "@searchstax-inc/searchstudio-ux-react"`
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Following components are experted by this library:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
SearchstaxWrapper
|
|
40
|
+
SearchstaxInputWidget
|
|
41
|
+
SearchstaxResultWidget
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Initialization
|
|
45
|
+
JS
|
|
46
|
+
```
|
|
47
|
+
const config = {
|
|
48
|
+
searchURL: '', // - SeachStudio select endpoint
|
|
49
|
+
suggesterURL: '', // - SeachStudio suggest endpoint
|
|
50
|
+
trackApiKey: '', // - Api key used for tracking events
|
|
51
|
+
searchAuth: '', // - Authentication value. based on authType it's either a token value or basic auth value
|
|
52
|
+
authType: '', // - Type of authentication
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function initialized(searchstax: Searchstax){ // - optional function that returns an instance of Searchstax class. can be used for advanced workflows
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
HTML
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
<SearchstaxWrapper
|
|
65
|
+
searchURL={config.searchURL}
|
|
66
|
+
suggesterURL={config.suggesterURL}
|
|
67
|
+
trackApiKey={config.trackApiKey}
|
|
68
|
+
searchAuth={config.searchAuth}
|
|
69
|
+
initialized={initialized}
|
|
70
|
+
authType="basic"
|
|
71
|
+
language="en"
|
|
72
|
+
>
|
|
73
|
+
// other widgets go here
|
|
74
|
+
</SearchstaxWrapper>
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Input widget
|
|
79
|
+
JS
|
|
80
|
+
```
|
|
81
|
+
function beforeSearch(props: ISearchstaxSearchProps) {
|
|
82
|
+
// - this function gets called before firing search. searchProps are being passed as a property and can be modified, if passed along further search will execute with modified properties, if null is returned then event gets canceled and search never fires.
|
|
83
|
+
const propsCopy = { ...props }
|
|
84
|
+
return propsCopy
|
|
85
|
+
}
|
|
86
|
+
function afterSearch(results: ISearchstaxParsedResult[]) {
|
|
87
|
+
//- this function gets called after firing search and before rendering. It needs to return array of results that are either modified or untouched.
|
|
88
|
+
const copy = [...results]
|
|
89
|
+
return copy
|
|
90
|
+
}
|
|
91
|
+
function afterAutosuggest(result: ISearchstaxSuggestResponse) {
|
|
92
|
+
// - this function gets called before firing autosuggest. autosuggestProps are being passed as a property and can be modified, if passed along further search will execute with modified properties, if null is returned then event gets canceled and search never fires.
|
|
93
|
+
const copy = { ...result }
|
|
94
|
+
return copy
|
|
95
|
+
}
|
|
96
|
+
function beforeAutosuggest(props: ISearchstaxSuggestProps) {
|
|
97
|
+
// - this function gets called after autosuggest has values but before rendering. It needs to return same type of data but it can be modified.
|
|
98
|
+
const propsCopy = { ...props }
|
|
99
|
+
return propsCopy
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const suggestAfterMinChars = 3; // - controls how many characters the UI should accept at the minimum before showing suggestions
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
JSX Input template sample
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
function InputTemplate(): React.ReactElement {
|
|
109
|
+
return (
|
|
110
|
+
<div className="searchstax-search-input-wrapper">
|
|
111
|
+
<input
|
|
112
|
+
type="text"
|
|
113
|
+
id="searchstax-search-input"
|
|
114
|
+
className="searchstax-search-input"
|
|
115
|
+
placeholder="SEARCH FOR222..."
|
|
116
|
+
/>
|
|
117
|
+
<button
|
|
118
|
+
className="searchstax-spinner-icon"
|
|
119
|
+
id="searchstax-search-input-action-button"
|
|
120
|
+
></button>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
HTML example with input override
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
<SearchstaxInputWidget
|
|
130
|
+
beforeSearch={beforeSearch}
|
|
131
|
+
afterSearch={afterSearch}
|
|
132
|
+
afterAutosuggest={afterAutosuggest}
|
|
133
|
+
beforeAutosuggest={beforeAutosuggest}
|
|
134
|
+
inputTemplate={InputTemplate}
|
|
135
|
+
></SearchstaxInputWidget>
|
|
136
|
+
```
|
|
137
|
+
## Result widget
|
|
138
|
+
|
|
139
|
+
JS
|
|
140
|
+
```
|
|
141
|
+
function afterLinkClick(result: ISearchstaxParsedResult) {
|
|
142
|
+
// - function is called after user clicks result and passes that result as a property. when result is passed along tracking will execute and user will be navigated if null is returned events are canceled and nothing happens.
|
|
143
|
+
const propsCopy = { ...result }
|
|
144
|
+
|
|
145
|
+
return propsCopy
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
JSX no results emplate sample
|
|
150
|
+
|
|
151
|
+
```function noResultTemplate(
|
|
152
|
+
searchTerm: string,
|
|
153
|
+
searchSuggestion: string
|
|
154
|
+
): React.ReactElement {
|
|
155
|
+
return (
|
|
156
|
+
<div>
|
|
157
|
+
<div className="searchstax-no-results">
|
|
158
|
+
Showing <strong>no results</strong> forRRRRR
|
|
159
|
+
<strong>"{searchTerm}"</strong>
|
|
160
|
+
<br />
|
|
161
|
+
{searchSuggestion && (
|
|
162
|
+
<span>
|
|
163
|
+
Did you mean
|
|
164
|
+
<a href="#" className="searchstax-suggestion-term">
|
|
165
|
+
{searchSuggestion}
|
|
166
|
+
</a>
|
|
167
|
+
?
|
|
168
|
+
</span>
|
|
169
|
+
)}
|
|
170
|
+
</div>
|
|
171
|
+
<div>
|
|
172
|
+
<p>
|
|
173
|
+
Try searching for search related terms or topics. We offer a wide
|
|
174
|
+
variety of content to help you get the information you need.
|
|
175
|
+
</p>
|
|
176
|
+
<p>Lost? Click on the ‘X” in the Search Box to reset your search.</p>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
JSX results template sample
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
function resultsTemplate(
|
|
188
|
+
searchResults: ISearchstaxParsedResult[],
|
|
189
|
+
linkClick: (
|
|
190
|
+
results: ISearchstaxParsedResult[],
|
|
191
|
+
event: any
|
|
192
|
+
) => ISearchstaxParsedResult[]
|
|
193
|
+
): React.ReactElement {
|
|
194
|
+
return (
|
|
195
|
+
<div className="searchstax-search-results">
|
|
196
|
+
{searchResults !== null &&
|
|
197
|
+
searchResults.map(function (searchResult, i) {
|
|
198
|
+
return (
|
|
199
|
+
<div
|
|
200
|
+
className="searchstax-search-result"
|
|
201
|
+
key={searchResult.uniqueId}
|
|
202
|
+
>
|
|
203
|
+
{searchResult.url && (
|
|
204
|
+
<a
|
|
205
|
+
href={searchResult.url}
|
|
206
|
+
data-searchstax-unique-result-id={searchResult.uniqueId}
|
|
207
|
+
onClick={(event) => {
|
|
208
|
+
linkClick(searchResult, event);
|
|
209
|
+
}}
|
|
210
|
+
className="searchstax-result-item-link"
|
|
211
|
+
></a>
|
|
212
|
+
)}
|
|
213
|
+
|
|
214
|
+
{searchResult.ribbon && (
|
|
215
|
+
<div className="searchstax-search-result-ribbon">
|
|
216
|
+
{searchResult.ribbon}
|
|
217
|
+
</div>
|
|
218
|
+
)}
|
|
219
|
+
|
|
220
|
+
{searchResult.thumbnail && (
|
|
221
|
+
<img
|
|
222
|
+
src={searchResult.thumbnail}
|
|
223
|
+
className="searchstax-thumbnail"
|
|
224
|
+
/>
|
|
225
|
+
)}
|
|
226
|
+
|
|
227
|
+
<div className="searchstax-search-result-title-container">
|
|
228
|
+
<span className="searchstax-search-result-title">
|
|
229
|
+
{searchResult.title}
|
|
230
|
+
</span>
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
{searchResult.paths && (
|
|
234
|
+
<p className="searchstax-search-result-common">
|
|
235
|
+
{searchResult.paths}
|
|
236
|
+
</p>
|
|
237
|
+
)}
|
|
238
|
+
|
|
239
|
+
{searchResult.description && (
|
|
240
|
+
<p className="searchstax-search-result-description searchstax-search-result-common">
|
|
241
|
+
{searchResult.description}
|
|
242
|
+
</p>
|
|
243
|
+
)}
|
|
244
|
+
|
|
245
|
+
{searchResult.unmappedFields.map(function (unmappedField: any) {
|
|
246
|
+
return (
|
|
247
|
+
<div key={unmappedField.value}>
|
|
248
|
+
{unmappedField.isImage && (
|
|
249
|
+
<div className="searchstax-search-result-image-container">
|
|
250
|
+
<img
|
|
251
|
+
src={unmappedField.value}
|
|
252
|
+
className="searchstax-result-image"
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
|
|
257
|
+
{!unmappedField.isImage && (
|
|
258
|
+
<div>
|
|
259
|
+
<p className="searchstax-search-result-common">
|
|
260
|
+
{unmappedField.value}
|
|
261
|
+
</p>
|
|
262
|
+
</div>
|
|
263
|
+
)}
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
})}
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
})}
|
|
270
|
+
|
|
271
|
+
{searchResults !== null && searchResults.length && (
|
|
272
|
+
<div v-if="searchResults && searchResults.length && hasResultSlot">
|
|
273
|
+
{/* <slot name="results" ></slot> */}
|
|
274
|
+
</div>
|
|
275
|
+
)}
|
|
276
|
+
</div>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
HTML
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
<SearchstaxResultWidget
|
|
287
|
+
afterLinkClick={afterLinkClick}
|
|
288
|
+
noResultTemplate={noResultTemplate}
|
|
289
|
+
resultsTemplate={resultsTemplate}
|
|
290
|
+
></SearchstaxResultWidget>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## STYLING
|
|
294
|
+
|
|
295
|
+
scss styles can be imported from searchstudio-ux-js
|
|
296
|
+
```
|
|
297
|
+
@import './../node_modules/@searchstax-inc/searchstudio-ux-js/dist/styles/scss/mainTheme.scss';
|
|
298
|
+
```
|
|
299
|
+
css can be taken from
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
./../node_modules/@searchstax-inc/searchstudio-ux-js/dist/styles/mainTheme.css
|
|
303
|
+
```
|
package/index.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Vite + React + TS</title>
|
|
8
|
+
<script type="text/javascript">
|
|
9
|
+
var _msq = _msq || []; //declare object
|
|
10
|
+
var analyticsBaseUrl = 'https://analytics-us-east.searchstax.co';
|
|
11
|
+
(function () {
|
|
12
|
+
var ms = document.createElement('script');
|
|
13
|
+
ms.type = 'text/javascript';
|
|
14
|
+
ms.src = 'https://static.searchstax.co/studio-js/v3/js/studio-analytics.js';
|
|
15
|
+
var s = document.getElementsByTagName('script')[0];
|
|
16
|
+
s.parentNode.insertBefore(ms, s);
|
|
17
|
+
})();
|
|
18
|
+
</script>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="root"></div>
|
|
22
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@searchstax-inc/searchstudio-ux-react",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/searchstudio-ux-react-ts.umd.js",
|
|
7
|
+
"module": "./dist/searchstudio-ux-react-ts.es.js",
|
|
8
|
+
"types": "./dist/main.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/searchstudio-ux-react-ts.es.js",
|
|
12
|
+
"require": "./dist/searchstudio-ux-react-ts.umd.js"
|
|
13
|
+
},
|
|
14
|
+
"./dist/searchstudio-ux-react-ts.css": {
|
|
15
|
+
"import": "./dist/searchstudio-ux-react-ts.css",
|
|
16
|
+
"require": "./dist/searchstudio-ux-react-ts.css"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite",
|
|
21
|
+
"build": "tsc && vite build",
|
|
22
|
+
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
23
|
+
"preview": "vite preview"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@searchstax-inc/searchstudio-ux-js": "^0.0.7",
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^18.0.28",
|
|
32
|
+
"@types/react-dom": "^18.0.11",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
34
|
+
"@typescript-eslint/parser": "^5.57.1",
|
|
35
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
36
|
+
"eslint": "^8.38.0",
|
|
37
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
38
|
+
"eslint-plugin-react-refresh": "^0.3.4",
|
|
39
|
+
"sass": "^1.62.1",
|
|
40
|
+
"typescript": "^5.0.2",
|
|
41
|
+
"vite": "^4.3.2",
|
|
42
|
+
"vite-plugin-dts": "^2.3.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/public/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/src/App.scss
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import './../node_modules/@searchstax-inc/searchstudio-ux-js/dist/styles/scss/mainTheme.scss';
|
package/src/App.tsx
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import "./App.scss";
|
|
3
|
+
import SearchstaxInputWidget from "./components/SearchstaxInputWidget";
|
|
4
|
+
import SearchstaxResultWidget from "./components/SearchstaxResultWidget";
|
|
5
|
+
import SearchstaxWrapper from "./components/SearchstaxWrapper";
|
|
6
|
+
import type {
|
|
7
|
+
ISearchstaxSuggestResponse,
|
|
8
|
+
ISearchstaxSearchProps,
|
|
9
|
+
ISearchstaxParsedResult,
|
|
10
|
+
ISearchstaxSuggestProps,
|
|
11
|
+
//@ts-expect-error
|
|
12
|
+
} from "@searchstax-inc/searchstudio-ux-js";
|
|
13
|
+
//@ts-expect-error
|
|
14
|
+
import { Searchstax } from "@searchstax-inc/searchstudio-ux-js";
|
|
15
|
+
|
|
16
|
+
function App() {
|
|
17
|
+
//@ts-expect-error
|
|
18
|
+
const [searchstaxInstance, setSearchstaxInstance] = useState(
|
|
19
|
+
null as null | Searchstax
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
function beforeSearch(props: ISearchstaxSearchProps) {
|
|
23
|
+
// gets searchProps, if passed along further search will execute, if null then event gets canceled
|
|
24
|
+
// props can be modified and passed along
|
|
25
|
+
const propsCopy = { ...props };
|
|
26
|
+
// propsCopy.term = propsCopy.term;
|
|
27
|
+
return propsCopy;
|
|
28
|
+
}
|
|
29
|
+
function afterSearch(results: ISearchstaxParsedResult[]) {
|
|
30
|
+
const copy = [...results];
|
|
31
|
+
// copy.splice(0, 1);
|
|
32
|
+
return copy;
|
|
33
|
+
}
|
|
34
|
+
function afterAutosuggest(result: ISearchstaxSuggestResponse) {
|
|
35
|
+
const copy = { ...result };
|
|
36
|
+
return copy;
|
|
37
|
+
}
|
|
38
|
+
function beforeAutosuggest(props: ISearchstaxSuggestProps) {
|
|
39
|
+
// gets suggestProps, if passed along further autosuggest will execute, if null then event gets canceled
|
|
40
|
+
// props can be modified and passed along
|
|
41
|
+
const propsCopy = { ...props };
|
|
42
|
+
// propsCopy.term = propsCopy.term + '222';
|
|
43
|
+
return propsCopy;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function afterLinkClick(result: ISearchstaxParsedResult) {
|
|
47
|
+
// gets result that was clicked, if passed along further functions will execute, if null then event gets canceled
|
|
48
|
+
const propsCopy = { ...result };
|
|
49
|
+
|
|
50
|
+
return propsCopy;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function initialized(searchstax: Searchstax) {
|
|
54
|
+
setSearchstaxInstance(searchstax);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function InputTemplate(): React.ReactElement {
|
|
58
|
+
return (
|
|
59
|
+
<div className="searchstax-search-input-wrapper">
|
|
60
|
+
<input
|
|
61
|
+
type="text"
|
|
62
|
+
id="searchstax-search-input"
|
|
63
|
+
className="searchstax-search-input"
|
|
64
|
+
placeholder="SEARCH FOR222..."
|
|
65
|
+
/>
|
|
66
|
+
<button
|
|
67
|
+
className="searchstax-spinner-icon"
|
|
68
|
+
id="searchstax-search-input-action-button"
|
|
69
|
+
></button>
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function noResultTemplate(
|
|
75
|
+
searchTerm: string,
|
|
76
|
+
searchSuggestion: string
|
|
77
|
+
): React.ReactElement {
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<div className="searchstax-no-results">
|
|
81
|
+
Showing <strong>no results</strong> forRRRRR
|
|
82
|
+
<strong>"{searchTerm}"</strong>
|
|
83
|
+
<br />
|
|
84
|
+
{searchSuggestion && (
|
|
85
|
+
<span>
|
|
86
|
+
Did you mean
|
|
87
|
+
<a href="#" className="searchstax-suggestion-term">
|
|
88
|
+
{searchSuggestion}
|
|
89
|
+
</a>
|
|
90
|
+
?
|
|
91
|
+
</span>
|
|
92
|
+
)}
|
|
93
|
+
</div>
|
|
94
|
+
<div>
|
|
95
|
+
<p>
|
|
96
|
+
Try searching for search related terms or topics. We offer a wide
|
|
97
|
+
variety of content to help you get the information you need.
|
|
98
|
+
</p>
|
|
99
|
+
<p>Lost? Click on the ‘X” in the Search Box to reset your search.</p>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function resultsTemplate(
|
|
106
|
+
searchResults: ISearchstaxParsedResult[],
|
|
107
|
+
linkClick: (
|
|
108
|
+
results: ISearchstaxParsedResult[],
|
|
109
|
+
event: any
|
|
110
|
+
) => ISearchstaxParsedResult[]
|
|
111
|
+
): React.ReactElement {
|
|
112
|
+
return (
|
|
113
|
+
<div className="searchstax-search-results">
|
|
114
|
+
{searchResults !== null &&
|
|
115
|
+
searchResults.map(function (searchResult) {
|
|
116
|
+
return (
|
|
117
|
+
<div
|
|
118
|
+
className="searchstax-search-result"
|
|
119
|
+
key={searchResult.uniqueId}
|
|
120
|
+
>
|
|
121
|
+
{searchResult.url && (
|
|
122
|
+
<a
|
|
123
|
+
href={searchResult.url}
|
|
124
|
+
data-searchstax-unique-result-id={searchResult.uniqueId}
|
|
125
|
+
onClick={(event) => {
|
|
126
|
+
linkClick(searchResult, event);
|
|
127
|
+
}}
|
|
128
|
+
className="searchstax-result-item-link"
|
|
129
|
+
></a>
|
|
130
|
+
)}
|
|
131
|
+
|
|
132
|
+
{searchResult.ribbon && (
|
|
133
|
+
<div className="searchstax-search-result-ribbon">
|
|
134
|
+
{searchResult.ribbon}
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
|
|
138
|
+
{searchResult.thumbnail && (
|
|
139
|
+
<img
|
|
140
|
+
src={searchResult.thumbnail}
|
|
141
|
+
className="searchstax-thumbnail"
|
|
142
|
+
/>
|
|
143
|
+
)}
|
|
144
|
+
|
|
145
|
+
<div className="searchstax-search-result-title-container">
|
|
146
|
+
<span className="searchstax-search-result-title">
|
|
147
|
+
{searchResult.title}
|
|
148
|
+
</span>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
{searchResult.paths && (
|
|
152
|
+
<p className="searchstax-search-result-common">
|
|
153
|
+
{searchResult.paths}
|
|
154
|
+
</p>
|
|
155
|
+
)}
|
|
156
|
+
|
|
157
|
+
{searchResult.description && (
|
|
158
|
+
<p className="searchstax-search-result-description searchstax-search-result-common">
|
|
159
|
+
{searchResult.description}
|
|
160
|
+
</p>
|
|
161
|
+
)}
|
|
162
|
+
|
|
163
|
+
{searchResult.unmappedFields.map(function (unmappedField: any) {
|
|
164
|
+
return (
|
|
165
|
+
<div key={unmappedField.value}>
|
|
166
|
+
{unmappedField.isImage && (
|
|
167
|
+
<div className="searchstax-search-result-image-container">
|
|
168
|
+
<img
|
|
169
|
+
src={unmappedField.value}
|
|
170
|
+
className="searchstax-result-image"
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
)}
|
|
174
|
+
|
|
175
|
+
{!unmappedField.isImage && (
|
|
176
|
+
<div>
|
|
177
|
+
<p className="searchstax-search-result-common">
|
|
178
|
+
{unmappedField.value}
|
|
179
|
+
</p>
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
})}
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
})}
|
|
188
|
+
|
|
189
|
+
{searchResults !== null && searchResults.length && (
|
|
190
|
+
<div v-if="searchResults && searchResults.length && hasResultSlot">
|
|
191
|
+
{/* <slot name="results" ></slot> */}
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const config = {
|
|
199
|
+
searchURL: 'https://ss325316-pz27ybgj-us-east-1-aws.searchstax.co/solr/corpsiteproductionclone-1512/emselect',
|
|
200
|
+
suggesterURL: 'https://ss325316-pz27ybgj-us-east-1-aws.searchstax.co/solr/corpsiteproductionclone-1512-suggester/emsuggest',
|
|
201
|
+
trackApiKey: 'K48zwO871m7aYwowBkweALTWVQRZTMBpVNq0Qg2Mamo',
|
|
202
|
+
searchAuth: 'YXBwMTUxMi1hcGk6U3R1ZGlvITIz',
|
|
203
|
+
authType: 'basic',
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<>
|
|
208
|
+
<SearchstaxWrapper
|
|
209
|
+
searchURL={config.searchURL}
|
|
210
|
+
suggesterURL={config.suggesterURL}
|
|
211
|
+
trackApiKey={config.trackApiKey}
|
|
212
|
+
searchAuth={config.searchAuth}
|
|
213
|
+
initialized={initialized}
|
|
214
|
+
authType="basic"
|
|
215
|
+
language="en"
|
|
216
|
+
>
|
|
217
|
+
<SearchstaxInputWidget
|
|
218
|
+
beforeSearch={beforeSearch}
|
|
219
|
+
afterSearch={afterSearch}
|
|
220
|
+
afterAutosuggest={afterAutosuggest}
|
|
221
|
+
beforeAutosuggest={beforeAutosuggest}
|
|
222
|
+
inputTemplate={InputTemplate}
|
|
223
|
+
></SearchstaxInputWidget>
|
|
224
|
+
<SearchstaxResultWidget
|
|
225
|
+
afterLinkClick={afterLinkClick}
|
|
226
|
+
noResultTemplate={noResultTemplate}
|
|
227
|
+
resultsTemplate={resultsTemplate}
|
|
228
|
+
></SearchstaxResultWidget>
|
|
229
|
+
</SearchstaxWrapper>
|
|
230
|
+
</>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export default App;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
//@ts-expect-error
|
|
3
|
+
import { store } from "./../stores/searchstaxStore.js";
|
|
4
|
+
import type {
|
|
5
|
+
ISearchstaxSearchProps,
|
|
6
|
+
ISearchstaxSuggestProps,
|
|
7
|
+
ISearchstaxParsedResult,
|
|
8
|
+
ISearchstaxSuggestResponse,
|
|
9
|
+
//@ts-expect-error
|
|
10
|
+
} from "@searchstax-inc/searchstudio-ux-js";
|
|
11
|
+
|
|
12
|
+
function SearchstaxInputWidget(props: {
|
|
13
|
+
beforeSearch: (
|
|
14
|
+
props: ISearchstaxSearchProps
|
|
15
|
+
) => ISearchstaxSearchProps | null;
|
|
16
|
+
afterSearch: (
|
|
17
|
+
results: ISearchstaxParsedResult[]
|
|
18
|
+
) => ISearchstaxParsedResult[];
|
|
19
|
+
afterAutosuggest: (
|
|
20
|
+
result: ISearchstaxSuggestResponse
|
|
21
|
+
) => ISearchstaxSuggestResponse;
|
|
22
|
+
beforeAutosuggest: (
|
|
23
|
+
props: ISearchstaxSuggestProps
|
|
24
|
+
) => ISearchstaxSuggestProps | null;
|
|
25
|
+
searchInputId?: string;
|
|
26
|
+
suggestAfterMinChars?: number;
|
|
27
|
+
inputTemplate?: ()=> React.ReactElement;
|
|
28
|
+
}) {
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (store.searchstax) {
|
|
32
|
+
const hooks: { [key: string]: (prop: any) => any } = {};
|
|
33
|
+
if (props.beforeSearch) {
|
|
34
|
+
hooks.beforeSearch = props.beforeSearch;
|
|
35
|
+
}
|
|
36
|
+
if (props.afterSearch) {
|
|
37
|
+
hooks.afterSearch = props.afterSearch;
|
|
38
|
+
}
|
|
39
|
+
if (props.afterAutosuggest) {
|
|
40
|
+
hooks.afterAutosuggest = props.afterAutosuggest;
|
|
41
|
+
}
|
|
42
|
+
if (props.beforeAutosuggest) {
|
|
43
|
+
hooks.beforeAutosuggest = props.beforeAutosuggest;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
store.searchstax.addSearchInputWidget("searchstax-input-container", {
|
|
47
|
+
suggestAfterMinChars: props.suggestAfterMinChars ?? 3,
|
|
48
|
+
hooks: hooks,
|
|
49
|
+
templates: {
|
|
50
|
+
searchInputId: props.searchInputId ?? "searchstax-search-input",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
throw Error("Searchstax instance needs to be passed via props");
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<div id="searchstax-input-container">
|
|
61
|
+
<div className="searchstax-search-input-container">
|
|
62
|
+
{!props.inputTemplate && (
|
|
63
|
+
<div className="searchstax-search-input-wrapper">
|
|
64
|
+
<input
|
|
65
|
+
type="text"
|
|
66
|
+
id="searchstax-search-input"
|
|
67
|
+
className="searchstax-search-input"
|
|
68
|
+
placeholder="SEARCH FOR..."
|
|
69
|
+
/>
|
|
70
|
+
<button
|
|
71
|
+
className="searchstax-spinner-icon"
|
|
72
|
+
id="searchstax-search-input-action-button"
|
|
73
|
+
></button>
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
{props.inputTemplate && <>{props.inputTemplate()}</>}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default SearchstaxInputWidget;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
//@ts-expect-error
|
|
3
|
+
|
|
4
|
+
import { store } from "./../stores/searchstaxStore.js";
|
|
5
|
+
//@ts-expect-error
|
|
6
|
+
import type { ISearchstaxParsedResult, ISearchstaxSearchMetadata } from '@searchstax-inc/searchstudio-ux-js'
|
|
7
|
+
|
|
8
|
+
function SearchstaxResultWidget(props: {
|
|
9
|
+
afterLinkClick: (
|
|
10
|
+
results: ISearchstaxParsedResult[]
|
|
11
|
+
) => ISearchstaxParsedResult[];
|
|
12
|
+
noResultTemplate?: (searchTerm: string, searchSuggestion: string) => React.ReactElement;
|
|
13
|
+
resultsTemplate?: (results: ISearchstaxParsedResult[], resultClicked: (result: ISearchstaxParsedResult, event: any) => any) => React.ReactElement;
|
|
14
|
+
}) {
|
|
15
|
+
//state variable
|
|
16
|
+
const [searchResults, setResults] = useState(
|
|
17
|
+
null as ISearchstaxParsedResult[] | null
|
|
18
|
+
);
|
|
19
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
20
|
+
const [searchSuggestion, setSearchSuggestion] = useState("");
|
|
21
|
+
|
|
22
|
+
const resultClicked = (result: ISearchstaxParsedResult, event: any) => {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
event.stopPropagation();
|
|
25
|
+
store.searchstax.executeLinkClick(result.uniqueId);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const hooks: { [key: string]: (prop: any) => any } = {};
|
|
30
|
+
if (props.afterLinkClick) {
|
|
31
|
+
hooks.afterLinkClick = props.afterLinkClick;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
store.searchstax.dataLayer.searchResultsObservable.subscribe(
|
|
35
|
+
(results: ISearchstaxParsedResult[] | null) => {
|
|
36
|
+
setResults(results);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
store.searchstax.dataLayer.searchResultsMetadataObservable.subscribe(
|
|
40
|
+
(results: ISearchstaxSearchMetadata | null) => {
|
|
41
|
+
setSearchSuggestion(results?.spellingSuggestion ?? "");
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
store.searchstax.dataLayer.searchTermChangeObservable.subscribe(
|
|
46
|
+
(result: string) => {
|
|
47
|
+
setSearchTerm(result);
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
store.searchstax.addSearchResultsWidget("searchstax-results-container", {
|
|
52
|
+
searchResultsContainerId: "searchstax-result-container", // if main template is over ridden this points to an
|
|
53
|
+
templates: {},
|
|
54
|
+
hooks: hooks,
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<div id="searchstax-results-container">
|
|
61
|
+
<div className="searchstax-search-results-container">
|
|
62
|
+
<div id="searchstax-result-container">
|
|
63
|
+
{searchResults &&
|
|
64
|
+
searchResults.length === 0 &&
|
|
65
|
+
!props.noResultTemplate && (
|
|
66
|
+
<div>
|
|
67
|
+
<div className="searchstax-no-results">
|
|
68
|
+
Showing <strong>no results</strong> for
|
|
69
|
+
<strong>"{searchTerm}"</strong>
|
|
70
|
+
<br />
|
|
71
|
+
{searchSuggestion && (
|
|
72
|
+
<span>
|
|
73
|
+
Did you mean
|
|
74
|
+
<a href="#" className="searchstax-suggestion-term">
|
|
75
|
+
{searchSuggestion}
|
|
76
|
+
</a>
|
|
77
|
+
?
|
|
78
|
+
</span>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
<div>
|
|
82
|
+
<p>
|
|
83
|
+
Try searching for search related terms or topics. We offer
|
|
84
|
+
a wide variety of content to help you get the information
|
|
85
|
+
you need.
|
|
86
|
+
</p>
|
|
87
|
+
<p>
|
|
88
|
+
Lost? Click on the ‘X” in the Search Box to reset your
|
|
89
|
+
search.
|
|
90
|
+
</p>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
|
|
95
|
+
{searchResults &&
|
|
96
|
+
searchResults.length === 0 &&
|
|
97
|
+
props.noResultTemplate && (
|
|
98
|
+
<>{props.noResultTemplate(searchTerm, searchSuggestion)}</>
|
|
99
|
+
)}
|
|
100
|
+
|
|
101
|
+
{searchResults &&
|
|
102
|
+
searchResults.length &&
|
|
103
|
+
!props.resultsTemplate && (
|
|
104
|
+
<div className="searchstax-search-results">
|
|
105
|
+
{searchResults !== null &&
|
|
106
|
+
searchResults.map(function (searchResult) {
|
|
107
|
+
return (
|
|
108
|
+
<div
|
|
109
|
+
className="searchstax-search-result"
|
|
110
|
+
key={searchResult.uniqueId}
|
|
111
|
+
>
|
|
112
|
+
{searchResult.url && (
|
|
113
|
+
<a
|
|
114
|
+
href={searchResult.url}
|
|
115
|
+
data-searchstax-unique-result-id={
|
|
116
|
+
searchResult.uniqueId
|
|
117
|
+
}
|
|
118
|
+
onClick={(event) => {
|
|
119
|
+
resultClicked(searchResult, event);
|
|
120
|
+
}}
|
|
121
|
+
className="searchstax-result-item-link"
|
|
122
|
+
></a>
|
|
123
|
+
)}
|
|
124
|
+
|
|
125
|
+
{searchResult.ribbon && (
|
|
126
|
+
<div className="searchstax-search-result-ribbon">
|
|
127
|
+
{searchResult.ribbon}
|
|
128
|
+
</div>
|
|
129
|
+
)}
|
|
130
|
+
|
|
131
|
+
{searchResult.thumbnail && (
|
|
132
|
+
<img
|
|
133
|
+
src={searchResult.thumbnail}
|
|
134
|
+
className="searchstax-thumbnail"
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
|
|
138
|
+
<div className="searchstax-search-result-title-container">
|
|
139
|
+
<span className="searchstax-search-result-title">
|
|
140
|
+
{searchResult.title}
|
|
141
|
+
</span>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
{searchResult.paths && (
|
|
145
|
+
<p className="searchstax-search-result-common">
|
|
146
|
+
{searchResult.paths}
|
|
147
|
+
</p>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{searchResult.description && (
|
|
151
|
+
<p className="searchstax-search-result-description searchstax-search-result-common">
|
|
152
|
+
{searchResult.description}
|
|
153
|
+
</p>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
{searchResult.unmappedFields.map(function (
|
|
157
|
+
unmappedField: any
|
|
158
|
+
) {
|
|
159
|
+
return (
|
|
160
|
+
<div key={unmappedField.value}>
|
|
161
|
+
{unmappedField.isImage && (
|
|
162
|
+
<div className="searchstax-search-result-image-container">
|
|
163
|
+
<img
|
|
164
|
+
src={unmappedField.value}
|
|
165
|
+
className="searchstax-result-image"
|
|
166
|
+
/>
|
|
167
|
+
</div>
|
|
168
|
+
)}
|
|
169
|
+
|
|
170
|
+
{!unmappedField.isImage && (
|
|
171
|
+
<div>
|
|
172
|
+
<p className="searchstax-search-result-common">
|
|
173
|
+
{unmappedField.value}
|
|
174
|
+
</p>
|
|
175
|
+
</div>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
})}
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
})}
|
|
183
|
+
|
|
184
|
+
{searchResults !== null && searchResults.length && (
|
|
185
|
+
<div v-if="searchResults && searchResults.length && hasResultSlot">
|
|
186
|
+
{/* <slot name="results" ></slot> */}
|
|
187
|
+
</div>
|
|
188
|
+
)}
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
|
|
192
|
+
{searchResults && searchResults.length && props.resultsTemplate && (
|
|
193
|
+
<>{props.resultsTemplate(searchResults, resultClicked)}</>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
</>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export default SearchstaxResultWidget;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
//@ts-expect-error
|
|
3
|
+
import { store } from "./../stores/searchstaxStore.js";
|
|
4
|
+
//@ts-expect-error
|
|
5
|
+
import Searchstax from '@searchstax-inc/searchstudio-ux-js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function SearchstaxWrapper(props: {
|
|
9
|
+
language?: string;
|
|
10
|
+
searchURL: string;
|
|
11
|
+
suggesterURL: string;
|
|
12
|
+
trackApiKey: string;
|
|
13
|
+
searchAuth: string;
|
|
14
|
+
authType?: "basic" | "token";
|
|
15
|
+
children: any;
|
|
16
|
+
initialized: (searchstax: Searchstax) => void;
|
|
17
|
+
}) {
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
store.searchstax.initialize({
|
|
20
|
+
language: props.language ?? 'en',
|
|
21
|
+
searchURL: props.searchURL,
|
|
22
|
+
suggesterURL: props.suggesterURL,
|
|
23
|
+
trackApiKey: props.trackApiKey,
|
|
24
|
+
searchAuth: props.searchAuth,
|
|
25
|
+
authType: props.authType ?? "basic"
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
props.initialized(store.searchstax);
|
|
29
|
+
}, [props.initialized]);
|
|
30
|
+
|
|
31
|
+
return <>{props.children}</>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default SearchstaxWrapper;
|
package/src/index.css
ADDED
|
File without changes
|
package/src/main.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import SearchstaxWrapper from './components/SearchstaxWrapper.vue'
|
|
2
|
+
import SearchstaxResultWidget from './components/SearchstaxResultWidget.vue'
|
|
3
|
+
import SearchstaxInputWidget from './components/SearchstaxInputWidget.vue'
|
|
4
|
+
export { SearchstaxWrapper, SearchstaxResultWidget, SearchstaxInputWidget }
|
package/src/main.tsx
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import SearchstaxInputWidget from "./components/SearchstaxInputWidget";
|
|
2
|
+
import SearchstaxWrapper from "./components/SearchstaxWrapper";
|
|
3
|
+
import SearchstaxResultWidget from "./components/SearchstaxResultWidget";
|
|
4
|
+
|
|
5
|
+
export { SearchstaxWrapper, SearchstaxResultWidget, SearchstaxInputWidget };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
|
|
8
|
+
/* Bundler mode */
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"jsx": "react-jsx",
|
|
15
|
+
|
|
16
|
+
/* Linting */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true
|
|
21
|
+
},
|
|
22
|
+
"include": ["src"],
|
|
23
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
24
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import dts from 'vite-plugin-dts';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [
|
|
7
|
+
react(),
|
|
8
|
+
dts({
|
|
9
|
+
insertTypesEntry: true,
|
|
10
|
+
}),
|
|
11
|
+
],
|
|
12
|
+
build: {
|
|
13
|
+
lib: {
|
|
14
|
+
entry: "src/main.tsx",
|
|
15
|
+
name: 'searchstudioUxReactTs',
|
|
16
|
+
formats: ["es", "cjs", "umd"],
|
|
17
|
+
fileName: (format) => `searchstudio-ux-react-ts.${format}.js`,
|
|
18
|
+
},
|
|
19
|
+
rollupOptions: {
|
|
20
|
+
external: ['react', 'react-dom', 'styled-components'],
|
|
21
|
+
output: {
|
|
22
|
+
globals: {
|
|
23
|
+
react: 'React',
|
|
24
|
+
'react-dom': 'ReactDOM',
|
|
25
|
+
'styled-components': 'styled',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|