@m3e/nav-rail 1.0.0-rc.1 → 1.0.0-rc.2
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/README.md +1 -2
- package/dist/custom-elements.json +2626 -9
- package/dist/html-custom-data.json +8 -2
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +1 -1
- package/package.json +5 -5
- package/cem.config.mjs +0 -16
- package/demo/index.html +0 -63
- package/dist/src/NavRailElement.d.ts +0 -70
- package/dist/src/NavRailElement.d.ts.map +0 -1
- package/dist/src/NavRailToggleElement.d.ts +0 -52
- package/dist/src/NavRailToggleElement.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.d.ts.map +0 -1
- package/eslint.config.mjs +0 -13
- package/rollup.config.js +0 -32
- package/src/NavRailElement.ts +0 -153
- package/src/NavRailToggleElement.ts +0 -112
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -9
package/src/NavRailElement.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { css, CSSResultGroup } from "lit";
|
|
2
|
-
import { customElement } from "lit/decorators.js";
|
|
3
|
-
|
|
4
|
-
import { DesignToken } from "@m3e/core";
|
|
5
|
-
import { M3eInteractivityChecker, RovingTabIndexManager, selectionManager } from "@m3e/core/a11y";
|
|
6
|
-
import { M3eNavBarElement, NavItemOrientation } from "@m3e/nav-bar";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @summary
|
|
10
|
-
* A vertical bar, typically used on larger devices, that allows a user to switch between views.
|
|
11
|
-
*
|
|
12
|
-
* @description
|
|
13
|
-
* The `m3e-nav-rail` component provides a vertical navigation rail for switching between views in
|
|
14
|
-
* an application. Designed for larger devices, it supports compact and expanded modes, interactive
|
|
15
|
-
* items, and theming via CSS custom properties.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* The following example illustrates a nav rail whose expanded state is automatically determined by the
|
|
19
|
-
* current screen size. In addition, a toggle button is used to allow the user to manually toggle the
|
|
20
|
-
* expanded state.
|
|
21
|
-
*
|
|
22
|
-
* ```html
|
|
23
|
-
* <m3e-nav-rail id="nav-rail" mode="auto">
|
|
24
|
-
* <m3e-icon-button toggle>
|
|
25
|
-
* <m3e-icon name="menu"></m3e-icon>
|
|
26
|
-
* <m3e-icon slot="selected" name="menu_open"></m3e-icon>
|
|
27
|
-
* <m3e-nav-rail-toggle for="nav-rail"></m3e-nav-rail-toggle>
|
|
28
|
-
* </m3e-icon-button>
|
|
29
|
-
* <m3e-fab size="small">
|
|
30
|
-
* <m3e-icon name="edit"></m3e-icon>
|
|
31
|
-
* <span slot="label">Extended</span>
|
|
32
|
-
* </m3e-fab>
|
|
33
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="news"></m3e-icon>News</m3e-nav-item>
|
|
34
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="globe"></m3e-icon>Global</m3e-nav-item>
|
|
35
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="star"></m3e-icon>For you</m3e-nav-item>
|
|
36
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="newsstand"></m3e-icon>Trending</m3e-nav-item>
|
|
37
|
-
* </m3e-nav-rail>
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @tag m3e-nav-rail
|
|
41
|
-
*
|
|
42
|
-
* @attr mode - The mode in which items in the rail are presented.
|
|
43
|
-
*
|
|
44
|
-
* @fires change - Emitted when the selected state of an item changes.
|
|
45
|
-
*
|
|
46
|
-
* @cssprop --m3e-nav-rail-top-space - Top block padding for the nav rail.
|
|
47
|
-
* @cssprop --m3e-nav-rail-bottom-space - Bottom block padding for the nav rail.
|
|
48
|
-
* @cssprop --m3e-nav-rail-compact-width - Width of the nav rail in compact mode.
|
|
49
|
-
* @cssprop --m3e-nav-rail-expanded-inline-padding - Inline padding for expanded nav rail.
|
|
50
|
-
* @cssprop --m3e-nav-rail-expanded-min-width - Minimum width of the nav rail in expanded mode.
|
|
51
|
-
* @cssprop --m3e-nav-rail-expanded-max-width - Maximum width of the nav rail in expanded mode.
|
|
52
|
-
* @cssprop --m3e-nav-rail-expanded-item-height - Height of nav items in expanded mode.
|
|
53
|
-
* @cssprop --m3e-nav-rail-button-item-space - Space below icon buttons and FABs.
|
|
54
|
-
* @cssprop --m3e-nav-rail-expanded-icon-button-inset - Inset for icon buttons in expanded mode.
|
|
55
|
-
*/
|
|
56
|
-
@customElement("m3e-nav-rail")
|
|
57
|
-
export class M3eNavRailElement extends M3eNavBarElement {
|
|
58
|
-
/** The styles of the element. */
|
|
59
|
-
static override styles: CSSResultGroup = css`
|
|
60
|
-
:host {
|
|
61
|
-
display: flex;
|
|
62
|
-
flex-direction: column;
|
|
63
|
-
overflow-x: hidden;
|
|
64
|
-
overflow-y: auto;
|
|
65
|
-
scrollbar-width: ${DesignToken.scrollbar.thinWidth};
|
|
66
|
-
scrollbar-color: ${DesignToken.scrollbar.color};
|
|
67
|
-
padding-block-start: var(--m3e-nav-rail-top-space, 2.75rem);
|
|
68
|
-
padding-block-end: var(--m3e-nav-rail-bottom-space, 0.5rem);
|
|
69
|
-
}
|
|
70
|
-
:host(.-compact) {
|
|
71
|
-
width: var(--m3e-nav-rail-compact-width, 6rem);
|
|
72
|
-
}
|
|
73
|
-
:host(.-compact) ::slotted(m3e-fab) {
|
|
74
|
-
align-self: center;
|
|
75
|
-
}
|
|
76
|
-
:host(:not(.-compact)) {
|
|
77
|
-
padding-inline: var(--m3e-nav-rail-expanded-inline-padding, 1.25rem);
|
|
78
|
-
min-width: var(--m3e-nav-rail-expanded-min-width, 13.75rem);
|
|
79
|
-
max-width: var(--m3e-nav-rail-expanded-max-width, 22.5rem);
|
|
80
|
-
align-items: flex-start;
|
|
81
|
-
--m3e-horizontal-nav-item-active-indicator-height: var(--m3e-nav-rail-expanded-item-height, 3.5rem);
|
|
82
|
-
--_nav-item-align-self: stretch;
|
|
83
|
-
--_nav-item-justify-content: flex-start;
|
|
84
|
-
}
|
|
85
|
-
::slotted(*) {
|
|
86
|
-
flex: none;
|
|
87
|
-
}
|
|
88
|
-
::slotted(m3e-icon-button),
|
|
89
|
-
::slotted(m3e-fab) {
|
|
90
|
-
margin-block-end: var(--m3e-nav-rail-button-item-space, 1rem);
|
|
91
|
-
}
|
|
92
|
-
:host(.-compact) ::slotted(m3e-icon-button) {
|
|
93
|
-
align-self: center;
|
|
94
|
-
}
|
|
95
|
-
:host(:not(.-compact)) ::slotted(m3e-icon-button) {
|
|
96
|
-
margin-inline-start: var(--m3e-nav-rail-expanded-icon-button-inset, 0.5rem);
|
|
97
|
-
}
|
|
98
|
-
`;
|
|
99
|
-
|
|
100
|
-
/** @private */ #focusKeyManager = new RovingTabIndexManager().withHomeAndEnd().withWrap();
|
|
101
|
-
/** @private */ readonly #keyDownHandler = (e: KeyboardEvent) => this.#handleKeyDown(e);
|
|
102
|
-
|
|
103
|
-
constructor() {
|
|
104
|
-
super();
|
|
105
|
-
|
|
106
|
-
this[selectionManager].onSelectedItemsChange(() => {
|
|
107
|
-
this.#focusKeyManager.updateActiveItem(this[selectionManager].activeItem);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** @inheritdoc */
|
|
112
|
-
override connectedCallback(): void {
|
|
113
|
-
super.connectedCallback();
|
|
114
|
-
this.addEventListener("keydown", this.#keyDownHandler);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** @inheritdoc */
|
|
118
|
-
override disconnectedCallback(): void {
|
|
119
|
-
super.disconnectedCallback();
|
|
120
|
-
this.removeEventListener("keydown", this.#keyDownHandler);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** @private */
|
|
124
|
-
#handleKeyDown(e: KeyboardEvent): void {
|
|
125
|
-
this.#focusKeyManager.onKeyDown(e);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** @inheritdoc @internal */
|
|
129
|
-
protected override _updateItems(): void {
|
|
130
|
-
const items = M3eInteractivityChecker.findInteractiveElements(this);
|
|
131
|
-
const { added } = this.#focusKeyManager.setItems(items);
|
|
132
|
-
if (!this.#focusKeyManager.activeItem) {
|
|
133
|
-
const active = added.find((x) => !x.hasAttribute("disabled"));
|
|
134
|
-
if (active) {
|
|
135
|
-
this.#focusKeyManager.updateActiveItem(active);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
super._updateItems();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** @inheritdoc @internal */
|
|
143
|
-
protected override _updateOrientation(orientation: NavItemOrientation): void {
|
|
144
|
-
super._updateOrientation(orientation);
|
|
145
|
-
this.querySelectorAll("m3e-fab").forEach((x) => x.toggleAttribute("extended", orientation === "horizontal"));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
declare global {
|
|
150
|
-
interface HTMLElementTagNameMap {
|
|
151
|
-
"m3e-nav-rail": M3eNavRailElement;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { css, CSSResultGroup, html, LitElement } from "lit";
|
|
2
|
-
import { customElement } from "lit/decorators.js";
|
|
3
|
-
|
|
4
|
-
import { HtmlFor, MutationController, Role } from "@m3e/core";
|
|
5
|
-
|
|
6
|
-
import { M3eNavRailElement } from "./NavRailElement";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* An element, nested within a clickable element, used to toggle the expanded state of a navigation rail.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* The following example illustrates a nav rail whose expanded state is automatically determined by the
|
|
13
|
-
* current screen size. In addition, a toggle button is used to allow the user to manually toggle the
|
|
14
|
-
* expanded state.
|
|
15
|
-
*
|
|
16
|
-
* ```html
|
|
17
|
-
* <m3e-nav-rail id="nav-rail" mode="auto">
|
|
18
|
-
* <m3e-icon-button toggle>
|
|
19
|
-
* <m3e-icon name="menu"></m3e-icon>
|
|
20
|
-
* <m3e-icon slot="selected" name="menu_open"></m3e-icon>
|
|
21
|
-
* <m3e-nav-rail-toggle for="nav-rail"></m3e-nav-rail-toggle>
|
|
22
|
-
* </m3e-icon-button>
|
|
23
|
-
* <m3e-fab size="small">
|
|
24
|
-
* <m3e-icon name="edit"></m3e-icon>
|
|
25
|
-
* <span slot="label">Extended</span>
|
|
26
|
-
* </m3e-fab>
|
|
27
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="news"></m3e-icon>News</m3e-nav-item>
|
|
28
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="globe"></m3e-icon>Global</m3e-nav-item>
|
|
29
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="star"></m3e-icon>For you</m3e-nav-item>
|
|
30
|
-
* <m3e-nav-item><m3e-icon slot="icon" name="newsstand"></m3e-icon>Trending</m3e-nav-item>
|
|
31
|
-
* </m3e-nav-rail>
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @tag m3e-nav-rail-toggle
|
|
35
|
-
*/
|
|
36
|
-
@customElement("m3e-nav-rail-toggle")
|
|
37
|
-
export class M3eNavRailToggleElement extends HtmlFor(Role(LitElement, "none")) {
|
|
38
|
-
/** The styles of the element. */
|
|
39
|
-
static override styles: CSSResultGroup = css`
|
|
40
|
-
:host {
|
|
41
|
-
display: contents;
|
|
42
|
-
}
|
|
43
|
-
::slotted(.material-icons) {
|
|
44
|
-
font-size: inherit !important;
|
|
45
|
-
}
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
/** @private */ readonly #clickHandler = (e: Event) => this.#handleClick(e);
|
|
49
|
-
/** @private */ readonly #mutationController = new MutationController(this, {
|
|
50
|
-
target: null,
|
|
51
|
-
config: { attributeFilter: ["class"] },
|
|
52
|
-
callback: () => this.#updateToggle(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
/** @inheritdoc */
|
|
56
|
-
override connectedCallback(): void {
|
|
57
|
-
super.connectedCallback();
|
|
58
|
-
this.parentElement?.addEventListener("click", this.#clickHandler);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** @inheritdoc */
|
|
62
|
-
override disconnectedCallback(): void {
|
|
63
|
-
super.disconnectedCallback();
|
|
64
|
-
this.parentElement?.removeEventListener("click", this.#clickHandler);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** @inheritdoc */
|
|
68
|
-
override attach(control: HTMLElement): void {
|
|
69
|
-
if (control instanceof M3eNavRailElement) {
|
|
70
|
-
this.#mutationController.observe(control);
|
|
71
|
-
}
|
|
72
|
-
super.attach(control);
|
|
73
|
-
this.#updateToggle();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @inheritdoc */
|
|
77
|
-
override detach(): void {
|
|
78
|
-
for (const target of this.#mutationController.targets) {
|
|
79
|
-
this.#mutationController.unobserve(target);
|
|
80
|
-
}
|
|
81
|
-
this.#updateToggle();
|
|
82
|
-
super.detach();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** @inheritdoc */
|
|
86
|
-
protected override render(): unknown {
|
|
87
|
-
return html`<slot></slot>`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** @private */
|
|
91
|
-
#handleClick(e: Event): void {
|
|
92
|
-
if (!e.defaultPrevented && this.control instanceof M3eNavRailElement) {
|
|
93
|
-
this.control.currentMode = this.control.currentMode === "compact" ? "expanded" : "compact";
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** @private */
|
|
98
|
-
#updateToggle(): void {
|
|
99
|
-
if (this.parentElement?.hasAttribute("toggle")) {
|
|
100
|
-
this.parentElement.toggleAttribute(
|
|
101
|
-
"selected",
|
|
102
|
-
this.control instanceof M3eNavRailElement && this.control.currentMode === "expanded"
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
declare global {
|
|
109
|
-
interface HTMLElementTagNameMap {
|
|
110
|
-
"m3e-nav-rail-toggle": M3eNavRailToggleElement;
|
|
111
|
-
}
|
|
112
|
-
}
|
package/src/index.ts
DELETED