UNPKG

@ionic/core

Version:
4 lines 2.43 kB
/*! * (C) Ionic http://ionicframework.com - MIT License */ import{r as t,d as s,h as e,j as o,k as l}from"./p-B_U9CtaY.js";const n=class{constructor(e){t(this,e),this.ionSegmentViewScroll=s(this,"ionSegmentViewScroll",7),this.scrollEndTimeout=null,this.isTouching=!1,this.disabled=!1}handleScroll(t){var s;const{scrollLeft:e,scrollWidth:o,clientWidth:l}=t.target;this.ionSegmentViewScroll.emit({scrollRatio:e/(o-l),isManualScroll:null===(s=this.isManualScroll)||void 0===s||s}),this.resetScrollEndTimeout()}handleScrollStart(){this.scrollEndTimeout&&(clearTimeout(this.scrollEndTimeout),this.scrollEndTimeout=null),this.isTouching=!0}handleTouchEnd(){this.isTouching=!1}resetScrollEndTimeout(){this.scrollEndTimeout&&(clearTimeout(this.scrollEndTimeout),this.scrollEndTimeout=null),this.scrollEndTimeout=setTimeout((()=>{this.checkForScrollEnd()}),100)}checkForScrollEnd(){this.isTouching||(this.isManualScroll=void 0)}async setContent(t,s=!0){const e=this.getSegmentContents().findIndex((s=>s.id===t));-1!==e&&(this.isManualScroll=!1,this.resetScrollEndTimeout(),this.el.scrollTo({top:0,left:e*this.el.offsetWidth,behavior:s?"smooth":"instant"}))}getSegmentContents(){return Array.from(this.el.querySelectorAll("ion-segment-content"))}render(){const{disabled:t,isManualScroll:s}=this;return e(o,{key:"754a374e89fd4dd682eb00497e717242a6f83357",class:{"segment-view-disabled":t,"segment-view-scroll-disabled":!1===s}},e("slot",{key:"77366044eb61f0d4bba305bd6f0ef8fd1e25194b"}))}get el(){return l(this)}};n.style={ios:":host{display:-ms-flexbox;display:flex;height:100%;overflow-x:scroll;-webkit-scroll-snap-type:x mandatory;-ms-scroll-snap-type:x mandatory;scroll-snap-type:x mandatory;scrollbar-width:none;-ms-overflow-style:none}:host::-webkit-scrollbar{display:none}:host(.segment-view-disabled){-ms-touch-action:none;touch-action:none;overflow-x:hidden}:host(.segment-view-scroll-disabled){pointer-events:none}:host(.segment-view-disabled){opacity:0.3}",md:":host{display:-ms-flexbox;display:flex;height:100%;overflow-x:scroll;-webkit-scroll-snap-type:x mandatory;-ms-scroll-snap-type:x mandatory;scroll-snap-type:x mandatory;scrollbar-width:none;-ms-overflow-style:none}:host::-webkit-scrollbar{display:none}:host(.segment-view-disabled){-ms-touch-action:none;touch-action:none;overflow-x:hidden}:host(.segment-view-scroll-disabled){pointer-events:none}:host(.segment-view-disabled){opacity:0.3}"};export{n as ion_segment_view}