UNPKG

@evermade/overflow-slider

Version:

Accessible slider that is powered by overflow: auto.

2 lines (1 loc) 2.92 kB
const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return i=>{var r,s,a,l,c,u,d;const v={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(r=null==o?void 0:o.container)&&void 0!==r?r:null,containerPrev:null!==(s=null==o?void 0:o.containerPrev)&&void 0!==s?s:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null,movementType:null!==(l=null==o?void 0:o.movementType)&&void 0!==l?l:"view"},b=document.createElement("div");b.classList.add(v.classNames.navContainer);const p=document.createElement("button");p.setAttribute("class",v.classNames.prevButton),p.setAttribute("type","button"),p.setAttribute("aria-label",v.texts.buttonPrevious),p.setAttribute("aria-controls",null!==(c=i.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","prev"),p.innerHTML=i.options.rtl?v.icons.next:v.icons.prev,p.addEventListener("click",()=>{"true"===p.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("prev"):i.moveToDirection("prev"))});const h=document.createElement("button");h.setAttribute("class",v.classNames.nextButton),h.setAttribute("type","button"),h.setAttribute("aria-label",v.texts.buttonNext),h.setAttribute("aria-controls",null!==(u=i.container.getAttribute("id"))&&void 0!==u?u:""),h.setAttribute("data-type","next"),h.innerHTML=i.options.rtl?v.icons.prev:v.icons.next,h.addEventListener("click",()=>{"true"===h.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("next"):i.moveToDirection("next"))}),b.appendChild(p),b.appendChild(h);const m=()=>{const t=i.getScrollLeft(),e=i.getInclusiveScrollWidth(),n=i.getInclusiveClientWidth();0===Math.floor(t)?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?h.setAttribute("data-has-content","false"):h.setAttribute("data-has-content","true")};v.containerNext&&v.containerPrev?(v.containerPrev.appendChild(p),v.containerNext.appendChild(h)):v.container?v.container.appendChild(b):null===(d=i.container.parentNode)||void 0===d||d.insertBefore(b,i.container.nextSibling),m(),i.on("scrollEnd",m),i.on("contentsChanged",m),i.on("containerSizeChanged",m)}}export{o as default};