UNPKG

@tarojs/components

Version:
85 lines (80 loc) 4.21 kB
import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-5bd7cbab.js'; import { c as classnames } from './index-cd1a2d33.js'; function convertStyle(style) { if (style) { const regex = /([\w-]*)\s*:\s*([^;]*)/g; const properties = {}; let match; while ((match = regex.exec(style))) properties[`${match[1]}`] = match[2].trim(); return properties; } } const indexCss = ".taro-picker-view-container{display:-ms-flexbox;display:flex;position:relative}.taro-picker-view-mask-container{display:-ms-flexbox;display:flex;position:absolute;left:0;right:0;top:0;bottom:0;-ms-flex-direction:column;flex-direction:column;pointer-events:none}.taro-picker-view-mask-indicator{display:-ms-flexbox;display:flex;border-top:1px solid #ddd;border-bottom:1px solid #ddd;height:50px}.taro-picker-view-mask-top{-ms-flex:1;flex:1;background-image:-webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0.95)), to(rgba(255, 255, 255, 0.6)));background-image:linear-gradient(to bottom, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.6))}.taro-picker-view-mask-bottom{-ms-flex:1;flex:1;background:-webkit-gradient(linear, left bottom, left top, from(rgba(255, 255, 255, 0.95)), to(rgba(255, 255, 255, 0.6)));background:linear-gradient(to top, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.6))}"; let PickerView = class { constructor(hostRef) { registerInstance(this, hostRef); this.onChange = createEvent(this, "change", 7); this.onPickStart = createEvent(this, "pickstart", 7); this.onPickEnd = createEvent(this, "pickend", 7); } onSelect(e) { e.stopPropagation(); if (e.target.tagName !== 'TARO-PICKER-VIEW-COLUMN-CORE') return; let _curIndex = +e.detail.curIndex; let _selectedIndex = +e.detail.selectedIndex; this.value[_curIndex] = _selectedIndex; this.onChange.emit({ value: this.value }); } onSelectStart(e) { e.stopPropagation(); if (e.target.tagName !== 'TARO-PICKER-VIEW-COLUMN-CORE') return; this.onPickStart.emit(); } onPickerColEnd(e) { e.stopPropagation(); if (e.target.tagName !== 'TARO-PICKER-VIEW-COLUMN-CORE') return; this.onPickEnd.emit(); } componentDidLoad() { const childList = this.el.querySelectorAll('taro-picker-view-column-core'); childList.forEach((element, index) => { var _a; element.setAttribute('col', `${index}`); let selectIndex = '0'; if (!!this.value && this.value.length > index) { selectIndex = `${this.value[index]}`; } const pickerHeight = this.el.getBoundingClientRect().height; const indicatorHeight = ((_a = this.indicator) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0; const paddingVertical = (pickerHeight - indicatorHeight) / 2.0; element.setAttribute('initial-position', `${selectIndex}`); element.setAttribute('padding-vertical', `${paddingVertical}`); }); } // 过滤非 PickerViewColumn 组件 componentDidRender() { this.el.childNodes.forEach(item => { const childEle = item; if ('TARO-PICKER-VIEW-COLUMN-CORE' !== childEle.tagName && childEle.className !== 'taro-picker-view-mask-container') { this.el.removeChild(item); } }); } render() { const indicatorCls = classnames('taro-picker-view-mask-indicator', this.indicatorClass); const maskTopCls = classnames('taro-picker-view-mask-top', this.maskClass); const maskBtmCls = classnames('taro-picker-view-mask-bottom', this.maskClass); const indicatorStyle = convertStyle(this.indicatorStyle); const maskTopStyle = convertStyle(this.maskStyle); const maskBottomStyle = 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: maskTopCls, style: maskTopStyle }), h("div", { class: indicatorCls, style: indicatorStyle, ref: indicator => (this.indicator = indicator) }), h("div", { class: maskBtmCls, style: maskBottomStyle })))); } get el() { return getElement(this); } }; PickerView.style = indexCss; export { PickerView as taro_picker_view_core };