@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.
@@ -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
@@ -544,7 +544,7 @@ export function buildTopNavMenus(
544
544
  analyticsEvent: 'UserLoans',
545
545
  },
546
546
  {
547
- url: `${baseHost}/details/fav-${userid}`,
547
+ url: `${baseHost}/details/@${userid}/favorites`,
548
548
  title: 'My favorites',
549
549
  analyticsEvent: 'UserFavorites',
550
550
  },
@@ -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
+ }