UNPKG

@salla.sa/twilight-components

Version:
5 lines 5.86 kB
/*! * Crafted with ❤ by Salla */ import{r as t,c as i,h as s,H as e}from"./p-bdd00808.js";import{a as r}from"./p-91a1d8b6.js";const l=`\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`;const n=":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%}";const h=class{constructor(s){t(this,s);this.changed=i(this,"changed",7);this.filterValues=[];this.minPrice=undefined;this.maxPrice=undefined;this.option=undefined;this.filtersData=undefined;this.min=0;this.max=1e4;this.priceOptions=undefined;this.moreThanLabel="أكثر من";this.lessThanLabel="أقل من";this.toLabel="الى";this.fromLabel="من";this.typing=false;this.isMin=false;this.isRTL=salla.config.get("theme.is_rtl",true)}connectedCallback(){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((()=>{this.moreThanLabel=salla.lang.getWithDefault("common.elements.more_than",this.moreThanLabel);this.lessThanLabel=salla.lang.getWithDefault("common.elements.less_than",this.lessThanLabel);this.toLabel=salla.lang.getWithDefault("common.elements.to",this.toLabel);this.fromLabel=salla.lang.getWithDefault("common.elements.from",this.fromLabel)}));if(this.option.values.length==1){return}if(this.option.values.length<=5){this.filterValues=this.option.values;return}const i=Math.ceil(this.option.values.length/5);for(let t=0;t<this.option.values.length;t+=i){this.filterValues.push(this.option.values.slice(t,t+i).reduce(((t,i)=>{t.to=i.to;t.count+=i.count;return t})))}}async reset(){this.minInput.value=null;this.maxInput.value=null;this.minPrice=null;this.maxPrice=null}getPriceLabel(t){if(isNaN(t.from)||t.from<1){return`${this.lessThanLabel} ${salla.money(t.to)}`}if(isNaN(t.to)||t.to<1){return`${this.moreThanLabel} ${salla.money(t.from)}`}return`${salla.money(t.from)} ${this.toLabel} ${salla.money(t.to)}`}minInputValidation(t){if(t&&(t>this.max||this.maxPrice&&t>this.maxPrice)){return}if(t<this.min){this.minPrice=this.min;return}if(t){this.minPrice=t}}maxInputValidation(t){if(t&&(t<this.min||this.minPrice&&t<this.minPrice)){return}if(t>this.max){this.maxPrice=this.max;return}}async changedEventHandler(t){salla.helpers.inputDigitsOnly(this.minInput);salla.helpers.inputDigitsOnly(this.maxInput);const i=this.minPrice?+this.minPrice*1:null;const s=this.maxPrice?+this.maxPrice*1:null;if(!this.maxPrice){this.maxPrice=""}if(this.isMin){this.minInputValidation(i)}else{if(!this.minPrice){this.minPrice=0}this.maxInputValidation(s)}this.isReady&&this.changed.emit({event:t,option:this.option,value:{max:this.maxPrice,min:this.minPrice}})}handleMinMaxPrice(t,i){this.minPrice=i.from;this.maxPrice=i.to!=="*"?i.to:"";this.changedEventHandler(t)}isChecked(t){if(!this.minPrice&&!this.maxPrice){return false}let i=(t.from<1||t.from=="*")&&this.minPrice==0||t.from==this.minPrice;let s=t.to=="*"||!t.to||t.to==this.maxPrice;return i&&s}handleMinPrice(t){this.isMin=true;const i=t.target.value;this.minPrice=i===""?0:i}handleMaxPrice(t){this.isMin=false;const i=t.target.value;this.maxPrice=i===undefined?"":i}render(){return s(e,null,this.filterValues.map(((t,i)=>s("label",{class:"s-filters-label",htmlFor:`${this.option.key}-${i}`,key:i},s("input",{id:`${this.option.key}-${i}`,name:"price",type:"radio",checked:this.isChecked(t),class:"s-filters-radio",onChange:i=>this.handleMinMaxPrice(i,t)}),s("span",{innerHTML:this.getPriceLabel(t)})))),s("div",{class:"flex justify-center items-center"},s("div",{class:"relative max-w-xl w-full"},s("div",{class:"s-price-range-inputs"},s("div",{class:"s-price-range-relative"},s("div",{class:"s-price-range-currency"}," ",salla.config.currency().symbol),s("input",{type:"number",maxlength:"5",ref:t=>this.minInput=t,onBlur:t=>this.handleMinPrice(t),value:this.minPrice,placeholder:this.fromLabel,class:"s-price-range-number-input"})),s("div",{class:"s-price-range-gray-text"}," -"),s("div",{class:"s-price-range-relative"},s("div",{class:"s-price-range-currency"}," ",salla.config.currency().symbol),s("input",{type:"number",maxlength:"5",ref:t=>this.maxInput=t,onBlur:t=>this.handleMaxPrice(t),value:this.maxPrice,placeholder:this.toLabel,class:"s-price-range-number-input","aria-describedby":"price-currency"})),s("salla-button",{color:"gray",shape:"icon",size:"small",fill:"outline",onClick:t=>this.changedEventHandler(t)},s("span",{innerHTML:this.isRTL?r:l}))))))}componentDidLoad(){this.isReady=true}};h.style=n;export{h as salla_price_range}; //# sourceMappingURL=p-8fb53758.entry.js.map