@salla.sa/twilight-components 2.12.10 → 2.12.12

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 (103) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/salla-add-product-button_40.cjs.entry.js +18 -6
  3. package/dist/cjs/salla-add-product-button_40.cjs.entry.js.map +1 -1
  4. package/dist/cjs/salla-filters-widget.cjs.entry.js +7 -0
  5. package/dist/cjs/salla-filters-widget.cjs.entry.js.map +1 -1
  6. package/dist/cjs/salla-filters.cjs.entry.js +1 -0
  7. package/dist/cjs/salla-filters.cjs.entry.js.map +1 -1
  8. package/dist/cjs/salla-product-options.cjs.entry.js +31 -2
  9. package/dist/cjs/salla-product-options.cjs.entry.js.map +1 -1
  10. package/dist/cjs/twilight.cjs.js +1 -1
  11. package/dist/collection/components/salla-file-upload/salla-file-upload.css +6 -0
  12. package/dist/collection/components/salla-filters/salla-filters.js +1 -0
  13. package/dist/collection/components/salla-filters/salla-filters.js.map +1 -1
  14. package/dist/collection/components/salla-filters-widget/salla-filters-widget.js +26 -0
  15. package/dist/collection/components/salla-filters-widget/salla-filters-widget.js.map +1 -1
  16. package/dist/collection/components/salla-gifting/salla-gifting.js +22 -1
  17. package/dist/collection/components/salla-gifting/salla-gifting.js.map +1 -1
  18. package/dist/collection/components/salla-product-options/interfaces.js.map +1 -1
  19. package/dist/collection/components/salla-product-options/salla-product-options.js +34 -2
  20. package/dist/collection/components/salla-product-options/salla-product-options.js.map +1 -1
  21. package/dist/collection/components/salla-rating-modal/salla-rating-modal.js +2 -2
  22. package/dist/collection/components/salla-rating-modal/salla-rating-modal.js.map +1 -1
  23. package/dist/collection/components/salla-slider/salla-slider.js +16 -5
  24. package/dist/collection/components/salla-slider/salla-slider.js.map +1 -1
  25. package/dist/components/salla-file-upload2.js +1 -1
  26. package/dist/components/salla-file-upload2.js.map +1 -1
  27. package/dist/components/salla-filters-widget2.js +8 -0
  28. package/dist/components/salla-filters-widget2.js.map +1 -1
  29. package/dist/components/salla-filters.js +1 -0
  30. package/dist/components/salla-filters.js.map +1 -1
  31. package/dist/components/salla-gifting.js +3 -1
  32. package/dist/components/salla-gifting.js.map +1 -1
  33. package/dist/components/salla-product-options.js +34 -2
  34. package/dist/components/salla-product-options.js.map +1 -1
  35. package/dist/components/salla-rating-modal.js +2 -2
  36. package/dist/components/salla-rating-modal.js.map +1 -1
  37. package/dist/components/salla-slider2.js +14 -2
  38. package/dist/components/salla-slider2.js.map +1 -1
  39. package/dist/esm/loader.js +1 -1
  40. package/dist/esm/salla-add-product-button_40.entry.js +18 -6
  41. package/dist/esm/salla-add-product-button_40.entry.js.map +1 -1
  42. package/dist/esm/salla-filters-widget.entry.js +7 -0
  43. package/dist/esm/salla-filters-widget.entry.js.map +1 -1
  44. package/dist/esm/salla-filters.entry.js +1 -0
  45. package/dist/esm/salla-filters.entry.js.map +1 -1
  46. package/dist/esm/salla-product-options.entry.js +31 -2
  47. package/dist/esm/salla-product-options.entry.js.map +1 -1
  48. package/dist/esm/twilight.js +1 -1
  49. package/dist/esm-es5/loader.js +1 -1
  50. package/dist/esm-es5/loader.js.map +1 -1
  51. package/dist/esm-es5/salla-add-product-button_40.entry.js +1 -1
  52. package/dist/esm-es5/salla-add-product-button_40.entry.js.map +1 -1
  53. package/dist/esm-es5/salla-filters-widget.entry.js +1 -1
  54. package/dist/esm-es5/salla-filters-widget.entry.js.map +1 -1
  55. package/dist/esm-es5/salla-filters.entry.js +1 -1
  56. package/dist/esm-es5/salla-filters.entry.js.map +1 -1
  57. package/dist/esm-es5/salla-product-options.entry.js +2 -2
  58. package/dist/esm-es5/salla-product-options.entry.js.map +1 -1
  59. package/dist/esm-es5/twilight.js +1 -1
  60. package/dist/esm-es5/twilight.js.map +1 -1
  61. package/dist/twilight/p-03cfdef7.system.js +1 -1
  62. package/dist/twilight/p-03cfdef7.system.js.map +1 -1
  63. package/dist/twilight/p-285c9f29.system.entry.js +5 -0
  64. package/dist/twilight/p-285c9f29.system.entry.js.map +1 -0
  65. package/dist/twilight/p-36937f5d.entry.js +5 -0
  66. package/dist/twilight/p-36937f5d.entry.js.map +1 -0
  67. package/dist/twilight/p-517438b5.system.entry.js +5 -0
  68. package/dist/twilight/p-517438b5.system.entry.js.map +1 -0
  69. package/dist/twilight/p-6bfa8251.entry.js +54 -0
  70. package/dist/twilight/p-6bfa8251.entry.js.map +1 -0
  71. package/dist/twilight/p-7101b078.system.entry.js +54 -0
  72. package/dist/twilight/p-7101b078.system.entry.js.map +1 -0
  73. package/dist/twilight/p-a60b73b6.entry.js +5 -0
  74. package/dist/twilight/p-a60b73b6.entry.js.map +1 -0
  75. package/dist/twilight/p-c474d44b.entry.js +5 -0
  76. package/dist/twilight/p-c474d44b.entry.js.map +1 -0
  77. package/dist/twilight/p-e57562e7.system.entry.js +5 -0
  78. package/dist/twilight/p-e57562e7.system.entry.js.map +1 -0
  79. package/dist/twilight/twilight.esm.js +1 -1
  80. package/dist/twilight/twilight.esm.js.map +1 -1
  81. package/dist/types/components/salla-filters-widget/salla-filters-widget.d.ts +1 -0
  82. package/dist/types/components/salla-gifting/salla-gifting.d.ts +7 -0
  83. package/dist/types/components/salla-product-options/interfaces.d.ts +2 -0
  84. package/dist/types/components/salla-product-options/salla-product-options.d.ts +5 -0
  85. package/dist/types/components/salla-slider/salla-slider.d.ts +2 -0
  86. package/dist/types/components.d.ts +9 -0
  87. package/package.json +3 -3
  88. package/dist/twilight/p-09f141a9.system.entry.js +0 -5
  89. package/dist/twilight/p-09f141a9.system.entry.js.map +0 -1
  90. package/dist/twilight/p-1342a68f.entry.js +0 -5
  91. package/dist/twilight/p-1342a68f.entry.js.map +0 -1
  92. package/dist/twilight/p-8ce4ca08.entry.js +0 -54
  93. package/dist/twilight/p-8ce4ca08.entry.js.map +0 -1
  94. package/dist/twilight/p-9d88d784.system.entry.js +0 -54
  95. package/dist/twilight/p-9d88d784.system.entry.js.map +0 -1
  96. package/dist/twilight/p-c50e7524.entry.js +0 -5
  97. package/dist/twilight/p-c50e7524.entry.js.map +0 -1
  98. package/dist/twilight/p-d9be595b.entry.js +0 -5
  99. package/dist/twilight/p-d9be595b.entry.js.map +0 -1
  100. package/dist/twilight/p-f8addbca.system.entry.js +0 -5
  101. package/dist/twilight/p-f8addbca.system.entry.js.map +0 -1
  102. package/dist/twilight/p-ffec6e8f.system.entry.js +0 -5
  103. package/dist/twilight/p-ffec6e8f.system.entry.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"names":["sallaFiltersCss","SallaFilters","exports","class_1","hostRef","_this","this","isReady","salla","event","on","host","style","display","lang","onLoaded","apply","get","reset","_c","filters","freshFilterData","map","filter","label","category_id","brand_id","rating","price","key","inputType","FilterOptionInputType","RADIO","values","max_1","max","min_1","min","stars","filtersData","prototype","connectedCallback","URLSearchParams","window","location","search","JSON","parse","decodeURIComponent","e","logger","warn","message","getFilters","applyFilters","hasFilters","Object","keys","length","setTimeout","history","pushState","url","addParamToUrl","encodeURIComponent","stringify","URL","href","_a","searchParams","delete","toString","emit","changed","resetFilters","childNodes","forEach","widget","handleOptionChange","option","value","type","FilterOptionTypes","RANGE","isChecked","target","checked","VARIANTS","variants","push","val","render","h","Host","onChanged","_d","detail","_b","class","color","onClick","fill","componentDidLoad"],"sources":["src/components/salla-filters/salla-filters.scss?tag=salla-filters","src/components/salla-filters/salla-filters.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n.s-rating-stars-small {\n line-height: 12px;\n}\n.s-filters-radio{\n background-image: none !important;\n}","import { Component, Element, h, Event, EventEmitter, Host, Method, Prop, State } from '@stencil/core';\nimport { Filter, FilterOptionInputType, FilterOptionTypes } from \"./interfaces\";\n\n@Component({\n tag: 'salla-filters',\n styleUrl: 'salla-filters.scss',\n})\nexport class SallaFilters {\n\n constructor() {\n salla.event.on('filters::hidden', () => this.host.style.display = 'none');\n\n salla.lang.onLoaded(() => {\n this.apply = salla.lang.get('pages.checkout.apply');\n this.reset = salla.lang.get('pages.categories.filters_reset');\n });\n\n salla.event.on('filters::fetched', ({ filters }) => {\n this.host.style.display = '';\n let freshFilterData = {};\n this.filters = filters\n .map((filter: Filter) => {\n filter.label = {\n category_id: salla.lang.get('common.titles.categories'),\n brand_id: salla.lang.get('common.titles.brands'),\n rating: salla.lang.get('pages.categories.filter_rating'),\n price: salla.lang.get('pages.categories.filter_price'),\n }[filter.key] || filter.label;\n filter.inputType = FilterOptionInputType.RADIO;//todo:: support FilterOptionInputType.CHECKBOX\n if (filter.key == 'rating') {\n filter.inputType = FilterOptionInputType.RADIO;\n //@ts-ignore\n let { max, min } = filter.values;\n //@ts-ignore\n filter.values = [5, 4, 3, 2, 1].filter(stars => stars >= min || stars <= max)\n }\n\n //when getting new filters, maybe less than we had, so let's get from the old one, only what is existed now.\n if (this.filtersData[filter.key]) {\n freshFilterData[filter.key] = this.filtersData[filter.key];\n }\n\n return filter;\n });\n this.filtersData = freshFilterData;\n });\n }\n\n connectedCallback() {\n try {\n let filters = (new URLSearchParams(window.location.search)).get('filters')\n this.filtersData = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n }\n\n @Element() host: HTMLElement;\n\n /**\n * Array of filter options\n */\n @Prop({ reflect: true, mutable: true }) filters?: Filter[];\n\n private isReady = false;//to avoid triggering the changed event\n\n @State() isSidebarOpen: boolean;\n @State() filtersData: object|any = {}\n @State() apply: string;\n @State() reset: string;\n\n /**\n * Custom event fired when the selected filters are changed.\n */\n @Event() changed: EventEmitter;\n\n /**\n * Method to get filter data.\n */\n @Method()\n async getFilters() {\n return this.filtersData;\n }\n\n /**\n * Apply filter action.\n */\n @Method()\n async applyFilters() {\n if (!this.isReady) {\n return;\n }\n let hasFilters = Object.keys(this.filtersData).length > 0;\n setTimeout(() => {\n if (hasFilters) {\n window.history.pushState({}, '', salla.url.addParamToUrl('filters', encodeURIComponent(JSON.stringify(this.filtersData))));\n } else {\n let url = new URL(window.location.href);\n url.searchParams?.delete('filters');\n window.history.pushState({}, '', url.toString());\n }\n salla.event.emit('salla-filters::changed', this.filtersData);\n this.changed.emit(this.filtersData);\n }, 300);\n }\n\n /**\n * Reset selected filters.\n */\n @Method()\n async resetFilters() {\n this.filtersData = {};\n this.host.childNodes.forEach((widget: HTMLSallaFiltersWidgetElement) => widget.reset && widget.reset())\n salla.event.emit('salla-filters::reset');\n return this.applyFilters();\n }\n\n\n /**\n * @param {{target:HTMLInputElement}} event\n * @param option\n * @param value\n * @private\n */\n private handleOptionChange(event, option: Filter, value) {\n if (option.type === FilterOptionTypes.RANGE) {\n this.filtersData[option.key] = value;\n return;\n }\n let isChecked = event.target.checked;\n\n if(option.type === FilterOptionTypes.VARIANTS){\n this.filtersData.variants=this.filtersData.variants||{};\n isChecked && (this.filtersData.variants[option.key] = value);\n isChecked || (delete this.filtersData.variants[option.key]);\n return;\n }\n \n if (event.target.type == FilterOptionInputType.RADIO) {\n isChecked && (this.filtersData[option.key] = value);\n isChecked || (delete this.filtersData[option.key]);\n return;\n }\n\n //it's checkbox\n this.filtersData[option.key] = this.filtersData[option.key] || [];\n if (isChecked) {\n this.filtersData[option.key].push(value);\n return;\n }\n this.filtersData[option.key] = this.filtersData[option.key].filter(val => val != value);\n }\n\n render() {\n return <Host>\n {this.filters?.map(option => <salla-filters-widget\n option={option}\n filtersData={this.filtersData}\n onChanged={({ detail: { event, option, value } }) => this.handleOptionChange(event, option, value)} />)}\n\n {this.filters?.length? <div class=\"s-filters-footer\">\n <salla-button color='primary' onClick={() => this.applyFilters()}>{this.apply}</salla-button>\n <salla-button color='gray' fill='outline' onClick={() => this.resetFilters()}>{this.reset}</salla-button>\n </div>:''}\n </Host>;\n }\n\n componentDidLoad() {\n this.isReady = true;\n }\n}\n\n"],"mappings":";;;2NAAA,IAAMA,EAAkB,gH,ICOXC,EAAYC,EAAA,2BAEvB,SAAAC,EAAAC,GAAA,IAAAC,EAAAC,K,2CAuDQA,KAAAC,QAAU,M,qEA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as e,g as h}from"./p-c76c4ed2.js";import{H as l}from"./p-431fcc73.js";import{a,F as n}from"./p-d3cc3770.js";const r=":host{display:block}";const o=class{constructor(i){s(this,i);this.changed=t(this,"changed",7);this.initHeight=195;this.widgetTitle=undefined;this.withLoadMore=undefined;this.filtersData=undefined;this.option=undefined;this.isOpen=true;this.isShowMore=false;this.showMoreLabel="عرض المزيد";this.showLessLabel="عرض أقل"}connectedCallback(){this.withLoadMore=this.option.key!="price"&&Array.isArray(this.option.values)&&this.option.values.length>8;this.widgetTitle=this.option.label;salla.lang.onLoaded((()=>{this.showMoreLabel=salla.lang.getWithDefault("common.titles.more",this.showMoreLabel);this.showLessLabel=salla.lang.getWithDefault("common.elements.show_less",this.showLessLabel)}))}componentDidLoad(){this.widgetValues.scrollHeight<this.initHeight&&(this.withLoadMore=false);this.withLoadMore&&this.widgetValues&&(this.widgetValues.style.maxHeight=`${this.initHeight}px`);this.widgetContent.style.height=`${this.widgetContent.scrollHeight}px`}async reset(){if(this.option.type===a.RANGE){this.priceRange.reset()}Array.from(this.host.querySelectorAll("input")).forEach((s=>s.checked=false))}async showMore(){this.isShowMore=!this.isShowMore;this.widgetContent.style.height="auto";this.widgetValues.style.maxHeight=this.isShowMore?`${this.widgetValues.scrollHeight}px`:`${this.initHeight}px`;setTimeout((()=>{this.widgetContent.style.height=`${this.widgetContent.scrollHeight}px`}),400)}async toggleWidget(){this.isOpen=!this.isOpen;l.toggleElementClassIf(this.widgetContent,"s-filters-widget-opened","s-filters-widget-closed",(()=>this.isOpen))}renderFilterOption(s){if(![a.VALUES,a.MINIMUM,a.VARIANTS].includes(s.type)){return""}return s.values.map(((t,e)=>{let h=typeof t=="number"?t:t.key||t.value;return i("label",{class:"s-filters-label",htmlFor:`${s.key}-option-${e}`},i("input",{id:`${s.key}-option-${e}`,name:s.key,type:s.inputType,checked:this.isSelectedOption(s,h),class:`s-filters-${s.inputType}`,onChange:t=>this.changed.emit({event:t,option:s,value:h})}),this.getOptionLabel(s,t))}))}isSelectedOption(s,t){if(!this.filtersData||!this.filtersData[s.key]){return false}return s.inputType===n.CHECKBOX?this.filtersData[s.key].includes(t):this.filtersData[s.key]==t}getOptionLabel(s,t){if(s.key=="rating"){return i("salla-rating-stars",{size:"small",value:t})}let e=t.value||"null";return i("span",{class:"s-filters-option-name"},e)}render(){return i(e,{class:"s-filters-widget-container"},i("h3",{class:"s-filters-widget-title",onClick:()=>this.toggleWidget()},i("span",null,this.widgetTitle),i("span",{class:`s-filters-widget-plusminus ${this.isOpen?"s-filters-widget-plusminus-active":""}`})),i("div",{class:"s-filters-widget-content",ref:s=>this.widgetContent=s},i("div",{class:"s-filters-widget-values",ref:s=>this.widgetValues=s},i("slot",null),this.option.type!==a.RANGE?this.renderFilterOption(this.option):i("salla-price-range",{onChanged:s=>this.changed.emit(s.detail),ref:s=>this.priceRange=s,filtersData:this.filtersData,option:this.option})),this.withLoadMore&&i("a",{class:"s-filters-widget-more",onClick:()=>this.showMore()},!this.isShowMore?this.showMoreLabel:this.showLessLabel)))}get host(){return h(this)}};o.style=r;export{o as salla_filters_widget};
