UNPKG

@salla.sa/twilight-components

Version:
5 lines 8.64 kB
var __awaiter=this&&this.__awaiter||function(e,t,i,r){function n(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,s){function a(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r["throw"](e))}catch(e){s(e)}}function l(e){e.done?i(e.value):n(e.value).then(a,c)}l((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var i={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,n,s,a;return a={next:c(0),throw:c(1),return:c(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function c(e){return function(t){return l([e,t])}}function l(c){if(r)throw new TypeError("Generator is already executing.");while(a&&(a=0,c[0]&&(i=0)),i)try{if(r=1,n&&(s=c[0]&2?n["return"]:c[0]?n["throw"]||((s=n["return"])&&s.call(n),0):n.next)&&!(s=s.call(n,c[1])).done)return s;if(n=0,s)c=[c[0]&2,s.value];switch(c[0]){case 0:case 1:s=c;break;case 4:i.label++;return{value:c[1],done:false};case 5:i.label++;n=c[1];c=[0];continue;case 7:c=i.ops.pop();i.trys.pop();continue;default:if(!(s=i.trys,s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){i=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){i.label=c[1];break}if(c[0]===6&&i.label<s[1]){i.label=s[1];s=c;break}if(s&&i.label<s[2]){i.label=s[2];i.ops.push(c);break}if(s[2])i.ops.pop();i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e];n=0}finally{r=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:true}}}; /*! * Crafted with ❤ by Salla */import{r as registerInstance,c as createEvent,h,H as Host}from"./index-BrMYHkA5.js";import{a as arrowLeft}from"./arrow-left-BedNk7k1.js";var arrowRight='\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>arrow-right</title>\n<path d="M29.217 15.465c-0.019-0.044-0.056-0.077-0.080-0.119-0.067-0.116-0.139-0.227-0.236-0.317-0.011-0.009-0.013-0.024-0.024-0.033l-10.667-9.333c-0.553-0.484-1.396-0.429-1.881 0.125-0.484 0.555-0.428 1.396 0.127 1.881l7.996 6.997h-20.452c-0.737 0-1.333 0.597-1.333 1.333s0.596 1.333 1.333 1.333h20.452l-7.996 6.997c-0.555 0.485-0.611 1.327-0.127 1.881 0.264 0.3 0.633 0.455 1.004 0.455 0.312 0 0.625-0.109 0.877-0.331l10.667-9.333c0.011-0.009 0.015-0.024 0.024-0.033 0.097-0.091 0.169-0.201 0.236-0.317 0.024-0.041 0.060-0.075 0.080-0.119 0.073-0.163 0.116-0.343 0.116-0.533s-0.043-0.371-0.116-0.535z"></path>\n</svg>\n';var sallaPriceRangeCss=":host{display:block}.rtl .rtl-range-slider,[dir=rtl] .rtl-range-slider{-webkit-transform:rotateY(180deg);transform:rotateY(180deg)}.rtl .rtl-range-numbers,[dir=rtl] .rtl-range-numbers{-ms-flex-direction:row-reverse;flex-direction:row-reverse}.rtl .form-select,.rtl select,[dir=rtl] .form-select,[dir=rtl] select{background-position:left 0.5rem center;padding-right:12px}.rtl .menu-divide li:not(:last-child):after,[dir=rtl] .menu-divide li:not(:last-child):after{left:0;right:auto}input[type=range]::-webkit-slider-thumb{pointer-events:all;width:24px;height:24px;-webkit-appearance:none}[type=checkbox]:checked{background-size:80%}";var SallaPriceRange=function(){function e(e){registerInstance(this,e);this.changed=createEvent(this,"changed");this.min=0;this.max=1e4;this.moreThanLabel="أكثر من";this.lessThanLabel="أقل من";this.toLabel="الى";this.fromLabel="من";this.typing=false;this.isMin=false;this.isRTL=salla.config.get("theme.is_rtl",true);this.filterValues=[]}e.prototype.connectedCallback=function(){var e=this;var t;if(this.filtersData&&((t=this.filtersData)===null||t===void 0?void 0:t.price)){this.minPrice=this.filtersData.price.min;this.maxPrice=this.filtersData.price.max}salla.lang.onLoaded((function(){e.moreThanLabel=salla.lang.getWithDefault("common.elements.more_than",e.moreThanLabel);e.lessThanLabel=salla.lang.getWithDefault("common.elements.less_than",e.lessThanLabel);e.toLabel=salla.lang.getWithDefault("common.elements.to",e.toLabel);e.fromLabel=salla.lang.getWithDefault("common.elements.from",e.fromLabel)}));if(this.option.values.length==1){return}if(this.option.values.length<=5){this.filterValues=this.option.values;return}var i=Math.ceil(this.option.values.length/5);for(var r=0;r<this.option.values.length;r+=i){this.filterValues.push(this.option.values.slice(r,r+i).reduce((function(e,t){e.to=t.to;e.count+=t.count;return e})))}};e.prototype.reset=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){this.minInput.value=null;this.maxInput.value=null;this.minPrice=null;this.maxPrice=null;return[2]}))}))};e.prototype.getPriceLabel=function(e){if(isNaN(e.from)||e.from<1){return"".concat(this.lessThanLabel," ").concat(salla.money(e.to))}if(isNaN(e.to)||e.to<1){return"".concat(this.moreThanLabel," ").concat(salla.money(e.from))}return"".concat(salla.money(e.from)," ").concat(this.toLabel," ").concat(salla.money(e.to))};e.prototype.minInputValidation=function(e){if(e&&(e>this.max||this.maxPrice&&e>this.maxPrice)){return}if(e<this.min){this.minPrice=this.min;return}if(e){this.minPrice=e}};e.prototype.maxInputValidation=function(e){if(e&&(e<this.min||this.minPrice&&e<this.minPrice)){return}if(e>this.max){this.maxPrice=this.max;return}};e.prototype.changedEventHandler=function(e){return __awaiter(this,void 0,void 0,(function(){var t,i;return __generator(this,(function(r){salla.helpers.inputDigitsOnly(this.minInput);salla.helpers.inputDigitsOnly(this.maxInput);t=this.minPrice?+this.minPrice*1:null;i=this.maxPrice?+this.maxPrice*1:null;if(!this.maxPrice){this.maxPrice=""}if(this.isMin){this.minInputValidation(t)}else{if(!this.minPrice){this.minPrice=0}this.maxInputValidation(i)}this.isReady&&this.changed.emit({event:e,option:this.option,value:{max:this.maxPrice,min:this.minPrice}});return[2]}))}))};e.prototype.handleMinMaxPrice=function(e,t){this.minPrice=t.from;this.maxPrice=t.to!=="*"?t.to:"";this.changedEventHandler(e)};e.prototype.isChecked=function(e){if(!this.minPrice&&!this.maxPrice){return false}var t=(e.from<1||e.from=="*")&&this.minPrice==0||e.from==this.minPrice;var i=e.to=="*"||!e.to||e.to==this.maxPrice;return t&&i};e.prototype.handleMinPrice=function(e){this.isMin=true;var t=e.target.value;this.minPrice=t===""?0:t};e.prototype.handleMaxPrice=function(e){this.isMin=false;var t=e.target.value;this.maxPrice=t===undefined?"":t};e.prototype.render=function(){var e=this;return h(Host,{key:"4bbf78038f7e7da06f17d24717726e60b842b272"},this.filterValues.map((function(t,i){return h("label",{class:"s-filters-label",htmlFor:"".concat(e.option.key,"-").concat(i),key:i},h("input",{id:"".concat(e.option.key,"-").concat(i),name:"price",type:"radio",checked:e.isChecked(t),class:"s-filters-radio",onChange:function(i){return e.handleMinMaxPrice(i,t)}}),h("span",{innerHTML:e.getPriceLabel(t)}))})),h("div",{key:"97253ed3be349943cf2595557328a987739b3086",class:"flex justify-center items-center"},h("div",{key:"f4d087f5bef0c07cf01dc071613dc3932bd96670",class:"relative max-w-xl w-full"},h("div",{key:"f806be59df222454c8c709d637203a6e5c6d1fb0",class:"s-price-range-inputs"},h("div",{key:"a86e781533ee820428de9a669cb0737ac3ce33d6",class:"s-price-range-relative"},h("div",{key:"7bf5e038d4eaac20831a866ed478bf2f66694abe",class:"s-price-range-currency"}," ",salla.config.currency().symbol),h("input",{key:"b58f77102c6833adc859d4f345d64f9269549e7c",type:"number",maxlength:"5",ref:function(t){return e.minInput=t},onBlur:function(t){return e.handleMinPrice(t)},value:this.minPrice,placeholder:this.fromLabel,class:"s-price-range-number-input"})),h("div",{key:"2f3a516a52253fadeecaf6e86b14ee202cd67d41",class:"s-price-range-gray-text"}," -"),h("div",{key:"cd4bdc28326a4294c06e5c77c23858900af3799b",class:"s-price-range-relative"},h("div",{key:"b1a1f86fd82a201050ce5036bbdc55faaf9ced54",class:"s-price-range-currency"}," ",salla.config.currency().symbol),h("input",{key:"7e598948746a4260278b59ec7110b0acef60a89c",type:"number",maxlength:"5",ref:function(t){return e.maxInput=t},onBlur:function(t){return e.handleMaxPrice(t)},value:this.maxPrice,placeholder:this.toLabel,class:"s-price-range-number-input","aria-describedby":"price-currency"})),h("salla-button",{key:"a4b33af3ae0353cda9e76c3103aae16f767d37de",color:"gray",shape:"icon",size:"small",fill:"outline",onClick:function(t){return e.changedEventHandler(t)}},h("span",{key:"4e7084ac446928a2f840a80234187b4366428d0b",innerHTML:this.isRTL?arrowLeft:arrowRight}))))))};e.prototype.componentDidLoad=function(){this.isReady=true};return e}();SallaPriceRange.style=sallaPriceRangeCss;export{SallaPriceRange as salla_price_range}; //# sourceMappingURL=salla-price-range.entry.js.map