@limetech/lime-elements 33.14.0-next.11 → 33.14.0-next.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/component-f7ef9087.js +2365 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/limel-list_2.cjs.entry.js +497 -0
- package/dist/cjs/limel-menu-list.cjs.entry.js +885 -0
- package/dist/cjs/limel-menu.cjs.entry.js +4 -4
- package/dist/cjs/limel-portal.cjs.entry.js +1935 -0
- package/dist/cjs/limel-tooltip-content.cjs.entry.js +5 -2
- package/dist/cjs/limel-tooltip.cjs.entry.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/header/header.js +0 -1
- package/dist/collection/components/list/list-renderer.js +161 -163
- package/dist/collection/components/list/list.css +0 -10
- package/dist/collection/components/list/list.js +77 -125
- package/dist/collection/components/menu/menu.js +9 -9
- package/dist/collection/components/menu-list/menu-list-renderer-config.js +1 -0
- package/dist/collection/components/menu-list/menu-list-renderer.js +158 -0
- package/dist/collection/components/menu-list/menu-list.css +3397 -0
- package/dist/collection/components/menu-list/menu-list.js +288 -0
- package/dist/collection/components/menu-list/menu-list.types.js +1 -0
- package/dist/collection/components/menu-surface/menu-surface.js +84 -87
- package/dist/collection/components/popover/popover.js +0 -1
- package/dist/collection/components/tooltip/tooltip-content.css +25 -13
- package/dist/collection/components/tooltip/tooltip-content.js +4 -3
- package/dist/collection/components/tooltip/tooltip.css +0 -6
- package/dist/collection/components/tooltip/tooltip.js +31 -5
- package/dist/esm/component-2eb4e07b.js +2357 -0
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/limel-list_2.entry.js +492 -0
- package/dist/esm/limel-menu-list.entry.js +881 -0
- package/dist/esm/limel-menu.entry.js +4 -4
- package/dist/esm/limel-portal.entry.js +1931 -0
- package/dist/esm/limel-tooltip-content.entry.js +5 -2
- package/dist/esm/limel-tooltip.entry.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/p-31299106.js +126 -0
- package/dist/lime-elements/p-6ea02589.entry.js +82 -0
- package/dist/lime-elements/{p-b0b18dfc.entry.js → p-8e4e13b3.entry.js} +1 -1
- package/dist/lime-elements/p-aeada929.entry.js +1 -0
- package/dist/lime-elements/{p-63e4f918.entry.js → p-cd5e3858.entry.js} +1 -1
- package/dist/lime-elements/p-d3aefa5f.entry.js +1 -0
- package/dist/lime-elements/p-f8c33335.entry.js +1 -0
- package/dist/types/components/header/header.d.ts +0 -1
- package/dist/types/components/list/list-item.types.d.ts +2 -1
- package/dist/types/components/list/list-renderer-config.d.ts +0 -1
- package/dist/types/components/list/list-renderer.d.ts +0 -1
- package/dist/types/components/list/list.d.ts +0 -7
- package/dist/types/components/list/list.types.d.ts +1 -1
- package/dist/types/components/menu/menu.d.ts +2 -3
- package/dist/types/components/menu/menu.types.d.ts +35 -3
- package/dist/types/components/menu-list/menu-list-renderer-config.d.ts +8 -0
- package/dist/types/components/menu-list/menu-list-renderer.d.ts +49 -0
- package/dist/types/components/menu-list/menu-list.d.ts +59 -0
- package/dist/types/components/menu-list/menu-list.types.d.ts +6 -0
- package/dist/types/components/menu-surface/menu-surface.d.ts +0 -1
- package/dist/types/components/popover/popover.d.ts +0 -1
- package/dist/types/components/tooltip/tooltip-content.d.ts +1 -1
- package/dist/types/components/tooltip/tooltip.d.ts +31 -5
- package/dist/types/components.d.ts +66 -5
- package/dist/types/interface.d.ts +1 -0
- package/package.json +2 -1
- package/dist/cjs/limel-list_3.cjs.entry.js +0 -5418
- package/dist/esm/limel-list_3.entry.js +0 -5412
- package/dist/lime-elements/p-a6a7dd00.entry.js +0 -1
- package/dist/lime-elements/p-e078c459.entry.js +0 -177
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { MDCList } from '@material/list';
|
|
2
|
-
import { MDCMenu } from '@material/menu';
|
|
3
2
|
import { MDCRipple } from '@material/ripple';
|
|
4
3
|
import { strings as listStrings } from '@material/list/constants';
|
|
5
|
-
import { strings as menuStrings } from '@material/menu/constants';
|
|
6
4
|
import { Component, Element, Event, h, Host, Prop, Watch, } from '@stencil/core';
|
|
7
5
|
import { ListRenderer } from './list-renderer';
|
|
8
6
|
const { ACTION_EVENT } = listStrings;
|
|
9
|
-
const { SELECTED_EVENT } = menuStrings;
|
|
10
7
|
/**
|
|
11
8
|
* @exampleComponent limel-example-list
|
|
12
9
|
* @exampleComponent limel-example-list-secondary
|
|
@@ -37,8 +34,81 @@ export class List {
|
|
|
37
34
|
// eslint-disable-next-line no-magic-numbers
|
|
38
35
|
this.maxLinesSecondaryText = 3;
|
|
39
36
|
this.listRenderer = new ListRenderer();
|
|
40
|
-
this.
|
|
41
|
-
|
|
37
|
+
this.setup = () => {
|
|
38
|
+
this.setupList();
|
|
39
|
+
this.setupListeners();
|
|
40
|
+
};
|
|
41
|
+
this.setupList = () => {
|
|
42
|
+
const element = this.element.shadowRoot.querySelector('.mdc-deprecated-list');
|
|
43
|
+
if (!element) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.mdcList = new MDCList(element);
|
|
47
|
+
this.mdcList.listElements.forEach((item) => new MDCRipple(item));
|
|
48
|
+
};
|
|
49
|
+
this.setupListeners = () => {
|
|
50
|
+
if (!this.mdcList) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.mdcList.unlisten(ACTION_EVENT, this.handleAction);
|
|
54
|
+
this.selectable = ['selectable', 'radio', 'checkbox'].includes(this.type);
|
|
55
|
+
this.multiple = this.type === 'checkbox';
|
|
56
|
+
if (!this.selectable) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.mdcList.listen(ACTION_EVENT, this.handleAction);
|
|
60
|
+
this.mdcList.singleSelection = !this.multiple;
|
|
61
|
+
};
|
|
62
|
+
this.teardown = () => {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
(_a = this.mdcList) === null || _a === void 0 ? void 0 : _a.unlisten(ACTION_EVENT, this.handleAction);
|
|
65
|
+
(_b = this.mdcList) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
66
|
+
};
|
|
67
|
+
this.handleAction = (event) => {
|
|
68
|
+
if (!this.multiple) {
|
|
69
|
+
this.handleSingleSelect(event.detail.index);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.handleMultiSelect(event.detail.index);
|
|
73
|
+
};
|
|
74
|
+
this.handleSingleSelect = (index) => {
|
|
75
|
+
const listItems = this.items.filter(this.isListItem);
|
|
76
|
+
if (listItems[index].disabled) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const selectedItem = listItems.find((item) => {
|
|
80
|
+
return !!item.selected;
|
|
81
|
+
});
|
|
82
|
+
if (selectedItem) {
|
|
83
|
+
this.change.emit(Object.assign(Object.assign({}, selectedItem), { selected: false }));
|
|
84
|
+
}
|
|
85
|
+
if (listItems[index] !== selectedItem) {
|
|
86
|
+
this.change.emit(Object.assign(Object.assign({}, listItems[index]), { selected: true }));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
this.handleMultiSelect = (index) => {
|
|
90
|
+
const listItems = this.items.filter(this.isListItem);
|
|
91
|
+
if (listItems[index].disabled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const selectedItems = listItems
|
|
95
|
+
.filter((item, listIndex) => {
|
|
96
|
+
if (listIndex === index) {
|
|
97
|
+
// This is the item that was selected or deselected,
|
|
98
|
+
// so we negate its previous selection status.
|
|
99
|
+
return !item.selected;
|
|
100
|
+
}
|
|
101
|
+
// This is an item that didn't change, so we keep its selection status.
|
|
102
|
+
return item.selected;
|
|
103
|
+
})
|
|
104
|
+
.map((item) => {
|
|
105
|
+
return Object.assign(Object.assign({}, item), { selected: true });
|
|
106
|
+
});
|
|
107
|
+
this.change.emit(selectedItems);
|
|
108
|
+
};
|
|
109
|
+
this.isListItem = (item) => {
|
|
110
|
+
return !('separator' in item);
|
|
111
|
+
};
|
|
42
112
|
}
|
|
43
113
|
connectedCallback() {
|
|
44
114
|
this.setup();
|
|
@@ -61,9 +131,6 @@ export class List {
|
|
|
61
131
|
maxLinesSecondaryText = 1;
|
|
62
132
|
}
|
|
63
133
|
const html = this.listRenderer.render(this.items, this.config);
|
|
64
|
-
if (this.type === 'menu') {
|
|
65
|
-
return h("div", { class: "mdc-menu mdc-menu-surface" }, html);
|
|
66
|
-
}
|
|
67
134
|
return (h(Host, { style: {
|
|
68
135
|
'--maxLinesSecondaryText': `${maxLinesSecondaryText}`,
|
|
69
136
|
} }, html));
|
|
@@ -84,121 +151,6 @@ export class List {
|
|
|
84
151
|
.filter((item) => item.selected)
|
|
85
152
|
.map((item) => listItems.indexOf(item));
|
|
86
153
|
}
|
|
87
|
-
setup() {
|
|
88
|
-
if (this.type === 'menu') {
|
|
89
|
-
this.setupMenu();
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.setupList();
|
|
93
|
-
}
|
|
94
|
-
this.setupListeners();
|
|
95
|
-
}
|
|
96
|
-
setupList() {
|
|
97
|
-
const element = this.element.shadowRoot.querySelector('.mdc-deprecated-list');
|
|
98
|
-
if (!element) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.mdcList = new MDCList(element);
|
|
102
|
-
this.mdcList.listElements.forEach((item) => new MDCRipple(item));
|
|
103
|
-
}
|
|
104
|
-
setupMenu() {
|
|
105
|
-
const element = this.element.shadowRoot.querySelector('.mdc-menu');
|
|
106
|
-
if (!element) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.mdcMenu = new MDCMenu(element);
|
|
110
|
-
this.mdcMenu.hasTypeahead = true;
|
|
111
|
-
this.mdcMenu.wrapFocus = true;
|
|
112
|
-
this.mdcMenu.items.forEach((item) => new MDCRipple(item));
|
|
113
|
-
}
|
|
114
|
-
setupListeners() {
|
|
115
|
-
if (this.type === 'menu') {
|
|
116
|
-
this.setupMenuListeners();
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.setupListListeners();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
setupListListeners() {
|
|
123
|
-
if (!this.mdcList) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this.mdcList.unlisten(ACTION_EVENT, this.handleAction);
|
|
127
|
-
this.selectable = ['selectable', 'radio', 'checkbox', 'menu'].includes(this.type);
|
|
128
|
-
this.multiple = this.type === 'checkbox';
|
|
129
|
-
if (!this.selectable) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
this.mdcList.listen(ACTION_EVENT, this.handleAction);
|
|
133
|
-
this.mdcList.singleSelection = !this.multiple;
|
|
134
|
-
}
|
|
135
|
-
setupMenuListeners() {
|
|
136
|
-
if (!this.mdcMenu) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
this.mdcMenu.unlisten(SELECTED_EVENT, this.handleMenuSelect);
|
|
140
|
-
this.selectable = true;
|
|
141
|
-
this.mdcMenu.listen(SELECTED_EVENT, this.handleMenuSelect);
|
|
142
|
-
}
|
|
143
|
-
teardown() {
|
|
144
|
-
var _a, _b, _c, _d;
|
|
145
|
-
(_a = this.mdcList) === null || _a === void 0 ? void 0 : _a.unlisten(ACTION_EVENT, this.handleAction);
|
|
146
|
-
(_b = this.mdcList) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
147
|
-
(_c = this.mdcMenu) === null || _c === void 0 ? void 0 : _c.unlisten(SELECTED_EVENT, this.handleMenuSelect);
|
|
148
|
-
(_d = this.mdcMenu) === null || _d === void 0 ? void 0 : _d.destroy();
|
|
149
|
-
}
|
|
150
|
-
handleAction(event) {
|
|
151
|
-
if (!this.multiple) {
|
|
152
|
-
this.handleSingleSelect(event.detail.index);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
this.handleMultiSelect(event.detail.index);
|
|
156
|
-
}
|
|
157
|
-
handleMenuSelect(event) {
|
|
158
|
-
this.handleSingleSelect(event.detail.index);
|
|
159
|
-
}
|
|
160
|
-
handleSingleSelect(index) {
|
|
161
|
-
const listItems = this.items.filter(this.isListItem);
|
|
162
|
-
if (listItems[index].disabled) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const selectedItem = listItems.find((item) => {
|
|
166
|
-
return !!item.selected;
|
|
167
|
-
});
|
|
168
|
-
if (selectedItem) {
|
|
169
|
-
this.change.emit(Object.assign(Object.assign({}, selectedItem), { selected: false }));
|
|
170
|
-
}
|
|
171
|
-
if (listItems[index] !== selectedItem) {
|
|
172
|
-
if (this.type === 'menu') {
|
|
173
|
-
this.change.emit(Object.assign(Object.assign({}, listItems[index]), { selected: false }));
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
this.change.emit(Object.assign(Object.assign({}, listItems[index]), { selected: true }));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
handleMultiSelect(index) {
|
|
180
|
-
const listItems = this.items.filter(this.isListItem);
|
|
181
|
-
if (listItems[index].disabled) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const selectedItems = listItems
|
|
185
|
-
.filter((item, listIndex) => {
|
|
186
|
-
if (listIndex === index) {
|
|
187
|
-
// This is the item that was selected or deselected,
|
|
188
|
-
// so we negate its previous selection status.
|
|
189
|
-
return !item.selected;
|
|
190
|
-
}
|
|
191
|
-
// This is an item that didn't change, so we keep its selection status.
|
|
192
|
-
return item.selected;
|
|
193
|
-
})
|
|
194
|
-
.map((item) => {
|
|
195
|
-
return Object.assign(Object.assign({}, item), { selected: true });
|
|
196
|
-
});
|
|
197
|
-
this.change.emit(selectedItems);
|
|
198
|
-
}
|
|
199
|
-
isListItem(item) {
|
|
200
|
-
return !('separator' in item);
|
|
201
|
-
}
|
|
202
154
|
static get is() { return "limel-list"; }
|
|
203
155
|
static get encapsulation() { return "shadow"; }
|
|
204
156
|
static get originalStyleUrls() { return {
|
|
@@ -280,7 +232,7 @@ export class List {
|
|
|
280
232
|
"mutable": false,
|
|
281
233
|
"complexType": {
|
|
282
234
|
"original": "ListType",
|
|
283
|
-
"resolved": "\"checkbox\" | \"
|
|
235
|
+
"resolved": "\"checkbox\" | \"radio\" | \"selectable\"",
|
|
284
236
|
"references": {
|
|
285
237
|
"ListType": {
|
|
286
238
|
"location": "import",
|
|
@@ -292,7 +244,7 @@ export class List {
|
|
|
292
244
|
"optional": false,
|
|
293
245
|
"docs": {
|
|
294
246
|
"tags": [],
|
|
295
|
-
"text": "The type of the list, omit to get a regular list. Available types are:\n`selectable`: regular list with single selection.\n`radio`: radio button list with single selection.\n`checkbox`: checkbox list with multiple selection
|
|
247
|
+
"text": "The type of the list, omit to get a regular list. Available types are:\n`selectable`: regular list with single selection.\n`radio`: radio button list with single selection.\n`checkbox`: checkbox list with multiple selection."
|
|
296
248
|
},
|
|
297
249
|
"attribute": "type",
|
|
298
250
|
"reflect": false
|
|
@@ -97,8 +97,8 @@ export class Menu {
|
|
|
97
97
|
var _a;
|
|
98
98
|
const activeElement = this.list.shadowRoot.activeElement;
|
|
99
99
|
activeElement === null || activeElement === void 0 ? void 0 : activeElement.blur();
|
|
100
|
-
const
|
|
101
|
-
const selectedIndex = Math.max(
|
|
100
|
+
const MenuItems = this.items.filter(this.isMenuItem);
|
|
101
|
+
const selectedIndex = Math.max(MenuItems.findIndex((item) => item.selected), 0);
|
|
102
102
|
const menuElements = Array.from(this.list.shadowRoot.querySelectorAll('[role="menuitem"]'));
|
|
103
103
|
(_a = menuElements[selectedIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
104
104
|
};
|
|
@@ -131,7 +131,7 @@ export class Menu {
|
|
|
131
131
|
h("slot", { name: "trigger" }, this.renderTrigger()),
|
|
132
132
|
h("limel-portal", { class: portalClasses, style: portalPosition, visible: this.open, containerId: this.portalId, openDirection: this.openDirection, position: this.fixed ? 'fixed' : 'absolute', containerStyle: { 'z-index': dropdownZIndex } },
|
|
133
133
|
h("limel-menu-surface", { open: this.open, onDismiss: this.onClose, style: cssProperties },
|
|
134
|
-
h("limel-list", { class: {
|
|
134
|
+
h("limel-menu-list", { class: {
|
|
135
135
|
'has-grid-layout has-interactive-items': this.gridLayout,
|
|
136
136
|
}, items: this.items, type: "menu", badgeIcons: this.badgeIcons, onChange: this.onListChange, ref: this.setListElement })))));
|
|
137
137
|
}
|
|
@@ -173,7 +173,7 @@ export class Menu {
|
|
|
173
173
|
});
|
|
174
174
|
return zipObject(propertyNames, values);
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
isMenuItem(item) {
|
|
177
177
|
return !('separator' in item);
|
|
178
178
|
}
|
|
179
179
|
static get is() { return "limel-menu"; }
|
|
@@ -218,7 +218,7 @@ export class Menu {
|
|
|
218
218
|
},
|
|
219
219
|
"MenuItem": {
|
|
220
220
|
"location": "import",
|
|
221
|
-
"path": "
|
|
221
|
+
"path": "@limetech/lime-elements"
|
|
222
222
|
},
|
|
223
223
|
"ListSeparator": {
|
|
224
224
|
"location": "import",
|
|
@@ -261,7 +261,7 @@ export class Menu {
|
|
|
261
261
|
"references": {
|
|
262
262
|
"OpenDirection": {
|
|
263
263
|
"location": "import",
|
|
264
|
-
"path": "
|
|
264
|
+
"path": "@limetech/lime-elements"
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
},
|
|
@@ -377,10 +377,10 @@ export class Menu {
|
|
|
377
377
|
"text": "Is emitted when a menu item is selected."
|
|
378
378
|
},
|
|
379
379
|
"complexType": {
|
|
380
|
-
"original": "
|
|
381
|
-
"resolved": "
|
|
380
|
+
"original": "MenuItem | MenuItem[]",
|
|
381
|
+
"resolved": "MenuItem<any> | MenuItem<any>[]",
|
|
382
382
|
"references": {
|
|
383
|
-
"
|
|
383
|
+
"MenuItem": {
|
|
384
384
|
"location": "import",
|
|
385
385
|
"path": "@limetech/lime-elements"
|
|
386
386
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { h } from '@stencil/core';
|
|
2
|
+
export class MenuListRenderer {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.defaultConfig = {
|
|
5
|
+
isOpen: true,
|
|
6
|
+
badgeIcons: false,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Determine which MenuItem should have the `tab-index` attribute set,
|
|
10
|
+
* and return the index at which that MenuItem is located in `items`.
|
|
11
|
+
* Returns `undefined` if no item should have the attribute set.
|
|
12
|
+
* See https://github.com/material-components/material-components-web/tree/e66a43a75fef4f9179e24856649518e15e279a04/packages/mdc-list#accessibility
|
|
13
|
+
*
|
|
14
|
+
* @param {Array<ListSeparator | MenuItems>} items the items of the list, including any `ListSeparator`:s
|
|
15
|
+
* @returns {number} the index as per the description
|
|
16
|
+
*/
|
|
17
|
+
this.getIndexForWhichToApplyTabIndex = (items) => {
|
|
18
|
+
let result;
|
|
19
|
+
for (let i = 0, max = items.length; i < max; i += 1) {
|
|
20
|
+
if ('separator' in items[i]) {
|
|
21
|
+
// Ignore ListSeparator
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const item = items[i];
|
|
25
|
+
if (item.selected) {
|
|
26
|
+
result = i;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (result === undefined && !item.disabled) {
|
|
30
|
+
result = i;
|
|
31
|
+
// Do NOT break, as any later item with
|
|
32
|
+
// `selected=true` should get the tab-index instead!
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Render a single list item
|
|
40
|
+
*
|
|
41
|
+
* @param {ListSeparator | MenuItems} item the item to render
|
|
42
|
+
* @param {number} index the index the item had in the `items` array
|
|
43
|
+
* @returns {HTMLElement} the list item
|
|
44
|
+
*/
|
|
45
|
+
this.renderMenuItem = (item, index) => {
|
|
46
|
+
if ('separator' in item) {
|
|
47
|
+
return h("li", { class: "mdc-deprecated-list-divider", role: "separator" });
|
|
48
|
+
}
|
|
49
|
+
const classNames = {
|
|
50
|
+
'mdc-deprecated-list-item': true,
|
|
51
|
+
'mdc-deprecated-list-item--disabled': item.disabled,
|
|
52
|
+
'mdc-deprecated-list-item--selected': item.selected,
|
|
53
|
+
};
|
|
54
|
+
const attributes = {};
|
|
55
|
+
if (index === this.applyTabIndexToItemAtIndex) {
|
|
56
|
+
attributes.tabindex = '0';
|
|
57
|
+
}
|
|
58
|
+
return (h("li", Object.assign({ class: classNames, role: "menuitem", "aria-disabled": item.disabled ? 'true' : 'false', "aria-selected": item.selected ? 'true' : 'false', "data-index": index }, attributes),
|
|
59
|
+
item.icon ? this.renderIcon(this.config, item) : null,
|
|
60
|
+
this.renderText(item),
|
|
61
|
+
this.twoLines && this.avatarList ? this.renderDivider() : null,
|
|
62
|
+
this.renderActionMenu(item.actions)));
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Render the text of the list item
|
|
66
|
+
*
|
|
67
|
+
* @param {MenuItem} item the list item
|
|
68
|
+
* @returns {HTMLElement | string} the text for the list item
|
|
69
|
+
*/
|
|
70
|
+
this.renderText = (item) => {
|
|
71
|
+
if (this.isSimpleItem(item)) {
|
|
72
|
+
return (h("span", { class: "mdc-deprecated-list-item__text" }, item.text));
|
|
73
|
+
}
|
|
74
|
+
return (h("div", { class: "mdc-deprecated-list-item__text" },
|
|
75
|
+
h("div", { class: "mdc-deprecated-list-item__primary-command-text" },
|
|
76
|
+
h("div", { class: "mdc-deprecated-list-item__primary-text" }, item.text),
|
|
77
|
+
this.renderCommandText(item)),
|
|
78
|
+
h("div", { class: "mdc-deprecated-list-item__secondary-text" }, item.secondaryText)));
|
|
79
|
+
};
|
|
80
|
+
this.renderCommandText = (item) => {
|
|
81
|
+
if (!('commandText' in item)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return (h("div", { class: "mdc-deprecated-list-item__command-text" }, item.commandText));
|
|
85
|
+
};
|
|
86
|
+
this.isSimpleItem = (item) => {
|
|
87
|
+
if ('commandText' in item) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if ('secondaryText' in item) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Render an icon for a list item
|
|
97
|
+
*
|
|
98
|
+
* @param {MenuListRendererConfig} config the config object, passed on from the `renderMenuItem` function
|
|
99
|
+
* @param {MenuItem} item the list item
|
|
100
|
+
* @returns {HTMLElement} the icon element
|
|
101
|
+
*/
|
|
102
|
+
this.renderIcon = (config, item) => {
|
|
103
|
+
const style = {};
|
|
104
|
+
if (item.iconColor) {
|
|
105
|
+
if (config.badgeIcons) {
|
|
106
|
+
style['--icon-background-color'] = item.iconColor;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
style.color = item.iconColor;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return (h("limel-icon", { badge: config.badgeIcons, class: "mdc-deprecated-list-item__graphic", name: item.icon, style: style, size: config.iconSize }));
|
|
113
|
+
};
|
|
114
|
+
this.renderDivider = () => {
|
|
115
|
+
const classes = {
|
|
116
|
+
'mdc-deprecated-list-divider': true,
|
|
117
|
+
'mdc-deprecated-list-divider--inset': true,
|
|
118
|
+
};
|
|
119
|
+
if (this.config.iconSize) {
|
|
120
|
+
classes[this.config.iconSize] = true;
|
|
121
|
+
}
|
|
122
|
+
return h("hr", { class: classes });
|
|
123
|
+
};
|
|
124
|
+
this.renderActionMenu = (actions) => {
|
|
125
|
+
if (!actions || actions.length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
return (h("limel-menu", { class: "mdc-deprecated-list-item__meta", items: actions, openDirection: "left" },
|
|
129
|
+
h("limel-icon", { slot: "trigger", name: "menu_2", size: "small" })));
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
render(items, config = {}) {
|
|
133
|
+
items = items || [];
|
|
134
|
+
this.config = Object.assign(Object.assign({}, this.defaultConfig), config);
|
|
135
|
+
this.twoLines = items.some((item) => {
|
|
136
|
+
return 'secondaryText' in item && !!item.secondaryText;
|
|
137
|
+
});
|
|
138
|
+
this.commandKey = items.some((item) => {
|
|
139
|
+
return 'commandText' in item && !!item.commandText;
|
|
140
|
+
});
|
|
141
|
+
this.hasIcons = items.some((item) => {
|
|
142
|
+
return 'icon' in item && !!item.icon;
|
|
143
|
+
});
|
|
144
|
+
this.avatarList = this.config.badgeIcons && this.hasIcons;
|
|
145
|
+
this.applyTabIndexToItemAtIndex =
|
|
146
|
+
this.getIndexForWhichToApplyTabIndex(items);
|
|
147
|
+
const classNames = {
|
|
148
|
+
'mdc-deprecated-list': true,
|
|
149
|
+
'mdc-deprecated-list--two-line': this.twoLines,
|
|
150
|
+
selectable: true,
|
|
151
|
+
'mdc-deprecated-list--avatar-list': this.avatarList,
|
|
152
|
+
'list--compact': this.twoLines &&
|
|
153
|
+
this.commandKey &&
|
|
154
|
+
['small', 'x-small'].includes(this.config.iconSize),
|
|
155
|
+
};
|
|
156
|
+
return (h("ul", { class: classNames, "aria-hidden": true, role: "menu", "aria-orientation": "vertical" }, items.map(this.renderMenuItem)));
|
|
157
|
+
}
|
|
158
|
+
}
|