UNPKG

@ionic/core

Version:
4 lines 2.43 kB
/*! * (C) Ionic http://ionicframework.com - MIT License */ import{r as s,c as t,h as e,d as o,g as l}from"./p-4DxY6_gG.js";const n=class{constructor(e){s(this,e),this.ionSegmentViewScroll=t(this,"ionSegmentViewScroll",7),this.scrollEndTimeout=null,this.isTouching=!1,this.disabled=!1}handleScroll(s){var t;const{scrollLeft:e,scrollWidth:o,clientWidth:l}=s.target;this.ionSegmentViewScroll.emit({scrollRatio:e/(o-l),isManualScroll:null===(t=this.isManualScroll)||void 0===t||t}),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(s,t=!0){const e=this.getSegmentContents().findIndex((t=>t.id===s));-1!==e&&(this.isManualScroll=!1,this.resetScrollEndTimeout(),this.el.scrollTo({top:0,left:e*this.el.offsetWidth,behavior:t?"smooth":"instant"}))}getSegmentContents(){return Array.from(this.el.querySelectorAll("ion-segment-content"))}render(){const{disabled:s,isManualScroll:t}=this;return e(o,{key:"754a374e89fd4dd682eb00497e717242a6f83357",class:{"segment-view-disabled":s,"segment-view-scroll-disabled":!1===t}},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}