@m3e/nav-bar 1.0.0-rc.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,153 @@
1
+ import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
2
+ import { customElement, property, state } from "lit/decorators.js";
3
+
4
+ import { DesignToken, Role } from "@m3e/core";
5
+
6
+ import { SelectionManager, selectionManager } from "@m3e/core/a11y";
7
+ import { Breakpoint, M3eBreakpointObserver } from "@m3e/core/layout";
8
+
9
+ import { M3eNavItemElement } from "./NavItemElement";
10
+ import { NavItemOrientation } from "./NavItemOrientation";
11
+ import { NavBarMode } from "./NavBarMode";
12
+
13
+ /**
14
+ * @summary
15
+ * A horizontal bar, typically used on smaller devices, that allows a user to switch between 3-5 views.
16
+ *
17
+ * @description
18
+ * The `m3e-nav-bar` component provides a horizontal navigation bar for switching between primary destinations in
19
+ * an application. Designed for smaller devices, it supports 3-5 interactive items, orientation, and theming
20
+ * via CSS custom properties.
21
+ *
22
+ * @example
23
+ * The following example illustrates a nav bar with vertically oriented items.
24
+ * ```html
25
+ * <m3e-nav-bar>
26
+ * <m3e-nav-item><m3e-icon slot="icon" name="news"></m3e-icon>News</m3e-nav-item>
27
+ * <m3e-nav-item><m3e-icon slot="icon" name="globe"></m3e-icon>Global</m3e-nav-item>
28
+ * <m3e-nav-item><m3e-icon slot="icon" name="star"></m3e-icon>For you</m3e-nav-item>
29
+ * <m3e-nav-item><m3e-icon slot="icon" name="newsstand"></m3e-icon>Trending</m3e-nav-item>
30
+ * </m3e-nav-bar>
31
+ * ```
32
+ *
33
+ * @tag m3e-nav-bar
34
+ *
35
+ * @slot - Renders the items of the bar.
36
+ *
37
+ * @attr mode - The mode in which items in the bar are presented.
38
+ *
39
+ * @fires change - Emitted when the selected state of an item changes.
40
+ *
41
+ * @cssprop --m3e-nav-bar-height - Height of the navigation bar.
42
+ * @cssprop --m3e-nav-bar-container-color - Background color of the navigation bar container.
43
+ * @cssprop --m3e-nav-bar-vertical-item-width - Minimum width of vertical nav items.
44
+ */
45
+ @customElement("m3e-nav-bar")
46
+ export class M3eNavBarElement extends Role(LitElement, "navigation") {
47
+ /** The styles of the element. */
48
+ static override styles: CSSResultGroup = css`
49
+ :host {
50
+ display: flex;
51
+ overflow-x: auto;
52
+ align-items: stretch;
53
+ scrollbar-width: ${DesignToken.scrollbar.thinWidth};
54
+ scrollbar-color: ${DesignToken.scrollbar.color};
55
+ min-height: var(--m3e-nav-bar-height, 4rem);
56
+ background-color: var(--m3e-nav-bar-container-color, ${DesignToken.color.surfaceContainer});
57
+ justify-content: center;
58
+ --_nav-item-min-width: var(--m3e-nav-bar-vertical-item-width, 7rem);
59
+ }
60
+ `;
61
+
62
+ /** @internal */ [selectionManager] = new SelectionManager<M3eNavItemElement>().disableRovingTabIndex();
63
+ /** @internal */ #breakpointUnobserve?: () => void;
64
+ /** @internal */ @state() private _mode?: Exclude<NavBarMode, "auto">;
65
+
66
+ /**
67
+ * The mode in which items in the bar are presented.
68
+ * @default "compact"
69
+ */
70
+ @property({ reflect: true }) mode: NavBarMode = "compact";
71
+
72
+ /** The items of the bar. */
73
+ get items(): readonly M3eNavItemElement[] {
74
+ return this[selectionManager].items;
75
+ }
76
+
77
+ /** The selected item. */
78
+ get selected(): M3eNavItemElement | null {
79
+ return this[selectionManager].selectedItems[0] ?? null;
80
+ }
81
+
82
+ /** The current mode applied to the bar. */
83
+ get currentMode(): Exclude<NavBarMode, "auto"> {
84
+ return this._mode ?? (this.mode !== "compact" ? "expanded" : "compact");
85
+ }
86
+ set currentMode(value: Exclude<NavBarMode, "auto">) {
87
+ this._mode = value;
88
+ }
89
+
90
+ /** @inheritdoc */
91
+ override disconnectedCallback(): void {
92
+ super.disconnectedCallback();
93
+
94
+ this._mode = undefined;
95
+ this.#breakpointUnobserve?.();
96
+ }
97
+
98
+ /** @inheritdoc */
99
+ protected override update(changedProperties: PropertyValues): void {
100
+ super.update(changedProperties);
101
+
102
+ if (changedProperties.has("mode")) {
103
+ this.#breakpointUnobserve?.();
104
+
105
+ if (this.mode === "auto") {
106
+ this.#breakpointUnobserve = M3eBreakpointObserver.observe([Breakpoint.XSmall, Breakpoint.Small], (matches) => {
107
+ this._mode = matches.get(Breakpoint.XSmall) || matches.get(Breakpoint.Small) ? "compact" : "expanded";
108
+ this._updateItems();
109
+ });
110
+ } else {
111
+ this._updateItems();
112
+ }
113
+ }
114
+ if (changedProperties.has("_mode")) {
115
+ this._updateItems();
116
+ }
117
+ }
118
+
119
+ /** @inheritdoc */
120
+ protected override render(): unknown {
121
+ return html`<slot @change="${this.#handleChange}" @slotchange="${this.#handleSlotChange}"></slot>`;
122
+ }
123
+
124
+ /** @private */
125
+ #handleSlotChange(): void {
126
+ this[selectionManager].setItems([...this.querySelectorAll("m3e-nav-item")]);
127
+ this._updateItems();
128
+ }
129
+
130
+ /** @private */
131
+ #handleChange(e: Event): void {
132
+ e.stopPropagation();
133
+ this.dispatchEvent(new Event("change", { bubbles: true }));
134
+ }
135
+
136
+ /** @internal */
137
+ protected _updateItems(): void {
138
+ const orientation: NavItemOrientation = this.currentMode === "compact" ? "vertical" : "horizontal";
139
+ this._updateOrientation(orientation);
140
+ this.classList.toggle("-compact", orientation === "vertical");
141
+ }
142
+
143
+ /** @internal */
144
+ protected _updateOrientation(orientation: NavItemOrientation): void {
145
+ this[selectionManager].items.forEach((x) => (x.orientation = orientation));
146
+ }
147
+ }
148
+
149
+ declare global {
150
+ interface HTMLElementTagNameMap {
151
+ "m3e-nav-bar": M3eNavBarElement;
152
+ }
153
+ }
@@ -0,0 +1,2 @@
1
+ /** Specifies the possible modes in which to present items in a navigation bar. */
2
+ export type NavBarMode = "compact" | "expanded" | "auto";
@@ -0,0 +1,421 @@
1
+ import { css, CSSResultGroup, html, LitElement, nothing, PropertyValues } from "lit";
2
+ import { customElement, property, query } from "lit/decorators.js";
3
+
4
+ import {
5
+ AttachInternals,
6
+ DesignToken,
7
+ Disabled,
8
+ DisabledInteractive,
9
+ Focusable,
10
+ KeyboardClick,
11
+ LinkButton,
12
+ M3eFocusRingElement,
13
+ M3eRippleElement,
14
+ M3eStateLayerElement,
15
+ renderPseudoLink,
16
+ Role,
17
+ Selected,
18
+ } from "@m3e/core";
19
+
20
+ import { selectionManager } from "@m3e/core/a11y";
21
+
22
+ import type { M3eNavBarElement } from "./NavBarElement";
23
+ import { NavItemOrientation } from "./NavItemOrientation";
24
+
25
+ /**
26
+ * @summary
27
+ * An item, placed in a navigation bar or rail, used to navigate to destinations in an application.
28
+ *
29
+ * @description
30
+ * The `m3e-nav-item` component represents an interactive navigation item for use in navigation bars
31
+ * or rails. Designed according to Material 3 principles, it supports icon and label slots, selection state,
32
+ * orientation, and extensive theming via CSS custom properties.
33
+ *
34
+ * @example
35
+ * The following example illustrates a nav bar with vertically oriented items.
36
+ * ```html
37
+ * <m3e-nav-bar>
38
+ * <m3e-nav-item><m3e-icon slot="icon" name="news"></m3e-icon>News</m3e-nav-item>
39
+ * <m3e-nav-item><m3e-icon slot="icon" name="globe"></m3e-icon>Global</m3e-nav-item>
40
+ * <m3e-nav-item><m3e-icon slot="icon" name="star"></m3e-icon>For you</m3e-nav-item>
41
+ * <m3e-nav-item><m3e-icon slot="icon" name="newsstand"></m3e-icon>Trending</m3e-nav-item>
42
+ * </m3e-nav-bar>
43
+ * ```
44
+ *
45
+ * @tag m3e-nav-item
46
+ *
47
+ * @slot - Renders the label of the item.
48
+ * @slot icon - Renders the icon of the item.
49
+ * @slot selected-icon - Renders the icon of the item when selected.
50
+ *
51
+ * @attr disabled - A value indicating whether the element is disabled.
52
+ * @attr disabled-interactive - A value indicating whether the element is disabled and interactive.
53
+ * @attr download - A value indicating whether the `target` of the link button will be downloaded, optionally specifying the new name of the file.
54
+ * @attr href - The URL to which the link button points.
55
+ * @attr orientation - The layout orientation of the item.
56
+ * @attr rel - The relationship between the `target` of the link button and the document.
57
+ * @attr selected - A value indicating whether the element is selected.
58
+ * @attr target - The target of the link button.
59
+ *
60
+ * @fires input - Emitted when the selected state changes.
61
+ * @fires change - Emitted when the selected state changes.
62
+ *
63
+ * @cssprop --m3e-nav-item-label-text-font-size - Font size for the label text.
64
+ * @cssprop --m3e-nav-item-label-text-font-weight - Font weight for the label text.
65
+ * @cssprop --m3e-nav-item-label-text-line-height - Line height for the label text.
66
+ * @cssprop --m3e-nav-item-label-text-tracking - Letter spacing for the label text.
67
+ * @cssprop --m3e-nav-item-shape - Border radius of the nav item.
68
+ * @cssprop --m3e-nav-item-icon-size - Size of the icon.
69
+ * @cssprop --m3e-nav-item-spacing - Spacing between icon and label.
70
+ * @cssprop --m3e-nav-item-inactive-label-text-color - Color of the label text when inactive.
71
+ * @cssprop --m3e-nav-item-inactive-icon-color - Color of the icon when inactive.
72
+ * @cssprop --m3e-nav-item-inactive-hover-state-layer-color - State layer color on hover when inactive.
73
+ * @cssprop --m3e-nav-item-inactive-focus-state-layer-color - State layer color on focus when inactive.
74
+ * @cssprop --m3e-nav-item-inactive-pressed-state-layer-color - State layer color on press when inactive.
75
+ * @cssprop --m3e-nav-item-active-label-text-color - Color of the label text when active/selected.
76
+ * @cssprop --m3e-nav-item-active-icon-color - Color of the icon when active/selected.
77
+ * @cssprop --m3e-nav-item-active-container-color - Container color when active/selected.
78
+ * @cssprop --m3e-nav-item-active-hover-state-layer-color - State layer color on hover when active.
79
+ * @cssprop --m3e-nav-item-active-focus-state-layer-color - State layer color on focus when active.
80
+ * @cssprop --m3e-nav-item-active-pressed-state-layer-color - State layer color on press when active.
81
+ * @cssprop --m3e-nav-item-focus-ring-shape - Border radius for the focus ring.
82
+ * @cssprop --m3e-nav-item-disabled-label-text-color - Color of the label text when disabled.
83
+ * @cssprop --m3e-nav-item-disabled-label-text-opacity - Opacity of the label text when disabled.
84
+ * @cssprop --m3e-nav-item-disabled-icon-color - Color of the icon when disabled.
85
+ * @cssprop --m3e-nav-item-disabled-icon-opacity - Opacity of the icon when disabled.
86
+ * @cssprop --m3e-horizontal-nav-item-padding - Padding for horizontal orientation.
87
+ * @cssprop --m3e-horizontal-nav-item-active-indicator-height - Height of the active indicator in horizontal orientation.
88
+ * @cssprop --m3e-vertical-nav-item-active-indicator-width - Width of the active indicator in vertical orientation.
89
+ * @cssprop --m3e-vertical-nav-item-active-indicator-height - Height of the active indicator in vertical orientation.
90
+ * @cssprop --m3e-vertical-nav-item-active-indicator-margin - Margin for the active indicator in vertical orientation.
91
+ */
92
+ @customElement("m3e-nav-item")
93
+ export class M3eNavItemElement extends LinkButton(
94
+ Selected(KeyboardClick(Focusable(DisabledInteractive(Disabled(AttachInternals(Role(LitElement, "button"), true))))))
95
+ ) {
96
+ /** The styles of the element. */
97
+ static override styles: CSSResultGroup = css`
98
+ :host {
99
+ display: inline-block;
100
+ vertical-align: middle;
101
+ position: relative;
102
+ outline: none;
103
+ user-select: none;
104
+ flex: 1;
105
+ font-size: var(--m3e-nav-item-label-text-font-size, ${DesignToken.typescale.standard.label.medium.fontSize});
106
+ font-weight: var(
107
+ --m3e-nav-item-label-text-font-weight,
108
+ ${DesignToken.typescale.standard.label.medium.fontWeight}
109
+ );
110
+ line-height: var(
111
+ --m3e-nav-item-label-text-line-height,
112
+ ${DesignToken.typescale.standard.label.medium.lineHeight}
113
+ );
114
+ letter-spacing: var(--m3e-nav-item-label-text-tracking, ${DesignToken.typescale.standard.label.medium.tracking});
115
+ border-radius: var(--m3e-nav-item-shape, ${DesignToken.shape.corner.full});
116
+ min-width: var(--_nav-item-min-width);
117
+ align-self: var(--_nav-item-align-self);
118
+ }
119
+ :host([orientation="horizontal"]) {
120
+ max-width: fit-content;
121
+ }
122
+ :host(:not(:disabled):not([disabled-interactive])) {
123
+ cursor: pointer;
124
+ }
125
+ :host([disabled-interactive]) {
126
+ cursor: not-allowed;
127
+ }
128
+ .outer {
129
+ height: 100%;
130
+ }
131
+ .outer,
132
+ .inner {
133
+ display: flex;
134
+ align-items: center;
135
+ justify-content: var(--_nav-item-justify-content, center);
136
+ position: relative;
137
+ border-radius: inherit;
138
+ }
139
+ .icon-wrapper {
140
+ position: relative;
141
+ flex: none;
142
+ }
143
+ .base {
144
+ justify-content: unset;
145
+ box-sizing: border-box;
146
+ vertical-align: middle;
147
+ display: inline-flex;
148
+ align-items: center;
149
+ justify-content: center;
150
+ position: relative;
151
+ width: 100%;
152
+ }
153
+ .icon {
154
+ position: absolute;
155
+ }
156
+ .label {
157
+ vertical-align: middle;
158
+ }
159
+ ::slotted([slot="icon"]),
160
+ ::slotted([slot="selected-icon"]) {
161
+ width: 1em;
162
+ font-size: var(--m3e-nav-item-icon-size, 1.5rem) !important;
163
+ }
164
+ :host(:not([selected]):not(:disabled):not([disabled-interactive])) .outer {
165
+ --m3e-state-layer-hover-color: var(
166
+ --m3e-nav-item-inactive-hover-state-layer-color,
167
+ ${DesignToken.color.onSecondaryContainer}
168
+ );
169
+ --m3e-state-layer-focus-color: var(
170
+ --m3e-nav-item-inactive-focus-state-layer-color,
171
+ ${DesignToken.color.onSecondaryContainer}
172
+ );
173
+ --m3e-ripple-color: var(
174
+ --m3e-nav-item-inactive-pressed-state-layer-color,
175
+ ${DesignToken.color.onSecondaryContainer}
176
+ );
177
+ }
178
+ :host(:not([selected]):not(:disabled):not([disabled-interactive])) .label {
179
+ color: var(--m3e-nav-item-inactive-label-text-color, ${DesignToken.color.onSurfaceVariant});
180
+ }
181
+ :host(:not([selected]):not(:disabled):not([disabled-interactive])) .icon {
182
+ color: var(--m3e-nav-item-inactive-icon-color, ${DesignToken.color.onSecondaryContainer});
183
+ }
184
+ :host([selected]:not(:disabled):not([disabled-interactive])) .outer {
185
+ --m3e-state-layer-hover-color: var(
186
+ --m3e-nav-item-active-hover-state-layer-color,
187
+ ${DesignToken.color.onSecondaryContainer}
188
+ );
189
+ --m3e-state-layer-focus-color: var(
190
+ --m3e-nav-item-active-focus-state-layer-color,
191
+ ${DesignToken.color.onSecondaryContainer}
192
+ );
193
+ --m3e-ripple-color: var(
194
+ --m3e-nav-item-active-pressed-state-layer-color,
195
+ ${DesignToken.color.onSecondaryContainer}
196
+ );
197
+ }
198
+ :host([selected]:not(:disabled):not([disabled-interactive])) .label {
199
+ color: var(--m3e-nav-item-active-label-text-color, ${DesignToken.color.secondary});
200
+ }
201
+ :host([selected]:not(:disabled):not([disabled-interactive])) .state-layer {
202
+ background-color: var(--m3e-nav-item-active-container-color, ${DesignToken.color.secondaryContainer});
203
+ }
204
+ :host([selected]:not(:disabled):not([disabled-interactive])) .icon {
205
+ color: var(--m3e-nav-item-active-icon-color, ${DesignToken.color.onSecondaryContainer});
206
+ }
207
+ :host([orientation="vertical"]) .outer {
208
+ align-self: stretch;
209
+ align-items: flex-start;
210
+ }
211
+ :host([orientation="vertical"]) .label {
212
+ text-align: center;
213
+ display: -webkit-box;
214
+ -webkit-line-clamp: 2;
215
+ -webkit-box-orient: vertical;
216
+ overflow: hidden;
217
+ line-clamp: 2;
218
+ }
219
+ :host([orientation="vertical"]) .base {
220
+ flex-direction: column;
221
+ row-gap: var(--m3e-nav-item-spacing, 0.25rem);
222
+ }
223
+ :host([orientation="vertical"]) .base {
224
+ margin-block: var(--m3e-vertical-nav-item-active-indicator-margin, 0.375rem);
225
+ }
226
+ :host([orientation="vertical"]) .state-layer,
227
+ :host([orientation="vertical"]) .ripple {
228
+ top: var(--m3e-vertical-nav-item-active-indicator-margin, 0.375rem);
229
+ bottom: unset;
230
+ }
231
+ :host([orientation="vertical"]) .state-layer,
232
+ :host([orientation="vertical"]) .ripple,
233
+ :host([orientation="vertical"]) .icon-wrapper {
234
+ width: var(--m3e-vertical-nav-item-active-indicator-width, 3.5rem);
235
+ }
236
+ :host([orientation="vertical"]) .state-layer,
237
+ :host([orientation="vertical"]) .ripple,
238
+ :host([orientation="vertical"]) .icon-wrapper {
239
+ height: var(--m3e-vertical-nav-item-active-indicator-height, 2rem);
240
+ }
241
+ :host([orientation="vertical"]) .icon {
242
+ top: calc(
243
+ calc(var(--m3e-vertical-nav-item-active-indicator-height, 2rem) / 2) -
244
+ calc(var(--m3e-nav-item-icon-size, 1.5rem) / 2)
245
+ );
246
+ left: calc(
247
+ calc(var(--m3e-vertical-nav-item-active-indicator-width, 3.5rem) / 2) -
248
+ calc(var(--m3e-nav-item-icon-size, 1.5rem) / 2)
249
+ );
250
+ }
251
+ :host([orientation="vertical"]) .focus-ring {
252
+ border-radius: var(--m3e-nav-item-focus-ring-shape, ${DesignToken.shape.corner.extraSmall});
253
+ }
254
+ :host([orientation="horizontal"]) .icon-wrapper {
255
+ width: var(--m3e-nav-item-icon-size, 1.5rem);
256
+ height: var(--m3e-nav-item-icon-size, 1.5rem);
257
+ }
258
+ :host([orientation="horizontal"]) .base {
259
+ padding: var(--m3e-horizontal-nav-item-padding, 1rem);
260
+ }
261
+ :host([orientation="horizontal"]) .label {
262
+ flex: 1 1 auto;
263
+ }
264
+ :host([orientation="horizontal"]) .base {
265
+ column-gap: var(--m3e-nav-item-spacing, 0.25rem);
266
+ }
267
+ :host([orientation="horizontal"]) .inner {
268
+ height: var(--m3e-horizontal-nav-item-active-indicator-height, 2.5rem);
269
+ width: fit-content;
270
+ }
271
+ .state-layer,
272
+ .ripple {
273
+ margin-inline: auto;
274
+ }
275
+ :host(:disabled) .label,
276
+ :host([disabled-interactive]) .label {
277
+ color: color-mix(
278
+ in srgb,
279
+ var(--m3e-nav-item-disabled-label-text-color, ${DesignToken.color.onSurface})
280
+ var(--m3e-nav-item-disabled-label-text-opacity, 38%),
281
+ transparent
282
+ );
283
+ }
284
+ :host(:disabled) .icon,
285
+ :host([disabled-interactive]) .icon {
286
+ color: color-mix(
287
+ in srgb,
288
+ var(--m3e-nav-item-disabled-icon-color, ${DesignToken.color.onSurface})
289
+ var(--m3e-nav-item-disabled-icon-opacity, 38%),
290
+ transparent
291
+ );
292
+ }
293
+ @media (forced-colors: active) {
294
+ :host(:disabled) .label,
295
+ :host([disabled-interactive]) .label,
296
+ :host(:disabled) .icon,
297
+ :host([disabled-interactive]) .icon {
298
+ color: GrayText;
299
+ }
300
+ :host(:not([selected]):not(:disabled):not([disabled-interactive])) .label,
301
+ :host(:not([selected]):not(:disabled):not([disabled-interactive])) .icon {
302
+ color: ButtonText;
303
+ }
304
+ :host([selected]:not(:disabled):not([disabled-interactive])) .state-layer {
305
+ background-color: ButtonText;
306
+ }
307
+ :host([orientation="vertical"][selected]:not(:disabled):not([disabled-interactive])) .label {
308
+ color: ButtonText;
309
+ }
310
+ :host([orientation="horizontal"][selected]:not(:disabled):not([disabled-interactive])) .label,
311
+ :host([selected]:not(:disabled):not([disabled-interactive])) .icon {
312
+ forced-color-adjust: none;
313
+ color: ButtonFace;
314
+ }
315
+ }
316
+ `;
317
+
318
+ /** @private */ readonly #clickHandler = (e: Event) => this.#handleClick(e);
319
+ /** @private */ @query(".focus-ring") private readonly _focusRing?: M3eFocusRingElement;
320
+ /** @private */ @query(".state-layer") private readonly _stateLayer?: M3eStateLayerElement;
321
+ /** @private */ @query(".ripple") private readonly _ripple?: M3eRippleElement;
322
+
323
+ /**
324
+ * The layout orientation of the item.
325
+ * @default "vertical"
326
+ */
327
+ @property({ reflect: true }) orientation: NavItemOrientation = "vertical";
328
+
329
+ /** The navigation bar to which this item belongs. */
330
+ get navBar(): M3eNavBarElement | null {
331
+ return this.closest("m3e-nav-bar") ?? this.closest("m3e-nav-rail") ?? null;
332
+ }
333
+
334
+ /** @inheritdoc */
335
+ override connectedCallback(): void {
336
+ super.connectedCallback();
337
+ this.addEventListener("click", this.#clickHandler);
338
+ }
339
+
340
+ /** @inheritdoc */
341
+ override disconnectedCallback(): void {
342
+ super.disconnectedCallback();
343
+ this.removeEventListener("click", this.#clickHandler);
344
+ }
345
+
346
+ /** @inheritdoc */
347
+ protected override update(changedProperties: PropertyValues<this>): void {
348
+ super.update(changedProperties);
349
+
350
+ if (changedProperties.has("selected")) {
351
+ this.ariaSelected = null;
352
+ this.ariaPressed = null;
353
+ this.ariaCurrent = `${this.selected}`;
354
+ for (const icon of this.querySelectorAll("m3e-icon")) {
355
+ icon.toggleAttribute("filled", this.selected);
356
+ }
357
+ this.navBar?.[selectionManager].notifySelectionChange(this);
358
+ }
359
+ }
360
+
361
+ /** @inheritdoc */
362
+ protected override updated(_changedProperties: PropertyValues<this>): void {
363
+ super.updated(_changedProperties);
364
+
365
+ if (_changedProperties.has("orientation")) {
366
+ this._focusRing?.attach(this);
367
+ }
368
+ }
369
+
370
+ /** @inheritdoc */
371
+ protected override firstUpdated(_changedProperties: PropertyValues<this>): void {
372
+ super.firstUpdated(_changedProperties);
373
+ [this._focusRing, this._stateLayer, this._ripple].forEach((x) => x?.attach(this));
374
+ }
375
+
376
+ /** @inheritdoc */
377
+ protected override render(): unknown {
378
+ const disabled = this.disabled || this.disabledInteractive;
379
+ return html`${this.orientation === "vertical"
380
+ ? html`<m3e-focus-ring class="focus-ring" inward></m3e-focus-ring>`
381
+ : nothing}
382
+ <div class="outer">
383
+ ${this[renderPseudoLink]()}
384
+ <div class="inner">
385
+ ${this.orientation === "horizontal" ? html`<m3e-focus-ring class="focus-ring"></m3e-focus-ring>` : nothing}
386
+ <m3e-state-layer class="state-layer" ?disabled="${disabled}"></m3e-state-layer>
387
+ <m3e-ripple class="ripple" centered ?disabled="${disabled}"></m3e-ripple>
388
+ <div class="touch" aria-hidden="true"></div>
389
+ <div class="base">
390
+ <div class="icon-wrapper" aria-hidden="true">
391
+ <div class="icon">
392
+ <slot name="icon" aria-hidden="true"></slot>
393
+ </div>
394
+ </div>
395
+ <div class="label">
396
+ <slot></slot>
397
+ </div>
398
+ </div>
399
+ </div>
400
+ </div>`;
401
+ }
402
+
403
+ /** @private */
404
+ #handleClick(e: Event): void {
405
+ if (e.defaultPrevented) return;
406
+
407
+ this.selected = true;
408
+ if (this.dispatchEvent(new Event("input", { bubbles: true, composed: true, cancelable: true }))) {
409
+ this.navBar?.[selectionManager].notifySelectionChange(this);
410
+ this.dispatchEvent(new Event("change", { bubbles: true }));
411
+ } else {
412
+ this.selected = false;
413
+ }
414
+ }
415
+ }
416
+
417
+ declare global {
418
+ interface HTMLElementTagNameMap {
419
+ "m3e-nav-item": M3eNavItemElement;
420
+ }
421
+ }
@@ -0,0 +1,2 @@
1
+ /** Specifies the possible layout orientations of a navigation item. */
2
+ export type NavItemOrientation = "vertical" | "horizontal";
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./NavBarElement";
2
+ export * from "./NavBarMode";
3
+ export * from "./NavItemElement";
4
+ export * from "./NavItemOrientation";
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist/src"
6
+ },
7
+ "include": ["src/**/*.ts", "**/*.mjs", "**/*.js"],
8
+ "exclude": []
9
+ }