@empathyco/x-components 9.0.0 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/core/index.js.map +1 -1
  3. package/docs/API-reference/api/x-adapter-platform.facetschema.md +1 -1
  4. package/docs/API-reference/api/x-adapter-platform.md +11 -0
  5. package/docs/API-reference/api/x-adapter-platform.platformfacet.md +1 -1
  6. package/docs/API-reference/api/x-adapter-platform.platformfacet.values.md +1 -1
  7. package/docs/API-reference/api/x-adapter-platform.platformfacettype.md +1 -1
  8. package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.max.md +11 -0
  9. package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.md +90 -0
  10. package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.min.md +11 -0
  11. package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.unit.md +11 -0
  12. package/docs/API-reference/api/x-components.baseslider.md +2 -8
  13. package/docs/API-reference/api/x-components.facetsxevents.md +19 -0
  14. package/docs/API-reference/api/x-components.facetsxevents.usermodifiedsliderfilter.md +13 -0
  15. package/docs/API-reference/api/x-components.hierarchicalfilter.md +1 -0
  16. package/docs/API-reference/api/x-components.md +19 -0
  17. package/docs/API-reference/api/x-components.simplefilter.md +1 -0
  18. package/docs/API-reference/api/x-components.sliderfilter.md +57 -0
  19. package/docs/API-reference/api/x-components.snippetcallbacks.md +1 -0
  20. package/docs/API-reference/api/x-types.facetmodelname.md +1 -1
  21. package/docs/API-reference/api/x-types.filtermodelname.md +1 -1
  22. package/docs/API-reference/api/x-types.issliderfacet.md +56 -0
  23. package/docs/API-reference/api/x-types.issliderfilter.md +56 -0
  24. package/docs/API-reference/api/x-types.md +44 -0
  25. package/docs/API-reference/api/x-types.sliderfacet.filters.md +13 -0
  26. package/docs/API-reference/api/x-types.sliderfacet.md +78 -0
  27. package/docs/API-reference/api/x-types.sliderfacet.modelname.md +13 -0
  28. package/docs/API-reference/api/x-types.sliderfilter.md +116 -0
  29. package/docs/API-reference/api/x-types.sliderfilter.modelname.md +13 -0
  30. package/docs/API-reference/api/x-types.sliderfilter.range.md +16 -0
  31. package/docs/API-reference/api/x-types.sliderfilter.selectedrange.md +13 -0
  32. package/docs/API-reference/api/x-types.sliderfilter.unit.md +13 -0
  33. package/docs/API-reference/components/common/x-components.base-slider.md +1 -1
  34. package/docs/API-reference/components/facets/x-components.filters/slider-filter.md +33 -0
  35. package/facets/index.js +2 -0
  36. package/js/components/base-slider.vue.js +14 -5
  37. package/js/components/base-slider.vue.js.map +1 -1
  38. package/js/components/base-slider.vue2.js +1 -1
  39. package/js/components/base-slider.vue2.js.map +1 -1
  40. package/js/index.js +2 -0
  41. package/js/index.js.map +1 -1
  42. package/js/x-modules/facets/components/filters/slider-filter.vue.js +74 -0
  43. package/js/x-modules/facets/components/filters/slider-filter.vue.js.map +1 -0
  44. package/js/x-modules/facets/components/filters/slider-filter.vue2.js +207 -0
  45. package/js/x-modules/facets/components/filters/slider-filter.vue2.js.map +1 -0
  46. package/js/x-modules/facets/components/filters/slider-filter.vue3.js +7 -0
  47. package/js/x-modules/facets/components/filters/slider-filter.vue3.js.map +1 -0
  48. package/js/x-modules/facets/entities/filter-entity.factory.js +2 -0
  49. package/js/x-modules/facets/entities/filter-entity.factory.js.map +1 -1
  50. package/js/x-modules/facets/entities/slider-filter.entity.js +107 -0
  51. package/js/x-modules/facets/entities/slider-filter.entity.js.map +1 -0
  52. package/js/x-modules/facets/wiring.js +3 -0
  53. package/js/x-modules/facets/wiring.js.map +1 -1
  54. package/package.json +4 -4
  55. package/report/x-adapter-platform.api.json +130 -4
  56. package/report/x-components.api.json +282 -6
  57. package/report/x-components.api.md +69 -13
  58. package/report/x-types.api.json +351 -2
  59. package/types/src/components/base-slider.vue.d.ts +3 -8
  60. package/types/src/components/base-slider.vue.d.ts.map +1 -1
  61. package/types/src/components/snippet-callbacks.vue.d.ts +1 -0
  62. package/types/src/components/snippet-callbacks.vue.d.ts.map +1 -1
  63. package/types/src/x-modules/facets/components/filters/hierarchical-filter.vue.d.ts +1 -0
  64. package/types/src/x-modules/facets/components/filters/hierarchical-filter.vue.d.ts.map +1 -1
  65. package/types/src/x-modules/facets/components/filters/simple-filter.vue.d.ts +1 -0
  66. package/types/src/x-modules/facets/components/filters/simple-filter.vue.d.ts.map +1 -1
  67. package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts +85 -0
  68. package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts.map +1 -0
  69. package/types/src/x-modules/facets/components/index.d.ts +1 -0
  70. package/types/src/x-modules/facets/components/index.d.ts.map +1 -1
  71. package/types/src/x-modules/facets/entities/filter-entity.factory.d.ts.map +1 -1
  72. package/types/src/x-modules/facets/entities/index.d.ts +1 -0
  73. package/types/src/x-modules/facets/entities/index.d.ts.map +1 -1
  74. package/types/src/x-modules/facets/entities/slider-filter.entity.d.ts +65 -0
  75. package/types/src/x-modules/facets/entities/slider-filter.entity.d.ts.map +1 -0
  76. package/types/src/x-modules/facets/events.types.d.ts +6 -1
  77. package/types/src/x-modules/facets/events.types.d.ts.map +1 -1
  78. package/types/src/x-modules/facets/wiring.d.ts +3 -0
  79. package/types/src/x-modules/facets/wiring.d.ts.map +1 -1
  80. package/types/src/x-modules/related-prompts/components/related-prompts-tag-list.vue.d.ts.map +1 -1
