UNPKG

4.21 kBJavaScriptView Raw
1import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-8809c729.js';
2import { c as classnames } from './index-1d8e8acd.js';
3
4function convertStyle(style) {
5 if (style) {
6 const regex = /([\w-]*)\s*:\s*([^;]*)/g;
7 const properties = {};
8 let match;
9 while ((match = regex.exec(style)))
10 properties[`${match[1]}`] = match[2].trim();
11 return properties;
12 }
13}
14
15const 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))}";
16
17let PickerView = class {
18 constructor(hostRef) {
19 registerInstance(this, hostRef);
20 this.onChange = createEvent(this, "change", 7);
21 this.onPickStart = createEvent(this, "pickstart", 7);
22 this.onPickEnd = createEvent(this, "pickend", 7);
23 }
24 onSelect(e) {
25 e.stopPropagation();
26 if (e.target.tagName !== 'TARO-PICKER-VIEW-COLUMN-CORE')
27 return;
28 let _curIndex = +e.detail.curIndex;
29 let _selectedIndex = +e.detail.selectedIndex;
30 this.value[_curIndex] = _selectedIndex;
31 this.onChange.emit({ value: this.value });
32 }
33 onSelectStart(e) {
34 e.stopPropagation();
35 if (e.target.tagName !== 'TARO-PICKER-VIEW-COLUMN-CORE')
36 return;
37 this.onPickStart.emit();
38 }
39 onPickerColEnd(e) {
40 e.stopPropagation();
41 if (e.target.tagName !== 'TARO-PICKER-VIEW-COLUMN-CORE')
42 return;
43 this.onPickEnd.emit();
44 }
45 componentDidLoad() {
46 const childList = this.el.querySelectorAll('taro-picker-view-column-core');
47 childList.forEach((element, index) => {
48 var _a;
49 element.setAttribute('col', `${index}`);
50 let selectIndex = '0';
51 if (!!this.value && this.value.length > index) {
52 selectIndex = `${this.value[index]}`;
53 }
54 const pickerHeight = this.el.getBoundingClientRect().height;
55 const indicatorHeight = ((_a = this.indicator) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
56 const paddingVertical = (pickerHeight - indicatorHeight) / 2.0;
57 element.setAttribute('initial-position', `${selectIndex}`);
58 element.setAttribute('padding-vertical', `${paddingVertical}`);
59 });
60 }
61 // 过滤非 PickerViewColumn 组件
62 componentDidRender() {
63 this.el.childNodes.forEach(item => {
64 const childEle = item;
65 if ('TARO-PICKER-VIEW-COLUMN-CORE' !== childEle.tagName &&
66 childEle.className !== 'taro-picker-view-mask-container') {
67 this.el.removeChild(item);
68 }
69 });
70 }
71 render() {
72 const indicatorCls = classnames('taro-picker-view-mask-indicator', this.indicatorClass);
73 const maskTopCls = classnames('taro-picker-view-mask-top', this.maskClass);
74 const maskBtmCls = classnames('taro-picker-view-mask-bottom', this.maskClass);
75 const indicatorStyle = convertStyle(this.indicatorStyle);
76 const maskTopStyle = convertStyle(this.maskStyle);
77 const maskBottomStyle = convertStyle(this.maskStyle);
78 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 }))));
79 }
80 get el() { return getElement(this); }
81};
82PickerView.style = indexCss;
83
84export { PickerView as taro_picker_view_core };