@empathyco/x-components 3.0.0-alpha.243 → 3.0.0-alpha.244

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/core/index.js +1 -0
  3. package/core/index.js.map +1 -1
  4. package/design-system/default-theme.css +9 -9
  5. package/design-system/full-theme.css +25 -24
  6. package/docs/API-reference/api/x-components.basesuggestion.md +0 -1
  7. package/docs/API-reference/api/x-components.highlight.highlight.md +13 -0
  8. package/docs/API-reference/api/x-components.highlight.matchclass.md +13 -0
  9. package/docs/API-reference/api/x-components.highlight.md +23 -0
  10. package/docs/API-reference/api/x-components.highlight.text.md +13 -0
  11. package/docs/API-reference/api/x-components.md +1 -0
  12. package/docs/API-reference/components/common/suggestions/x-components.base-suggestion.md +88 -47
  13. package/docs/API-reference/components/history-queries/x-components.history-query.md +9 -8
  14. package/docs/API-reference/components/next-queries/x-components.next-query.md +3 -3
  15. package/docs/API-reference/components/popular-searches/x-components.popular-search.md +3 -3
  16. package/docs/API-reference/components/query-suggestions/x-components.query-suggestion.md +7 -7
  17. package/js/components/suggestions/base-suggestion.vue.js +3 -8
  18. package/js/components/suggestions/base-suggestion.vue.js.map +1 -1
  19. package/js/components/suggestions/base-suggestion.vue_rollup-plugin-vue_script.vue.js +4 -49
  20. package/js/components/suggestions/base-suggestion.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  21. package/js/index.js +1 -0
  22. package/js/index.js.map +1 -1
  23. package/js/x-modules/extra-params/components/extra-params.vue_rollup-plugin-vue_script.vue.js +1 -0
  24. package/js/x-modules/extra-params/components/extra-params.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  25. package/js/x-modules/extra-params/components/renderless-extra-param.vue_rollup-plugin-vue_script.vue.js +1 -0
  26. package/js/x-modules/extra-params/components/renderless-extra-param.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  27. package/js/x-modules/facets/components/clear-filters.vue_rollup-plugin-vue_script.vue.js +1 -0
  28. package/js/x-modules/facets/components/clear-filters.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  29. package/js/x-modules/facets/components/facets/facets-provider.vue_rollup-plugin-vue_script.vue.js +1 -0
  30. package/js/x-modules/facets/components/facets/facets-provider.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  31. package/js/x-modules/facets/components/filters/all-filter.vue_rollup-plugin-vue_script.vue.js +1 -0
  32. package/js/x-modules/facets/components/filters/all-filter.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  33. package/js/x-modules/facets/components/filters/number-range-filter.vue_rollup-plugin-vue_script.vue.js +1 -0
  34. package/js/x-modules/facets/components/filters/number-range-filter.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  35. package/js/x-modules/facets/components/filters/renderless-filter.vue_rollup-plugin-vue_script.vue.js +1 -0
  36. package/js/x-modules/facets/components/filters/renderless-filter.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  37. package/js/x-modules/facets/components/filters/simple-filter.vue_rollup-plugin-vue_script.vue.js +1 -0
  38. package/js/x-modules/facets/components/filters/simple-filter.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  39. package/js/x-modules/facets/components/lists/exclude-filters-with-no-results.vue_rollup-plugin-vue_script.vue.js +1 -0
  40. package/js/x-modules/facets/components/lists/exclude-filters-with-no-results.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  41. package/js/x-modules/facets/components/lists/filters-list.vue_rollup-plugin-vue_script.vue.js +1 -0
  42. package/js/x-modules/facets/components/lists/filters-list.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  43. package/js/x-modules/facets/components/lists/filters-search.vue_rollup-plugin-vue_script.vue.js +1 -0
  44. package/js/x-modules/facets/components/lists/filters-search.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  45. package/js/x-modules/facets/components/lists/selected-filters.vue_rollup-plugin-vue_script.vue.js +1 -0
  46. package/js/x-modules/facets/components/lists/selected-filters.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  47. package/js/x-modules/facets/components/lists/sliced-filters.vue_rollup-plugin-vue_script.vue.js +1 -0
  48. package/js/x-modules/facets/components/lists/sliced-filters.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  49. package/js/x-modules/facets/components/lists/sorted-filters.vue_rollup-plugin-vue_script.vue.js +1 -0
  50. package/js/x-modules/facets/components/lists/sorted-filters.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  51. package/js/x-modules/history-queries/components/history-query.vue.js +7 -7
  52. package/js/x-modules/history-queries/components/history-query.vue.js.map +1 -1
  53. package/js/x-modules/history-queries/components/history-query.vue_rollup-plugin-vue_script.vue.js +4 -3
  54. package/js/x-modules/history-queries/components/history-query.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  55. package/js/x-modules/next-queries/components/next-query.vue.js +4 -8
  56. package/js/x-modules/next-queries/components/next-query.vue.js.map +1 -1
  57. package/js/x-modules/next-queries/components/next-query.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  58. package/js/x-modules/popular-searches/components/popular-search.vue.js +2 -11
  59. package/js/x-modules/popular-searches/components/popular-search.vue.js.map +1 -1
  60. package/js/x-modules/popular-searches/components/popular-search.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  61. package/js/x-modules/query-suggestions/components/query-suggestion.vue.js +3 -12
  62. package/js/x-modules/query-suggestions/components/query-suggestion.vue.js.map +1 -1
  63. package/js/x-modules/query-suggestions/components/query-suggestion.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  64. package/js/x-modules/scroll/components/main-scroll-item.vue_rollup-plugin-vue_script.vue.js +1 -0
  65. package/js/x-modules/scroll/components/main-scroll-item.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  66. package/js/x-modules/scroll/components/scroll-to-top.vue_rollup-plugin-vue_script.vue.js +1 -0
  67. package/js/x-modules/scroll/components/scroll-to-top.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  68. package/js/x-modules/scroll/components/window-scroll.vue_rollup-plugin-vue_script.vue.js +1 -0
  69. package/js/x-modules/scroll/components/window-scroll.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  70. package/js/x-modules/search/components/sort-list.vue_rollup-plugin-vue_script.vue.js +1 -0
  71. package/js/x-modules/search/components/sort-list.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  72. package/js/x-modules/search/components/sort.mixin.js +1 -0
  73. package/js/x-modules/search/components/sort.mixin.js.map +1 -1
  74. package/js/x-modules/search/components/spellcheck.vue_rollup-plugin-vue_script.vue.js +1 -0
  75. package/js/x-modules/search/components/spellcheck.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  76. package/js/x-modules/search-box/components/search-input-placeholder.vue_rollup-plugin-vue_script.vue.js +1 -0
  77. package/js/x-modules/search-box/components/search-input-placeholder.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  78. package/js/x-modules/url/components/url-handler.vue_rollup-plugin-vue_script.vue.js +1 -0
  79. package/js/x-modules/url/components/url-handler.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  80. package/package.json +2 -2
  81. package/report/x-components.api.json +110 -27
  82. package/report/x-components.api.md +19 -5
  83. package/types/components/index.d.ts +1 -0
  84. package/types/components/index.d.ts.map +1 -1
  85. package/types/components/suggestions/base-suggestion.vue.d.ts +0 -30
  86. package/types/components/suggestions/base-suggestion.vue.d.ts.map +1 -1
  87. package/types/x-modules/history-queries/components/history-query.vue.d.ts.map +1 -1
  88. package/types/x-modules/next-queries/components/next-query.vue.d.ts.map +1 -1
  89. package/types/x-modules/popular-searches/components/popular-search.vue.d.ts.map +1 -1
  90. package/types/x-modules/query-suggestions/components/query-suggestion.vue.d.ts.map +1 -1
  91. package/docs/API-reference/api/x-components.basesuggestion.queryhtml.md +0 -18
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this project will be documented in this file. See
4
4
  [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.0-alpha.244](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.243...@empathyco/x-components@3.0.0-alpha.244) (2022-12-08)
