@illinois-toolkit/ilw-header-megamenu 0.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.
@@ -0,0 +1 @@
1
+ ilw-header-megamenu[compact]{--ilw-header-megamenu--background: #e8e9eb;--ilw-header-megamenu--flex-direction: column;--ilw-header-megamenu--items--position: relative;--ilw-header-megamenu--items--border: none;--ilw-header-megamenu--items--box-shadow: none;--ilw-header-megamenu--items--width: 100%;--ilw-header-megamenu--font: 600 18px / 28px var(--il-font-sans);--ilw-header-megamenu--grid-template-columns: auto 52px;--ilw-header-megamenu--link-border-left-highlight: 4px solid transparent;--ilw-header-megamenu--link-border-left-highlight--hover: 4px solid var(--il-orange);--ilw-header-megamenu--link-border-left-highlight--focus: 4px solid var(--il-blue);--ilw-header-megamenu--link-border-bottom-highlight: none;--ilw-header-megamenu--link-border-bottom-highlight--hover: none;--ilw-header-megamenu--link-border-bottom-highlight--focus: none;--ilw-header-megamenu--items--position: initial;--ilw-header-megamenu-section--grid-template-columns--header: auto 22px;--ilw-header-megamenu--grid-template-columns: auto 51px}ilw-header-megamenu{all:initial;display:block;background:var(--ilw-header-megamenu--background)}ilw-header-megamenu>ul{all:initial;display:flex;flex-direction:var(--ilw-header-megamenu--flex-direction)}ilw-header-megamenu>ul>li{all:initial;display:block;background:var(--ilw-header-megamenu--background)}ilw-header-megamenu>ul>li>a{all:initial;box-sizing:border-box;height:100%;display:flex;align-items:center;position:relative;padding:6px 20px;font:var(--ilw-header-megamenu--font);background:var(--ilw-header-megamenu--link-background);color:var(--ilw-header-megamenu--link-color);outline:0;cursor:pointer;border-width:0 0 3px 0;border-style:solid;border-color:transparent;border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight);border-left:var(--ilw-header-megamenu--link-border-left-highlight)}ilw-header-megamenu>ul>li>a[aria-current=true],ilw-header-megamenu>ul>li>a[aria-current=page]{border-color:var(--il-blue)}ilw-header-megamenu>ul>li>a:hover{background:var(--ilw-header-megamenu--link-background--hover);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--hover);border-left:var(--ilw-header-megamenu--link-border-left-highlight--hover);color:var(--ilw-header-megamenu--link-color--hover);text-decoration:underline}ilw-header-megamenu>ul>li>a:focus{background:var(--ilw-header-megamenu--link-background--focus);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--focus);border-left:var(--ilw-header-megamenu--link-border-left-highlight--focus)}ilw-header-megamenu[compact]>ul>li>a{border-bottom:1px solid var(--il-storm-lighter-3)}ilw-header-megamenu-section[linked] a[slot=link]{all:initial;box-sizing:border-box;height:100%;display:flex;align-items:center;text-indent:var(--ilw-header-megamenu-section--anchor--text-indent);position:relative;font:var(--ilw-header-megamenu--font);background:var(--ilw-header-megamenu--link-background);color:var(--ilw-header-megamenu--link-color);outline:0;cursor:pointer;padding:9px 2px 6px 20px;border-width:0 0 3px 0;border-style:solid;border-color:transparent;border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight)}ilw-header-megamenu-section[linked] a[slot=link]:hover{background:var(--ilw-header-megamenu--link-background--hover);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--hover);color:var(--ilw-header-megamenu--link-color--hover);text-decoration:underline}ilw-header-megamenu-section[linked] a[slot=link]:focus{background:var(--ilw-header-megamenu--link-background--focus);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--focus)}ilw-header-megamenu-section[linked][aria-current=page] a[slot=link]{border-color:var(--il-blue)}ilw-header-megamenu-section[linked][aria-current=page] a[slot=link]:hover{border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--hover)}ilw-header-megamenu-section[linked][aria-current=page] a[slot=link]:focus{border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--focus)}ilw-header-megamenu-section img{margin:30px;object-fit:cover;width:90%;height:auto;border-radius:30px;grid-column:4;justify-self:right}ilw-header-megamenu-section img.span-2,ilw-header-megamenu-section span[slot=action].span-2{grid-column:3 / span 2}ilw-header-megamenu-section img.span-3,ilw-header-megamenu-section span[slot=action].span-3{grid-column:2 / span 3}ilw-header-megamenu-section img.align-left,ilw-header-megamenu-section span[slot=action].align-left{grid-column:1;justify-self:left}ilw-header-megamenu-section img.span-2.align-left,ilw-header-megamenu-section span[slot=action].span-2.align-left{grid-column:1 / span 2;justify-self:left}ilw-header-megamenu-section img.span-3.align-left,ilw-header-megamenu-section span[slot=action].span-3.align-left{grid-column:1 / span 3;justify-self:left}ilw-header-megamenu-section span[slot=action]{margin:auto;position:relative;width:100%;height:100%;display:flex;justify-content:center;flex-direction:column}ilw-header-megamenu-section span[slot=action] *{display:none}ilw-header-megamenu-section span[slot=action] button:first-of-type{display:block;position:relative;z-index:1;margin:0 auto}ilw-header-megamenu-section span[slot=action] p:first-of-type{display:block;text-align:center;font-size:21px;font-weight:700;color:var(--il-blue);font-family:Source Sans,sans-serif;position:relative;z-index:1}ilw-header-megamenu-section span[slot=action] img:first-of-type{display:block;position:absolute;top:0;left:0;width:100%;height:85%;object-fit:cover;z-index:0;margin:30px 0}ilw-header-megamenu-section span[slot=action].span-2 img:first-of-type,ilw-header-megamenu-section span[slot=action].span-3 img:first-of-type{width:90%;margin:30px}ilw-header-megamenu-section ul{list-style:none;margin:30px 0;padding-left:0;display:grid;grid-template-columns:repeat(4,minmax(0,320px));grid-template-rows:repeat(5,34px);grid-auto-flow:column;max-width:100vw}ilw-header-megamenu-section ul li{list-style:none;padding-left:30px}ilw-header-megamenu-section ul li span{display:inline-block;text-indent:var(--ilw-header-megamenu-section--anchor--text-indent)}ilw-header-megamenu-section ul li ul{display:inherit}ilw-header-megamenu-section ul li ul a{font-weight:400}ilw-header-megamenu-section ul li a{--ilw-header-megamenu--link-border-left-highlight: 4px solid transparent;--ilw-header-megamenu--link-border-left-highlight--hover: 4px solid var(--il-orange);--ilw-header-megamenu--link-border-left-highlight--focus: 4px solid var(--il-blue);--ilw-header-megamenu--link-border-bottom-highlight: initial;--ilw-header-megamenu--link-border-bottom-highlight--focus: initial;--ilw-header-megamenu--link-border-bottom-highlight--hover: initial;all:initial;box-sizing:border-box;text-indent:var(--ilw-header-megamenu-section--anchor--text-indent);display:block;position:relative;padding:var(--ilw-header-megamenu-section--anchor--padding);font:var(--ilw-header-megamenu--font);font-weight:700;background:transparent;color:var(--il-blue);outline:0;cursor:pointer;border-top:var(--ilw-header-megamenu-section--anchor--border);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight)}ilw-header-megamenu-section ul li a:hover{background:var(--ilw-header-megamenu--link-background--hover);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--hover);color:var(--ilw-header-megamenu--link-color--hover);text-decoration:underline}ilw-header-megamenu-section ul li a:focus{background:var(--ilw-header-megamenu--link-background--sub--focus);border-bottom:var(--ilw-header-megamenu--link-border-left-highlight--focus)}ilw-header-megamenu-section div ul:nth-child(n+5),ilw-header-megamenu-section div img:nth-child(n+5),ilw-header-megamenu-section div span:nth-child(n+5),ilw-header-megamenu-section>ul>li>ul{display:none}ilw-header-megamenu-section div{display:grid;grid-template-columns:repeat(4,minmax(0,320px));max-width:100vw;grid-auto-flow:column}ilw-header-megamenu-section div ul{border-left:solid 2px var(--il-storm-85, #d5d3d3)}ilw-header-megamenu-section div ul:first-child{border:none}ilw-header-megamenu-section div ul{display:block}ilw-header-megamenu-section div ul li{border-right:none}ilw-header-megamenu-section div ul li ul{margin-top:0;margin-bottom:0;border:none}ilw-header-megamenu-section div ul li ul li{border-right:none}ilw-header-megamenu-section ilw-header-megamenu-section{--ilw-header-megamenu--items--top: 0;--ilw-header-megamenu--items--left: 250px;--ilw-header-megamenu--link-border-left-highlight: 4px solid transparent;--ilw-header-megamenu--link-border-left-highlight--hover: 4px solid var(--il-orange);--ilw-header-megamenu--link-border-left-highlight--focus: 4px solid var(--il-blue);--ilw-header-megamenu--link-border-bottom-highlight: initial;--ilw-header-megamenu--link-border-bottom-highlight--hover: initial;--ilw-header-megamenu--link-border-bottom-highlight--focus: initial;--ilw-header-megamenu--grid-template-columns: auto 55px;--ilw-header-megamenu-section--transform: rotate(270deg);--ilw-header-megamenu-section--transform--selected: rotate(90deg)}ilw-header-megamenu[compact] ilw-header-megamenu-section{display:block;border-bottom:1px solid var(--il-storm-lighter-3)}ilw-header-megamenu[compact] ilw-header-megamenu-section a:focus{background:var(--ilw-header-megamenu--link-background--sub--focus);border-left:var(--ilw-header-megamenu--link-border-left-highlight--focus)}ilw-header-megamenu[compact] ilw-header-megamenu-section span[slot=action]{grid-column:auto;height:auto}ilw-header-megamenu[compact] ilw-header-megamenu-section span[slot=action] button{margin-bottom:20px}ilw-header-megamenu[compact] ilw-header-megamenu-section span[slot=action].span-3 img,ilw-header-megamenu[compact] ilw-header-megamenu-section span[slot=action].span-2 img,ilw-header-megamenu[compact] ilw-header-megamenu-section span[slot=action] img{margin:auto 0;width:100%;height:100%}ilw-header-megamenu[compact] ilw-header-megamenu-section img{display:none}ilw-header-megamenu[compact] ilw-header-megamenu-section div{display:block}ilw-header-megamenu[compact] ilw-header-megamenu-section ul{display:inherit;padding:0;margin:0}ilw-header-megamenu[compact] ilw-header-megamenu-section ul li{--ilw-header-megamenu-section--anchor--text-indent: 20px;border-top:1px solid var(--il-storm-lighter-3);background:var(--il-storm-lighter-4);padding-left:0}ilw-header-megamenu[compact] ilw-header-megamenu-section ul li a:focus{background:var(--ilw-header-megamenu--link-background--sub--focus);border-left:var(--ilw-header-megamenu--link-border-left-highlight--focus);border-bottom:none}ilw-header-megamenu[compact] ilw-header-megamenu-section ul li ul li a{padding-left:45px}ilw-header-megamenu[compact] ilw-header-megamenu-section ilw-header-megamenu-section{border-bottom:none;--ilw-header-megamenu-section--transform: none;--ilw-header-megamenu-section--transform--selected: rotate(180deg);--ilw-header-megamenu--grid-template-columns: auto 51px}ilw-header-megamenu[compact] ilw-header-megamenu-section ilw-header-megamenu-section ul a,ilw-header-megamenu[compact] ilw-header-megamenu-section ilw-header-megamenu-section ul button{--ilw-header-megamenu-section--anchor--text-indent: 40px}ul>span[action],li>span[action],ul>img,li>img,ul li:nth-child(n+21){display:none}.no-border{border:none}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=ilw-header-megamenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ilw-header-megamenu.d.ts","sourceRoot":"","sources":["../src/ilw-header-megamenu.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAC;AACpB,OAAO,mBAAmB,CAAC"}
@@ -0,0 +1,248 @@
1
+ import { LitElement as f, unsafeCSS as v, html as h } from "lit";
2
+ import { property as s, customElement as k } from "lit/decorators.js";
3
+ const x = "@layer base{:host{--ilw-header-megamenu--link-color: var(--il-blue);--ilw-header-megamenu--link-color--hover: var(--il-altgeld);--ilw-header-megamenu--link-background: transparent;--ilw-header-megamenu--link-background--hover: white;--ilw-header-megamenu--link-background--focus: var(--il-industrial-lighter-4);--ilw-header-megamenu--link-background--sub--focus: var(--il-industrial-lighter-4);--ilw-header-megamenu--link-border-bottom-highlight: 4px solid transparent;--ilw-header-megamenu--link-border-bottom-highlight--hover: 4px solid var(--il-orange);--ilw-header-megamenu--link-border-bottom-highlight--focus: 4px solid var(--il-blue);--ilw-header-megamenu--link-border-left-highlight: none;--ilw-header-megamenu--link-border-left-highlight--focus: none;--ilw-header-megamenu--background: #E8E9EB;--ilw-header-megamenu--flex-direction: row;--ilw-header-megamenu--items--position: absolute;--ilw-header-megamenu--items--border: 1px solid rgb(0, 0, 0, .01);--ilw-header-megamenu--items--box-shadow: 0 0 4px #00000040;--ilw-header-megamenu--items--width: 1270px;--ilw-header-megamenu--items--top: initial;--ilw-header-megamenu--items--left: calc(var(--ilw-margin--side) - 39px);--ilw-header-megamenu--font: 700 16px/22px var(--il-font-sans);--ilw-header-megamenu--grid-template-columns: auto auto;--ilw-header-megamenu-section--grid-template-columns--header: auto 24px;--ilw-header-megamenu-section--anchor--padding: 6px 20px;--ilw-header-megamenu-section--anchor--border: none;--ilw-header-megamenu-section--anchor--text-indent: 0;--ilw-header-megamenu-section--transform: none;--ilw-header-megamenu-section--transform--selected: rotate(180deg)}}div.parent.full{padding-top:6px;margin:0 calc(var(--ilw-margin--side) - 9px)}";
4
+ var E = Object.defineProperty, y = Object.getOwnPropertyDescriptor, p = (e, t, n, o) => {
5
+ for (var i = o > 1 ? void 0 : o ? y(t, n) : t, l = e.length - 1, r; l >= 0; l--)
6
+ (r = e[l]) && (i = (o ? r(t, n, i) : r(i)) || i);
7
+ return o && i && E(t, n, i), i;
8
+ };
9
+ let m = class extends f {
10
+ constructor() {
11
+ super(), this.compact = !1, this.width = 990, this.addEventListener("keydown", this.handleWindowKeydown.bind(this)), this.handleWindowResize = this.handleWindowResize.bind(this), this.handleWindowClick = this.handleWindowClick.bind(this);
12
+ }
13
+ static get styles() {
14
+ return v(x);
15
+ }
16
+ connectedCallback() {
17
+ super.connectedCallback(), window.addEventListener("click", this.handleWindowClick.bind(this)), window.addEventListener("resize", this.handleWindowResize), this.handleWindowResize();
18
+ }
19
+ disconnectedCallback() {
20
+ super.disconnectedCallback(), window.removeEventListener("click", this.handleWindowClick.bind(this)), window.removeEventListener("resize", this.handleWindowResize);
21
+ }
22
+ handleWindowClick(e) {
23
+ this.contains(e.target) || this.closeAllExceptOneSections(null);
24
+ }
25
+ handleWindowKeydown(e) {
26
+ e.key === "Escape" && this.closeAllExceptOneSections(null), e.key === "ArrowRight" && (e.preventDefault(), this.closeAllExceptOneSections(null), this.gotoNextSection()), e.key === "ArrowLeft" && (e.preventDefault(), this.closeAllExceptOneSections(null), this.gotoPreviousSection());
27
+ }
28
+ handleNavigationSectionToggleClick(e) {
29
+ this.closeAllExceptOneSections(e.target);
30
+ }
31
+ gotoPreviousSection() {
32
+ let e = null, t = document.activeElement;
33
+ if (t != null) {
34
+ if (t.closest("li") && t.closest("li").previousElementSibling) {
35
+ const n = t.closest("li").previousElementSibling;
36
+ n && n.children.length > 0 && (e = n.children[0]);
37
+ }
38
+ e && e.tagName === "ILW-HEADER-MEGAMENU-SECTION" ? e.setFocus(!0) : e.focus();
39
+ }
40
+ }
41
+ gotoNextSection() {
42
+ let e = null, t = document.activeElement;
43
+ if (t != null) {
44
+ if (t.closest("li") && t.closest("li").nextElementSibling) {
45
+ const n = t.closest("li").nextElementSibling;
46
+ n && n.children.length > 0 && (e = n.children[0]);
47
+ }
48
+ e && e.tagName === "ILW-HEADER-MEGAMENU-SECTION" ? e.setFocus() : e.focus();
49
+ }
50
+ }
51
+ handleWindowResize() {
52
+ (this.offsetWidth == 0 ? window.innerWidth : this.offsetWidth) < this.width ? this.compact || this.setCompactTrue() : this.compact && this.setCompactFalse();
53
+ }
54
+ setCompactTrue() {
55
+ this.compact = !0, this.querySelectorAll("ilw-header-megamenu-section").forEach((e) => {
56
+ e.compact = !0;
57
+ });
58
+ }
59
+ setCompactFalse() {
60
+ this.compact = !1, this.querySelectorAll("ilw-header-megamenu-section").forEach((e) => {
61
+ e.compact = !1;
62
+ });
63
+ }
64
+ getSections() {
65
+ return this.querySelectorAll("ilw-header-megamenu-section");
66
+ }
67
+ closeAllExceptOneSections(e) {
68
+ this.getSections().forEach((t) => {
69
+ (e == null || e != t) && (t.expanded = !1);
70
+ });
71
+ }
72
+ render() {
73
+ return h`
74
+ <nav aria-label="Header Menu Navigation" @ilw-header-megamenu-section-expanded=${this.handleNavigationSectionToggleClick}>
75
+ <div class="parent ${this.compact ? "compact" : "full"}"><slot></slot></div>
76
+ </nav>
77
+ `;
78
+ }
79
+ };
80
+ p([
81
+ s({
82
+ type: Boolean,
83
+ reflect: !0
84
+ })
85
+ ], m.prototype, "compact", 2);
86
+ p([
87
+ s({
88
+ type: Number
89
+ })
90
+ ], m.prototype, "width", 2);
91
+ m = p([
92
+ k("ilw-header-megamenu")
93
+ ], m);
94
+ const S = '#items{display:none}#items.expanded{all:initial;box-sizing:border-box;flex-direction:column;border:var(--ilw-header-megamenu--items--border);box-shadow:var(--ilw-header-megamenu--items--box-shadow);width:var(--ilw-header-megamenu--items--width);max-width:100vw + 39px;position:var(--ilw-header-megamenu--items--position);display:grid;left:var(--ilw-header-megamenu--items--left);top:var(--ilw-header-megamenu--items--top);z-index:100;background:#fff}.parent{height:100%}button,.link{all:initial;box-sizing:border-box;display:block;position:relative;padding:var(--ilw-header-megamenu-section--anchor--padding);font:var(--ilw-header-megamenu--font);background:var(--ilw-header-megamenu--link-background);color:var(--ilw-header-megamenu--link-color);fill:var(--ilw-header-megamenu--link-color);border-width:0 0 3px 0;border-style:solid;border-color:transparent;outline:0;cursor:pointer;height:100%;width:100%;border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight)}:is(button,.link) svg{padding:2px;transform:var(--ilw-header-megamenu-section--transform)}:is(button,.link).current{border-color:var(--il-blue)}:is(button,.link):hover{background:var(--ilw-header-megamenu--link-background--hover);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--hover);color:var(--ilw-header-megamenu--link-color--hover);fill:var(--ilw-header-megamenu--link-color--hover);text-decoration:underline}:is(button,.link):hover svg{outline:2px dotted var(--il-altgeld)}:is(button,.link):focus{background:var(--ilw-header-megamenu--link-background--focus);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--focus);border-left:var(--ilw-header-megamenu--link-border-left-highlight--focus)}button[aria-expanded=true]{text-decoration:underline;color:var(--ilw-header-megamenu--link-color--hover);background:var(--ilw-header-megamenu--link-background--hover)}button[aria-expanded=true]:focus{background:var(--ilw-header-megamenu--link-background--hover);border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--hover)}button[aria-expanded=true] svg{fill:var(--ilw-header-megamenu--link-color--hover);transform:var(--ilw-header-megamenu-section--transform--selected);background:var(--ilw-header-megamenu--link-background--hover)}button[aria-expanded=true] svg:focus{background:var(--ilw-header-megamenu--link-background--hover)}.header{position:relative;display:grid;grid-template-columns:var(--ilw-header-megamenu-section--grid-template-columns--header);grid-template-areas:"label icon";grid-gap:4px}.header-link.current button{border-color:var(--il-blue)}.header-link{position:relative;display:grid;grid-template-columns:var(--ilw-header-megamenu--grid-template-columns);grid-template-areas:"label icon";align-items:center;height:100%}.header-link.highlighted{background:var(--ilw-header-megamenu--link-background--hover)}.header-link .link{padding:6px 0 6px 20px}.header-link button{padding:6px 20px 6px 8px}.label,.link{box-sizing:border-box;display:block;position:relative;grid-area:label}.icon,.header-link button{align-self:center;align-items:center;justify-content:center;grid-area:icon}.icon{display:flex}.arrow{display:block;height:14px;width:14px}.submenu.parent button:hover .label ::slotted(span[slot="label"]),.submenu.parent button:focus .label ::slotted(span[slot="label"]){text-decoration:underline}.menu.parent .header-link.highlighted button,.menu.parent .header-link.highlighted ::slotted(a[slot="link"]){border-bottom:var(--ilw-header-megamenu--link-border-bottom-highlight--focus)!important}.submenu.parent button.arrow-only:hover,.submenu.parent button.arrow-only:focus{border-left:4px solid transparent!important}.menu.parent .compact button.arrow-only:hover,.menu.parent .compact button.arrow-only:focus{border-left:4px solid transparent!important}';
95
+ var A = Object.defineProperty, C = Object.getOwnPropertyDescriptor, d = (e, t, n, o) => {
96
+ for (var i = o > 1 ? void 0 : o ? C(t, n) : t, l = e.length - 1, r; l >= 0; l--)
97
+ (r = e[l]) && (i = (o ? r(t, n, i) : r(i)) || i);
98
+ return o && i && A(t, n, i), i;
99
+ };
100
+ let a = class extends f {
101
+ constructor() {
102
+ super(), this.current = !1, this.compact = !1, this.right = !1, this.expanded = !1, this.mouseover = !1, this.linked = !1, this.addEventListener("keydown", this.handleWindowKeydown.bind(this));
103
+ }
104
+ static get styles() {
105
+ return v(S);
106
+ }
107
+ connectedCallback() {
108
+ super.connectedCallback();
109
+ }
110
+ handleToggleClick(e) {
111
+ this.expanded = !this.expanded, this.dispatchEvent(new CustomEvent("ilw-header-megamenu-section-expanded", { detail: !this.expanded, bubbles: !0, composed: !0 }));
112
+ }
113
+ handleWindowKeydown(e) {
114
+ e.key === "ArrowDown" ? (e.stopPropagation(), e.preventDefault(), this.moveToNextItem(), this.closeAllExceptOneSections(e.target)) : e.key === "ArrowRight" || e.key === "ArrowLeft" ? this.isOnAnchorInLinked() && e.key === "ArrowRight" ? (e.stopPropagation(), e.preventDefault(), this.expanded = !1, this.setFocus(!0)) : this.isOnButtonInLinked() && e.key === "ArrowLeft" ? (e.stopPropagation(), e.preventDefault(), this.expanded = !1, this.setFocus()) : this.isOnButtonInLinked() && e.key === "ArrowRight" ? this.expanded = !1 : this.isOnAnchorInLinked() && e.key === "ArrowLeft" ? this.expanded = !1 : (this.expanded = !1, this.setFocus()) : e.key === "ArrowUp" ? (e.stopPropagation(), e.preventDefault(), this.moveToPreviousItem(), this.closeAllExceptOneSections(e.target)) : e.key === "Escape" && this.expanded && (e.stopPropagation(), this.setFocus(), this.expanded = !1);
115
+ }
116
+ isEmbedded() {
117
+ return this.parentElement && this.parentElement.closest("ilw-header-megamenu-section") != null;
118
+ }
119
+ isOnAnchorInLinked() {
120
+ return this.linked && document.activeElement && document.activeElement.tagName === "A";
121
+ }
122
+ isOnButtonInLinked() {
123
+ return this.linked && document.activeElement && document.activeElement.tagName === "ILW-HEADER-MEGAMENU-SECTION";
124
+ }
125
+ setFocus(e = !1) {
126
+ let t = null;
127
+ this.linked && !e ? t = this.querySelector("a") : this.shadowRoot && (t = this.shadowRoot.querySelector("a"), t == null && (t = this.shadowRoot.querySelector("button"))), t?.focus();
128
+ }
129
+ moveToNextItem() {
130
+ !this.expanded && !this.isEmbedded() && (this.expanded = !0);
131
+ const e = document.activeElement;
132
+ if (!e) return;
133
+ const t = e.closest("ILW-HEADER-MEGAMENU-SECTION");
134
+ if (!t) return;
135
+ const n = Array.from(t.querySelectorAll("a, button")), o = n.indexOf(e);
136
+ let i = o + 1;
137
+ o === -1 && (i = 0), i >= 0 && i < n.length && n[i].focus();
138
+ }
139
+ moveToPreviousItem() {
140
+ const e = document.activeElement;
141
+ if (!e) return;
142
+ const t = e.closest("ILW-HEADER-MEGAMENU-SECTION");
143
+ if (!t) return;
144
+ const n = Array.from(t.querySelectorAll("a, button")), o = n.indexOf(e);
145
+ let i = o - 1;
146
+ o === -1 && (i = n.length - 1), i >= 0 && i < n.length && n[i].focus();
147
+ }
148
+ renderArrow() {
149
+ return h`<svg class="arrow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40.4 23.82" aria-hidden="true">
150
+ <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"/>
151
+ </svg>`;
152
+ }
153
+ toggleMouseOver() {
154
+ this.mouseover = !this.mouseover;
155
+ }
156
+ handleNavigationSectionToggleClick(e) {
157
+ e.stopPropagation(), this.closeAllExceptOneSections(e.target);
158
+ }
159
+ getSections() {
160
+ return this.querySelectorAll("ilw-header-megamenu-section");
161
+ }
162
+ closeAllExceptOneSections(e) {
163
+ this.getSections().forEach((t) => {
164
+ (e == null || e != t) && (t.expanded = !1);
165
+ });
166
+ }
167
+ render() {
168
+ const e = this.querySelector('span[slot="action"]');
169
+ let t = null;
170
+ if (e) {
171
+ const r = e.querySelector("p")?.textContent?.trim() || "";
172
+ let c = e.querySelector("a, button");
173
+ r && (t = `action-${r.replace(/\s+/g, "-")}`, e.id = t), c && t && c.setAttribute("aria-labelledby", t);
174
+ }
175
+ document.querySelectorAll("ilw-header-megamenu-section").forEach((r) => {
176
+ const c = r.querySelectorAll("ilw-header-megamenu-section > ul > li"), b = c.length;
177
+ if (b === 5) {
178
+ c.forEach((u, w) => {
179
+ u.style.borderRight = "none";
180
+ });
181
+ return;
182
+ }
183
+ let g = Math.floor(b / 5) * 5;
184
+ g = Math.min(g, 15), c.forEach((u, w) => {
185
+ w + 1 <= g ? u.style.borderRight = "solid 2px var(--il-storm-85, #d5d3d3)" : u.style.borderRight = "none";
186
+ });
187
+ });
188
+ let o = this.parentElement != null && this.parentElement.closest("ilw-header-megamenu-section") != null;
189
+ this.current = this.current || this.getAttribute("aria-current") != null && (this.getAttribute("aria-current") === "page" || this.getAttribute("aria-current") === "true");
190
+ var i = h`
191
+ <div class="header-link ${this.mouseover ? "highlighted" : ""} ${this.compact ? "compact" : ""} ${this.current ? "current" : ""}" @mouseover="${this.toggleMouseOver.bind(this)}" @mouseout="${this.toggleMouseOver.bind(this)}">
192
+ <slot name="link"></slot>
193
+ <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">
194
+ ${this.renderArrow()}
195
+ </button>
196
+ </div>
197
+ `, l = h`
198
+ <button class="${this.current ? "current" : ""}" @click=${this.handleToggleClick.bind(this)} aria-expanded=${this.expanded ? "true" : "false"} aria-controls="items">
199
+ <div class="header">
200
+ <div class="label"><slot name="label"></slot> </div>
201
+ <div class="icon">${this.renderArrow()}</div>
202
+ </div>
203
+ </button>
204
+ `;
205
+ return h`
206
+ <div class="${o ? "submenu" : "menu"} parent" @ilw-header-megamenu-section-expanded=${this.handleNavigationSectionToggleClick}>
207
+ ${this.linked ? i : l}
208
+ <div id="items" class="${this.expanded ? "expanded" : ""} ${this.right ? "right" : ""}">
209
+ <slot></slot>
210
+ </div>
211
+ </div>
212
+ `;
213
+ }
214
+ };
215
+ d([
216
+ s({
217
+ type: Boolean
218
+ })
219
+ ], a.prototype, "current", 2);
220
+ d([
221
+ s({
222
+ type: Boolean
223
+ })
224
+ ], a.prototype, "compact", 2);
225
+ d([
226
+ s({
227
+ type: Boolean
228
+ })
229
+ ], a.prototype, "right", 2);
230
+ d([
231
+ s({
232
+ type: Boolean
233
+ })
234
+ ], a.prototype, "expanded", 2);
235
+ d([
236
+ s({
237
+ type: Boolean
238
+ })
239
+ ], a.prototype, "mouseover", 2);
240
+ d([
241
+ s({
242
+ reflect: !0,
243
+ type: Boolean
244
+ })
245
+ ], a.prototype, "linked", 2);
246
+ a = d([
247
+ k("ilw-header-megamenu-section")
248
+ ], a);
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@illinois-toolkit/ilw-header-megamenu",
3
+ "description": "Mega Menu for the top of the page.",
4
+ "repository": "github:web-illinois/ilw-header-megamenu",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "version": "0.0.1",
8
+ "type": "module",
9
+ "files": [
10
+ "src/**",
11
+ "dist/**",
12
+ "builder/**"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/ilw-header-megamenu.js",
17
+ "require": "./dist/ilw-header-megamenu.cjs",
18
+ "default": "./dist/ilw-header-megamenu.js"
19
+ },
20
+ "./ilw-header-megamenu.css": {
21
+ "import": "./dist/ilw-header-megamenu.css"
22
+ }
23
+ },
24
+ "main": "./dist/ilw-header-megamenu.js",
25
+ "module": "./dist/ilw-header-megamenu.js",
26
+ "scripts": {
27
+ "dev": "vite",
28
+ "build": "tsc --noEmit && vite build --config vite.transpile.config.ts --emptyOutDir && vite build --config vite.build.config.ts --emptyOutDir",
29
+ "preview": "vite preview",
30
+ "prepack": "npm run build",
31
+ "test:axe": "playwright test",
32
+ "test:axe:github": "playwright test --config playwright.ci.config.ts",
33
+ "test": "vitest run --browser.headless",
34
+ "test:browser": "vitest watch --browser chromium"
35
+ },
36
+ "dependencies": {
37
+ "lit": "3.1.3"
38
+ },
39
+ "devDependencies": {
40
+ "@illinois-toolkit/ilw-core": "^1.0.5",
41
+ "@playwright/test": "^1.57.0",
42
+ "@vitest/browser": "^3.2.4",
43
+ "playwright": "^1.57.0",
44
+ "typescript": "^5.9.2",
45
+ "vite": "^7.2.4",
46
+ "vite-plugin-dts": "^4.5.4",
47
+ "vitest-browser-lit": "^0.1.0"
48
+ }
49
+ }
@@ -0,0 +1,80 @@
1
+ ilw-header-megamenu[compact] {
2
+ --ilw-header-megamenu--background: #e8e9eb;
3
+ --ilw-header-megamenu--flex-direction: column;
4
+ --ilw-header-megamenu--items--position: relative;
5
+ --ilw-header-megamenu--items--border: none;
6
+ --ilw-header-megamenu--items--box-shadow: none;
7
+ --ilw-header-megamenu--items--width: 100%;
8
+ --ilw-header-megamenu--font: 600 18px / 28px var(--il-font-sans);
9
+ --ilw-header-megamenu--grid-template-columns: auto 52px;
10
+ --ilw-header-megamenu--link-border-left-highlight: 4px solid transparent;
11
+ --ilw-header-megamenu--link-border-left-highlight--hover: 4px solid var(--il-orange);
12
+ --ilw-header-megamenu--link-border-left-highlight--focus: 4px solid var(--il-blue);
13
+ --ilw-header-megamenu--link-border-bottom-highlight: none;
14
+ --ilw-header-megamenu--link-border-bottom-highlight--hover: none;
15
+ --ilw-header-megamenu--link-border-bottom-highlight--focus: none;
16
+ --ilw-header-megamenu--items--position: initial;
17
+ --ilw-header-megamenu-section--grid-template-columns--header: auto 22px;
18
+ --ilw-header-megamenu--grid-template-columns: auto 51px;
19
+ }
20
+
21
+ ilw-header-megamenu {
22
+ all: initial;
23
+ display: block;
24
+ background: var(--ilw-header-megamenu--background);
25
+
26
+
27
+ & > ul {
28
+ all: initial;
29
+ display: flex;
30
+ flex-direction: var(--ilw-header-megamenu--flex-direction);
31
+ }
32
+
33
+ & > ul > li {
34
+ all: initial;
35
+ display: block;
36
+ background: var(--ilw-header-megamenu--background);
37
+ }
38
+
39
+ & > ul > li > a {
40
+ all: initial;
41
+ box-sizing: border-box;
42
+ height: 100%;
43
+ display: flex;
44
+ align-items: center;
45
+ position: relative;
46
+ padding: 6px 20px 6px;
47
+ font: var(--ilw-header-megamenu--font);
48
+ background: var(--ilw-header-megamenu--link-background);
49
+ color: var(--ilw-header-megamenu--link-color);
50
+ outline: 0;
51
+ cursor: pointer;
52
+ border-width: 0 0 3px 0;
53
+ border-style: solid;
54
+ border-color: transparent;
55
+ border-bottom: var(--ilw-header-megamenu--link-border-bottom-highlight);
56
+ border-left: var(--ilw-header-megamenu--link-border-left-highlight);
57
+
58
+ &[aria-current="true"], &[aria-current="page"] {
59
+ border-color: var(--il-blue);
60
+ }
61
+
62
+ &:hover {
63
+ background: var(--ilw-header-megamenu--link-background--hover);
64
+ border-bottom: var(--ilw-header-megamenu--link-border-bottom-highlight--hover);
65
+ border-left: var(--ilw-header-megamenu--link-border-left-highlight--hover);
66
+ color: var(--ilw-header-megamenu--link-color--hover);
67
+ text-decoration: underline;
68
+ }
69
+
70
+ &:focus {
71
+ background: var(--ilw-header-megamenu--link-background--focus);
72
+ border-bottom: var(--ilw-header-megamenu--link-border-bottom-highlight--focus);
73
+ border-left: var(--ilw-header-megamenu--link-border-left-highlight--focus);
74
+ }
75
+ }
76
+ }
77
+
78
+ ilw-header-megamenu[compact] > ul > li > a {
79
+ border-bottom: 1px solid var(--il-storm-lighter-3);
80
+ }
@@ -0,0 +1,37 @@
1
+ /* Styleable variables are in the base layer so they can be overridden easily */
2
+ @layer base {
3
+ :host {
4
+ --ilw-header-megamenu--link-color: var(--il-blue);
5
+ --ilw-header-megamenu--link-color--hover: var(--il-altgeld);
6
+ --ilw-header-megamenu--link-background: transparent;
7
+ --ilw-header-megamenu--link-background--hover: white;
8
+ --ilw-header-megamenu--link-background--focus: var(--il-industrial-lighter-4);
9
+ --ilw-header-megamenu--link-background--sub--focus: var(--il-industrial-lighter-4);
10
+ --ilw-header-megamenu--link-border-bottom-highlight: 4px solid transparent;
11
+ --ilw-header-megamenu--link-border-bottom-highlight--hover: 4px solid var(--il-orange);
12
+ --ilw-header-megamenu--link-border-bottom-highlight--focus: 4px solid var(--il-blue);
13
+ --ilw-header-megamenu--link-border-left-highlight: none;
14
+ --ilw-header-megamenu--link-border-left-highlight--focus: none;
15
+ --ilw-header-megamenu--background: #E8E9EB;
16
+ --ilw-header-megamenu--flex-direction: row;
17
+ --ilw-header-megamenu--items--position: absolute;
18
+ --ilw-header-megamenu--items--border: 1px solid rgb(0, 0, 0, .01);
19
+ --ilw-header-megamenu--items--box-shadow: 0 0 4px #00000040;
20
+ --ilw-header-megamenu--items--width: 1270px;
21
+ --ilw-header-megamenu--items--top: initial;
22
+ --ilw-header-megamenu--items--left: calc(var(--ilw-margin--side) - 39px);
23
+ --ilw-header-megamenu--font: 700 16px/22px var(--il-font-sans);
24
+ --ilw-header-megamenu--grid-template-columns: auto auto;
25
+ --ilw-header-megamenu-section--grid-template-columns--header: auto 24px;
26
+ --ilw-header-megamenu-section--anchor--padding: 6px 20px;
27
+ --ilw-header-megamenu-section--anchor--border: none;
28
+ --ilw-header-megamenu-section--anchor--text-indent: 0;
29
+ --ilw-header-megamenu-section--transform: none;
30
+ --ilw-header-megamenu-section--transform--selected: rotate(180deg);
31
+ }
32
+ }
33
+
34
+ div.parent.full {
35
+ padding-top: 6px;
36
+ margin: 0 calc(var(--ilw-margin--side) - 9px);
37
+ }
@@ -0,0 +1,145 @@
1
+ import { LitElement, html, unsafeCSS, CSSResultGroup } from "lit";
2
+ // @ts-ignore
3
+ import styles from './MegaMenu.styles.css?inline';
4
+ import './MegaMenu.css';
5
+ import { customElement, property } from "lit/decorators.js";
6
+ import MegaMenuSection from "./MegaMenuSection";
7
+
8
+ @customElement("ilw-header-megamenu")
9
+ export default class MegaMenu extends LitElement {
10
+
11
+ @property({
12
+ type: Boolean,
13
+ reflect: true
14
+ })
15
+ compact = false;
16
+
17
+ @property({
18
+ type: Number
19
+ })
20
+ width = 990;
21
+
22
+ static get styles() : CSSResultGroup {
23
+ return unsafeCSS(styles);
24
+ }
25
+
26
+ constructor() {
27
+ super();
28
+ this.addEventListener('keydown', this.handleWindowKeydown.bind(this));
29
+ this.handleWindowResize = this.handleWindowResize.bind(this);
30
+ this.handleWindowClick = this.handleWindowClick.bind(this);
31
+ }
32
+
33
+ connectedCallback() {
34
+ super.connectedCallback();
35
+ window.addEventListener('click', this.handleWindowClick.bind(this));
36
+ window.addEventListener('resize', this.handleWindowResize);
37
+ this.handleWindowResize();
38
+ }
39
+
40
+ disconnectedCallback() {
41
+ super.disconnectedCallback();
42
+ window.removeEventListener('click', this.handleWindowClick.bind(this));
43
+ window.removeEventListener('resize', this.handleWindowResize);
44
+ }
45
+
46
+ handleWindowClick(evt: MouseEvent) {
47
+ if (!this.contains(evt.target as HTMLElement)) this.closeAllExceptOneSections(null);
48
+ }
49
+
50
+ handleWindowKeydown(evt: KeyboardEvent) {
51
+ if (evt.key === 'Escape') this.closeAllExceptOneSections(null);
52
+ if (evt.key === 'ArrowRight') {
53
+ evt.preventDefault();
54
+ this.closeAllExceptOneSections(null);
55
+ this.gotoNextSection();
56
+ }
57
+ if (evt.key === 'ArrowLeft') {
58
+ evt.preventDefault();
59
+ this.closeAllExceptOneSections(null);
60
+ this.gotoPreviousSection();
61
+ }
62
+ }
63
+
64
+ handleNavigationSectionToggleClick(evt: CustomEvent) {
65
+ this.closeAllExceptOneSections(evt.target);
66
+ }
67
+
68
+ gotoPreviousSection() {
69
+ let newNode: Element | null = null;
70
+ let activeElement = document.activeElement;
71
+ if (activeElement != null) {
72
+ if (activeElement.closest('li') && (activeElement.closest('li') as Element).previousElementSibling ) {
73
+ const previousSibling = (activeElement.closest('li') as Element).previousElementSibling;
74
+ if (previousSibling && previousSibling.children.length > 0) {
75
+ newNode = previousSibling.children[0];
76
+ }
77
+ }
78
+ if (newNode && newNode.tagName === 'ILW-HEADER-MEGAMENU-SECTION') {
79
+ (newNode as MegaMenuSection).setFocus(true);
80
+ } else {
81
+ (newNode as HTMLElement).focus();
82
+ }
83
+ }
84
+ }
85
+
86
+ gotoNextSection() {
87
+ let newNode: Element | null = null;
88
+ let activeElement = document.activeElement;
89
+ if (activeElement != null) {
90
+ if (activeElement.closest('li') && (activeElement.closest('li') as Element).nextElementSibling) {
91
+ const nextSibling = (activeElement.closest('li') as Element).nextElementSibling;
92
+ if (nextSibling && nextSibling.children.length > 0) {
93
+ newNode = nextSibling.children[0];
94
+ }
95
+ }
96
+ if (newNode && newNode.tagName === 'ILW-HEADER-MEGAMENU-SECTION') {
97
+ (newNode as MegaMenuSection).setFocus();
98
+ } else {
99
+ (newNode as HTMLElement).focus();
100
+ }
101
+ }
102
+ }
103
+
104
+ handleWindowResize() {
105
+ let currentWidth = this.offsetWidth == 0 ? window.innerWidth : this.offsetWidth;
106
+ if (currentWidth < this.width) {
107
+ if (!this.compact) this.setCompactTrue();
108
+ }
109
+ else {
110
+ if (this.compact) this.setCompactFalse();
111
+ }
112
+ }
113
+
114
+ setCompactTrue() {
115
+ this.compact = true;
116
+ this.querySelectorAll('ilw-header-megamenu-section').forEach(s => { s.compact = true; });
117
+ }
118
+
119
+ setCompactFalse() {
120
+ this.compact = false;
121
+ this.querySelectorAll('ilw-header-megamenu-section').forEach(s => { s.compact = false; });
122
+ }
123
+
124
+ getSections() {
125
+ return this.querySelectorAll('ilw-header-megamenu-section');
126
+ }
127
+
128
+ closeAllExceptOneSections(target: EventTarget | null) {
129
+ this.getSections().forEach(s => { if (target == null || target != s) { s.expanded = false; } });
130
+ }
131
+
132
+ render() {
133
+ return html`
134
+ <nav aria-label="Header Menu Navigation" @ilw-header-megamenu-section-expanded=${this.handleNavigationSectionToggleClick}>
135
+ <div class="parent ${this.compact ? 'compact' : 'full'}"><slot></slot></div>
136
+ </nav>
137
+ `;
138
+ }
139
+ }
140
+
141
+ declare global {
142
+ interface HTMLElementTagNameMap {
143
+ "ilw-header-megamenu": MegaMenu;
144
+ }
145
+ }