@tarojs/components
Version:
1 lines • 4.04 kB
JavaScript
import{r as t,c as i,h as e,g as s,H as o}from"./p-d0cabaaa.js";import{d as r}from"./p-5893c3ed.js";import{c as n}from"./p-160d710a.js";function a(t){if(t){const i=/([\w-]*)\s*:\s*([^;]*)/g,e={};let s;for(;s=i.exec(t);)e[`${s[1]}`]=s[2].trim();return e}}const c=class{constructor(e){t(this,e),this.onChange=i(this,"onselect",7),this.onSelectStart=i(this,"onselectstart",7),this.onSelectEnd=i(this,"onselectend",7),this.handleSelected=r((()=>{const t=this.el.childNodes;let i=0,e="0";for(const s in t){const o=t[s].offsetHeight;if(i+o/2>this.el.scrollTop){e=s;break}i+=o}this.el.scrollTo({top:i,behavior:"smooth"}),this.onChange.emit({curIndex:this.col,selectedIndex:e}),this.onSelectEnd.emit()}),500),this.col=void 0,this.initialPosition="0",this.paddingVertical=0,this.isInit=!1}onTouchStart(){this.onSelectStart.emit()}onTouchEnd(){this.handleSelected()}componentDidLoad(){this.handleChange()}componentDidUpdate(){this.handleChange()}handleChange(){const t=this.el.childNodes;let i=0,e=0;for(const s in t){const o=t[s];if(this.initialPosition===s||!o||"number"!=typeof o.offsetHeight)break;e+=o.offsetHeight,i++}this.el.scrollTo({top:e}),i>=t.length&&this.onChange.emit({curIndex:this.col,selectedIndex:i-1})}render(){const{paddingVertical:t=0}=this;return e(o,{class:"taro-picker-view-column-container",style:{"padding-top":`${t}px`,"padding-bottom":`${t}px`}})}get el(){return s(this)}};c.style=".taro-picker-view-column-container{text-align:center;flex-direction:column;flex:1;display:flex;position:relative;overflow:hidden scroll}.taro-picker-view-column-container::-webkit-scrollbar{display:none}";const h=class{constructor(e){t(this,e),this.onChange=i(this,"change",7),this.onPickStart=i(this,"pickstart",7),this.onPickEnd=i(this,"pickend",7),this.indicatorStyle=void 0,this.indicatorClass=void 0,this.value=void 0,this.maskStyle=void 0,this.maskClass=void 0}onPropsChange(){this.handleValueChange()}onSelect(t){t.stopPropagation(),"TARO-PICKER-VIEW-COLUMN-CORE"===t.target.tagName&&(this.value[+t.detail.curIndex]=+t.detail.selectedIndex,this.onChange.emit({value:this.value}))}onSelectStart(t){t.stopPropagation(),"TARO-PICKER-VIEW-COLUMN-CORE"===t.target.tagName&&this.onPickStart.emit()}onPickerColEnd(t){t.stopPropagation(),"TARO-PICKER-VIEW-COLUMN-CORE"===t.target.tagName&&this.onPickEnd.emit()}componentDidLoad(){this.handleValueChange()}handleValueChange(){this.el.querySelectorAll("taro-picker-view-column-core").forEach(((t,i)=>{var e;t.setAttribute("col",`${i}`);let s=0;this.value&&this.value.length>i&&(s=this.value[i]);const o=(this.el.getBoundingClientRect().height-((null===(e=this.indicator)||void 0===e?void 0:e.offsetHeight)||0))/2;t.setAttribute("initial-position",`${s}`),t.setAttribute("padding-vertical",`${o}`)}))}componentDidRender(){this.el.childNodes.forEach((t=>{"TARO-PICKER-VIEW-COLUMN-CORE"!==t.tagName&&"taro-picker-view-mask-container"!==t.className&&this.el.removeChild(t)}))}render(){const t=n("taro-picker-view-mask-indicator",this.indicatorClass),i=n("taro-picker-view-mask-top",this.maskClass),s=n("taro-picker-view-mask-bottom",this.maskClass),r=a(this.indicatorStyle),c=a(this.maskStyle),h=a(this.maskStyle);return e(o,{class:"taro-picker-view-container"},e("slot",null),e("div",{class:"taro-picker-view-mask-container"},e("div",{class:i,style:c}),e("div",{class:t,style:r,ref:t=>this.indicator=t}),e("div",{class:s,style:h})))}get el(){return s(this)}static get watchers(){return{value:["onPropsChange"]}}};h.style=".taro-picker-view-container{display:flex;position:relative}.taro-picker-view-mask-container{pointer-events:none;flex-direction:column;display:flex;position:absolute;inset:0}.taro-picker-view-mask-indicator{border-top:1px solid #ddd;border-bottom:1px solid #ddd;height:50px;display:flex}.taro-picker-view-mask-top{background-image:linear-gradient(rgba(255,255,255,.95),rgba(255,255,255,.6));flex:1}.taro-picker-view-mask-bottom{background:linear-gradient(rgba(255,255,255,.6),rgba(255,255,255,.95));flex:1}";export{c as taro_picker_view_column_core,h as taro_picker_view_core}