@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/src/MegaMenu.css CHANGED
@@ -1,80 +1,83 @@
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);
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-color--focus: var(--il-blue);
14
+ --ilw-header-megamenu--link-border-bottom-highlight: none;
15
+ --ilw-header-megamenu--link-border-bottom-highlight--hover: none;
16
+ --ilw-header-megamenu--link-border-bottom-highlight--focus: none;
17
+ --ilw-header-megamenu--items--position: initial;
18
+ --ilw-header-megamenu-section--grid-template-columns--header: auto 22px;
19
+ --ilw-header-megamenu--grid-template-columns: auto 51px;
20
+ }
21
+
22
+ ilw-header-megamenu {
23
+ all: initial;
24
+ display: block;
25
+ background: var(--ilw-header-megamenu--background);
26
+
27
+
28
+ &>ul {
29
+ all: initial;
30
+ display: flex;
31
+ flex-direction: var(--ilw-header-megamenu--flex-direction);
32
+ }
33
+
34
+ &>ul>li {
35
+ all: initial;
36
+ display: block;
37
+ background: var(--ilw-header-megamenu--background);
38
+ }
39
+
40
+ &>ul>li>a {
41
+ all: initial;
42
+ box-sizing: border-box;
43
+ height: 100%;
44
+ display: flex;
45
+ align-items: center;
46
+ position: relative;
47
+ padding: 6px 20px 6px;
48
+ font: var(--ilw-header-megamenu--font);
49
+ background: var(--ilw-header-megamenu--link-background);
50
+ color: var(--ilw-header-megamenu--link-color);
51
+ outline: 0;
52
+ cursor: pointer;
53
+ border-width: 0 0 3px 0;
54
+ border-style: solid;
55
+ border-color: transparent;
56
+ border-bottom: var(--ilw-header-megamenu--link-border-bottom-highlight);
57
+ border-left: var(--ilw-header-megamenu--link-border-left-highlight);
58
+
59
+ &[aria-current="true"],
60
+ &[aria-current="page"] {
61
+ border-color: var(--il-blue);
62
+ }
63
+
64
+ &:hover {
65
+ background: var(--ilw-header-megamenu--link-background--hover);
66
+ border-bottom: var(--ilw-header-megamenu--link-border-bottom-highlight--hover);
67
+ border-left: var(--ilw-header-megamenu--link-border-left-highlight--hover);
68
+ color: var(--ilw-header-megamenu--link-color--hover);
69
+ text-decoration: underline;
70
+ }
71
+
72
+ &:focus {
73
+ background: var(--ilw-header-megamenu--link-background--focus);
74
+ border-bottom: var(--ilw-header-megamenu--link-border-bottom-highlight--focus);
75
+ border-left: var(--ilw-header-megamenu--link-border-left-highlight--focus);
76
+ color: var(--ilw-header-megamenu--link-color--focus);
77
+ }
78
+ }
79
+ }
80
+
81
+ ilw-header-megamenu[compact]>ul>li>a {
82
+ border-bottom: 1px solid var(--il-storm-lighter-3);
80
83
  }
@@ -1,37 +1,38 @@
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);
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(--ilw-color--focus--background);
9
+ --ilw-header-megamenu--link-background--sub--focus: var(--ilw-color--focus--background);
10
+ --ilw-header-megamenu--link-color--focus: var(--il-blue);
11
+ --ilw-header-megamenu--link-border-bottom-highlight: 4px solid transparent;
12
+ --ilw-header-megamenu--link-border-bottom-highlight--hover: 4px solid var(--il-orange);
13
+ --ilw-header-megamenu--link-border-bottom-highlight--focus: 4px solid var(--il-blue);
14
+ --ilw-header-megamenu--link-border-left-highlight: none;
15
+ --ilw-header-megamenu--link-border-left-highlight--focus: none;
16
+ --ilw-header-megamenu--background: #E8E9EB;
17
+ --ilw-header-megamenu--flex-direction: row;
18
+ --ilw-header-megamenu--items--position: absolute;
19
+ --ilw-header-megamenu--items--border: 1px solid rgb(0, 0, 0, .01);
20
+ --ilw-header-megamenu--items--box-shadow: 0 0 4px #00000040;
21
+ --ilw-header-megamenu--items--width: 1270px;
22
+ --ilw-header-megamenu--items--top: initial;
23
+ --ilw-header-megamenu--items--left: calc(var(--ilw-margin--side) - 39px);
24
+ --ilw-header-megamenu--font: 700 16px/22px var(--il-font-sans);
25
+ --ilw-header-megamenu--grid-template-columns: auto auto;
26
+ --ilw-header-megamenu-section--grid-template-columns--header: auto 24px;
27
+ --ilw-header-megamenu-section--anchor--padding: 6px 20px;
28
+ --ilw-header-megamenu-section--anchor--border: none;
29
+ --ilw-header-megamenu-section--anchor--text-indent: 0;
30
+ --ilw-header-megamenu-section--transform: none;
31
+ --ilw-header-megamenu-section--transform--selected: rotate(180deg);
32
+ }
33
+ }
34
+
35
+ div.parent.full {
36
+ padding-top: 6px;
37
+ margin: 0 calc(var(--ilw-margin--side) - 9px);
37
38
  }
