@m3e/nav-rail 1.0.0-rc.1 → 1.0.0-rc.3

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,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
@@ -1,2 +0,0 @@
1
- export * from "./NavRailElement";
2
- export * from "./NavRailToggleElement";
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist/src"
6
- },
7
- "include": ["src/**/*.ts", "**/*.mjs", "**/*.js"],
8
- "exclude": []
9
- }