@searchstax-inc/searchstudio-ux-js 0.0.8 → 0.1.0

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 CHANGED
@@ -59,6 +59,32 @@ searchstax.initialize({
59
59
  });
60
60
  ```
61
61
 
62
+ ## Initial layout
63
+ Our base theme is designed with this layout in mind but it is optional as all widgets have id parameters and can be attached to any element.
64
+ ```
65
+ <div class="searchstax-page-layout-container">
66
+ <div id="searchstax-input-container"></div>
67
+
68
+ <div class="search-details-container">
69
+ <div id="search-feedback-container"></div>
70
+ <div id="search-sorting-container"></div>
71
+ </div>
72
+
73
+ <div class="searchstax-page-layout-facet-result-container">
74
+ <div class="searchstax-page-layout-facet-container">
75
+ <div id="searchstax-facets-container"></div>
76
+ </div>
77
+
78
+ <div class="searchstax-page-layout-result-container">
79
+ <div id="searchstax-external-promotions-layout-container"></div>
80
+ <div id="searchstax-results-container"></div>
81
+ <div id="searchstax-related-searches-container"></div>
82
+ <div id="searchstax-pagination-container"></div>
83
+ </div>
84
+ </div>
85
+ </div>
86
+ ```
87
+
62
88
  ## Input widget
63
89
  Initialization properties
64
90
 
@@ -70,17 +96,19 @@ b. {
70
96
 
71
97
  `templates?: {` - optional object that defines template override options
72
98
 
73
- `mainTemplate?: string;` - main template in Mustache templating language
74
-
75
- `searchInputId?: string;` - id of search input within the mainTemplate
76
-
77
- `autosuggestItemTemplate?: string;` - autosuggest item template in Mustache
99
+ `mainTemplate?: {` - optional object for overriding main template
100
+ `template: string;` - main template in Mustache templating language
101
+ `searchInputId: string;` - id of search input within the mainTemplate
102
+ `};`
78
103
 
104
+ `autosuggestItemTemplate?: {` - autosuggest item template in Mustache
105
+ `template: string;` - autosuggest template in Mustache templating language
106
+ `};`
79
107
  `};`
80
108
 
81
109
  `hooks?: {` - optional object that provides various hook options
82
110
 
83
- `beforeSearch?: (props: ISearchstaxSearchProps) => ISearchstaxSearchProps | null;` - 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.
111
+ `beforeSearch?: (props: ISearchObject) => ISearchObject | null;` - 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.
84
112
 
85
113
  `afterSearch?: (results: ISearchstaxParsedResult[]) => ISearchstaxParsedResult[];` - this function gets called after firing search and before rendering. It needs to return array of results that are either modified or untouched.
86
114
 
@@ -98,7 +126,7 @@ example of input widget initialization with various options
98
126
  searchstax.addSearchInputWidget("searchstax-input-container", {
99
127
  suggestAfterMinChars: 3,
100
128
  hooks: {
101
- beforeSearch: function (props: ISearchstaxSearchProps) {
129
+ beforeSearch: function (props: ISearchObject) {
102
130
  const propsCopy = { ...props };
103
131
  return propsCopy;
104
132
  },
@@ -109,7 +137,6 @@ example of input widget initialization with various options
109
137
  },
110
138
  afterAutosuggest: function (result: ISearchstaxSuggestResponse) {
111
139
  const copy = { ...result };
112
- console.log("copy", copy);
113
140
  return copy;
114
141
  },
115
142
  beforeAutosuggest: function (props: ISearchstaxSuggestProps) {
@@ -121,14 +148,22 @@ example of input widget initialization with various options
121
148
  },
122
149
  },
123
150
  templates: {
124
- mainTemplate: `<div class="searchstax-search-input-container">
125
- <div class="searchstax-search-input-wrapper">
126
- <input type="text" id="searchstax-search-input" class="searchstax-search-input" placeholder="SEARCH FOR..." />
127
- <button class="searchstax-spinner-icon" id="searchstax-search-input-action-button"></button>
128
- </div>
129
- </div>`,
130
- searchInputId: "searchstax-input-container",
131
- autosuggestItemTemplate: `<div class="searchstax-autosuggest-item-term-container">{{{term}}}</div>`,
151
+ mainTemplate: {
152
+ template: `
153
+ <div class="searchstax-search-input-container">
154
+ <div class="searchstax-search-input-wrapper">
155
+ <input type="text" id="searchstax-search-input" class="searchstax-search-input" placeholder="SEARCH FOR..." />
156
+ <button class="searchstax-spinner-icon" id="searchstax-search-input-action-button"></button>
157
+ </div>
158
+ </div>
159
+ `,
160
+ searchInputId: "searchstax-search-input"
161
+ }
162
+ autosuggestItemTemplate: {
163
+ template: `
164
+ <div class="searchstax-autosuggest-item-term-container">{{{term}}}</div>
165
+ `,
166
+ }
132
167
  },
133
168
  });
134
169
  ```
@@ -139,17 +174,23 @@ a. id of container where widget will be rendered
139
174
 
140
175
  b. {
141
176
 
142
- `searchResultsContainerId?: string;` - this is needed only if mainTemplate is overridden. It points to an element in the template where results need to be rendered
143
-
144
- `searchResultUniqueIdAttribute?: string;` - this is needed only if searchResultTemplate is overridden. searchResultTemplate needs to have unique result id property. Default is data-searchstax-unique-result-id="{{uniqueId}}". see example below on how it is used
177
+ `searchResultUniqueIdAttribute?: string;` - this is needed only if searchResultTemplate is overridden. searchResultTemplate needs to have unique result id property. Default is data-searchstax-unique-result-id="uniqueId". see example below on how it is used
145
178
 
146
179
  `templates?: {` - optional object that defines template override options
147
180
 
148
- `mainTemplate?: string;` - main template in Mustache templating language.
181
+ `mainTemplate?: {`
182
+ template: string; - main template in Mustache templating language.,
183
+ searchResultsContainerId: string;` - this is needed only if mainTemplate is overridden. It points to an element in the template where results need to be rendered
184
+ }
149
185
 
150
- `searchResultTemplate?: string;` - result template using Mustache. ISearchstaxParsedResult is passed to the template and all its properties are available to be used when rendering
186
+ `searchResultTemplate?: {`
187
+ template: string - result template using Mustache. ISearchstaxParsedResult is passed to the template and all its properties are available to be used when rendering;
188
+ searchResultUniqueIdAttribute?: string - this is needed only if searchResultTemplate is overridden. searchResultTemplate needs to have unique result id property. Default is data-searchstax-unique-result-id="niqueId". see example below on how it is used
189
+ }
151
190
 
152
- `noSearchResultTemplate?: string;` - Mustache template for no results section override. spellingSuggestion and searchTerm are values available in the template
191
+ `noSearchResultTemplate?: {`
192
+ template: string - Mustache template for no results section override. spellingSuggestion and searchTerm are values available in the template
193
+ }
153
194
 
154
195
  `};`
155
196
 
@@ -163,54 +204,82 @@ b. {
163
204
  example of result widget initialization with various options
164
205
  ```
165
206
  searchstax.addSearchResultsWidget("searchstax-results-container", {
166
- // searchResultUniqueIdAttribute: ' data-searchstax-unique-result-id', if custom result template is used
167
- // points to an attribute that will be used to identify a result
168
- searchResultsContainerId: "searchstax-result-container", // if main template is over ridden this points to an
169
- // id in the main element where results need to be rendered
170
207
  templates: {
171
- mainTemplate: `
172
- <div class="searchstax-search-results-container">
173
- <div id="searchstax-result-container"></div>
174
- </div>
175
- `,
176
- searchResultTemplate: `<div class="searchstax-search-result">
177
- {{#url}}
178
- <a href="{{url}}" data-searchstax-unique-result-id="{{uniqueId}}" class="searchstax-result-item-link"></a>
179
- {{/url}}
180
- {{#ribbon}}
181
- <div class="searchstax-search-result-ribbon">
182
- {{ribbon}}
183
- </div>
184
- {{/ribbon}}
185
- {{#thumbnail}}
186
- <img :src="thumbnail" class="searchstax-thumbnail">
187
- {{/thumbnail}}
188
- <div class="searchstax-search-result-title-container">
189
- <span class="searchstax-search-result-title">{{title}}</span>
190
- </div>
191
- {{#paths}}
192
- <p class="searchstax-search-result-common">
193
- {{paths}}
194
- </p>
195
- {{/paths}}
196
- {{#description}}
197
- <p class="searchstax-search-result-description searchstax-search-result-common">
198
- {{description}}
199
- </p>
200
- {{/description}}
201
- {{#unmappedFields}}
202
- {{#isImage}}
203
- <div class="searchstax-search-result-image-container">
204
- <img :src="result[value]" class="searchstax-result-image">
205
- </div>
206
- {{/isImage}}
207
- {{^isImage}}
208
- <p class="searchstax-search-result-common">
209
- {{value}}
210
- </p>
211
- {{/isImage}}
212
- {{/unmappedFields}}
213
- </div>`,
208
+ mainTemplate: {
209
+ template: `
210
+ <div class="searchstax-search-results-container">
211
+ <div class="searchstax-search-results" id="searchstax-search-results"></div>
212
+ </div>
213
+ `,
214
+ searchResultsContainerId: "searchstax-search-results",
215
+ },
216
+ searchResultTemplate: {
217
+ template: `
218
+ <div class="searchstax-search-result {{#thumbnail}} has-thumbnail {{/thumbnail}}">
219
+ {{#promoted}}
220
+ <div class="searchstax-search-result-promoted"></div>
221
+ {{/promoted}}
222
+
223
+ {{#url}}
224
+ <a href="{{url}}" data-searchstax-unique-result-id="{{uniqueId}}" class="searchstax-result-item-link"></a>
225
+ {{/url}}
226
+
227
+ {{#ribbon}}
228
+ <div class="searchstax-search-result-ribbon">
229
+ {{ribbon}}
230
+ </div>
231
+ {{/ribbon}}
232
+
233
+ {{#thumbnail}}
234
+ <img src="{{thumbnail}}" class="searchstax-thumbnail">
235
+ {{/thumbnail}}
236
+ <div class="searchstax-search-result-title-container">
237
+ <span class="searchstax-search-result-title">{{title}}</span>
238
+ </div>
239
+
240
+ {{#paths}}
241
+ <p class="searchstax-search-result-common">
242
+ {{paths}}
243
+ </p>
244
+ {{/paths}}
245
+
246
+ {{#description}}
247
+ <p class="searchstax-search-result-description searchstax-search-result-common">
248
+ {{description}}
249
+ </p>
250
+ {{/description}}
251
+
252
+ {{#unmappedFields}}
253
+ {{#isImage}}
254
+ <div class="searchstax-search-result-image-container">
255
+ <img src="{{value}}" class="searchstax-result-image">
256
+ </div>
257
+ {{/isImage}}
258
+ {{^isImage}}
259
+ <p class="searchstax-search-result-common">
260
+ {{value}}
261
+ </p>
262
+ {{/isImage}}
263
+ {{/unmappedFields}}
264
+ </div>
265
+ `,
266
+ searchResultUniqueIdAttribute: "data-searchstax-unique-result-id"
267
+ },
268
+ noSearchResultTemplate: {
269
+ template: `
270
+ <div class="searchstax-no-results">
271
+ Showing <strong>no results</strong> for <strong>"{{ searchTerm }}"</strong>
272
+ <br>
273
+ {{#spellingSuggestion}}
274
+ <span>&nbsp;Did you mean <a href="#" class="searchstax-suggestion-term">{{ spellingSuggestion }}</a>?</span>
275
+ {{/spellingSuggestion}}
276
+ </div>
277
+ <div>
278
+ <p>Try searching for search related terms or topics. We offer a wide variety of content to help you get the information you need.</p>
279
+ <p>Lost? Click on the ‘X” in the Search Box to reset your search.</p>
280
+ </div>
281
+ `
282
+ }
214
283
  },
215
284
  hooks: {
216
285
  afterLinkClick: function (result: ISearchstaxParsedResult) {
@@ -223,6 +292,222 @@ example of result widget initialization with various options
223
292
  });
224
293
  ```
225
294
 
295
+ ## Pagination widget
296
+ Initialization properties
297
+
298
+ a. id of container where widget will be rendered
299
+
300
+ b. {
301
+
302
+ `templates?: {` - optional object that defines template override options
303
+
304
+ `mainTemplate?: {` - optional object for overriding main template
305
+ `template: string;` - main template in Mustache templating language
306
+ `previousButtonClass: string;` - class of previous page link within template,
307
+ `nextButtonClass: string;` - class of next page link within template,
308
+ `};`
309
+ `};`
310
+
311
+ }
312
+
313
+
314
+ example of input widget initialization with various options
315
+ ```
316
+ searchstax.addPaginationWidget("searchstax-pagination-container", {
317
+ templates: {
318
+ mainTemplate: {
319
+ template: `
320
+ {{#results.length}}
321
+ <div class="searchstax-pagination-container">
322
+ <div class="searchstax-pagination-content">
323
+ <a class="searchstax-pagination-previous {{#isFirstPage}}disabled{{/isFirstPage}}" id="searchstax-pagination-previous">< Previous</a>
324
+ <div class="searchstax-pagination-details">
325
+ {{startResultIndex}} - {{endResultIndex}} of {{totalResults}}
326
+ </div>
327
+ <a class="searchstax-pagination-next {{#isLastPage}}disabled{{/isLastPage}}" id="searchstax-pagination-next">Next ></a>
328
+ </div>
329
+ </div>
330
+ {{/results.length}}
331
+ `,
332
+ previousButtonClass: "searchstax-pagination-previous",
333
+ nextButtonClass: "searchstax-pagination-next"
334
+ }
335
+ },
336
+ });
337
+ ```
338
+
339
+ ## Facets widget
340
+ Initialization properties
341
+
342
+ a. id of container where widget will be rendered
343
+
344
+ b. {
345
+
346
+ `facetingType`: "and" | "or" | "showUnavailable" - type that determines how facets will behave,
347
+
348
+ `itemsPerPageDesktop`: number - default expanded facets for desktop,
349
+
350
+ `itemsPerPageMobile`: number - default expanded facets for mobile,
351
+
352
+ `templates?: {` - optional object that defines template override options
353
+
354
+ `mainTemplateDesktop?: {` - optional object for overriding main template
355
+ `template: string;` - main template in Mustache templating language
356
+ `facetsContainerClass: string;` - class of container where facets will be placed
357
+ `},`
358
+
359
+ `mainTemplateMobile?: {` - optional object for overriding main mobile template
360
+ `template: string;` - main template in Mustache templating language
361
+ `facetsContainerId: string;` - id of container where facets will be placed
362
+ `closeOverlayTriggerClasses: string[];` - class list of all elements that should trigger mobile overlay close action
363
+ `filterByContainerId: string` - id of container where "Filter By" button will be rendered
364
+ 'selectedFacetsContainerId: string' - id of container where selected facets will be listed
365
+ `},`
366
+
367
+ `showMoreButtonContainerTemplate?: {` - optional object for overriding facet section show more/less template
368
+ `template: string;` - main template in Mustache templating language
369
+ `showMoreButtonClass: string;` - class of container where show more/less button will be placed
370
+ `},`
371
+
372
+ `facetItemContainerTemplate?: {` - optional object for overriding facet container template
373
+ `template: string;` - main template in Mustache templating language
374
+ 'facetListTitleContainerClass: string;' - container class where facet category title will be rendered within template
375
+ `facetListContainerClass: string;` - container class where facet items will be listed
376
+ `},`
377
+
378
+ `clearFacetsTemplate?: {` - optional object for overriding clear facets container template
379
+ `template: string;` - main template in Mustache templating language
380
+ 'containerId: string;' - container id where clear facets button will be rendered
381
+ `},`
382
+
383
+ `facetItemTemplate?: {` - optional object for overriding clear facet item template
384
+ `template: string;` - main template in Mustache templating language
385
+ 'inputCheckboxClass: string;' - class of checkboxes
386
+ 'checkTriggerClasses: string[];' - class list of elements that trigger facet select/unselect action
387
+ `},`
388
+
389
+ `filterByTemplate?: {` - optional object for overriding filter by button template
390
+ `template: string;` - main template in Mustache templating language
391
+ 'containerId: string;' - id where button will be placed within the template
392
+ `},`
393
+
394
+ `selectedFacetsTemplate?: {` - optional object for overriding selected facets template
395
+ `template: string;` - main template in Mustache templating language
396
+ 'containerId: string;' - id where selected facets will be placed within the template
397
+ `},`
398
+ `};`
399
+
400
+ }
401
+
402
+
403
+ example of facets widget initialization with various options
404
+ ```
405
+ searchstax.addFacetsWidget("searchstax-facets-container", {
406
+ facetingType: "and",
407
+ itemsPerPageDesktop: 3,
408
+ itemsPerPageMobile: 99,
409
+ templates: {
410
+ mainTemplateDesktop: {
411
+ template: `
412
+ {{#hasResultsOrExternalPromotions}}
413
+ <div class="searchstax-facets-container-desktop"></div>
414
+ {{/hasResultsOrExternalPromotions}}
415
+ `,
416
+ facetsContainerId: "",
417
+ },
418
+ mainTemplateMobile: {
419
+ template: `
420
+ <div class="searchstax-facets-pills-container">
421
+ <div class="searchstax-facets-pills-selected">
422
+ </div>
423
+ </div>
424
+
425
+ <div class="searchstax-facets-mobile-overlay {{#overlayOpened}} searchstax-show{{/overlayOpened}}" >
426
+ <div class="searchstax-facets-mobile-overlay-header">
427
+ <div class="searchstax-facets-mobile-overlay-header-title">Filter By</div>
428
+ <div class="searchstax-search-close"></div>
429
+ </div>
430
+ <div class="searchstax-facets-container-mobile"></div>
431
+ <button class="searchstax-facets-mobile-overlay-done">Done</button>
432
+ </div>
433
+ </div>
434
+ `,
435
+ facetsContainerId: ``,
436
+ closeOverlayTriggerClasses: ["searchstax-facets-mobile-overlay-done","searchstax-search-close",],
437
+ filterByContainerId: ``,
438
+ selectedFacetsContainerId: ``,
439
+ },
440
+ showMoreButtonContainerTemplate: {
441
+ template: `
442
+ <div class="searchstax-facet-show-more-container">
443
+ {{#showingAllFacets}}
444
+ <div class="searchstax-facet-show-less-button searchstax-facet-show-button">less</div>
445
+ {{/showingAllFacets}}
446
+ {{^showingAllFacets}}
447
+ <div class="searchstax-facet-show-more-button searchstax-facet-show-button">more {{onShowMoreLessClick}}</div>
448
+ {{/showingAllFacets}}
449
+ </div>
450
+ `,
451
+ showMoreButtonClass: `searchstax-facet-show-more-container`,
452
+ },
453
+ facetItemContainerTemplate: {
454
+ template: `
455
+ <div>
456
+ <div class="searchstax-facet-title-container">
457
+ <div class="searchstax-facet-title">
458
+ {{label}}
459
+ </div>
460
+ <div class="searchstax-facet-title-arrow active"></div>
461
+ </div>
462
+ <div class="searchstax-facet-values-container"></div>
463
+ </div>
464
+ `,
465
+ facetListTitleContainerClass: `searchstax-facet-title-container`,
466
+ facetListContainerClass: `searchstax-facet-values-container`,
467
+ },
468
+ clearFacetsTemplate: {
469
+ template: `
470
+ {{#shouldShow}}}
471
+ <div class="searchstax-facets-pill searchstax-clear-filters searchstax-facets-pill-clear-all">
472
+ <div class="searchstax-facets-pill-label">Clear Filters</div>
473
+ </div>
474
+ {{/shouldShow}}
475
+ `,
476
+ containerId: ``,
477
+ },
478
+ facetItemTemplate: {
479
+ template: `
480
+ <div class="searchstax-facet-input">
481
+ <input type="checkbox" class="searchstax-facet-input-checkbox" {{#disabled}}disabled{{/disabled}} {{#isChecked}}checked{{/isChecked}}/>
482
+ </div>
483
+ <div class="searchstax-facet-value-label">{{value}}</div>
484
+ <div class="searchstax-facet-value-count">({{count}})</div>
485
+ `,
486
+ inputCheckboxClass: `searchstax-facet-input-checkbox`,
487
+ checkTriggerClasses: ["searchstax-facet-value-label","searchstax-facet-value-count",],
488
+ },
489
+ filterByTemplate: {
490
+ template: `
491
+ <div class="searchstax-facets-pill searchstax-facets-pill-filter-by">
492
+ <div class="searchstax-facets-pill-label">Filter By</div>
493
+ </div>
494
+ `,
495
+ containerId: ``,
496
+ },
497
+ selectedFacetsTemplate: {
498
+ template: `
499
+ <div class="searchstax-facets-pill searchstax-facets-pill-facets">
500
+ <div class="searchstax-facets-pill-label">{{value}} ({{count}})</div>
501
+ <div class="searchstax-facets-pill-icon-close"></div>
502
+ </div>
503
+ `,
504
+ containerId: ``,
505
+ },
506
+
507
+ },
508
+ });
509
+ ```
510
+
226
511
  ## Template overrides
227
512
  Templates use mustache templating. For more info see https://github.com/janl/mustache.js
228
513