@illinois-toolkit/ilw-header-megamenu 0.0.1 → 1.0.1
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/LICENSE +20 -20
- package/README.md +229 -261
- package/builder/ilw-header-megamenu.json +12 -12
- package/builder/versions/ilw-header-megamenu.1.0-alpha.json +70 -70
- package/builder/versions/ilw-header-megamenu.1.0.1.json +70 -0
- package/builder/versions/ilw-header-megamenu.1.0.json +70 -0
- package/builder/versions/ilw-header-megamenu.2.0-alpha.json +76 -0
- package/dist/MegaMenu.d.ts.map +1 -1
- package/dist/MegaMenuSection.d.ts +2 -8
- package/dist/MegaMenuSection.d.ts.map +1 -1
- package/dist/cdn/ilw-header-megamenu.css +1 -1
- package/dist/cdn/ilw-header-megamenu.js +317 -329
- package/dist/ilw-header-megamenu.css +1 -1
- package/dist/ilw-header-megamenu.js +111 -123
- package/package.json +49 -49
- package/src/MegaMenu.css +82 -79
- package/src/MegaMenu.styles.css +37 -36
- package/src/MegaMenu.ts +169 -144
- package/src/MegaMenuSection.css +231 -347
- package/src/MegaMenuSection.styles.css +242 -162
- package/src/MegaMenuSection.ts +220 -284
- package/src/ilw-header-megamenu.ts +1 -1
package/src/MegaMenuSection.ts
CHANGED
|
@@ -1,285 +1,221 @@
|
|
|
1
|
-
import { LitElement, html, unsafeCSS } from "lit";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import styles from './MegaMenuSection.styles.css?inline';
|
|
4
|
-
import './MegaMenuSection.css';
|
|
5
|
-
import { customElement, property } from "lit/decorators.js";
|
|
6
|
-
|
|
7
|
-
@customElement("ilw-header-megamenu-section")
|
|
8
|
-
export default class MegaMenuSection extends LitElement {
|
|
9
|
-
|
|
10
|
-
@property({
|
|
11
|
-
type: Boolean
|
|
12
|
-
})
|
|
13
|
-
current = false;
|
|
14
|
-
|
|
15
|
-
@property({
|
|
16
|
-
type: Boolean
|
|
17
|
-
})
|
|
18
|
-
compact = false;
|
|
19
|
-
|
|
20
|
-
@property({
|
|
21
|
-
type: Boolean
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@property({
|
|
26
|
-
type: Boolean
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (listitems === 5) {
|
|
223
|
-
lists.forEach((list, index) => {
|
|
224
|
-
list.style.borderRight = 'none';
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
let columnend = Math.floor(listitems / 5) * 5;
|
|
230
|
-
|
|
231
|
-
columnend = Math.min(columnend, 15);
|
|
232
|
-
|
|
233
|
-
lists.forEach((list, index) => {
|
|
234
|
-
const position = index + 1;
|
|
235
|
-
|
|
236
|
-
if (position <= columnend) {
|
|
237
|
-
list.style.borderRight = 'solid 2px var(--il-storm-85, #d5d3d3)';
|
|
238
|
-
} else {
|
|
239
|
-
list.style.borderRight = 'none';
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
let isSubMenu = this.parentElement != null && this.parentElement.closest("ilw-header-megamenu-section") != null;
|
|
250
|
-
this.current = this.current || (this.getAttribute('aria-current') != null && (this.getAttribute('aria-current') === 'page' || this.getAttribute('aria-current') === 'true'));
|
|
251
|
-
var withLink = html`
|
|
252
|
-
<div class="header-link ${this.mouseover ? "highlighted" : ""} ${this.compact ? "compact" : ""} ${this.current ? "current" : ""}" @mouseover="${this.toggleMouseOver.bind(this)}" @mouseout="${this.toggleMouseOver.bind(this)}">
|
|
253
|
-
<slot name="link"></slot>
|
|
254
|
-
<button class="arrow-only" @click=${this.handleToggleClick.bind(this)} aria-expanded=${this.expanded ? 'true' : 'false'} aria-label=${this.querySelector('a[slot="link"]')?.textContent + ' submenu'} aria-controls="items">
|
|
255
|
-
${this.renderArrow()}
|
|
256
|
-
</button>
|
|
257
|
-
</div>
|
|
258
|
-
`;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var withoutLink = html`
|
|
262
|
-
<button class="${this.current ? "current" : ""}" @click=${this.handleToggleClick.bind(this)} aria-expanded=${this.expanded ? 'true' : 'false'} aria-controls="items">
|
|
263
|
-
<div class="header">
|
|
264
|
-
<div class="label"><slot name="label"></slot> </div>
|
|
265
|
-
<div class="icon">${this.renderArrow()}</div>
|
|
266
|
-
</div>
|
|
267
|
-
</button>
|
|
268
|
-
`;
|
|
269
|
-
|
|
270
|
-
return html`
|
|
271
|
-
<div class="${isSubMenu ? 'submenu' : 'menu'} parent" @ilw-header-megamenu-section-expanded=${this.handleNavigationSectionToggleClick}>
|
|
272
|
-
${this.linked ? withLink : withoutLink}
|
|
273
|
-
<div id="items" class="${this.expanded ? 'expanded' : ''} ${this.right ? 'right' : ''}">
|
|
274
|
-
<slot></slot>
|
|
275
|
-
</div>
|
|
276
|
-
</div>
|
|
277
|
-
`;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
declare global {
|
|
282
|
-
interface HTMLElementTagNameMap {
|
|
283
|
-
"ilw-header-megamenu-section": MegaMenuSection;
|
|
284
|
-
}
|
|
1
|
+
import { LitElement, html, unsafeCSS } from "lit";
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import styles from './MegaMenuSection.styles.css?inline';
|
|
4
|
+
import './MegaMenuSection.css';
|
|
5
|
+
import { customElement, property } from "lit/decorators.js";
|
|
6
|
+
|
|
7
|
+
@customElement("ilw-header-megamenu-section")
|
|
8
|
+
export default class MegaMenuSection extends LitElement {
|
|
9
|
+
|
|
10
|
+
@property({
|
|
11
|
+
type: Boolean
|
|
12
|
+
})
|
|
13
|
+
current = false;
|
|
14
|
+
|
|
15
|
+
@property({
|
|
16
|
+
type: Boolean
|
|
17
|
+
})
|
|
18
|
+
compact = false;
|
|
19
|
+
|
|
20
|
+
@property({
|
|
21
|
+
type: Boolean
|
|
22
|
+
})
|
|
23
|
+
expanded = false;
|
|
24
|
+
|
|
25
|
+
@property({
|
|
26
|
+
type: Boolean
|
|
27
|
+
})
|
|
28
|
+
mouseover = false;
|
|
29
|
+
|
|
30
|
+
static get styles() {
|
|
31
|
+
return unsafeCSS(styles);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
handleToggleClick(evt: Event) {
|
|
36
|
+
this.expanded = !this.expanded;
|
|
37
|
+
this.dispatchEvent(new CustomEvent('ilw-header-megamenu-section-expanded', {detail: !this.expanded, bubbles: true, composed: true}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
handleWindowKeydown(evt: KeyboardEvent) {
|
|
41
|
+
if (evt.key === 'ArrowDown') {
|
|
42
|
+
evt.stopPropagation();
|
|
43
|
+
evt.preventDefault();
|
|
44
|
+
this.moveToNextItem();
|
|
45
|
+
this.closeAllExceptOneSections(evt.target);
|
|
46
|
+
}
|
|
47
|
+
else if (evt.key === 'ArrowUp') {
|
|
48
|
+
evt.stopPropagation();
|
|
49
|
+
evt.preventDefault();
|
|
50
|
+
this.moveToPreviousItem();
|
|
51
|
+
this.closeAllExceptOneSections(evt.target);
|
|
52
|
+
}
|
|
53
|
+
else if (evt.key === 'Escape') {
|
|
54
|
+
if (this.expanded) {
|
|
55
|
+
evt.stopPropagation();
|
|
56
|
+
this.setFocus();
|
|
57
|
+
this.expanded = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
setFocus() {
|
|
64
|
+
const element = this.shadowRoot?.querySelector('button, a') as HTMLElement | null;
|
|
65
|
+
|
|
66
|
+
if (element) {
|
|
67
|
+
element.focus();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
moveToNextItem() {
|
|
73
|
+
if (!this.expanded) {
|
|
74
|
+
this.expanded = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const activeElement = document.activeElement as HTMLElement | null;
|
|
78
|
+
if (!activeElement) return;
|
|
79
|
+
|
|
80
|
+
const section = activeElement.closest('ILW-HEADER-MEGAMENU-SECTION');
|
|
81
|
+
if (!section) return;
|
|
82
|
+
|
|
83
|
+
const links = Array.from(section.querySelectorAll('a, button')) as HTMLElement[];
|
|
84
|
+
const currentIndex = links.indexOf(activeElement);
|
|
85
|
+
|
|
86
|
+
let nextIndex = currentIndex + 1;
|
|
87
|
+
if (currentIndex === -1) {
|
|
88
|
+
nextIndex = 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (nextIndex >= 0 && nextIndex < links.length) {
|
|
92
|
+
const nextLink = links[nextIndex];
|
|
93
|
+
nextLink.focus();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
moveToPreviousItem() {
|
|
98
|
+
const activeElement = document.activeElement as HTMLElement | null;
|
|
99
|
+
if (!activeElement) return;
|
|
100
|
+
|
|
101
|
+
const section = activeElement.closest('ILW-HEADER-MEGAMENU-SECTION');
|
|
102
|
+
if (!section) return;
|
|
103
|
+
|
|
104
|
+
const links = Array.from(section.querySelectorAll('a, button')) as HTMLElement[];
|
|
105
|
+
const currentIndex = links.indexOf(activeElement);
|
|
106
|
+
|
|
107
|
+
let prevIndex = currentIndex - 1;
|
|
108
|
+
if (currentIndex === -1) {
|
|
109
|
+
prevIndex = links.length - 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (prevIndex >= 0 && prevIndex < links.length) {
|
|
113
|
+
const prevLink = links[prevIndex];
|
|
114
|
+
prevLink.focus();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
renderArrow() {
|
|
119
|
+
return html`<svg class="arrow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40.4 23.82" aria-hidden="true">
|
|
120
|
+
<path id="chevron" d="m39.34,1.06c-1.41-1.41-3.7-1.41-5.12,0l-14.02,14.02L6.18,1.06C4.76-.35,2.47-.35,1.06,1.06s-1.41,3.7,0,5.12l16.58,16.58c1.41,1.41,3.7,1.41,5.12,0L39.34,6.18c1.41-1.41,1.41-3.7,0-5.12Z"/>
|
|
121
|
+
</svg>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
toggleMouseOver() {
|
|
125
|
+
this.mouseover = !this.mouseover;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
handleNavigationSectionToggleClick(evt: CustomEvent) {
|
|
129
|
+
evt.stopPropagation();
|
|
130
|
+
this.closeAllExceptOneSections(evt.target);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getSections() {
|
|
134
|
+
return this.querySelectorAll('ilw-header-megamenu-section');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
closeAllExceptOneSections(target: EventTarget | null) {
|
|
138
|
+
this.getSections().forEach(s => { if (target == null || target != s) { s.expanded = false; } });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private hasSlotContent(name: string): boolean {
|
|
142
|
+
const slot = this.shadowRoot!.querySelector(`slot[name="${name}"]`) as HTMLSlotElement;
|
|
143
|
+
if (!slot) return false;
|
|
144
|
+
return slot.assignedNodes({ flatten: true }).length > 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
render() {
|
|
148
|
+
const actionSpan = this.querySelector('span[slot="action-left"], span[slot="action-right"]');
|
|
149
|
+
let actionId: string | null = null;
|
|
150
|
+
if (actionSpan) {
|
|
151
|
+
const pText = actionSpan.querySelector('p')?.textContent?.trim() || '';
|
|
152
|
+
let link = actionSpan.querySelector('a, button');
|
|
153
|
+
if (pText) {
|
|
154
|
+
actionId = `action-${pText.replace(/\s+/g, '-')}`;
|
|
155
|
+
actionSpan.id = actionId;
|
|
156
|
+
}
|
|
157
|
+
if (link && actionId) {
|
|
158
|
+
link.setAttribute('aria-describedby', actionId);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const sections = document.querySelectorAll('ilw-header-megamenu-section');
|
|
163
|
+
sections.forEach((section) => {
|
|
164
|
+
|
|
165
|
+
const lists = section.querySelectorAll<HTMLLIElement>('ilw-header-megamenu-section.solo-list > ul > li');
|
|
166
|
+
const listitems = lists.length;
|
|
167
|
+
if (listitems === 5) {
|
|
168
|
+
lists.forEach((list, index) => {
|
|
169
|
+
list.style.borderRight = 'none';
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let columnend = Math.floor(listitems / 5) * 5;
|
|
174
|
+
columnend = Math.min(columnend, 15);
|
|
175
|
+
lists.forEach((list, index) => {
|
|
176
|
+
const position = index + 1;
|
|
177
|
+
if (position <= columnend) {
|
|
178
|
+
list.style.borderRight = 'solid 2px var(--il-storm-85, #d5d3d3)';
|
|
179
|
+
} else {
|
|
180
|
+
list.style.borderRight = 'none';
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
let isSubMenu = this.parentElement != null && this.parentElement.closest("ilw-header-megamenu-section") != null;
|
|
186
|
+
|
|
187
|
+
this.current = this.current || (this.getAttribute('aria-current') != null && (this.getAttribute('aria-current') === 'page' || this.getAttribute('aria-current') === 'true'));
|
|
188
|
+
|
|
189
|
+
const isSoloList = this.classList.contains('solo-list');
|
|
190
|
+
|
|
191
|
+
const needsWrapper = !isSoloList;
|
|
192
|
+
|
|
193
|
+
return html`
|
|
194
|
+
<div class="${isSubMenu ? 'submenu' : 'menu'} parent" @ilw-header-megamenu-section-expanded=${this.handleNavigationSectionToggleClick} @keydown=${this.handleWindowKeydown}>
|
|
195
|
+
<button class="${this.current ? "current" : ""}" @click=${this.handleToggleClick.bind(this)} aria-expanded=${this.expanded ? 'true' : 'false'} aria-controls="items">
|
|
196
|
+
<div class="header">
|
|
197
|
+
<div class="label"><slot name="label"></slot> </div>
|
|
198
|
+
<div class="icon">${this.renderArrow()}</div>
|
|
199
|
+
</div>
|
|
200
|
+
</button>
|
|
201
|
+
<div id="items" class="${this.expanded ? 'expanded' : ''}">
|
|
202
|
+
${needsWrapper
|
|
203
|
+
? html`
|
|
204
|
+
<div class="list-wrapper">
|
|
205
|
+
<slot name="action-left"></slot>
|
|
206
|
+
<slot id="list-slot"></slot>
|
|
207
|
+
<slot name="action-right"></slot>
|
|
208
|
+
</div>
|
|
209
|
+
`
|
|
210
|
+
: html`<slot id="list-slot"></slot>`}
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
declare global {
|
|
218
|
+
interface HTMLElementTagNameMap {
|
|
219
|
+
"ilw-header-megamenu-section": MegaMenuSection;
|
|
220
|
+
}
|
|
285
221
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import "./MegaMenu";
|
|
1
|
+
import "./MegaMenu";
|
|
2
2
|
import "./MegaMenuSection";
|