UNPKG

@tarojs/components

Version:
1 lines 5.6 kB
import{r as registerInstance,c as createEvent,h,g as getElement,H as Host}from"./index-ab3c86da.js";import{d as debounce}from"./index-a00a7418.js";import{c as classnames}from"./index-c3e4004b.js";function convertStyle(e){if(e){var t=/([\w-]*)\s*:\s*([^;]*)/g;var i={};var n=void 0;while(n=t.exec(e))i["".concat(n[1])]=n[2].trim();return i}}var columnCss=".taro-picker-view-column-container{text-align:center;-ms-flex-direction:column;flex-direction:column;-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;position:relative;overflow:hidden scroll}.taro-picker-view-column-container::-webkit-scrollbar{display:none}";var PickerViewColumn=function(){function e(e){var t=this;registerInstance(this,e);this.onChange=createEvent(this,"onselect",7);this.onSelectStart=createEvent(this,"onselectstart",7);this.onSelectEnd=createEvent(this,"onselectend",7);this.handleSelected=debounce((function(){var e=t.el.childNodes;var i=0;var n="0";for(var o in e){var r=e[o];var a=r.offsetHeight;if(i+a/2>t.el.scrollTop){n=o;break}i+=a}t.el.scrollTo({top:i,behavior:"smooth"});t.onChange.emit({curIndex:t.col,selectedIndex:n});t.onSelectEnd.emit()}),500);this.col=undefined;this.initialPosition="0";this.paddingVertical=0;this.isInit=false}e.prototype.onTouchStart=function(){this.onSelectStart.emit()};e.prototype.onTouchEnd=function(){this.handleSelected()};e.prototype.componentDidLoad=function(){this.handleChange()};e.prototype.componentDidUpdate=function(){this.handleChange()};e.prototype.handleChange=function(){var e=this.el.childNodes;var t=0;var i=0;for(var n in e){var o=e[n];if(this.initialPosition===n||!o||typeof o.offsetHeight!=="number"){break}i+=o.offsetHeight;t++}this.el.scrollTo({top:i});if(t>=e.length){this.onChange.emit({curIndex:this.col,selectedIndex:t-1})}};e.prototype.render=function(){var e=this.paddingVertical,t=e===void 0?0:e;return h(Host,{class:"taro-picker-view-column-container",style:{"padding-top":"".concat(t,"px"),"padding-bottom":"".concat(t,"px")}})};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();PickerViewColumn.style=columnCss;var indexCss=".taro-picker-view-container{display:-ms-flexbox;display:flex;position:relative}.taro-picker-view-mask-container{pointer-events:none;-ms-flex-direction:column;flex-direction:column;display:-ms-flexbox;display:flex;position:absolute;inset:0}.taro-picker-view-mask-indicator{border-top:1px solid #ddd;border-bottom:1px solid #ddd;height:50px;display:-ms-flexbox;display:flex}.taro-picker-view-mask-top{background-image:-webkit-gradient(linear,left top, left bottom,from(rgba(255,255,255,.95)),to(rgba(255,255,255,.6)));background-image:linear-gradient(rgba(255,255,255,.95),rgba(255,255,255,.6));-ms-flex:1;flex:1}.taro-picker-view-mask-bottom{background:-webkit-gradient(linear,left top, left bottom,from(rgba(255,255,255,.6)),to(rgba(255,255,255,.95)));background:linear-gradient(rgba(255,255,255,.6),rgba(255,255,255,.95));-ms-flex:1;flex:1}";var PickerView=function(){function e(e){registerInstance(this,e);this.onChange=createEvent(this,"change",7);this.onPickStart=createEvent(this,"pickstart",7);this.onPickEnd=createEvent(this,"pickend",7);this.indicatorStyle=undefined;this.indicatorClass=undefined;this.value=undefined;this.maskStyle=undefined;this.maskClass=undefined}e.prototype.onPropsChange=function(){this.handleValueChange()};e.prototype.onSelect=function(e){e.stopPropagation();if(e.target.tagName!=="TARO-PICKER-VIEW-COLUMN-CORE")return;var t=+e.detail.curIndex;var i=+e.detail.selectedIndex;this.value[t]=i;this.onChange.emit({value:this.value})};e.prototype.onSelectStart=function(e){e.stopPropagation();if(e.target.tagName!=="TARO-PICKER-VIEW-COLUMN-CORE")return;this.onPickStart.emit()};e.prototype.onPickerColEnd=function(e){e.stopPropagation();if(e.target.tagName!=="TARO-PICKER-VIEW-COLUMN-CORE")return;this.onPickEnd.emit()};e.prototype.componentDidLoad=function(){this.handleValueChange()};e.prototype.handleValueChange=function(){var e=this;var t=this.el.querySelectorAll("taro-picker-view-column-core");t.forEach((function(t,i){var n;t.setAttribute("col","".concat(i));var o=0;if(!!e.value&&e.value.length>i){o=e.value[i]}var r=e.el.getBoundingClientRect().height;var a=((n=e.indicator)===null||n===void 0?void 0:n.offsetHeight)||0;var s=(r-a)/2;t.setAttribute("initial-position","".concat(o));t.setAttribute("padding-vertical","".concat(s))}))};e.prototype.componentDidRender=function(){var e=this;this.el.childNodes.forEach((function(t){var i=t;if("TARO-PICKER-VIEW-COLUMN-CORE"!==i.tagName&&i.className!=="taro-picker-view-mask-container"){e.el.removeChild(t)}}))};e.prototype.render=function(){var e=this;var t=classnames("taro-picker-view-mask-indicator",this.indicatorClass);var i=classnames("taro-picker-view-mask-top",this.maskClass);var n=classnames("taro-picker-view-mask-bottom",this.maskClass);var o=convertStyle(this.indicatorStyle);var r=convertStyle(this.maskStyle);var a=convertStyle(this.maskStyle);return h(Host,{class:"taro-picker-view-container"},h("slot",null),h("div",{class:"taro-picker-view-mask-container"},h("div",{class:i,style:r}),h("div",{class:t,style:o,ref:function(t){return e.indicator=t}}),h("div",{class:n,style:a})))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{value:["onPropsChange"]}},enumerable:false,configurable:true});return e}();PickerView.style=indexCss;export{PickerViewColumn as taro_picker_view_column_core,PickerView as taro_picker_view_core};