7
+
8
+ ### Features
9
+
10
+ - **components:** Use `Highlight` component inside suggestion components.(#894)
11
+ ([ceb9c0c](https://github.com/empathyco/x/commit/ceb9c0c729d9a7a3b8a983e5b23912d561f2bd4d)),
12
+ closes [EX-7469](https://searchbroker.atlassian.net/browse/EX-7469)
13
+
14
+ # Change Log
15
+
16
+ All notable changes to this project will be documented in this file. See
17
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
18
+
6
19
  ## [3.0.0-alpha.243](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.242...@empathyco/x-components@3.0.0-alpha.243) (2022-12-08)
7
20
 
8
21
  ### Testing
package/core/index.js CHANGED
@@ -115,6 +115,7 @@ export { default as BaseRating } from '../js/components/base-rating.vue.js';
115
115
  export { default as BaseSwitch } from '../js/components/base-switch.vue.js';
116
116
  export { default as BaseVariableColumnGrid } from '../js/components/base-variable-column-grid.vue.js';
117
117
  export { default as GlobalXBus } from '../js/components/global-x-bus.vue.js';
118
+ export { default as Highlight } from '../js/components/highlight.vue.js';
118
119
  export { default as ItemsList } from '../js/components/items-list.vue.js';
119
120
  export { default as LocationProvider } from '../js/components/location-provider.vue.js';
120
121
  export { NoElement } from '../js/components/no-element.js';
package/core/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -734,6 +734,15 @@
734
734
  stroke: none;
735
735
  fill: var(--x-color-stroke-icon-default);
736
736
  }
737
+ :root {
738
+ --x-color-stroke-icon-default: currentColor;
739
+ --x-color-fill-icon-default: none;
740
+ --x-size-width-icon-default: var(--x-size-width-icon-m);
741
+ --x-size-height-icon-default: var(--x-size-height-icon-m);
742
+ --x-string-stroke-linecap-icon-default: butt;
743
+ --x-string-stroke-linejoin-icon-default: mitter;
744
+ --x-size-stroke-width-icon-default: 1px;
745
+ }
737
746
  :root {
738
747
  --x-color-background-input-group-default: var(--x-color-background-input-default);
739
748
  --x-color-border-input-group-default: var(--x-color-border-input-default);
@@ -954,15 +963,6 @@
954
963
  );
955
964
  --x-number-font-weight-input-group-default-button: var(--x-number-font-weight-base-light);
956
965
  }
957
- :root {
958
- --x-color-stroke-icon-default: currentColor;
959
- --x-color-fill-icon-default: none;
960
- --x-size-width-icon-default: var(--x-size-width-icon-m);
961
- --x-size-height-icon-default: var(--x-size-height-icon-m);
962
- --x-string-stroke-linecap-icon-default: butt;
963
- --x-string-stroke-linejoin-icon-default: mitter;
964
- --x-size-stroke-width-icon-default: 1px;
965
- }
966
966
  :root {
967
967
  --x-color-background-input-default: var(--x-color-base-neutral-100);
968
968
  --x-color-border-input-default: var(--x-color-base-neutral-70);
@@ -425,30 +425,6 @@
425
425
  --x-size-border-width-left-dropdown-list-line
426
426
  );
427
427
  }
428
- :root {
429
- --x-size-padding-block-dropdown-item-line: var(--x-size-base-03);
430
- --x-size-padding-inline-dropdown-item-line: 0 var(--x-size-base-03);
431
- --x-size-padding-top-dropdown-item-line: var(--x-size-base-03);
432
- --x-size-padding-right-dropdown-item-line: 0;
433
- --x-size-padding-bottom-dropdown-item-line: var(--x-size-base-03);
434
- --x-size-padding-left-dropdown-item-line: 0;
435
- --x-size-padding-top-dropdown-toggle-line: var(--x-size-base-03);
436
- --x-size-padding-right-dropdown-toggle-line: 0;
437
- --x-size-padding-bottom-dropdown-toggle-line: var(--x-size-base-03);
438
- --x-size-padding-left-dropdown-toggle-line: 0;
439
- --x-size-border-width-dropdown-toggle-line: var(--x-size-border-width-base);
440
- --x-size-border-width-top-dropdown-toggle-line: 0;
441
- --x-size-border-width-right-dropdown-toggle-line: 0;
442
- --x-size-border-width-bottom-dropdown-toggle-line: var(
443
- --x-size-border-width-dropdown-toggle-line
444
- );
445
- --x-size-border-width-left-dropdown-toggle-line: 0;
446
- --x-size-border-width-dropdown-list-line: 0;
447
- --x-size-border-width-top-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
448
- --x-size-border-width-right-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
449
- --x-size-border-width-bottom-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
450
- --x-size-border-width-left-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
451
- }
452
428
  .x-dropdown.x-dropdown--m {
453
429
  --x-size-width-dropdown-toggle-default: var(--x-size-width-dropdown-m);
454
430
  }
@@ -7236,3 +7212,28 @@
7236
7212
  .x-normal-case {
7237
7213
  text-transform: none;
7238
7214
  }
7215
+
7216
+ :root {
7217
+ --x-size-padding-block-dropdown-item-line: var(--x-size-base-03);
7218
+ --x-size-padding-inline-dropdown-item-line: 0 var(--x-size-base-03);
7219
+ --x-size-padding-top-dropdown-item-line: var(--x-size-base-03);
7220
+ --x-size-padding-right-dropdown-item-line: 0;
7221
+ --x-size-padding-bottom-dropdown-item-line: var(--x-size-base-03);
7222
+ --x-size-padding-left-dropdown-item-line: 0;
7223
+ --x-size-padding-top-dropdown-toggle-line: var(--x-size-base-03);
7224
+ --x-size-padding-right-dropdown-toggle-line: 0;
7225
+ --x-size-padding-bottom-dropdown-toggle-line: var(--x-size-base-03);
7226
+ --x-size-padding-left-dropdown-toggle-line: 0;
7227
+ --x-size-border-width-dropdown-toggle-line: var(--x-size-border-width-base);
7228
+ --x-size-border-width-top-dropdown-toggle-line: 0;
7229
+ --x-size-border-width-right-dropdown-toggle-line: 0;
7230
+ --x-size-border-width-bottom-dropdown-toggle-line: var(
7231
+ --x-size-border-width-dropdown-toggle-line
7232
+ );
7233
+ --x-size-border-width-left-dropdown-toggle-line: 0;
7234
+ --x-size-border-width-dropdown-list-line: 0;
7235
+ --x-size-border-width-top-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
7236
+ --x-size-border-width-right-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
7237
+ --x-size-border-width-bottom-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
7238
+ --x-size-border-width-left-dropdown-list-line: var(--x-size-border-width-dropdown-list-line);
7239
+ }
@@ -25,7 +25,6 @@ export default class BaseSuggestion extends Vue
25
25
  | [filter](./x-components.basesuggestion.filter.md) | | BooleanFilter \| undefined | Returns the suggestion filter object. It is a BooleanFilter because the label is needed. It returns only the first element because the facets and filters are being planned in the BaseSuggestions component. |
26
26
  | [highlightCurated](./x-components.basesuggestion.highlightcurated.md) | | boolean | Indicates if the curated suggestion should be highlighted. |
27
27
  | [query](./x-components.basesuggestion.query.md) | | string | The normalized query of the module using this component. |
28
- | [queryHTML](./x-components.basesuggestion.queryhtml.md) | | string | Highlights the matching part of the suggestion query with the query passed as prop of the component putting it inside a <code>&lt;span&gt;</code> tag. |
29
28
  | [suggestion](./x-components.basesuggestion.suggestion.md) | | Suggestion | The suggestion to render and use in the default slot. |
30
29
  | [suggestionSelectedEvents](./x-components.basesuggestion.suggestionselectedevents.md) | | Partial&lt;[XEventsTypes](./x-components.xeventstypes.md)<!-- -->&gt; | The [XEvents](./x-components.xevent.md) that will be emitted when selecting a suggestion. |
31
30
 
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [Highlight](./x-components.highlight.md) &gt; [highlight](./x-components.highlight.highlight.md)
4
+
5
+ ## Highlight.highlight property
6
+
7
+ The part of the text to be highlighted.
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ highlight: string;
13
+ ```
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [Highlight](./x-components.highlight.md) &gt; [matchClass](./x-components.highlight.matchclass.md)
4
+
5
+ ## Highlight.matchClass property
6
+
7
+ CSS Class to add when the `text` string contains the `highlight` string.
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ matchClass: string;
13
+ ```
@@ -0,0 +1,23 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [Highlight](./x-components.highlight.md)
4
+
5
+ ## Highlight class
6
+
7
+ Highlights the given part of the text. The component is smart enough to do matches between special characters like tilde, cedilla, eñe, capital letters...
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export default class Highlight extends Highlight_base
13
+ ```
14
+ <b>Extends:</b> Highlight\_base
15
+
16
+ ## Properties
17
+
18
+ | Property | Modifiers | Type | Description |
19
+ | --- | --- | --- | --- |
20
+ | [highlight](./x-components.highlight.highlight.md) | | string | The part of the text to be highlighted. |
21
+ | [matchClass](./x-components.highlight.matchclass.md) | | string | CSS Class to add when the <code>text</code> string contains the <code>highlight</code> string. |
22
+ | [text](./x-components.highlight.text.md) | | string | The text to highlight some part of it. |
23
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [Highlight](./x-components.highlight.md) &gt; [text](./x-components.highlight.text.md)
4
+
5
+ ## Highlight.text property
6
+
7
+ The text to highlight some part of it.
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ text: string;
13
+ ```
@@ -79,6 +79,7 @@ X-Components is a library usable everywhere not only for search experiences.
79
79
  | [FixedHeaderAndAsidesLayout](./x-components.fixedheaderandasideslayout.md) | Component for use as Layout to be filled with the rest of the components. |
80
80
  | [GlobalXBus](./x-components.globalxbus.md) | This component helps subscribing to any [XEvent](./x-components.xevent.md) with custom callbacks using Vue listeners API. |
81
81
  | [HierarchicalFilter](./x-components.hierarchicalfilter.md) | Renders a hierarchical filter recursively, emitting the needed events when clicked. |
82
+ | [Highlight](./x-components.highlight.md) | Highlights the given part of the text. The component is smart enough to do matches between special characters like tilde, cedilla, eñe, capital letters... |
82
83
  | [HistoryQueries](./x-components.historyqueries.md) | This component renders a list of suggestions coming from the user queries history. Allows the user to select one of them, emitting the needed events. A history query is just another type of suggestion that contains a query that the user has made in the past. |
83
84
  | [HistoryQueriesGetter](./x-components.historyqueriesgetter.md) | Class implementation for the [HistoryQueriesGetters.historyQueries](./x-components.historyqueriesgetters.historyqueries.md) getter. |
84
85
  | [HistoryQueriesSwitch](./x-components.historyqueriesswitch.md) | History Queries Switch is a component to enable or disable the history queries. This component emits events depending on the <code>isEnabled</code> value. |
@@ -24,56 +24,13 @@ The default slot receives the suggestion and the matched query has props.
24
24
 
25
25
  ## Slots
26
26
 
27
- | Name | Description | Bindings<br />(name - type - description) |
28
- | -------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29
- | <code>default</code> | Button content | **suggestion** <code>Suggestion</code> - Suggestion data<br />**queryHTML** <code>string</code> - Suggestion's query with the matching part inside a `<span>` tag<br />**filter** <code>Filter</code> - Suggestion's filter |
30
-
31
- ## Examples
32
-
33
- This default suggestion component expects a suggestion to render and pass to its default slot, a
34
- normalized query to compare with the suggestion's query and highlight its matching parts and events
35
- to emit when the suggestion is selected.
36
-
37
- If the suggestion contains a filter, it is displayed next to the suggestion.
38
-
39
- ### Default usage
40
-
41
- ```vue
42
- <BaseSuggestion v-bind="{ query, suggestion, suggestionSelectedEvents }" />
43
- ```
44
-
45
- ### Customized usage
46
-
47
- ```vue
48
- <BaseSuggestion v-bind="{ query, suggestion, suggestionSelectedEvents }">
49
- <template #default="{ suggestion, queryHTML }">
50
- <span
51
- class="my-suggestion"
52
- v-html="queryHTML"
53
- :aria-label="suggestion.query"
54
- />
55
- </template>
56
- </BaseSuggestion>
57
- ```
58
-
59
- ### Customized usage with filter
60
-
61
- ```vue
62
- <BaseSuggestion v-bind="{ query, suggestion, suggestionSelectedEvents }">
63
- <template #default="{ suggestion, queryHTML, filter }">
64
- <span
65
- class="my-suggestion"
66
- v-html="queryHTML"
67
- :aria-label="suggestion.query"
68
- />
69
- <span>{{ filter.label }}</span>
70
- </template>
71
- </BaseSuggestion>
72
- ```
27
+ | Name | Description | Bindings<br />(name - type - description) |
28
+ | -------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
29
+ | <code>default</code> | Button content | **suggestion** <code>Suggestion</code> - Suggestion data<br />**query** <code>String</code> - The query that the suggestion belongs to<br />**filter** <code>Filter</code> - Suggestion's filter |
73
30
 
74
31
  ## Events
75
32
 
76
- A list of events that the component will emit:
33
+ This component emits the following events:
77
34
 
78
35
  - `UserAcceptedAQuery`: the event is emitted after the user clicks the button. The event payload is
79
36
  the suggestion query data.
@@ -82,3 +39,87 @@ A list of events that the component will emit:
82
39
  - `UserClickedAFilter`: the event is emitted after the user clicks the button if the suggestion
83
40
  includes a filter. The event payload is the suggestion filter.
84
41
  - The component can emit more events on click using the `suggestionSelectedEvents` prop.
42
+
43
+ ## See it in action
44
+
45
+ This suggestion component expects a suggestion to render and pass to its default slot, a normalized
46
+ query to compare with the suggestion's query and highlight its matching parts, and events to emit
47
+ when the suggestion is selected.
48
+
49
+ If the suggestion contains a filter, it is displayed next to the suggestion.
50
+
51
+ ```vue live
52
+ <template>
53
+ <BaseSuggestion v-bind="{ query, suggestion }" />
54
+ </template>
55
+ <script>
56
+ import { BaseSuggestion } from "@empathyco/x-components";
57
+
58
+ export default {
59
+ name: "BaseSuggestionDemo",
60
+ components: {
61
+ BaseSuggestion
62
+ },
63
+ data() {
64
+ return {
65
+ query: "st",
66
+ suggestion: {
67
+ modelName: "QuerySuggestion",
68
+ query: "steak",
69
+ facet: {
70
+ namedModel: "SimpleFacet",
71
+ id: "category",
72
+ label: "Category",
73
+ filters: [
74
+ {
75
+ id: "category:groceries",
76
+ modelName: "SimpleFilter",
77
+ facetId: "category-facet",
78
+ label: "Groceries",
79
+ selected: false,
80
+ totalResults: 10
81
+ }
82
+ ]
83
+ }
84
+ }
85
+ };
86
+ }
87
+ };
88
+ </script>
89
+ ```
90
+
91
+ ### Customise the content
92
+
93
+ You can make this component render any content you want by using the `default` slot.
94
+
95
+ ```vue live
96
+ <template>
97
+ <BaseSuggestion
98
+ v-bind="{ query, suggestion }"
99
+ #default="{ suggestion, query, filter }"
100
+ >
101
+ <span>🔍</span>
102
+ <Highlight :text="suggestion.query" :highlight="query" />
103
+ <span v-if="filter">{{ filter.label }}</span>
104
+ </BaseSuggestion>
105
+ </template>
106
+ <script>
107
+ import { BaseSuggestion } from "@empathyco/x-components";
108
+
109
+ export default {
110
+ name: "BaseSuggestionDemo",
111
+ components: {
112
+ BaseSuggestion
113
+ },
114
+ data() {
115
+ return {
116
+ query: "st",
117
+ suggestion: {
118
+ modelName: "QuerySuggestion",
119
+ query: "steak"
120
+ }
121
+ };
122
+ }
123
+ };
124
+ </script>
125
+ ```
@@ -18,10 +18,10 @@ history queries.
18
18
 
19
19
  ## Slots
20
20
 
21
- | Name | Description | Bindings<br />(name - type - description) |
22
- | ---------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
- | <code>default</code> | History Query content | **suggestion** <code>Suggestion</code> - History Query suggestion data<br />**queryHTML** <code>string</code> - Suggestion's query with the matching part inside a span tag |
24
- | <code>remove-button-content</code> | History Query remove button content | **suggestion** <code>Suggestion</code> - History Query suggestion data |
21
+ | Name | Description | Bindings<br />(name - type - description) |
22
+ | ---------------------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | <code>default</code> | History Query content | **v-bind** <code>Object</code> - `BaseSuggestion` default slot scope: **suggestion** <code>Suggestion</code> - Suggestion data<br /> **query** <code>string</code> - The query that the suggestion belongs to<br /> **filter** <code>Filter \\ | undefined</code> - Suggestion's filter |
24
+ | <code>remove-button-content</code> | History Query remove button content | **suggestion** <code>Suggestion</code> - History Query suggestion data |
25
25
 
26
26
  ## Examples
27
27
 
@@ -67,9 +67,9 @@ that serves to remove this query from the history. This slot only has one proper
67
67
  ```vue live
68
68
  <template>
69
69
  <HistoryQuery :suggestion="suggestion">
70
- <template #default="{ suggestion, queryHTML }">
70
+ <template #default="{ suggestion }">
71
71
  <HistoryIcon />
72
- <span class="x-history-query__matching-part" v-html="queryHTML" />
72
+ <Highlight highlight="tro" :text="suggestion.query" />
73
73
  </template>
74
74
 
75
75
  <template #remove-button-content="{ suggestion }">
@@ -80,14 +80,15 @@ that serves to remove this query from the history. This slot only has one proper
80
80
 
81
81
  <script>
82
82
  import { HistoryQuery } from "@empathyco/x-components/history-queries";
83
- import { HistoryIcon, CrossIcon } from "@empathyco/x-components";
83
+ import { HistoryIcon, CrossIcon, Highlight } from "@empathyco/x-components";
84
84
 
85
85
  export default {
86
86
  name: "HistoryQueryDemo",
87
87
  components: {
88
88
  HistoryQuery,
89
89
  HistoryIcon,
90
- CrossIcon
90
+ CrossIcon,
91
+ Highlight
91
92
  },
92
93
  data() {
93
94
  return {
@@ -19,9 +19,9 @@ it will render the suggestion query by default.
19
19
 
20
20
  ## Slots
21
21
 
22
- | Name | Description | Bindings<br />(name - type - description) |
23
- | -------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
- | <code>default</code> | Next Query content | **suggestion** <code>Suggestion</code> - Next Query suggestion data<br />**shouldHighlightCurated** <code>boolean</code> - True if the curated NQ should be highlighted |
22
+ | Name | Description | Bindings<br />(name - type - description) |
23
+ | -------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | <code>default</code> | Next Query content | **shouldHighlightCurated** <code>boolean</code> - True if the curated NQ should be highlighted<br />**v-bind** <code>Object</code> - `BaseSuggestion` default slot scope: **suggestion** <code>Suggestion</code> - Suggestion data<br /> **query** <code>string</code> - The query that the suggestion belongs to<br /> **filter** <code>Filter \\ | undefined</code> - Suggestion's filter |
25
25
 
26
26
  ## Examples
27
27
 
@@ -18,9 +18,9 @@ it will render the suggestion query by default.
18
18
 
19
19
  ## Slots
20
20
 
21
- | Name | Description | Bindings<br />(name - type - description) |
22
- | -------------------- | ------------------------ | ----------------------------------------------------------------------- |
23
- | <code>default</code> | Popular Search's content | **suggestion** <code>Suggestion</code> - Popular Search suggestion data |
21
+ | Name | Description | Bindings<br />(name - type - description) |
22
+ | -------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | <code>default</code> | Popular Search content | **v-bind** <code>Object</code> - `BaseSuggestion` default slot scope: **suggestion** <code>Suggestion</code> - Suggestion data<br /> **query** <code>string</code> - The query that the suggestion belongs to<br /> **filter** <code>Filter \\ | undefined</code> - Suggestion's filter |
24
24
 
25
25
  ## Examples
26
26
 
@@ -18,9 +18,9 @@ For example, if you're searching for _shirt_, a query suggestion could be _long
18
18
 
19
19
  ## Slots
20
20
 
21
- | Name | Description | Bindings<br />(name - type - description) |
22
- | -------------------- | ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
- | <code>default</code> | Custom content that replaces the `QuerySuggestion` default content | **suggestion** <code>Suggestion</code> - Query Suggestion data<br />**queryHTML** <code>string</code> - Suggestion’s query with the matching part wrapped in a HTML span tag |
21
+ | Name | Description | Bindings<br />(name - type - description) |
22
+ | -------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | <code>default</code> | Query Suggestion content | **v-bind** <code>Object</code> - `BaseSuggestion` default slot scope: **suggestion** <code>Suggestion</code> - Suggestion data<br /> **query** <code>string</code> - The query that the suggestion belongs to<br /> **filter** <code>Filter \\ | undefined</code> - Suggestion's filter |
24
24
 
25
25
  ## Events
26
26
 
@@ -66,13 +66,13 @@ export default {
66
66
 
67
67
  ### Play with default slot
68
68
 
69
- In this example, the query suggestion is painted in blue by passing a color style in the HTML span
70
- element.
69
+ In this example, we are adding an emoji next to the suggestion.
71
70
 
72
71
  ```vue live
73
72
  <template>
74
- <QuerySuggestion :suggestion="suggestion" #default="{ queryHTML }">
75
- <span v-html="queryHTML" style="color: blue;" />
73
+ <QuerySuggestion :suggestion="suggestion" #default="{ suggestion }">
74
+ <span>🔍</span>
75
+ <span>{{ suggestion.query }}</span>
76
76
  </QuerySuggestion>
77
77
  </template>
78
78
 
@@ -21,10 +21,9 @@ var __vue_render__ = function () {
21
21
  "default",
22
22
  function () {
23
23
  return [
24
- _c("span", {
24
+ _c("Highlight", {
25
25
  staticClass: "x-suggestion__query",
26
- attrs: { "aria-label": _vm.suggestion.query },
27
- domProps: { innerHTML: _vm._s(_vm.queryHTML) },
26
+ attrs: { text: _vm.suggestion.query, highlight: _vm.query },
28
27
  }),
29
28
  _vm._v(" "),
30
29
  _vm.filter
@@ -35,11 +34,7 @@ var __vue_render__ = function () {
35
34
  ]
36
35
  },
37
36
  null,
38
- {
39
- suggestion: _vm.suggestion,
40
- queryHTML: _vm.queryHTML,
41
- filter: _vm.filter,
42
- }
37
+ { suggestion: _vm.suggestion, query: _vm.query, filter: _vm.filter }
43
38
  ),
44
39
  ],
45
40
  2
@@ -1 +1 @@
1
- {"version":3,"file":"base-suggestion.vue.js","sources":["../../../../src/components/suggestions/base-suggestion.vue"],"sourcesContent":["<template>\n <button @click=\"emitEvents\" :class=\"dynamicCSSClasses\" class=\"x-suggestion\">\n <!-- eslint-disable max-len -->\n <!--\n @slot Button content\n @binding {Suggestion} suggestion - Suggestion data\n @binding {string} queryHTML - Suggestion's query with the matching part inside a `<span>` tag\n @binding {Filter} filter - Suggestion's filter\n -->\n <!-- eslint-enable max-len -->\n <slot v-bind=\"{ suggestion, queryHTML, filter }\">\n <span v-html=\"queryHTML\" :aria-label=\"suggestion.query\" class=\"x-suggestion__query\" />\n <span v-if=\"filter\" class=\"x-suggestion__filter\">{{ filter.label }}</span>\n </slot>\n </button>\n</template>\n\n<script lang=\"ts\">\n import { BooleanFilter, Suggestion } from '@empathyco/x-types';\n import { forEach } from '@empathyco/x-utils';\n import Vue from 'vue';\n import { Component, Prop } from 'vue-property-decorator';\n import { QueryFeature } from '../../types';\n import { normalizeString } from '../../utils/normalize';\n import { sanitize } from '../../utils/sanitize';\n import { VueCSSClasses } from '../../utils/types';\n import { XEventsTypes } from '../../wiring/events.types';\n\n /**\n * Renders a button with a default slot. It receives a query, which should be the query of the\n * module using this component, a suggestion, the {@link XEvent | XEvents} that will be emitted\n * on click with a given feature.\n *\n * The default slot receives the suggestion and the matched query has props.\n *\n * @public\n */\n @Component\n export default class BaseSuggestion extends Vue {\n /**\n * The normalized query of the module using this component.\n *\n * @public\n */\n @Prop({ default: '' })\n protected query!: string;\n\n /**\n * The suggestion to render and use in the default slot.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestion!: Suggestion;\n\n /**\n * The feature from which the events will be emitted.\n *\n * @public\n */\n @Prop() //TODO: set to true when the suggestions components pass it.\n protected feature?: QueryFeature;\n\n /**\n * The {@link XEvent | XEvents} that will be emitted when selecting a suggestion.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestionSelectedEvents!: Partial<XEventsTypes>;\n\n /**\n * Indicates if the curated suggestion should be highlighted.\n *\n * @public\n */\n @Prop({ default: false, type: Boolean })\n protected highlightCurated!: boolean;\n\n /**\n * The event handler that will be triggered when clicking on a suggestion.\n *\n * @remarks\n * UserAcceptedAQuery: suggestion.query\n * UserSelectedASuggestion: suggestion\n * UserClickedAFilter: suggestion.facets[0].filters[0]\n * Merges the events defined in the suggestionSelectedEvents prop and also emits them\n *\n * @returns The {@link XEvent | XEvents} to emit.\n * @public\n */\n protected get events(): Partial<XEventsTypes> {\n const filterEvent: Partial<XEventsTypes> = this.filter\n ? { UserClickedAFilter: this.filter }\n : {};\n return {\n UserAcceptedAQuery: this.suggestion.query,\n UserSelectedASuggestion: this.suggestion,\n ...this.suggestionSelectedEvents,\n ...filterEvent\n };\n }\n\n /**\n * Emits the events when the button is clicked.\n *\n * @public\n */\n protected emitEvents(): void {\n forEach(this.events, (event, payload) => {\n this.$x.emit(event, payload, {\n target: this.$el as HTMLElement,\n feature: this.feature\n });\n });\n }\n\n /**\n * Returns the suggestion filter object.\n * It is a BooleanFilter because the label is needed.\n * It returns only the first element because the facets and filters are being planned\n * in the BaseSuggestions component.\n *\n * @returns The filter.\n * @public\n */\n protected get filter(): BooleanFilter | undefined {\n return this.suggestion.facets?.[0]?.filters[0] as BooleanFilter;\n }\n\n /**\n * Checks if the normalized suggestion query matches with the module's query, so it has a\n * matching part.\n *\n * @returns If the query has a matching part or not.\n * @internal\n */\n protected get hasMatchingQuery(): boolean {\n return !!this.query && normalizeString(this.suggestion.query).includes(this.query);\n }\n\n /**\n * Checks if the suggestion is curated and if it should be highlighted.\n *\n * @returns True if the suggestion is curated and should be highlighted.\n *\n * @internal\n */\n protected get shouldHighlightCurated(): boolean {\n return this.highlightCurated && !!this.suggestion.isCurated;\n }\n\n /**\n * Generates css classes dynamically.\n *\n * @remarks\n * 'x-suggestion--matching added when the query should be matched.\n *\n * @returns The {@link VueCSSClasses} classes.\n * @public\n */\n protected get dynamicCSSClasses(): VueCSSClasses {\n return {\n 'x-suggestion--matching': this.hasMatchingQuery,\n 'x-suggestion--is-curated': this.shouldHighlightCurated\n };\n }\n\n /**\n * Highlights the matching part of the suggestion query with the query passed as prop of the\n * component putting it inside a `<span>` tag.\n *\n * @remarks\n * The query prop should be normalized.\n *\n * @returns The suggestion's query with the matching part inside a `<span>` tag.\n * @public\n */\n protected get queryHTML(): string {\n if (this.hasMatchingQuery) {\n const matcherIndex = normalizeString(this.suggestion.query).indexOf(this.query);\n\n const [beginning, matching, end] = this.splitAt(\n this.suggestion.query,\n matcherIndex,\n this.query.length\n );\n\n const attrsMatching = 'data-test=\"matching-part\" class=\"x-suggestion__matching-part\"';\n return `${beginning}<span ${attrsMatching}>${matching}</span>${end}`;\n }\n\n return sanitize(this.suggestion.query);\n }\n\n /**\n * Splits the label in three parts based on two indexes.\n *\n * @param label - The string that will be divided in three parts.\n * @param start - The first index that the label will be divided by.\n * @param skip - The second index that the label will be divided by.\n *\n * @returns The three parts of the divided label.\n * @internal\n */\n protected splitAt(label: string, start: number, skip: number): [string, string, string] {\n const startPart = label.substring(0, start);\n const matchingPart = label.substring(start, start + skip);\n const endPart = label.substring(start + skip);\n\n return [sanitize(startPart), sanitize(matchingPart), sanitize(endPart)];\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis default suggestion component expects a suggestion to render and pass to its default slot, a\nnormalized query to compare with the suggestion's query and highlight its matching parts and events\nto emit when the suggestion is selected.\n\nIf the suggestion contains a filter, it is displayed next to the suggestion.\n\n### Default usage\n\n```vue\n<BaseSuggestion v-bind=\"{ query, suggestion, suggestionSelectedEvents }\" />\n```\n\n### Customized usage\n\n```vue\n<BaseSuggestion v-bind=\"{ query, suggestion, suggestionSelectedEvents }\">\n <template #default=\"{ suggestion, queryHTML }\">\n <span\n class=\"my-suggestion\"\n v-html=\"queryHTML\"\n :aria-label=\"suggestion.query\"\n />\n </template>\n</BaseSuggestion>\n```\n\n### Customized usage with filter\n\n```vue\n<BaseSuggestion v-bind=\"{ query, suggestion, suggestionSelectedEvents }\">\n <template #default=\"{ suggestion, queryHTML, filter }\">\n <span\n class=\"my-suggestion\"\n v-html=\"queryHTML\"\n :aria-label=\"suggestion.query\"\n />\n <span>{{ filter.label }}</span>\n </template>\n</BaseSuggestion>\n```\n\n## Events\n\nA list of events that the component will emit:\n\n- `UserAcceptedAQuery`: the event is emitted after the user clicks the button. The event payload is\n the suggestion query data.\n- `UserSelectedASuggestion`: the event is emitted after the user clicks the button. The event\n payload is the suggestion data.\n- `UserClickedAFilter`: the event is emitted after the user clicks the button if the suggestion\n includes a filter. The event payload is the suggestion filter.\n- The component can emit more events on click using the `suggestionSelectedEvents` prop.\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"base-suggestion.vue.js","sources":["../../../../src/components/suggestions/base-suggestion.vue"],"sourcesContent":["<template>\n <button @click=\"emitEvents\" :class=\"dynamicCSSClasses\" class=\"x-suggestion\">\n <!--\n @slot Button content\n @binding {Suggestion} suggestion - Suggestion data\n @binding {String} query - The query that the suggestion belongs to\n @binding {Filter} filter - Suggestion's filter\n -->\n <slot v-bind=\"{ suggestion, query, filter }\">\n <Highlight class=\"x-suggestion__query\" :text=\"suggestion.query\" :highlight=\"query\" />\n <span v-if=\"filter\" class=\"x-suggestion__filter\">{{ filter.label }}</span>\n </slot>\n </button>\n</template>\n\n<script lang=\"ts\">\n import { BooleanFilter, Suggestion } from '@empathyco/x-types';\n import { forEach } from '@empathyco/x-utils';\n import Vue from 'vue';\n import { Component, Prop } from 'vue-property-decorator';\n import { QueryFeature } from '../../types';\n import { VueCSSClasses } from '../../utils/types';\n import { XEventsTypes } from '../../wiring/events.types';\n import Highlight from '../highlight.vue';\n\n /**\n * Renders a button with a default slot. It receives a query, which should be the query of the\n * module using this component, a suggestion, the {@link XEvent | XEvents} that will be emitted\n * on click with a given feature.\n *\n * The default slot receives the suggestion and the matched query has props.\n *\n * @public\n */\n @Component({\n components: { Highlight }\n })\n export default class BaseSuggestion extends Vue {\n /**\n * The normalized query of the module using this component.\n *\n * @public\n */\n @Prop({ default: '' })\n protected query!: string;\n\n /**\n * The suggestion to render and use in the default slot.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestion!: Suggestion;\n\n /**\n * The feature from which the events will be emitted.\n *\n * @public\n */\n @Prop() //TODO: set to true when the suggestions components pass it.\n protected feature?: QueryFeature;\n\n /**\n * The {@link XEvent | XEvents} that will be emitted when selecting a suggestion.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestionSelectedEvents!: Partial<XEventsTypes>;\n\n /**\n * Indicates if the curated suggestion should be highlighted.\n *\n * @public\n */\n @Prop({ default: false, type: Boolean })\n protected highlightCurated!: boolean;\n\n /**\n * The event handler that will be triggered when clicking on a suggestion.\n *\n * @remarks\n * UserAcceptedAQuery: suggestion.query\n * UserSelectedASuggestion: suggestion\n * UserClickedAFilter: suggestion.facets[0].filters[0]\n * Merges the events defined in the suggestionSelectedEvents prop and also emits them\n *\n * @returns The {@link XEvent | XEvents} to emit.\n * @public\n */\n protected get events(): Partial<XEventsTypes> {\n const filterEvent: Partial<XEventsTypes> = this.filter\n ? { UserClickedAFilter: this.filter }\n : {};\n return {\n UserAcceptedAQuery: this.suggestion.query,\n UserSelectedASuggestion: this.suggestion,\n ...this.suggestionSelectedEvents,\n ...filterEvent\n };\n }\n\n /**\n * Emits the events when the button is clicked.\n *\n * @public\n */\n protected emitEvents(): void {\n forEach(this.events, (event, payload) => {\n this.$x.emit(event, payload, {\n target: this.$el as HTMLElement,\n feature: this.feature\n });\n });\n }\n\n /**\n * Returns the suggestion filter object.\n * It is a BooleanFilter because the label is needed.\n * It returns only the first element because the facets and filters are being planned\n * in the BaseSuggestions component.\n *\n * @returns The filter.\n * @public\n */\n protected get filter(): BooleanFilter | undefined {\n return this.suggestion.facets?.[0]?.filters[0] as BooleanFilter;\n }\n\n /**\n * Checks if the suggestion is curated and if it should be highlighted.\n *\n * @returns True if the suggestion is curated and should be highlighted.\n *\n * @internal\n */\n protected get shouldHighlightCurated(): boolean {\n return this.highlightCurated && !!this.suggestion.isCurated;\n }\n\n /**\n * Generates css classes dynamically.\n *\n * @remarks\n * 'x-suggestion--matching added when the query should be matched.\n *\n * @returns The {@link VueCSSClasses} classes.\n * @public\n */\n protected get dynamicCSSClasses(): VueCSSClasses {\n return {\n 'x-suggestion--is-curated': this.shouldHighlightCurated\n };\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the following events:\n\n- `UserAcceptedAQuery`: the event is emitted after the user clicks the button. The event payload is\n the suggestion query data.\n- `UserSelectedASuggestion`: the event is emitted after the user clicks the button. The event\n payload is the suggestion data.\n- `UserClickedAFilter`: the event is emitted after the user clicks the button if the suggestion\n includes a filter. The event payload is the suggestion filter.\n- The component can emit more events on click using the `suggestionSelectedEvents` prop.\n\n## See it in action\n\nThis suggestion component expects a suggestion to render and pass to its default slot, a normalized\nquery to compare with the suggestion's query and highlight its matching parts, and events to emit\nwhen the suggestion is selected.\n\nIf the suggestion contains a filter, it is displayed next to the suggestion.\n\n```vue live\n<template>\n <BaseSuggestion v-bind=\"{ query, suggestion }\" />\n</template>\n<script>\n import { BaseSuggestion } from '@empathyco/x-components';\n\n export default {\n name: 'BaseSuggestionDemo',\n components: {\n BaseSuggestion\n },\n data() {\n return {\n query: 'st',\n suggestion: {\n modelName: 'QuerySuggestion',\n query: 'steak',\n facet: {\n namedModel: 'SimpleFacet',\n id: 'category',\n label: 'Category',\n filters: [\n {\n id: 'category:groceries',\n modelName: 'SimpleFilter',\n facetId: 'category-facet',\n label: 'Groceries',\n selected: false,\n totalResults: 10\n }\n ]\n }\n }\n };\n }\n };\n</script>\n```\n\n### Customise the content\n\nYou can make this component render any content you want by using the `default` slot.\n\n```vue live\n<template>\n <BaseSuggestion v-bind=\"{ query, suggestion }\" #default=\"{ suggestion, query, filter }\">\n <span>🔍</span>\n <Highlight :text=\"suggestion.query\" :highlight=\"query\" />\n <span v-if=\"filter\">{{ filter.label }}</span>\n </BaseSuggestion>\n</template>\n<script>\n import { BaseSuggestion } from '@empathyco/x-components';\n\n export default {\n name: 'BaseSuggestionDemo',\n components: {\n BaseSuggestion\n },\n data() {\n return {\n query: 'st',\n suggestion: {\n modelName: 'QuerySuggestion',\n query: 'steak'\n }\n };\n }\n };\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,8 +2,7 @@ import { __decorate } from 'tslib';
2
2
  import { forEach } from '@empathyco/x-utils';
3
3
  import Vue from 'vue';
4
4
  import { Prop, Component } from 'vue-property-decorator';
5
- import { normalizeString } from '../../utils/normalize.js';
6
- import { sanitize } from '../../utils/sanitize.js';
5
+ import __vue_component__ from '../highlight.vue.js';
7
6
 
8
7
  /**
9
8
  * Renders a button with a default slot. It receives a query, which should be the query of the
@@ -63,16 +62,6 @@ let BaseSuggestion = class BaseSuggestion extends Vue {
63
62
  get filter() {
64
63
  return this.suggestion.facets?.[0]?.filters[0];
65
64
  }
66
- /**
67
- * Checks if the normalized suggestion query matches with the module's query, so it has a
68
- * matching part.
69
- *
70
- * @returns If the query has a matching part or not.
71
- * @internal
72
- */
73
- get hasMatchingQuery() {
74
- return !!this.query && normalizeString(this.suggestion.query).includes(this.query);
75
- }
76
65
  /**
77
66
  * Checks if the suggestion is curated and if it should be highlighted.
78
67
  *
@@ -94,45 +83,9 @@ let BaseSuggestion = class BaseSuggestion extends Vue {
94
83
  */
95
84
  get dynamicCSSClasses() {
96
85
  return {
97
- 'x-suggestion--matching': this.hasMatchingQuery,
98
86
  'x-suggestion--is-curated': this.shouldHighlightCurated
99
87
  };
100
88
  }
101
- /**
102
- * Highlights the matching part of the suggestion query with the query passed as prop of the
103
- * component putting it inside a `<span>` tag.
104
- *
105
- * @remarks
106
- * The query prop should be normalized.
107
- *
108
- * @returns The suggestion's query with the matching part inside a `<span>` tag.
109
- * @public
110
- */
111
- get queryHTML() {
112
- if (this.hasMatchingQuery) {
113
- const matcherIndex = normalizeString(this.suggestion.query).indexOf(this.query);
114
- const [beginning, matching, end] = this.splitAt(this.suggestion.query, matcherIndex, this.query.length);
115
- const attrsMatching = 'data-test="matching-part" class="x-suggestion__matching-part"';
116
- return `${beginning}<span ${attrsMatching}>${matching}</span>${end}`;
117
- }
118
- return sanitize(this.suggestion.query);
119
- }
120
- /**
121
- * Splits the label in three parts based on two indexes.
122
- *
123
- * @param label - The string that will be divided in three parts.
124
- * @param start - The first index that the label will be divided by.
125
- * @param skip - The second index that the label will be divided by.
126
- *
127
- * @returns The three parts of the divided label.
128
- * @internal
129
- */
130
- splitAt(label, start, skip) {
131
- const startPart = label.substring(0, start);
132
- const matchingPart = label.substring(start, start + skip);
133
- const endPart = label.substring(start + skip);
134
- return [sanitize(startPart), sanitize(matchingPart), sanitize(endPart)];
135
- }
136
89
  };
137
90
  __decorate([
138
91
  Prop({ default: '' })
@@ -150,7 +103,9 @@ __decorate([
150
103
  Prop({ default: false, type: Boolean })
151
104
  ], BaseSuggestion.prototype, "highlightCurated", void 0);
152
105
  BaseSuggestion = __decorate([
153
- Component
106
+ Component({
107
+ components: { Highlight: __vue_component__ }
108
+ })
154
109
  ], BaseSuggestion);
155
110
  var script = BaseSuggestion;
156
111