@internetarchive/ia-topnav 2.0.1 → 2.0.2-alpha2
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/.prettierignore +1 -1
- package/LICENSE +661 -661
- package/README.md +147 -147
- package/demo/index.html +28 -28
- package/dist/src/data/menus.js +1 -1
- package/dist/src/data/menus.js.map +1 -1
- package/dist/src/dropdown-menu.js +26 -26
- package/dist/src/dropdown-menu.js.map +1 -1
- package/dist/src/ia-topnav.js +66 -66
- package/dist/src/ia-topnav.js.map +1 -1
- package/dist/src/login-button.js +17 -17
- package/dist/src/login-button.js.map +1 -1
- package/dist/src/primary-nav.js +89 -89
- package/dist/src/primary-nav.js.map +1 -1
- package/dist/src/signed-out-dropdown.js.map +1 -1
- package/dist/src/styles/dropdown-menu.js +169 -169
- package/dist/src/styles/dropdown-menu.js.map +1 -1
- package/dist/src/user-menu.js +13 -13
- package/dist/src/user-menu.js.map +1 -1
- package/eslint.config.mjs +53 -53
- package/package.json +72 -72
- package/prettier.config.js +9 -9
- package/src/data/menus.ts +1 -1
- package/src/dropdown-menu.ts +132 -132
- package/src/ia-topnav.ts +332 -332
- package/src/login-button.ts +89 -89
- package/src/primary-nav.ts +300 -300
- package/src/signed-out-dropdown.ts +11 -11
- package/src/styles/dropdown-menu.ts +172 -172
- package/src/user-menu.ts +31 -31
- package/ssl/server.key +28 -28
- package/tsconfig.json +31 -31
- package/web-dev-server.config.mjs +32 -32
- package/web-test-runner.config.mjs +41 -41
package/prettier.config.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://prettier.io/docs/configuration
|
|
3
|
-
* @type {import("prettier").Config}
|
|
4
|
-
*/
|
|
5
|
-
const config = {
|
|
6
|
-
singleQuote: true,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default config;
|
|
1
|
+
/**
|
|
2
|
+
* @see https://prettier.io/docs/configuration
|
|
3
|
+
* @type {import("prettier").Config}
|
|
4
|
+
*/
|
|
5
|
+
const config = {
|
|
6
|
+
singleQuote: true,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default config;
|
package/src/data/menus.ts
CHANGED
package/src/dropdown-menu.ts
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CSSResultGroup,
|
|
3
|
-
html,
|
|
4
|
-
nothing,
|
|
5
|
-
PropertyValues,
|
|
6
|
-
TemplateResult,
|
|
7
|
-
} from 'lit';
|
|
8
|
-
import { property } from 'lit/decorators.js';
|
|
9
|
-
|
|
10
|
-
import icons from './assets/img/icons';
|
|
11
|
-
import { defaultTopNavConfig } from './data/menus';
|
|
12
|
-
import formatUrl from './lib/format-url';
|
|
13
|
-
import { makeBooleanString } from './lib/make-boolean-string';
|
|
14
|
-
import { IATopNavConfig, IATopNavLink } from './models';
|
|
15
|
-
import dropdownMenuCSS from './styles/dropdown-menu';
|
|
16
|
-
import TrackedElement from './tracked-element';
|
|
17
|
-
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
18
|
-
import KeyboardNavigation from './lib/keyboard-navigation';
|
|
19
|
-
|
|
20
|
-
export default class DropdownMenu extends TrackedElement {
|
|
21
|
-
@property({ type: String }) baseHost = '';
|
|
22
|
-
@property({ type: Object }) config: IATopNavConfig = defaultTopNavConfig;
|
|
23
|
-
@property({ type: Array }) menuItems: IATopNavLink[] | IATopNavLink[][] = [];
|
|
24
|
-
@property({ type: Boolean }) animated = false;
|
|
25
|
-
@property({ type: Boolean }) open = false;
|
|
26
|
-
|
|
27
|
-
private previousKeydownListener?: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
(this: HTMLElement, ev: KeyboardEvent) => any;
|
|
29
|
-
|
|
30
|
-
static get styles(): CSSResultGroup {
|
|
31
|
-
return dropdownMenuCSS;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
updated(props: PropertyValues) {
|
|
35
|
-
if (props.has('open') && this.open) {
|
|
36
|
-
const container = this.shadowRoot?.querySelector(
|
|
37
|
-
'.nav-container',
|
|
38
|
-
) as HTMLElement;
|
|
39
|
-
|
|
40
|
-
if (container) {
|
|
41
|
-
const keyboardNavigation = new KeyboardNavigation(
|
|
42
|
-
container,
|
|
43
|
-
'usermenu',
|
|
44
|
-
);
|
|
45
|
-
this.addEventListener('keydown', keyboardNavigation.handleKeyDown);
|
|
46
|
-
if (this.previousKeydownListener) {
|
|
47
|
-
this.removeEventListener('keydown', this.previousKeydownListener);
|
|
48
|
-
}
|
|
49
|
-
this.previousKeydownListener = keyboardNavigation.handleKeyDown;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get dropdownItems() {
|
|
55
|
-
if (!this.menuItems) return nothing;
|
|
56
|
-
|
|
57
|
-
if (!Array.isArray(this.menuItems[0])) {
|
|
58
|
-
const submenu = this.menuItems as IATopNavLink[];
|
|
59
|
-
return this.dropdownSection(submenu);
|
|
60
|
-
}
|
|
61
|
-
return this.menuItems.map((submenu, i) => {
|
|
62
|
-
const joiner = i ? DropdownMenu.dropdownDivider : html``;
|
|
63
|
-
if (!Array.isArray(submenu)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
return [joiner, ...this.dropdownSection(submenu)];
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static get dropdownDivider() {
|
|
71
|
-
return html`<li class="divider"></li>`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private dropdownSection(submenu: IATopNavLink[]): TemplateResult[] {
|
|
75
|
-
return submenu.map(
|
|
76
|
-
(item) => html`
|
|
77
|
-
<li>
|
|
78
|
-
${item.url
|
|
79
|
-
? this.dropdownLink(item)
|
|
80
|
-
: DropdownMenu.dropdownText(item)}
|
|
81
|
-
</li>
|
|
82
|
-
`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
dropdownLink(link: IATopNavLink): TemplateResult {
|
|
87
|
-
const calloutText = this.config?.callouts?.[link.title];
|
|
88
|
-
const isMobileUpload = link.class === 'mobile-upload';
|
|
89
|
-
const isTabbable = this.open && !isMobileUpload;
|
|
90
|
-
|
|
91
|
-
return html`<a
|
|
92
|
-
href="${formatUrl(link.url, this.baseHost)}"
|
|
93
|
-
class=${ifDefined(link.class)}
|
|
94
|
-
tabindex="${isTabbable ? '' : '-1'}"
|
|
95
|
-
@click=${this.trackClick}
|
|
96
|
-
data-event-click-tracking="${this.config
|
|
97
|
-
?.eventCategory}|Nav${link.analyticsEvent}"
|
|
98
|
-
aria-label=${calloutText ? `New feature: ${link.title}` : nothing}
|
|
99
|
-
>
|
|
100
|
-
${isMobileUpload ? icons.uploadUnpadded : nothing} ${link.title}
|
|
101
|
-
${calloutText
|
|
102
|
-
? html`<span class="callout" aria-hidden="true">${calloutText}</span>`
|
|
103
|
-
: nothing}
|
|
104
|
-
</a>`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static dropdownText(item: IATopNavLink) {
|
|
108
|
-
return html`<span class="info-item">${item.title}</span>`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get menuClass() {
|
|
112
|
-
if (this.open) return 'open';
|
|
113
|
-
if (this.animated) return 'closed';
|
|
114
|
-
return 'initial';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
render() {
|
|
118
|
-
return html`
|
|
119
|
-
<div class="nav-container">
|
|
120
|
-
<nav
|
|
121
|
-
class="${this.menuClass}"
|
|
122
|
-
aria-hidden="${makeBooleanString(!this.open)}"
|
|
123
|
-
aria-expanded="${makeBooleanString(this.open)}"
|
|
124
|
-
>
|
|
125
|
-
<ul>
|
|
126
|
-
${this.dropdownItems}
|
|
127
|
-
</ul>
|
|
128
|
-
</nav>
|
|
129
|
-
</div>
|
|
130
|
-
`;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
CSSResultGroup,
|
|
3
|
+
html,
|
|
4
|
+
nothing,
|
|
5
|
+
PropertyValues,
|
|
6
|
+
TemplateResult,
|
|
7
|
+
} from 'lit';
|
|
8
|
+
import { property } from 'lit/decorators.js';
|
|
9
|
+
|
|
10
|
+
import icons from './assets/img/icons';
|
|
11
|
+
import { defaultTopNavConfig } from './data/menus';
|
|
12
|
+
import formatUrl from './lib/format-url';
|
|
13
|
+
import { makeBooleanString } from './lib/make-boolean-string';
|
|
14
|
+
import { IATopNavConfig, IATopNavLink } from './models';
|
|
15
|
+
import dropdownMenuCSS from './styles/dropdown-menu';
|
|
16
|
+
import TrackedElement from './tracked-element';
|
|
17
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
18
|
+
import KeyboardNavigation from './lib/keyboard-navigation';
|
|
19
|
+
|
|
20
|
+
export default class DropdownMenu extends TrackedElement {
|
|
21
|
+
@property({ type: String }) baseHost = '';
|
|
22
|
+
@property({ type: Object }) config: IATopNavConfig = defaultTopNavConfig;
|
|
23
|
+
@property({ type: Array }) menuItems: IATopNavLink[] | IATopNavLink[][] = [];
|
|
24
|
+
@property({ type: Boolean }) animated = false;
|
|
25
|
+
@property({ type: Boolean }) open = false;
|
|
26
|
+
|
|
27
|
+
private previousKeydownListener?: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
(this: HTMLElement, ev: KeyboardEvent) => any;
|
|
29
|
+
|
|
30
|
+
static get styles(): CSSResultGroup {
|
|
31
|
+
return dropdownMenuCSS;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
updated(props: PropertyValues) {
|
|
35
|
+
if (props.has('open') && this.open) {
|
|
36
|
+
const container = this.shadowRoot?.querySelector(
|
|
37
|
+
'.nav-container',
|
|
38
|
+
) as HTMLElement;
|
|
39
|
+
|
|
40
|
+
if (container) {
|
|
41
|
+
const keyboardNavigation = new KeyboardNavigation(
|
|
42
|
+
container,
|
|
43
|
+
'usermenu',
|
|
44
|
+
);
|
|
45
|
+
this.addEventListener('keydown', keyboardNavigation.handleKeyDown);
|
|
46
|
+
if (this.previousKeydownListener) {
|
|
47
|
+
this.removeEventListener('keydown', this.previousKeydownListener);
|
|
48
|
+
}
|
|
49
|
+
this.previousKeydownListener = keyboardNavigation.handleKeyDown;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get dropdownItems() {
|
|
55
|
+
if (!this.menuItems) return nothing;
|
|
56
|
+
|
|
57
|
+
if (!Array.isArray(this.menuItems[0])) {
|
|
58
|
+
const submenu = this.menuItems as IATopNavLink[];
|
|
59
|
+
return this.dropdownSection(submenu);
|
|
60
|
+
}
|
|
61
|
+
return this.menuItems.map((submenu, i) => {
|
|
62
|
+
const joiner = i ? DropdownMenu.dropdownDivider : html``;
|
|
63
|
+
if (!Array.isArray(submenu)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
return [joiner, ...this.dropdownSection(submenu)];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static get dropdownDivider() {
|
|
71
|
+
return html`<li class="divider"></li>`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private dropdownSection(submenu: IATopNavLink[]): TemplateResult[] {
|
|
75
|
+
return submenu.map(
|
|
76
|
+
(item) => html`
|
|
77
|
+
<li>
|
|
78
|
+
${item.url
|
|
79
|
+
? this.dropdownLink(item)
|
|
80
|
+
: DropdownMenu.dropdownText(item)}
|
|
81
|
+
</li>
|
|
82
|
+
`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dropdownLink(link: IATopNavLink): TemplateResult {
|
|
87
|
+
const calloutText = this.config?.callouts?.[link.title];
|
|
88
|
+
const isMobileUpload = link.class === 'mobile-upload';
|
|
89
|
+
const isTabbable = this.open && !isMobileUpload;
|
|
90
|
+
|
|
91
|
+
return html`<a
|
|
92
|
+
href="${formatUrl(link.url, this.baseHost)}"
|
|
93
|
+
class=${ifDefined(link.class)}
|
|
94
|
+
tabindex="${isTabbable ? '' : '-1'}"
|
|
95
|
+
@click=${this.trackClick}
|
|
96
|
+
data-event-click-tracking="${this.config
|
|
97
|
+
?.eventCategory}|Nav${link.analyticsEvent}"
|
|
98
|
+
aria-label=${calloutText ? `New feature: ${link.title}` : nothing}
|
|
99
|
+
>
|
|
100
|
+
${isMobileUpload ? icons.uploadUnpadded : nothing} ${link.title}
|
|
101
|
+
${calloutText
|
|
102
|
+
? html`<span class="callout" aria-hidden="true">${calloutText}</span>`
|
|
103
|
+
: nothing}
|
|
104
|
+
</a>`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static dropdownText(item: IATopNavLink) {
|
|
108
|
+
return html`<span class="info-item">${item.title}</span>`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get menuClass() {
|
|
112
|
+
if (this.open) return 'open';
|
|
113
|
+
if (this.animated) return 'closed';
|
|
114
|
+
return 'initial';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
render() {
|
|
118
|
+
return html`
|
|
119
|
+
<div class="nav-container">
|
|
120
|
+
<nav
|
|
121
|
+
class="${this.menuClass}"
|
|
122
|
+
aria-hidden="${makeBooleanString(!this.open)}"
|
|
123
|
+
aria-expanded="${makeBooleanString(this.open)}"
|
|
124
|
+
>
|
|
125
|
+
<ul>
|
|
126
|
+
${this.dropdownItems}
|
|
127
|
+
</ul>
|
|
128
|
+
</nav>
|
|
129
|
+
</div>
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
}
|