@tarojs/components
Version:
Taro 组件库。
89 lines (82 loc) • 4.32 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-dd4b7ba3.js');
const index$1 = require('./index-dffbd352.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) {
index.registerInstance(this, hostRef);
this.onChange = index.createEvent(this, "change", 7);
this.onPickStart = index.createEvent(this, "pickstart", 7);
this.onPickEnd = index.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 = index$1.classnames('taro-picker-view-mask-indicator', this.indicatorClass);
const maskTopCls = index$1.classnames('taro-picker-view-mask-top', this.maskClass);
const maskBtmCls = index$1.classnames('taro-picker-view-mask-bottom', this.maskClass);
const indicatorStyle = convertStyle(this.indicatorStyle);
const maskTopStyle = convertStyle(this.maskStyle);
const maskBottomStyle = convertStyle(this.maskStyle);
return (index.h(index.Host, { class: "taro-picker-view-container" }, index.h("slot", null), index.h("div", { class: "taro-picker-view-mask-container" }, index.h("div", { class: maskTopCls, style: maskTopStyle }), index.h("div", { class: indicatorCls, style: indicatorStyle, ref: indicator => (this.indicator = indicator) }), index.h("div", { class: maskBtmCls, style: maskBottomStyle }))));
}
get el() { return index.getElement(this); }
};
PickerView.style = indexCss;
exports.taro_picker_view_core = PickerView;