@@ -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-types](./x-types.md) &gt; [SliderFacet](./x-types.sliderfacet.md) &gt; [modelName](./x-types.sliderfacet.modelname.md)
4
+
5
+ ## SliderFacet.modelName property
6
+
7
+ Model name to indicate the facet type.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ modelName: 'SliderFacet';
13
+ ```
@@ -0,0 +1,116 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-types](./x-types.md) &gt; [SliderFilter](./x-types.sliderfilter.md)
4
+
5
+ ## SliderFilter interface
6
+
7
+ A type of filter used in [SliderFacet](./x-types.sliderfacet.md) and extends from [FacetFilter](./x-types.facetfilter.md)<!-- -->. This filter has the particularity that its [RangeValue](./x-types.rangevalue.md) is editable by the user. Editable means that the value max and min can be changed by the user instead of having several boolean filters with different values.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export interface SliderFilter extends FacetFilter
13
+ ```
14
+ **Extends:** [FacetFilter](./x-types.facetfilter.md)
15
+
16
+ ## Properties
17
+
18
+ <table><thead><tr><th>
19
+
20
+ Property
21
+
22
+
23
+ </th><th>
24
+
25
+ Modifiers
26
+
27
+
28
+ </th><th>
29
+
30
+ Type
31
+
32
+
33
+ </th><th>
34
+
35
+ Description
36
+
37
+
38
+ </th></tr></thead>
39
+ <tbody><tr><td>
40
+
41
+ [modelName](./x-types.sliderfilter.modelname.md)
42
+
43
+
44
+ </td><td>
45
+
46
+
47
+ </td><td>
48
+
49
+ 'SliderFilter'
50
+
51
+
52
+ </td><td>
53
+
54
+ Model name to indicate the filter type.
55
+
56
+
57
+ </td></tr>
58
+ <tr><td>
59
+
60
+ [range](./x-types.sliderfilter.range.md)
61
+
62
+
63
+ </td><td>
64
+
65
+
66
+ </td><td>
67
+
68
+ { min: number; max: number; }
69
+
70
+
71
+ </td><td>
72
+
73
+ boundary range.
74
+
75
+
76
+ </td></tr>
77
+ <tr><td>
78
+
79
+ [selectedRange](./x-types.sliderfilter.selectedrange.md)
80
+
81
+
82
+ </td><td>
83
+
84
+
85
+ </td><td>
86
+
87
+ [RangeValue](./x-types.rangevalue.md)
88
+
89
+
90
+ </td><td>
91
+
92
+ Filter range to use in the frontend.
93
+
94
+
95
+ </td></tr>
96
+ <tr><td>
97
+
98
+ [unit](./x-types.sliderfilter.unit.md)
99
+
100
+
101
+ </td><td>
102
+
103
+
104
+ </td><td>
105
+
106
+ Intl.NumberFormatOptions\['style'\]
107
+
108
+
109
+ </td><td>
110
+
111
+ Units to format the values of the ranges. Currently unused, reserved for future formatting.
112
+
113
+
114
+ </td></tr>
115
+ </tbody></table>
116
+
@@ -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-types](./x-types.md) &gt; [SliderFilter](./x-types.sliderfilter.md) &gt; [modelName](./x-types.sliderfilter.modelname.md)
4
+
5
+ ## SliderFilter.modelName property
6
+
7
+ Model name to indicate the filter type.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ modelName: 'SliderFilter';
13
+ ```
@@ -0,0 +1,16 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-types](./x-types.md) &gt; [SliderFilter](./x-types.sliderfilter.md) &gt; [range](./x-types.sliderfilter.range.md)
4
+
5
+ ## SliderFilter.range property
6
+
7
+ boundary range.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ range: {
13
+ min: number;
14
+ max: number;
15
+ };
16
+ ```
@@ -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-types](./x-types.md) &gt; [SliderFilter](./x-types.sliderfilter.md) &gt; [selectedRange](./x-types.sliderfilter.selectedrange.md)
4
+
5
+ ## SliderFilter.selectedRange property
6
+
7
+ Filter range to use in the frontend.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ selectedRange: RangeValue;
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-types](./x-types.md) &gt; [SliderFilter](./x-types.sliderfilter.md) &gt; [unit](./x-types.sliderfilter.unit.md)
4
+
5
+ ## SliderFilter.unit property
6
+
7
+ Units to format the values of the ranges. Currently unused, reserved for future formatting.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ unit: Intl.NumberFormatOptions['style'];
13
+ ```
@@ -18,7 +18,7 @@ for the slider implementation.
18
18
  | Name | Description | Type | Default |
19
19
  | ------------------------- | ----------------------------------------------------------- | ----------------------------------------- | ------------------------------------------------------------- |
20
20
  | <code>threshold</code> | The threshold prop sets the limits for the slider. | <code>{ min: number; max: number }</code> | <code>() => ({ min: 0, max: Number.MAX_SAFE_INTEGER })</code> |
21
- | <code>modelValue</code> | The modelValue prop sets the initial values for the slider. | <code>{ min: number; max: number }</code> | <code></code> |
21
+ | <code>modelValue</code> | The modelValue prop sets the initial values for the slider. | <code>RangeValue</code> | <code></code> |
22
22
  | <code>contentClass</code> | Class to be able to customize slider styles. | <code>string</code> | <code>''</code> |
23
23
 
24
24
  ## Events
@@ -0,0 +1,33 @@
1
+ ---
2
+
3
+ title: SliderFilter
4
+
5
+ ---
6
+
7
+ # SliderFilter
8
+
9
+ Renders a slider filter with editable minimum and maximum values.
10
+
11
+ Users can select a range using the slider or by entering the minimum and
12
+ maximum values directly.
13
+
14
+ In instant mode, valid changes are emitted automatically. Otherwise, the
15
+ apply button is rendered and changes are emitted when it is clicked.
16
+
17
+ The clear action resets the selected range to the slider boundaries.
18
+
19
+ The default slot exposes the selected range, slider boundaries, validation
20
+ state, and methods to update, apply, or clear the selected values.
21
+
22
+ ## Props
23
+
24
+ | Name | Description | Type | Default |
25
+ | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------- |
26
+ | <code>filter</code> | The slider filter data to render and edit. | <code>SliderFilterModel</code> | <code></code> |
27
+ | <code>isInstant</code> | Whether changes should be emitted immediately.<br /><br />When false, the apply button is rendered and changes are emitted when<br />the user clicks it. | <code>boolean</code> | <code></code> |
28
+
29
+ ## Slots
30
+
31
+ | Name | Description | Bindings<br />(name - type - description) |
32
+ | -------------------- | ------------------------------------------- | ----------------------------------------- |
33
+ | <code>default</code> | Slot used to customize the whole component. | <br /><br /><br /><br /><br /><br /> |
package/facets/index.js CHANGED
@@ -7,6 +7,7 @@ export { default as HierarchicalFilter } from '../js/x-modules/facets/components
7
7
  export { default as NumberRangeFilter } from '../js/x-modules/facets/components/filters/number-range-filter.vue.js';
8
8
  export { default as RenderlessFilter } from '../js/x-modules/facets/components/filters/renderless-filter.vue.js';
9
9
  export { default as SimpleFilter } from '../js/x-modules/facets/components/filters/simple-filter.vue.js';
10
+ export { default as SliderFilter } from '../js/x-modules/facets/components/filters/slider-filter.vue.js';
10
11
  export { default as ExcludeFiltersWithNoResults } from '../js/x-modules/facets/components/lists/exclude-filters-with-no-results.vue.js';
11
12
  export { default as FiltersList } from '../js/x-modules/facets/components/lists/filters-list.vue.js';
12
13
  export { default as FiltersSearch } from '../js/x-modules/facets/components/lists/filters-search.vue.js';
@@ -24,6 +25,7 @@ export { NumberRangeFilterEntity } from '../js/x-modules/facets/entities/number-
24
25
  export { RawFilterEntity } from '../js/x-modules/facets/entities/raw-filter.entity.js';
25
26
  export { SimpleFilterEntity } from '../js/x-modules/facets/entities/simple-filter.entity.js';
26
27
  export { SingleSelectModifier } from '../js/x-modules/facets/entities/single-select.modifier.js';
28
+ export { SliderFilterEntity } from '../js/x-modules/facets/entities/slider-filter.entity.js';
27
29
  export { StickyModifier } from '../js/x-modules/facets/entities/sticky.modifier.js';
28
30
  export { BaseFilterEntityModifier } from '../js/x-modules/facets/entities/types.js';
29
31
  export { DefaultFacetsService } from '../js/x-modules/facets/service/facets.service.js';
@@ -3,10 +3,19 @@ import { openBlock, createElementBlock, createElementVNode, normalizeClass, rend
3
3
  import './base-slider.vue3.js';
4
4
  import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
5
5
 
6
- const _hoisted_1 = { class: "x-base-slider" };
6
+ const _hoisted_1 = {
7
+ class: "x-base-slider",
8
+ "data-test": "base-slider"
9
+ };
7
10
  const _hoisted_2 = { class: "x-base-slider__selected" };
8
- const _hoisted_3 = { class: "x-base-slider__selected-min" };
9
- const _hoisted_4 = { class: "x-base-slider__selected-max" };
11
+ const _hoisted_3 = {
12
+ class: "x-base-slider__selected-min",
13
+ "data-test": "base-slider-min"
14
+ };
15
+ const _hoisted_4 = {
16
+ class: "x-base-slider__selected-max",
17
+ "data-test": "base-slider-max"
18
+ };
10
19
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
11
20
  return openBlock(), createElementBlock("div", _hoisted_1, [
12
21
  createElementVNode(
@@ -57,7 +66,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
57
66
  ])
58
67
  ]);
59
68
  }
60
- var baseSlider = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
69
+ var BaseSlider = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
61
70
 
62
- export { baseSlider as default };
71
+ export { BaseSlider as default };
63
72
  //# sourceMappingURL=base-slider.vue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-slider.vue.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<{ min: number; max: number }>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch(\n () => props.threshold,\n ({ min, max }) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n },\n )\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min < props.threshold.min ? props.threshold.min : min\n const maxValidated = max > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_createElementVNode","_normalizeClass","_renderSlot","_toDisplayString"],"mappings":";;;;;AACO,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,eAAA,EAAe;AAEnB,MAAA,UAAA,GA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AAAA,YAEO,MAAA;AAAA,YAAA,IAAA;AAAA,YAAAG,eAAA,CADF,IAAA,CAAA,aAAA,CAAa,CAAA,CAAA,CAAA;AAAA,YAAA;AAAA;AAAA;AAAA,SAAA;;;;;;;;;"}
1
+ {"version":3,"file":"base-slider.vue.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\" data-test=\"base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\" data-test=\"base-slider-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\" data-test=\"base-slider-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { RangeValue } from '@empathyco/x-types'\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<RangeValue>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch([() => props.threshold.min, () => props.threshold.max], ([min, max]) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n })\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min! < props.threshold.min ? props.threshold.min : min\n const maxValidated = max! > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_createElementVNode","_normalizeClass","_renderSlot","_toDisplayString"],"mappings":";;;;;;EACO,KAAA,EAAM,eAAA;AAAA,EAAgB,WAAA,EAAU;;AAE9B,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,yBAAA,EAAyB;;EAO7B,KAAA,EAAM,6BAAA;AAAA,EAA8B,WAAA,EAAU;;;EAM9C,KAAA,EAAM,6BAAA;AAAA,EAA8B,WAAA,EAAU;;;AAfvD,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA,CAuBM,OAvBN,UAAA,EAuBM;AAAA,IAtBJC,kBAAA;AAAA,MAAqF,KAAA;AAAA,MAAA;AAAA,QAAhF,GAAA,EAAI,QAAA;AAAA,QAAU,KAAA,EAAKC,cAAA,CAAA,CAAA,2BAAA,CAAA,CAAgC,MAAA,CAAM,CAAA,EAAI,IAAA,CAAA,YAAY,CAAA,CAAA,CAAA;AAAA,OAAA;;;;;AAC9E,IAAAD,kBAAA,CAoBM,OApBN,UAAA,EAoBM;AAAA,MAdJE,UAAA,CAaO,IAAA,CAAA,MAAA,EAAA,SAAA,EAAA,EAbA,aAAA,EAAgB,IAAA,CAAA,aAAA,IAAvB,MAaO;AAAA,QAZLF,kBAAA,CAKI,KALJ,UAAA,EAKI;AAAA,UAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAJFA,kBAAA;AAAA,YAAsB,MAAA;AAAA,YAAA,IAAA;AAAA,YAAhB,WAAA;AAAA,YAAS;AAAA;AAAA,WAAA,CAAA;AAAA,UACfA,kBAAA;AAAA,YAEO,MAAA;AAAA,YAAA,IAAA;AAAA,YAAAG,eAAA,CADF,IAAA,CAAA,aAAA,CAAa,CAAA,CAAA,CAAA;AAAA,YAAA;AAAA;AAAA;AAAA,SAAA,CAAA;AAGpB,QAAAH,kBAAA,CAKI,KALJ,UAAA,EAKI;AAAA,UAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAJFA,kBAAA;AAAA,YAAsB,MAAA;AAAA,YAAA,IAAA;AAAA,YAAhB,WAAA;AAAA,YAAS;AAAA;AAAA,WAAA,CAAA;AAAA,UACfA,kBAAA;AAAA,YAEO,MAAA;AAAA,YAAA,IAAA;AAAA,YAAAG,eAAA,CADF,IAAA,CAAA,aAAA,CAAa,CAAA,CAAA,CAAA;AAAA,YAAA;AAAA;AAAA;AAAA,SAAA;;;;;;;;;"}
@@ -71,7 +71,7 @@ var _sfc_main = defineComponent({
71
71
  /**
72
72
  * Watch the threshold prop to update the slider state and emit the selected values.
73
73
  */
74
- watch(() => props.threshold, ({ min, max }) => {
74
+ watch([() => props.threshold.min, () => props.threshold.max], ([min, max]) => {
75
75
  sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false);
76
76
  emit('update:modelValue', { min, max });
77
77
  });
@@ -1 +1 @@
1
- {"version":3,"file":"base-slider.vue2.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<{ min: number; max: number }>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch(\n () => props.threshold,\n ({ min, max }) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n },\n )\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min < props.threshold.min ? props.threshold.min : min\n const maxValidated = max > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;AAiCA;;;;;;;;AAQE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,MAAgD;AACtD,YAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,gBAAe,EAAG,CAAC;AAC1D,SAAA;;AAED,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,MAAgD;AACtD,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,EAAE;AACZ,SAAA;AACF,KAAA;AACD;;;AAGE;IACF,KAAK,EAAE,CAAC,mBAAmB,CAAC;AAC5B,IAAA,KAAK,CAAC,KAAK,EAAE,EAAE,IAAG,EAAG,EAAA;;AAEnB,QAAA,IAAI,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AAA;YACpE;AACF,QAAA,CAAC,CAAA;QAED,OAAO;YACL,MAAM;YACN,aAAa;SACf;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"base-slider.vue2.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\" data-test=\"base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\" data-test=\"base-slider-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\" data-test=\"base-slider-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { RangeValue } from '@empathyco/x-types'\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<RangeValue>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch([() => props.threshold.min, () => props.threshold.max], ([min, max]) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n })\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min! < props.threshold.min ? props.threshold.min : min\n const maxValidated = max! > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;AAkCA;;;;;;;;AAQE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,MAAgD;AACtD,YAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,gBAAe,EAAG,CAAC;AAC1D,SAAA;;AAED,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,MAA8B;AACpC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,EAAE;AACZ,SAAA;AACF,KAAA;AACD;;;AAGE;IACF,KAAK,E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EAAE,YAAY,CAAC,CAAA;;YAG/C,IAAI,YAAW,KAAM,GAAE,IAAK,iBAAiB,GAAG,EAAE;AAChD,gBAAA,IAAI,CAAC,mBAAmB,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,YAAW,EAAG,CAAA;YACpE;AACF,QAAA,CAAC,CAAA;QAED,OAAO;YACL,MAAM;YACN,aAAa;SACf;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
package/js/index.js CHANGED
@@ -259,6 +259,7 @@ export { default as HierarchicalFilter } from './x-modules/facets/components/fil
259
259
  export { default as NumberRangeFilter } from './x-modules/facets/components/filters/number-range-filter.vue.js';
260
260
  export { default as RenderlessFilter } from './x-modules/facets/components/filters/renderless-filter.vue.js';
261
261
  export { default as SimpleFilter } from './x-modules/facets/components/filters/simple-filter.vue.js';
262
+ export { default as SliderFilter } from './x-modules/facets/components/filters/slider-filter.vue.js';
262
263
  export { default as ExcludeFiltersWithNoResults } from './x-modules/facets/components/lists/exclude-filters-with-no-results.vue.js';
263
264
  export { default as FiltersList } from './x-modules/facets/components/lists/filters-list.vue.js';
264
265
  export { default as FiltersSearch } from './x-modules/facets/components/lists/filters-search.vue.js';
@@ -276,6 +277,7 @@ export { NumberRangeFilterEntity } from './x-modules/facets/entities/number-rang
276
277
  export { RawFilterEntity } from './x-modules/facets/entities/raw-filter.entity.js';
277
278
  export { SimpleFilterEntity } from './x-modules/facets/entities/simple-filter.entity.js';
278
279
  export { SingleSelectModifier } from './x-modules/facets/entities/single-select.modifier.js';
280
+ export { SliderFilterEntity } from './x-modules/facets/entities/slider-filter.entity.js';
279
281
  export { StickyModifier } from './x-modules/facets/entities/sticky.modifier.js';
280
282
  export { BaseFilterEntityModifier } from './x-modules/facets/entities/types.js';
281
283
  export { DefaultFacetsService } from './x-modules/facets/service/facets.service.js';
package/js/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;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createBlock, normalizeClass, withCtx, renderSlot, normalizeProps, guardReactiveProps, createElementVNode, createElementBlock, createCommentVNode } from 'vue';
3
+ import './slider-filter.vue3.js';
4
+ import _export_sfc from '../../../../_virtual/_plugin-vue_export-helper.js';
5
+
6
+ const _hoisted_1 = ["value", "min", "max"];
7
+ const _hoisted_2 = ["value", "min", "max"];
8
+ const _hoisted_3 = ["disabled"];
9
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
10
+ const _component_BaseSlider = resolveComponent("BaseSlider");
11
+ return openBlock(), createBlock(_component_BaseSlider, {
12
+ modelValue: _ctx.selectedRange,
13
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => _ctx.selectedRange = $event),
14
+ threshold: _ctx.threshold,
15
+ class: normalizeClass(["x-slider-filter", { "x-slider-filter--error": _ctx.hasError }])
16
+ }, {
17
+ default: withCtx(() => [
18
+ renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({
19
+ threshold: _ctx.threshold,
20
+ selectedRange: _ctx.selectedRange,
21
+ setMin: _ctx.setMin,
22
+ setMax: _ctx.setMax,
23
+ emitUserModifiedFilter: _ctx.emitUserModifiedFilter,
24
+ clearValues: _ctx.clearValues,
25
+ hasError: _ctx.hasError
26
+ })), () => [
27
+ createElementVNode("div", null, [
28
+ createElementVNode("input", {
29
+ name: "min",
30
+ type: "number",
31
+ inputmode: "decimal",
32
+ class: "x-slider-filter__input x-slider-filter__input--min xds:input",
33
+ value: _ctx.selectedRange.min,
34
+ min: _ctx.threshold.min,
35
+ max: _ctx.threshold.max,
36
+ "data-test": "slider-filter-input-min",
37
+ "aria-label": "minimum amount",
38
+ onChange: _cache[0] || (_cache[0] = ($event) => _ctx.setMin($event.target.value))
39
+ }, null, 40, _hoisted_1),
40
+ createElementVNode("input", {
41
+ name: "max",
42
+ type: "number",
43
+ inputmode: "decimal",
44
+ class: "x-slider-filter__input x-slider-filter__input--max xds:input",
45
+ value: _ctx.selectedRange.max,
46
+ min: _ctx.threshold.min,
47
+ max: _ctx.threshold.max,
48
+ "data-test": "slider-filter-input-max",
49
+ "aria-label": "maximum amount",
50
+ onChange: _cache[1] || (_cache[1] = ($event) => _ctx.setMax($event.target.value))
51
+ }, null, 40, _hoisted_2),
52
+ !_ctx.isInstant ? (openBlock(), createElementBlock("button", {
53
+ key: 0,
54
+ class: "x-slider-filter__apply xds:button",
55
+ disabled: _ctx.hasError,
56
+ "data-test": "slider-filter-apply",
57
+ onClick: _cache[2] || (_cache[2] = (...args) => _ctx.emitUserModifiedFilter && _ctx.emitUserModifiedFilter(...args))
58
+ }, " ✓ ", 8, _hoisted_3)) : createCommentVNode("v-if", true),
59
+ createElementVNode("button", {
60
+ class: "x-slider-filter__clear xds:button",
61
+ "data-test": "slider-filter-clear",
62
+ onClick: _cache[3] || (_cache[3] = (...args) => _ctx.clearValues && _ctx.clearValues(...args))
63
+ }, " 𐄂 ")
64
+ ])
65
+ ], true)
66
+ ]),
67
+ _: 3
68
+ /* FORWARDED */
69
+ }, 8, ["modelValue", "threshold", "class"]);
70
+ }
71
+ var sliderFilter = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-b8e25e19"]]);
72
+
73
+ export { sliderFilter as default };
74
+ //# sourceMappingURL=slider-filter.vue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-filter.vue.js","sources":["../../../../../../src/x-modules/facets/components/filters/slider-filter.vue"],"sourcesContent":["<template>\n <BaseSlider\n v-model=\"selectedRange\"\n :threshold=\"threshold\"\n class=\"x-slider-filter\"\n :class=\"{ 'x-slider-filter--error': hasError }\"\n >\n <!--\n @slot Slot used to customize the whole component.\n\n @binding {selectedRange} RangeValue - Current selected minimum and maximum values.\n @binding {threshold} RangeValue - Minimum and maximum boundaries of the slider.\n @binding {setMin} function - Sets the selected minimum value.\n @binding {setMax} function - Sets the selected maximum value.\n @binding {emitUserModifiedFilter} function - Emits the `UserModifiedSliderFilter` event.\n @binding {clearValues} function - Resets the selected range to the slider boundaries.\n @binding {hasError} boolean - Whether the selected range is invalid.\n -->\n <slot\n v-bind=\"{\n threshold,\n selectedRange,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n }\"\n >\n <div>\n <input\n name=\"min\"\n type=\"number\"\n inputmode=\"decimal\"\n class=\"x-slider-filter__input x-slider-filter__input--min xds:input\"\n :value=\"selectedRange.min\"\n :min=\"threshold.min\"\n :max=\"threshold.max\"\n data-test=\"slider-filter-input-min\"\n aria-label=\"minimum amount\"\n @change=\"setMin(($event.target as HTMLInputElement).value)\"\n />\n\n <input\n name=\"max\"\n type=\"number\"\n inputmode=\"decimal\"\n class=\"x-slider-filter__input x-slider-filter__input--max xds:input\"\n :value=\"selectedRange.max\"\n :min=\"threshold.min\"\n :max=\"threshold.max\"\n data-test=\"slider-filter-input-max\"\n aria-label=\"maximum amount\"\n @change=\"setMax(($event.target as HTMLInputElement).value)\"\n />\n\n <button\n v-if=\"!isInstant\"\n class=\"x-slider-filter__apply xds:button\"\n :disabled=\"hasError\"\n data-test=\"slider-filter-apply\"\n @click=\"emitUserModifiedFilter\"\n >\n ✓\n </button>\n\n <button\n class=\"x-slider-filter__clear xds:button\"\n data-test=\"slider-filter-clear\"\n @click=\"clearValues\"\n >\n 𐄂\n </button>\n </div>\n </slot>\n </BaseSlider>\n</template>\n\n<script lang=\"ts\">\nimport type { SliderFilter as SliderFilterModel } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport BaseSlider from '../../../../components/base-slider.vue'\nimport { use$x } from '../../../../composables'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders a slider filter with editable minimum and maximum values.\n *\n * Users can select a range using the slider or by entering the minimum and\n * maximum values directly.\n *\n * In instant mode, valid changes are emitted automatically. Otherwise, the\n * apply button is rendered and changes are emitted when it is clicked.\n *\n * The clear action resets the selected range to the slider boundaries.\n *\n * The default slot exposes the selected range, slider boundaries, validation\n * state, and methods to update, apply, or clear the selected values.\n *\n * @public\n */\nexport default defineComponent({\n name: 'SliderFilter',\n xModule: facetsXModule.name,\n components: {\n BaseSlider,\n },\n props: {\n /**\n * The slider filter data to render and edit.\n *\n * @public\n */\n filter: {\n type: Object as PropType<SliderFilterModel>,\n required: true,\n },\n /**\n * Whether changes should be emitted immediately.\n *\n * When false, the apply button is rendered and changes are emitted when\n * the user clicks it.\n *\n * @default false\n * @public\n */\n isInstant: Boolean,\n },\n\n setup(props) {\n const $x = use$x()\n\n /**\n * Current selected minimum and maximum values.\n *\n * Values that are not selected are initialized to the corresponding\n * slider boundaries.\n *\n * @internal\n */\n const selectedRange = ref({\n min: props.filter.selectedRange.min ?? props.filter.range.min,\n max: props.filter.selectedRange.max ?? props.filter.range.max,\n })\n\n /**\n * Minimum and maximum boundaries of the slider.\n *\n * @internal\n */\n const threshold = computed(() => ({\n min: props.filter.range.min,\n max: props.filter.range.max,\n }))\n\n /**\n * Whether the selected range is invalid because its minimum is greater\n * than its maximum.\n *\n * @internal\n */\n const hasError = computed(\n () =>\n selectedRange.value.min !== null &&\n selectedRange.value.max !== null &&\n selectedRange.value.min > selectedRange.value.max,\n )\n\n /**\n * Whether the selected range differs from the range currently applied\n * to the filter.\n *\n * @internal\n */\n const areValuesDifferent = computed(\n () =>\n selectedRange.value.min !== (props.filter.selectedRange.min ?? props.filter.range.min) ||\n selectedRange.value.max !== (props.filter.selectedRange.max ?? props.filter.range.max),\n )\n\n /**\n * Emits the `UserModifiedSliderFilter` event when the selected range is\n * valid and differs from the currently applied filter range.\n *\n * @internal\n */\n const emitUserModifiedFilter = () => {\n if (hasError.value || !areValuesDifferent.value) {\n return\n }\n\n $x.emit('UserModifiedSliderFilter', {\n ...props.filter,\n selectedRange: selectedRange.value,\n })\n }\n\n /**\n * Sets one of the selected range values from a raw input value.\n *\n * Empty or invalid values are reset to the corresponding slider boundary.\n *\n * @param key - Range boundary to update.\n * @param rawValue - Raw input value.\n *\n * @internal\n */\n const setRangeValue = (key: 'min' | 'max', rawValue: string) => {\n const value = Number(rawValue)\n\n selectedRange.value[key] =\n rawValue === '' || Number.isNaN(value) ? threshold.value[key] : value\n }\n\n /**\n * Sets the selected minimum value.\n *\n * @param rawValue - Raw input value.\n *\n * @internal\n */\n const setMin = (rawValue: string) => {\n setRangeValue('min', rawValue)\n }\n\n /**\n * Sets the selected maximum value.\n *\n * @param rawValue - Raw input value.\n *\n * @internal\n */\n const setMax = (rawValue: string) => {\n setRangeValue('max', rawValue)\n }\n\n /**\n * Resets the selected range to the slider boundaries.\n *\n * @internal\n */\n const clearValues = () => {\n selectedRange.value = {\n min: threshold.value.min,\n max: threshold.value.max,\n }\n }\n\n /**\n * Resets the selected range when all filters, or the filters of this facet, are cleared.\n *\n * @public\n */\n $x.on('UserClickedClearAllFilters', false).subscribe(facetsIds => {\n if (!facetsIds || facetsIds.includes(props.filter.facetId)) {\n clearValues()\n }\n })\n\n /**\n * Updates the local selected range when the filter selected range changes,\n * but only if the values actually differ from the current local ones.\n *\n * @internal\n */\n watch(\n () => props.filter.selectedRange,\n newRange => {\n const min = newRange.min ?? props.filter.range.min\n const max = newRange.max ?? props.filter.range.max\n\n if (min !== selectedRange.value.min || max !== selectedRange.value.max) {\n selectedRange.value = { min, max }\n }\n },\n )\n\n /**\n * Emits the filter modification automatically when instant mode is enabled\n * and the selected range values (min or max) change.\n *\n * Replacing the selected range with an object holding the same values does\n * not trigger the emit.\n *\n * @internal\n */\n watch([() => selectedRange.value.min, () => selectedRange.value.max], () => {\n if (props.isInstant) {\n emitUserModifiedFilter()\n }\n })\n\n return {\n selectedRange,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n threshold,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-slider-filter--error .x-slider-filter__input {\n border-color: red;\n}\n</style>\n"],"names":["_createBlock","_normalizeClass","_renderSlot","_normalizeProps","_guardReactiveProps","_createElementVNode","_openBlock","_createElementBlock","_createCommentVNode"],"m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