@searchstax-inc/searchstudio-ux-js 0.1.5 → 0.3.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
@@ -56,6 +56,13 @@ Initialization object
56
56
 
57
57
  `}`
58
58
 
59
+ `hooks?: {` - optional object that provides various hook options
60
+
61
+ `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.
62
+
63
+ `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.
64
+ `};`
65
+
59
66
  }
60
67
 
61
68
  Initialization example
@@ -75,6 +82,16 @@ searchstax.initialize({
75
82
  return "Search results for: " + result.query;
76
83
  },
77
84
  ignoredKeys: [],
85
+ },
86
+ hooks: {
87
+ beforeSearch: function (props: ISearchObject) {
88
+ const propsCopy = { ...props };
89
+ return propsCopy;
90
+ },
91
+ afterSearch: function (results: ISearchstaxParsedResult[]) {
92
+ const copy = [...results];
93
+ return copy;
94
+ },
78
95
  }
79
96
  });
80
97
  ```
@@ -105,7 +122,26 @@ Our base theme is designed with this layout in mind but it is optional as all wi
105
122
  </div>
106
123
  ```
107
124
 
108
- ## Input widget
125
+ ### widgets
126
+ Following widgets are available:
127
+
128
+ [Input Widget](#input-widget)
129
+
130
+ [Result Widget](#result-widget)
131
+
132
+ [Facets Widget](#facets-widget)
133
+
134
+ [Pagination Widget](#pagination-widget)
135
+
136
+ [SearchFeedback Widget](#searchfeedback-widget)
137
+
138
+ [RelatedSearches Widget](#relatedsearches-widget)
139
+
140
+ [ExternalPromotions Widget](#externalpromotions-widget)
141
+
142
+ [sorting Widget](#sorting-widget)
143
+
144
+ ### Input Widget ###
109
145
  Initialization properties
110
146
 
111
147
  a. id of container where widget will be rendered
@@ -128,10 +164,6 @@ b. {
128
164
 
129
165
  `hooks?: {` - optional object that provides various hook options
130
166
 
131
- `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.
132
-
133
- `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.
134
-
135
167
  `beforeAutosuggest?: (props: ISearchstaxSuggestProps) => ISearchstaxSuggestProps | null;` - 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.
136
168
 
137
169
  `afterAutosuggest?: (result: ISearchstaxSuggestResponse) => ISearchstaxSuggestResponse;`- this function gets called after autosuggest has values but before rendering. It needs to return same type of data but it can be modified.
@@ -154,15 +186,6 @@ example of input widget initialization with various options
154
186
  searchstax.addSearchInputWidget("searchstax-input-container", {
155
187
  suggestAfterMinChars: 3,
156
188
  hooks: {
157
- beforeSearch: function (props: ISearchObject) {
158
- const propsCopy = { ...props };
159
- return propsCopy;
160
- },
161
- afterSearch: function (results: ISearchstaxParsedResult[]) {
162
- const copy = [...results];
163
- // copy.splice(0, 1);
164
- return copy;
165
- },
166
189
  afterAutosuggest: function (result: ISearchstaxSuggestResponse) {
167
190
  const copy = { ...result };
168
191
  return copy;
@@ -195,7 +218,7 @@ example of input widget initialization with various options
195
218
  },
196
219
  });
197
220
  ```
198
- ## Result widget
221
+ ### Result Widget ###
199
222
  Initialization properties
200
223
 
201
224
  a. id of container where widget will be rendered
@@ -325,7 +348,7 @@ example of result widget initialization with various options
325
348
  });
326
349
  ```
327
350
 
328
- ## Pagination widget
351
+ ### Pagination Widget ###
329
352
  Initialization properties
330
353
 
331
354
  a. id of container where widget will be rendered
@@ -335,7 +358,7 @@ b. {
335
358
  `templates?: {` - optional object that defines template override options
336
359
 
337
360
  `mainTemplate?: {` - optional object for overriding main template
338
- `template: string;` - main template in Mustache templating language
361
+ `template: string;` - main template in Mustache templating language. Data available: IPaginationData
339
362
  `previousButtonClass: string;` - class of previous page link within template,
340
363
  `nextButtonClass: string;` - class of next page link within template,
341
364
  `};`
@@ -373,14 +396,16 @@ example of pagination widget initialization with various options
373
396
  });
374
397
  ```
375
398
 
376
- ## Facets widget
399
+ ### Facets Widget ###
377
400
  Initialization properties
378
401
 
379
402
  a. id of container where widget will be rendered
380
403
 
381
404
  b. {
382
405
 
383
- `facetingType`: "and" | "or" | "showUnavailable" - type that determines how facets will behave,
406
+ `facetingType`: "and" | "or" | "showUnavailable" | "tabs" - type that determines how facets will behave,
407
+
408
+ 'specificFacets?: string[]' - optional array of facet names that if provided will only render those facets
384
409
 
385
410
  `itemsPerPageDesktop`: number - default expanded facets for desktop,
386
411
 
@@ -389,12 +414,12 @@ b. {
389
414
  `templates?: {` - optional object that defines template override options
390
415
 
391
416
  `mainTemplateDesktop?: {` - optional object for overriding main template
392
- `template: string;` - main template in Mustache templating language
417
+ `template: string;` - main template in Mustache templating language data available: IFacetsTemplateData
393
418
  `facetsContainerClass: string;` - class of container where facets will be placed
394
419
  `},`
395
420
 
396
421
  `mainTemplateMobile?: {` - optional object for overriding main mobile template
397
- `template: string;` - main template in Mustache templating language
422
+ `template: string;` - main template in Mustache templating language. data available: IFacetsTemplateData
398
423
  `facetsContainerId: string;` - id of container where facets will be placed
399
424
  `closeOverlayTriggerClasses: string[];` - class list of all elements that should trigger mobile overlay close action
400
425
  `filterByContainerId: string` - id of container where "Filter By" button will be rendered
@@ -402,23 +427,23 @@ b. {
402
427
  `},`
403
428
 
404
429
  `showMoreButtonContainerTemplate?: {` - optional object for overriding facet section show more/less template
405
- `template: string;` - main template in Mustache templating language
430
+ `template: string;` - main template in Mustache templating language. data available: IFacetData
406
431
  `showMoreButtonClass: string;` - class of container where show more/less button will be placed
407
432
  `},`
408
433
 
409
434
  `facetItemContainerTemplate?: {` - optional object for overriding facet container template
410
- `template: string;` - main template in Mustache templating language
435
+ `template: string;` - main template in Mustache templating language. data available: IFacetData
411
436
  'facetListTitleContainerClass: string;' - container class where facet category title will be rendered within template
412
437
  `facetListContainerClass: string;` - container class where facet items will be listed
413
438
  `},`
414
439
 
415
440
  `clearFacetsTemplate?: {` - optional object for overriding clear facets container template
416
- `template: string;` - main template in Mustache templating language
441
+ `template: string;` - main template in Mustache templating language. data available: {shouldShow: boolean}
417
442
  'containerId: string;' - container id where clear facets button will be rendered
418
443
  `},`
419
444
 
420
445
  `facetItemTemplate?: {` - optional object for overriding clear facet item template
421
- `template: string;` - main template in Mustache templating language
446
+ `template: string;` - main template in Mustache templating language. data available: { ...IFacetValueData, isChecked }
422
447
  'inputCheckboxClass: string;' - class of checkboxes
423
448
  'checkTriggerClasses: string[];' - class list of elements that trigger facet select/unselect action
424
449
  `},`
@@ -429,7 +454,7 @@ b. {
429
454
  `},`
430
455
 
431
456
  `selectedFacetsTemplate?: {` - optional object for overriding selected facets template
432
- `template: string;` - main template in Mustache templating language
457
+ `template: string;` - main template in Mustache templating language. data available: IFacetValue | IFacetValueRange
433
458
  'containerId: string;' - id where selected facets will be placed within the template
434
459
  `},`
435
460
  `};`
@@ -478,10 +503,10 @@ example of facets widget initialization with various options
478
503
  </div>
479
504
  </div>
480
505
  `,
481
- facetsContainerId: ``,
506
+ facetsContainerClass: `searchstax-facets-container-mobile`,
482
507
  closeOverlayTriggerClasses: ["searchstax-facets-mobile-overlay-done","searchstax-search-close",],
483
- filterByContainerId: ``,
484
- selectedFacetsContainerId: ``,
508
+ filterByContainerClass: `searchstax-facets-pills-container`,
509
+ selectedFacetsContainerClass: `searchstax-facets-pills-selected`,
485
510
  },
486
511
  showMoreButtonContainerTemplate: {
487
512
  template: `
@@ -519,7 +544,7 @@ example of facets widget initialization with various options
519
544
  </div>
520
545
  {{/shouldShow}}
521
546
  `,
522
- containerId: ``,
547
+ containerClass: `searchstax-facets-pill-clear-all`,
523
548
  },
524
549
  facetItemTemplate: {
525
550
  template: `
@@ -538,7 +563,7 @@ example of facets widget initialization with various options
538
563
  <div class="searchstax-facets-pill-label">Filter By</div>
539
564
  </div>
540
565
  `,
541
- containerId: ``,
566
+ containerClass: `searchstax-facets-pill-filter-by`,
542
567
  },
543
568
  selectedFacetsTemplate: {
544
569
  template: `
@@ -547,13 +572,249 @@ example of facets widget initialization with various options
547
572
  <div class="searchstax-facets-pill-icon-close"></div>
548
573
  </div>
549
574
  `,
550
- containerId: ``,
575
+ containerClass: `searchstax-facets-pill-facets`,
551
576
  },
552
577
 
553
578
  },
554
579
  });
555
580
  ```
556
581
 
582
+ ### SearchFeedback Widget ###
583
+ Initialization properties
584
+
585
+ a. id of container where widget will be rendered
586
+
587
+ b. {
588
+
589
+ `templates?: {` - optional object that defines template override options
590
+
591
+ `main?: {` - optional object for overriding main template
592
+ `template: string;` - main template in Mustache templating language
593
+ `};`
594
+
595
+ `};`
596
+
597
+ }
598
+
599
+
600
+ example of search feedback widget initialization with minimum options
601
+ ```
602
+ searchstax.addSearchFeedbackWidget("search-feedback-container", {});
603
+ ```
604
+
605
+
606
+ example of search feedback widget initialization with various options
607
+ ```
608
+ searchstax.addSearchFeedbackWidget("search-feedback-container", {
609
+ templates: {
610
+ main: {
611
+ template: `
612
+ {{#searchExecuted}}
613
+ <div class="searchstax-feedback-container">
614
+ Showing <b>{{startResultIndex}} - {{endResultIndex}}</b> of <b>{{totalResults}}</b> results {{#searchTerm}} for "<b>{{searchTerm}}</b>" {{/searchTerm}}
615
+ </div>
616
+ {{/searchExecuted}}
617
+ `,
618
+ }
619
+ },
620
+ });
621
+ ```
622
+
623
+ ## RelatedSearches widget
624
+ Initialization properties
625
+
626
+ a. id of container where widget will be rendered
627
+
628
+ b. {
629
+
630
+ `templates?: {` - optional object that defines template override options
631
+
632
+ `main?: {` - optional object for overriding main template
633
+ `template: string;` - main template in Mustache templating language
634
+ `relatedSearchesContainerClass: string;` - class where related searches will be rendered within the template
635
+ `};`
636
+
637
+ `relatedSearch?: {` - optional object for overriding main template
638
+ `template: string;` - main template in Mustache templating language
639
+ `relatedSearchContainerClass: string;` - class where related search item will be rendered within the template
640
+ `};`
641
+
642
+ `};`
643
+
644
+ }
645
+
646
+
647
+ example of search feedback widget initialization with minimum options
648
+ ```
649
+ searchstax.addRelatedSearchesWidget("searchstax-related-searches-container", {
650
+ relatedSearchesURL: "URL",
651
+ relatedSearchesAPIKey: "KEY"
652
+ })
653
+ ```
654
+
655
+
656
+ example of search feedback widget initialization with various options
657
+ ```
658
+ searchstax.addRelatedSearchesWidget("searchstax-related-searches-container", {
659
+ relatedSearchesURL: "URL",
660
+ relatedSearchesAPIKey: "KEY",
661
+ templates: {
662
+ main: {
663
+ template: `
664
+ {{#hasRelatedSearches}}
665
+ <div class="searchstax-related-searches-container" id="searchstax-related-searches-container">
666
+ Related searches: <span id="searchstax-related-searches"></span>
667
+ {{#relatedSearches}}
668
+ <span class="searchstax-related-search">
669
+
670
+ </span>
671
+ {{/relatedSearches}}
672
+ </div>
673
+ {{/hasRelatedSearches}}
674
+ `,
675
+ relatedSearchesContainerClass: `searchstax-related-search`,
676
+ },
677
+ relatedSearch: {
678
+ template: `
679
+ <span class="searchstax-related-search searchstax-related-search-item">
680
+ {{ related_search }}{{^last}}<span>,</span>{{/last}}
681
+ </span>
682
+ `,
683
+ relatedSearchContainerClass: `searchstax-related-search-item`,
684
+ },
685
+ },
686
+ });
687
+ ```
688
+
689
+ ### ExternalPromotions widget ###
690
+ Initialization properties
691
+
692
+ a. id of container where widget will be rendered
693
+
694
+ b. {
695
+
696
+ `templates?: {` - optional object that defines template override options
697
+
698
+ `mainTemplate?: {` - optional object for overriding main template
699
+ `template: string;` - main template in Mustache templating language
700
+ `externalPromotionsContainerId: string;` - id where external promotions will be rendered within the template
701
+ `};`
702
+
703
+ `externalPromotion?: {` - optional object for overriding main template
704
+ `template: string;` - main template in Mustache templating language
705
+ `};`
706
+
707
+ `};`
708
+
709
+ }
710
+
711
+
712
+ example of search feedback widget initialization with minimum options
713
+ ```
714
+ searchstax.addExternalPromotionsWidget("searchstax-external-promotions-layout-container", {})
715
+ ```
716
+
717
+
718
+ example of search feedback widget initialization with various options
719
+ ```
720
+ searchstax.addExternalPromotionsWidget("searchstax-external-promotions-layout-container", {
721
+ templates: {
722
+ mainTemplate: {
723
+ template: `
724
+ {{#hasExternalPromotions}}
725
+ <div class="searchstax-external-promotions-container" id="searchstax-external-promotions-container">
726
+ External promotions go here
727
+ </div>
728
+ {{/hasExternalPromotions}}
729
+ `,
730
+ externalPromotionsContainerId: `searchstax-external-promotions-container`,
731
+ },
732
+ externalPromotion: {
733
+ template: `
734
+ <div class="searchstax-external-promotion searchstax-search-result">
735
+ <div class="icon-elevated"></div>
736
+ {{#url}}
737
+ <a href="{{url}}" data-searchstax-unique-result-id="{{uniqueId}}" class="searchstax-result-item-link"></a>
738
+ {{/url}}
739
+ <div class="searchstax-search-result-title-container">
740
+ <span class="searchstax-search-result-title">{{name}}</span>
741
+ </div>
742
+ {{#description}}
743
+ <p class="searchstax-search-result-description searchstax-search-result-common">
744
+ {{description}}
745
+ </p>
746
+ {{/description}}
747
+ {{#url}}
748
+ <p class="searchstax-search-result-description searchstax-search-result-common">
749
+ {{url}}
750
+ </p>
751
+ {{/url}}
752
+ </div>
753
+ </div>
754
+ `,
755
+ },
756
+ },
757
+ });
758
+ ```
759
+
760
+
761
+ ### Sorting Widget ###
762
+ Initialization properties
763
+
764
+ a. id of container where widget will be rendered
765
+
766
+ b. {
767
+
768
+ `templates?: {` - optional object that defines template override options
769
+
770
+ `main?: {` - optional object for overriding main template
771
+ `template: string;` - main template in Mustache templating language
772
+ `selectId: string;` - id of select element within the template
773
+ `};`
774
+
775
+ `};`
776
+
777
+ }
778
+
779
+
780
+ example of sorting widget initialization with minimum options
781
+ ```
782
+ searchstax.addSearchSortingWidget("search-sorting-container", {});
783
+ ```
784
+
785
+
786
+ example of sorting widget initialization with various options
787
+ ```
788
+ searchstax.addSearchSortingWidget("search-sorting-container", {
789
+ templates: {
790
+ main: {
791
+ template: `
792
+ {{#searchExecuted}}
793
+ {{#hasResultsOrExternalPromotions}}
794
+ <div class="searchstax-sorting-container">
795
+ <label class="searchstax-sorting-label" for="sort-by">Sort By</label>
796
+ <select id="searchstax-search-order-select" class="searchstax-search-order-select">
797
+ <option value="">
798
+ Relevance
799
+ </option>
800
+ <option value="date desc">
801
+ Newest Content
802
+ </option>
803
+ <option value="date asc">
804
+ Oldest Content
805
+ </option>
806
+ </select>
807
+ </div>
808
+ {{/hasResultsOrExternalPromotions}}
809
+ {{/searchExecuted}}
810
+ `,
811
+ selectId: `searchstax-search-order-select`
812
+ }
813
+ },
814
+ });
815
+ ```
816
+
817
+
557
818
  ## Template overrides
558
819
  Templates use mustache templating. For more info see https://github.com/janl/mustache.js
559
820