5
- //# sourceMappingURL=p-1342a68f.entry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["sallaFiltersWidgetCss","SallaFiltersWidget","this","initHeight","connectedCallback","withLoadMore","option","key","Array","isArray","values","length","widgetTitle","label","salla","lang","onLoaded","showMoreLabel","getWithDefault","showLessLabel","componentDidLoad","widgetValues","scrollHeight","style","maxHeight","widgetContent","height","async","type","FilterOptionTypes","RANGE","priceRange","reset","from","host","querySelectorAll","forEach","input","checked","isShowMore","setTimeout","isOpen","Helper","toggleElementClassIf","renderFilterOption","VALUES","MINIMUM","VARIANTS","includes","map","filterOption","index","value","h","class","htmlFor","id","name","inputType","isSelectedOption","onChange","e","changed","emit","event","getOptionLabel","filtersData","FilterOptionInputType","CHECKBOX","size","render","Host","onClick","toggleWidget","ref","el","onChanged","detail","price","showMore"],"sources":["./src/components/salla-filters-widget/salla-filters-widget.scss?tag=salla-filters-widget","./src/components/salla-filters-widget/salla-filters-widget.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import {Component, Host, h, Method, State, Prop, Event, Element} from '@stencil/core';\nimport Helper from '../../Helpers/Helper';\nimport {Filter, FilterOptionInputType, FilterOptionTypes} from \"../salla-filters/interfaces\";\n\n@Component({\n tag: 'salla-filters-widget',\n styleUrl: 'salla-filters-widget.scss',\n})\nexport class SallaFiltersWidget {\n @Element() host: HTMLElement;\n\n\n /**\n * Widget title.\n */\n @Prop({mutable: true}) widgetTitle: string;\n\n /**\n * Show more or less filter options.\n */\n @Prop({mutable: true}) withLoadMore: boolean;\n\n /**\n * Selected filter options value.\n */\n @Prop({reflect: true}) filtersData: object;\n\n /**\n * Filter option along with possible values.\n */\n @Prop({reflect: true}) option: Filter;\n\n\n priceRange: HTMLSallaPriceRangeElement\n\n\n private widgetValues: HTMLElement;\n private widgetContent: HTMLDivElement;\n private initHeight: number = 195;\n\n @State() isOpen: boolean = true;\n @State() isShowMore: boolean = false;\n @State() showMoreLabel: string=\"عرض المزيد\";\n @State() showLessLabel: string=\"عرض أقل\";\n\n /**\n * Custom event emitted up on filter option selection changes.\n */\n @Event() changed: any;\n\n connectedCallback() {\n //lets be smart and don't show 5 and more link for 8 options\n this.withLoadMore = this.option.key!='price' && Array.isArray(this.option.values) && this.option.values.length > 8;\n this.widgetTitle = this.option.label;\n salla.lang.onLoaded(() => {\n this.showMoreLabel=salla.lang.getWithDefault('common.titles.more', this.showMoreLabel)\n this.showLessLabel=salla.lang.getWithDefault('common.elements.show_less', this.showLessLabel)\n })\n }\n\n componentDidLoad() {\n this.widgetValues.scrollHeight < this.initHeight && (this.withLoadMore = false);\n (this.withLoadMore && this.widgetValues) && (this.widgetValues.style.maxHeight = `${this.initHeight}px`);\n this.widgetContent.style.height = `${this.widgetContent.scrollHeight}px`;\n }\n\n /**\n * Reset selected filter options.\n */\n @Method()\n async reset() {\n if (this.option.type === FilterOptionTypes.RANGE) {\n this.priceRange.reset()\n }\n Array.from(this.host.querySelectorAll('input')).forEach(input => input.checked = false);\n }\n\n\n /**\n * Action to show more or less filter options.\n */\n @Method()\n async showMore() {\n this.isShowMore = !this.isShowMore\n this.widgetContent.style.height = 'auto';\n this.widgetValues.style.maxHeight = this.isShowMore ? `${this.widgetValues.scrollHeight}px` : `${this.initHeight}px`;\n setTimeout(() => {\n this.widgetContent.style.height = `${this.widgetContent.scrollHeight}px`;\n }, 400); // get height after time of collapse animtion (duration-300)\n }\n\n /**\n * Action to toggle widget open or closed (expand/ collapse).\n */\n @Method()\n async toggleWidget() {\n this.isOpen = !this.isOpen;\n Helper.toggleElementClassIf(this.widgetContent, 's-filters-widget-opened', 's-filters-widget-closed', () => this.isOpen);\n }\n\n renderFilterOption(option: Filter) {\n if (![FilterOptionTypes.VALUES, FilterOptionTypes.MINIMUM, FilterOptionTypes.VARIANTS].includes(option.type)) {\n return '';\n }\n //@ts-ignore\n return option.values.map((filterOption, index) => {\n let value = typeof filterOption == 'number' ? filterOption : (filterOption.key || filterOption.value);\n\n return <label class=\"s-filters-label\" htmlFor={`${option.key}-option-${index}`}>\n <input\n id={`${option.key}-option-${index}`}\n name={option.key}\n type={option.inputType}\n //TODO:: debug more why sometimes it's not rendered as selected🤨\n checked={this.isSelectedOption(option, value)}\n class={`s-filters-${option.inputType}`}\n onChange={e => this.changed.emit({event: e, option: option, value: value})}\n />\n {this.getOptionLabel(option, filterOption)}\n </label>\n }\n )\n }\n\n private isSelectedOption(option: Filter, value) {\n if (!this.filtersData || !this.filtersData[option.key]) {\n return false\n }\n\n return option.inputType === FilterOptionInputType.CHECKBOX\n ? this.filtersData[option.key].includes(value)\n : this.filtersData[option.key] == value;\n }\n\n private getOptionLabel(option: Filter, filterOption) {\n if (option.key == 'rating') {\n //in amazon has stars & up, should we add it, to avoid those people who will come to say I selected 4 why I see 5 sars products\n return <salla-rating-stars size=\"small\" value={filterOption}/>;\n }\n let label = filterOption.value || 'null';\n //label+=filterOption.count ? ` (${salla.helpers.number(filterOption.count)})` : '';\n return <span class=\"s-filters-option-name\">{label}</span>;\n }\n\n render() {\n return (\n <Host class=\"s-filters-widget-container\">\n <h3 class=\"s-filters-widget-title\" onClick={() => this.toggleWidget()}>\n <span>{this.widgetTitle}</span>\n <span class={`s-filters-widget-plusminus ${this.isOpen ? 's-filters-widget-plusminus-active' : ''}`}/>\n </h3>\n <div class=\"s-filters-widget-content\" ref={(el) => this.widgetContent = el}>\n <div class=\"s-filters-widget-values\" ref={(el) => this.widgetValues = el}>\n <slot/>\n {\n this.option.type !== FilterOptionTypes.RANGE\n ? this.renderFilterOption(this.option)\n : <salla-price-range onChanged={(event) => this.changed.emit(event.detail)}\n ref={price => this.priceRange = price}\n filtersData={this.filtersData}\n option={this.option}/>\n }\n </div>\n {this.withLoadMore &&\n <a class=\"s-filters-widget-more\"\n onClick={() => this.showMore()}>{!this.isShowMore ?this.showMoreLabel : this.showLessLabel}</a>\n }\n </div>\n </Host>\n );\n }\n\n}\n"],"mappings":";;;0IAAA,MAAMA,EAAwB,uB,MCQjBC,EAAkB,M,0DA8BrBC,KAAAC,WAAqB,I,oHAEF,K,gBACI,M,mBACA,a,mBACA,S,CAO/BC,oBAEEF,KAAKG,aAAeH,KAAKI,OAAOC,KAAK,SAAWC,MAAMC,QAAQP,KAAKI,OAAOI,SAAWR,KAAKI,OAAOI,OAAOC,OAAS,EACjHT,KAAKU,YAAcV,KAAKI,OAAOO,MAC/BC,MAAMC,KAAKC,UAAS,KAClBd,KAAKe,cAAcH,MAAMC,KAAKG,eAAe,qBAAsBhB,KAAKe,eACxEf,KAAKiB,cAAcL,MAAMC,KAAKG,eAAe,4BAA6BhB,KAAKiB,cAAc,G,CAIjGC,mBACElB,KAAKmB,aAAaC,aAAepB,KAAKC,aAAeD,KAAKG,aAAe,OACxEH,KAAKG,cAAgBH,KAAKmB,eAAkBnB,KAAKmB,aAAaE,MAAMC,UAAY,GAAGtB,KAAKC,gBACzFD,KAAKuB,cAAcF,MAAMG,OAAS,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