@ionic/core
Version:
Base components for Ionic
4 lines • 2.65 kB
JavaScript
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
import{r as s,d as e,h as t,f as o,g as i}from"./p-BpRUsN_W.js";import{i as l}from"./p-Dojwmvde.js";const n=class{constructor(t){s(this,t),this.ionSegmentViewScroll=e(this,"ionSegmentViewScroll",7),this.scrollEndTimeout=null,this.isTouching=!1,this.disabled=!1,this.swipeGesture=!0}handleScroll(s){const{scrollLeft:e,scrollWidth:t,clientWidth:o}=s.target,i=t-o,n=(l(this.el)?-1:1)*(e/i);this.ionSegmentViewScroll.emit({scrollRatio:n,isManualScroll:this.isManualScroll??!0}),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,e=!0){const t=this.getSegmentContents().findIndex((e=>e.id===s));if(-1===t)return;this.isManualScroll=!1,this.resetScrollEndTimeout();const o=t*this.el.offsetWidth;this.el.scrollTo({top:0,left:(l(this.el)?-1:1)*o,behavior:e?"smooth":"instant"})}getSegmentContents(){return Array.from(this.el.querySelectorAll("ion-segment-content"))}render(){const{disabled:s,isManualScroll:e,swipeGesture:i}=this;return t(o,{key:"b3cd48fead5d2877ead68cf6d81955fc31530c7a",class:{"segment-view-disabled":s,"segment-view-scroll-disabled":!1===e,"segment-view-swipe-disabled":!1===i}},t("slot",{key:"ad5aa8b79790c490e13438afa0cbb2c241eab0a1"}))}get el(){return i(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),:host(.segment-view-swipe-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),:host(.segment-view-swipe-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}