UNPKG

2.43 kBJavaScriptView Raw
1import { View, CSSType } from '../core/view';
2import { Property, CoercibleProperty } from '../core/properties';
3let ListPickerBase = class ListPickerBase extends View {
4 _getItemAsString(index) {
5 const items = this.items;
6 if (!items) {
7 return ' ';
8 }
9 const item = this.isItemsSource ? this.items.getItem(index) : this.items[index];
10 return item === undefined || item === null ? index + '' : this.parseItem(item);
11 }
12 parseItem(item) {
13 return this.textField ? item[this.textField] + '' : item + '';
14 }
15 updateSelectedValue(index) {
16 let newVal = null;
17 if (index >= 0) {
18 const item = this.items[index];
19 newVal = this.valueField ? item[this.valueField] : item;
20 }
21 if (this.selectedValue !== newVal) {
22 this.set('selectedValue', newVal);
23 }
24 }
25};
26ListPickerBase = __decorate([
27 CSSType('ListPicker')
28], ListPickerBase);
29export { ListPickerBase };
30ListPickerBase.prototype.recycleNativeView = 'auto';
31export const selectedIndexProperty = new CoercibleProperty({
32 name: 'selectedIndex',
33 defaultValue: -1,
34 valueConverter: (v) => parseInt(v),
35 coerceValue: (target, value) => {
36 const items = target.items;
37 if (items) {
38 const max = items.length - 1;
39 if (value < 0) {
40 value = 0;
41 }
42 if (value > max) {
43 value = max;
44 }
45 }
46 else {
47 value = -1;
48 }
49 target.updateSelectedValue(value);
50 return value;
51 },
52});
53selectedIndexProperty.register(ListPickerBase);
54export const itemsProperty = new Property({
55 name: 'items',
56 valueChanged: (target, oldValue, newValue) => {
57 const getItem = newValue && newValue.getItem;
58 target.isItemsSource = typeof getItem === 'function';
59 },
60});
61itemsProperty.register(ListPickerBase);
62export const textFieldProperty = new Property({
63 name: 'textField',
64 defaultValue: '',
65});
66textFieldProperty.register(ListPickerBase);
67export const valueFieldProperty = new Property({
68 name: 'valueField',
69 defaultValue: '',
70});
71valueFieldProperty.register(ListPickerBase);
72export const selectedValueProperty = new Property({
73 name: 'selectedValue',
74 defaultValue: null,
75});
76selectedValueProperty.register(ListPickerBase);
77//# sourceMappingURL=list-picker-common.js.map
\No newline at end of file