package/src/MegaMenu.ts CHANGED
@@ -1,145 +1,170 @@
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
- }
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
+
23
+ static get styles() : CSSResultGroup {
24
+ return unsafeCSS(styles);
25
+ }
26
+
27
+ constructor() {
28
+ super();
29
+ this.addEventListener('keydown', this.handleWindowKeydown.bind(this));
30
+ this.handleWindowResize = this.handleWindowResize.bind(this);
31
+ this.handleWindowClick = this.handleWindowClick.bind(this);
32
+ }
33
+
34
+ connectedCallback() {
35
+ super.connectedCallback();
36
+ window.addEventListener('click', this.handleWindowClick.bind(this));
37
+ window.addEventListener('resize', this.handleWindowResize);
38
+ this.handleWindowResize();
39
+ }
40
+
41
+ disconnectedCallback() {
42
+ super.disconnectedCallback();
43
+ window.removeEventListener('click', this.handleWindowClick.bind(this));
44
+ window.removeEventListener('resize', this.handleWindowResize);
45
+ }
46
+
47
+ handleWindowClick(evt: MouseEvent) {
48
+ if (!this.contains(evt.target as HTMLElement)) this.closeAllExceptOneSections(null);
49
+ }
50
+
51
+ handleWindowKeydown(evt: KeyboardEvent) {
52
+ if (evt.key === 'Escape') this.closeAllExceptOneSections(null);
53
+ if (evt.key === 'ArrowRight') {
54
+ evt.preventDefault();
55
+ this.closeAllExceptOneSections(null);
56
+ this.gotoNextSection();
57
+ }
58
+ if (evt.key === 'ArrowLeft') {
59
+ evt.preventDefault();
60
+ this.closeAllExceptOneSections(null);
61
+ this.gotoPreviousSection();
62
+ }
63
+ }
64
+
65
+ handleNavigationSectionToggleClick(evt: CustomEvent) {
66
+ this.closeAllExceptOneSections(evt.target);
67
+ }
68
+
69
+ gotoPreviousSection() {
70
+ const activeElement = document.activeElement;
71
+ if (!activeElement) return;
72
+
73
+ const currentSection = activeElement.closest(
74
+ 'ilw-header-megamenu-section'
75
+ ) || activeElement.closest('li a');
76
+
77
+ if (!currentSection) return;
78
+
79
+ const parentLi = currentSection.parentElement;
80
+ const previousLi = parentLi?.previousElementSibling;
81
+
82
+ if (!previousLi) return;
83
+
84
+ const previousSection = previousLi.querySelector(
85
+ 'ilw-header-megamenu-section'
86
+ ) || previousLi.querySelector('a');
87
+
88
+ if (!previousSection) return;
89
+
90
+ if ('setFocus' in previousSection) {
91
+ (previousSection as MegaMenuSection).setFocus();
92
+ } else {
93
+ (previousSection as HTMLAnchorElement).focus();
94
+ }
95
+ }
96
+
97
+ gotoNextSection() {
98
+ const activeElement = document.activeElement;
99
+ if (!activeElement) return;
100
+
101
+ const currentSection = activeElement.closest(
102
+ 'ilw-header-megamenu-section'
103
+ ) || activeElement.closest('li a');
104
+
105
+ if (!currentSection) return;
106
+
107
+ const parentLi = currentSection.parentElement;
108
+ const nextLi = parentLi?.nextElementSibling;
109
+
110
+ if (!nextLi) return;
111
+
112
+ const nextSection = nextLi.querySelector(
113
+ 'ilw-header-megamenu-section'
114
+ ) || nextLi.querySelector('a');
115
+
116
+ if (!nextSection) return;
117
+
118
+ if ('setFocus' in nextSection) {
119
+ (nextSection as MegaMenuSection).setFocus();
120
+ } else {
121
+ (nextSection as HTMLAnchorElement).focus();
122
+ }
123
+ }
124
+
125
+ handleWindowResize() {
126
+ let currentWidth = this.offsetWidth == 0 ? window.innerWidth : this.offsetWidth;
127
+ if (currentWidth < this.width) {
128
+ if (!this.compact) this.setCompactTrue();
129
+ }
130
+ else {
131
+ if (this.compact) this.setCompactFalse();
132
+ }
133
+ }
134
+
135
+ setCompactTrue() {
136
+ this.compact = true;
137
+ this.querySelectorAll('ilw-header-megamenu-section').forEach(s => { s.compact = true; });
138
+ }
139
+
140
+ setCompactFalse() {
141
+ this.compact = false;
142
+ this.querySelectorAll('ilw-header-megamenu-section').forEach(s => { s.compact = false; });
143
+ }
144
+
145
+ getSections() {
146
+ return this.querySelectorAll('ilw-header-megamenu-section');
147
+ }
148
+
149
+ closeAllExceptOneSections(target: EventTarget | null) {
150
+ this.getSections().forEach(s => { if (target == null || target != s) { s.expanded = false; } });
151
+ }
152
+
153
+
154
+
155
+ render() {
156
+ return html`
157
+ <nav aria-label="Header Menu Navigation" @ilw-header-megamenu-section-expanded=${this.handleNavigationSectionToggleClick}>
158
+ <div class="parent ${this.compact ? 'compact' : 'full'}">
159
+ <slot></slot>
160
+ </div>
161
+ </nav>
162
+ `;
163
+ }
164
+ }
165
+
166
+ declare global {
167
+ interface HTMLElementTagNameMap {
168
+ "ilw-header-megamenu": MegaMenu;
169
+ }
145
170
  }