UNPKG

@ionic/core

Version:
4 lines 3.28 kB
import{__awaiter,__generator}from"tslib"; /*! * (C) Ionic http://ionicframework.com - MIT License */import{r as registerInstance,c as createEvent,h,e as Host,f as getElement}from"./index-527b9e34.js";var segmentViewIosCss=":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}";var IonSegmentViewIosStyle0=segmentViewIosCss;var segmentViewMdCss=":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}";var IonSegmentViewMdStyle0=segmentViewMdCss;var SegmentView=function(){function e(e){registerInstance(this,e);this.ionSegmentViewScroll=createEvent(this,"ionSegmentViewScroll",7);this.scrollEndTimeout=null;this.isTouching=false;this.disabled=false;this.isManualScroll=undefined}e.prototype.handleScroll=function(e){var t;var s=e.target,n=s.scrollLeft,i=s.scrollWidth,o=s.clientWidth;var r=n/(i-o);this.ionSegmentViewScroll.emit({scrollRatio:r,isManualScroll:(t=this.isManualScroll)!==null&&t!==void 0?t:true});this.resetScrollEndTimeout()};e.prototype.handleScrollStart=function(){if(this.scrollEndTimeout){clearTimeout(this.scrollEndTimeout);this.scrollEndTimeout=null}this.isTouching=true};e.prototype.handleTouchEnd=function(){this.isTouching=false};e.prototype.resetScrollEndTimeout=function(){var e=this;if(this.scrollEndTimeout){clearTimeout(this.scrollEndTimeout);this.scrollEndTimeout=null}this.scrollEndTimeout=setTimeout((function(){e.checkForScrollEnd()}),100)};e.prototype.checkForScrollEnd=function(){if(!this.isTouching){this.isManualScroll=undefined}};e.prototype.setContent=function(e){return __awaiter(this,arguments,void 0,(function(e,t){var s,n,i;if(t===void 0){t=true}return __generator(this,(function(o){s=this.getSegmentContents();n=s.findIndex((function(t){return t.id===e}));if(n===-1)return[2];this.isManualScroll=false;this.resetScrollEndTimeout();i=this.el.offsetWidth;this.el.scrollTo({top:0,left:n*i,behavior:t?"smooth":"instant"});return[2]}))}))};e.prototype.getSegmentContents=function(){return Array.from(this.el.querySelectorAll("ion-segment-content"))};e.prototype.render=function(){var e=this,t=e.disabled,s=e.isManualScroll;return h(Host,{key:"fa528d2d9ae0f00fc3067defe2a047dce77c814a",class:{"segment-view-disabled":t,"segment-view-scroll-disabled":s===false}},h("slot",{key:"74dc8b4d073caeff1bab272d11b9ea3e1a215954"}))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();SegmentView.style={ios:IonSegmentViewIosStyle0,md:IonSegmentViewMdStyle0};export{SegmentView as ion_segment_view};