@m3e/nav-rail 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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 matraic
4
+ Contact: matraic@yahoo.com
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @m3e/nav-rail
2
+
3
+ The `m3e-nav-rail` component extends `@m3e/nav-bar` to provide a vertical navigation rail and interactive items for switching between primary destinations in your application. Designed for larger devices, the nav rail supports compact and expanded modes, orientation, selection, and extensive theming via CSS custom properties.
4
+
5
+ > **Part of the [M3E](../../README.md) monorepo**
6
+ > This package is maintained within the unified M3E repository, which provides a suite of Material 3 web components.
7
+
8
+ ## ๐Ÿ“ฆ Installation
9
+
10
+ ```bash
11
+ npm install @m3e/nav-rail
12
+ ```
13
+
14
+ ## ๐Ÿ’ป Editor Integration
15
+
16
+ This package includes a [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest) to support enhanced editor tooling and developer experience.
17
+
18
+ ### Visual Studio Code
19
+
20
+ To enable autocomplete and hover documentation for `@m3e/nav-rail`, install the [Custom Elements Manifest Language Server](https://marketplace.visualstudio.com/items?itemName=pwrs.cem-language-server-vscode) extension. It will automatically detect the manifest bundled with this package and surface tag names, attributes, slots, and events in supported files.
21
+
22
+ Alternately, you can explicitly reference the `html-custom-data.json` and `css-custom-data.json` in your workspace settings:
23
+
24
+ ```json
25
+ {
26
+ "html.customData": ["./node_modules/@m3e/nav-rail/dist/html-custom-data.json"],
27
+ "css.customData": ["./node_modules/@m3e/nav-rail/dist/css-custom-data.json"]
28
+ }
29
+ ```
30
+
31
+ ## ๐Ÿš€ Browser Usage
32
+
33
+ This package uses [JavaScript Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#module_specifiers). To use it directly in a browser without a bundler, use a module script similar to the following.
34
+
35
+ ```html
36
+ <script type="module" src="/node_modules/@m3e/nav-rail/dist/index.js"></script>
37
+ ```
38
+
39
+ You also need a module script for `@m3e/nav-bar` due to it being a dependency.
40
+
41
+ ```html
42
+ <script type="module" src="/node_modules/@m3e/nav-bar/dist/index.js"></script>
43
+ ```
44
+
45
+ In addition, you must use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap) to include dependencies.
46
+
47
+ ```html
48
+ <script type="importmap">
49
+ {
50
+ "imports": {
51
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
52
+ "@m3e/core": "/node_modules/@m3e/core/dist/index.js",
53
+ "@m3e/core/a11y": "/node_modules/@m3e/core/dist/a11y.js",
54
+ "@m3e/core/layout": "/node_modules/@m3e/core/dist/layout.js",
55
+ "@m3e/nav-bar": "/node_modules/@m3e/nav-bar/dist/index.js"
56
+ }
57
+ }
58
+ </script>
59
+ ```
60
+
61
+ > For production, use index.min.js, a11y.min.js, and layout.min.js for faster load times.
62
+
63
+ ## ๐Ÿ—‚๏ธ Elements
64
+
65
+ - `m3e-nav-rail` โ€” A vertical bar, typically used on larger devices, that allows a user to switch between views.
66
+
67
+ ## ๐Ÿงช Example
68
+
69
+ The following example illustrates a nav rail whose expanded state is automatically determined by the current screen size. In addition, a toggle button is used to allow the user to manually toggle the expanded state.
70
+
71
+ ```html
72
+ <m3e-nav-rail id="nav-rail" mode="auto">
73
+ <m3e-icon-button toggle>
74
+ <m3e-icon name="menu"></m3e-icon>
75
+ <m3e-icon slot="selected" name="menu_open"></m3e-icon>
76
+ <m3e-nav-rail-toggle for="nav-rail"></m3e-nav-rail-toggle>
77
+ </m3e-icon-button>
78
+ <m3e-fab size="small">
79
+ <m3e-icon name="edit"></m3e-icon>
80
+ <span slot="label">Extended</span>
81
+ </m3e-fab>
82
+ <m3e-nav-item><m3e-icon slot="icon" name="news"></m3e-icon>News</m3e-nav-item>
83
+ <m3e-nav-item><m3e-icon slot="icon" name="globe"></m3e-icon>Global</m3e-nav-item>
84
+ <m3e-nav-item><m3e-icon slot="icon" name="star"></m3e-icon>For you</m3e-nav-item>
85
+ <m3e-nav-item><m3e-icon slot="icon" name="newsstand"></m3e-icon>Trending</m3e-nav-item>
86
+ </m3e-nav-rail>
87
+ ```
88
+
89
+ ## ๐Ÿ“– API Reference
90
+
91
+ This section details the attributes, slots, events and CSS custom properties available for the `m3e-nav-rail` component.
92
+
93
+ ### โš™๏ธ Attributes
94
+
95
+ | Attribute | Type | Default | Description |
96
+ | --------- | --------------------------------- | ------- | -------------------------------------------------- |
97
+ | mode | "compact" \| "expanded" \| "auto" | auto | The mode in which items in the rail are presented. |
98
+
99
+ ### ๐Ÿ”” Events
100
+
101
+ | Event | Description |
102
+ | ------ | --------------------------------------------------- |
103
+ | change | Emitted when the selected state of an item changes. |
104
+
105
+ ### ๐Ÿงฉ Slots
106
+
107
+ | Slot | Description |
108
+ | ----------- | ------------------------------ |
109
+ | _(default)_ | Renders the items of the rail. |
110
+
111
+ ### ๐ŸŽ›๏ธ CSS Custom Properties
112
+
113
+ | Property | Description |
114
+ | ------------------------------------------- | ----------------------------------------------- |
115
+ | `--m3e-nav-rail-top-space` | Top block padding for the nav rail. |
116
+ | `--m3e-nav-rail-bottom-space` | Bottom block padding for the nav rail. |
117
+ | `--m3e-nav-rail-compact-width` | Width of the nav rail in compact mode. |
118
+ | `--m3e-nav-rail-expanded-inline-padding` | Inline padding for expanded nav rail. |
119
+ | `--m3e-nav-rail-expanded-min-width` | Minimum width of the nav rail in expanded mode. |
120
+ | `--m3e-nav-rail-expanded-max-width` | Maximum width of the nav rail in expanded mode. |
121
+ | `--m3e-nav-rail-expanded-item-height` | Height of nav items in expanded mode. |
122
+ | `--m3e-nav-rail-button-item-space` | Space below icon buttons and FABs. |
123
+ | `--m3e-nav-rail-expanded-icon-button-inset` | Inset for icon buttons in expanded mode. |
124
+
125
+ ## ๐Ÿค Contributing
126
+
127
+ See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
128
+
129
+ ## ๐Ÿ“„ License
130
+
131
+ This package is licensed under the MIT License.
package/cem.config.mjs ADDED
@@ -0,0 +1,16 @@
1
+ import { customElementVsCodePlugin } from "custom-element-vs-code-integration";
2
+
3
+ export default {
4
+ globs: ["src/**/*.ts"],
5
+ exclude: ["src/**/*.spec.ts"],
6
+ packagejson: true,
7
+ outdir: "dist",
8
+ litelement: true,
9
+ plugins: [
10
+ customElementVsCodePlugin({
11
+ outdir: "dist",
12
+ htmlFileName: "html-custom-data.json",
13
+ cssFileName: "css-custom-data.json",
14
+ }),
15
+ ],
16
+ };
@@ -0,0 +1,63 @@
1
+ <!doctype html>
2
+ <html lang="en" style="overflow-y: auto">
3
+ <head>
4
+ <title>Navigation Rail for M3E</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="description" content="Navigation Rail for M3E" />
8
+ <base href="./" />
9
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
11
+ <link
12
+ href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"
13
+ rel="stylesheet"
14
+ />
15
+ <link
16
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0..1,0"
17
+ rel="stylesheet"
18
+ />
19
+ <script type="importmap">
20
+ {
21
+ "imports": {
22
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
23
+ "@m3e/core": "../../core/dist/index.min.js",
24
+ "@m3e/core/a11y": "../../core/dist/a11y.min.js",
25
+ "@m3e/core/layout": "../../core/dist/layout.min.js",
26
+ "@m3e/nav-bar": "../../nav-bar/dist/index.min.js"
27
+ }
28
+ }
29
+ </script>
30
+ <script type="module" src="../../icon/dist/index.min.js"></script>
31
+ <script type="module" src="../../icon-button/dist/index.min.js"></script>
32
+ <script type="module" src="../../theme/dist/index.min.js"></script>
33
+ <script type="module" src="../../fab/dist/index.min.js"></script>
34
+ <script type="module" src="../dist/index.min.js"></script>
35
+ <style>
36
+ body {
37
+ font-family: "Roboto";
38
+ }
39
+ *:not(:defined) {
40
+ display: none;
41
+ }
42
+ </style>
43
+ </head>
44
+ <body>
45
+ <m3e-theme strong-focus>
46
+ <m3e-nav-rail mode="auto" onchange="console.log(this.selected)" id="nav-rail">
47
+ <m3e-icon-button toggle>
48
+ <m3e-icon name="menu"></m3e-icon>
49
+ <m3e-icon slot="selected" name="menu_open"></m3e-icon>
50
+ <m3e-nav-rail-toggle for="nav-rail"></m3e-nav-rail-toggle>
51
+ </m3e-icon-button>
52
+ <m3e-fab size="small">
53
+ <m3e-icon name="edit"></m3e-icon>
54
+ <span slot="label">Extended</span>
55
+ </m3e-fab>
56
+ <m3e-nav-item><m3e-icon slot="icon" name="news"></m3e-icon>News</m3e-nav-item>
57
+ <m3e-nav-item><m3e-icon slot="icon" name="globe"></m3e-icon>Global</m3e-nav-item>
58
+ <m3e-nav-item><m3e-icon slot="icon" name="star"></m3e-icon>For you</m3e-nav-item>
59
+ <m3e-nav-item><m3e-icon slot="icon" name="newsstand"></m3e-icon>Trending</m3e-nav-item>
60
+ </m3e-nav-rail>
61
+ </m3e-theme>
62
+ </body>
63
+ </html>
@@ -0,0 +1,52 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-css-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "properties": [
5
+ {
6
+ "name": "--m3e-nav-rail-top-space",
7
+ "description": "Top block padding for the nav rail.",
8
+ "values": []
9
+ },
10
+ {
11
+ "name": "--m3e-nav-rail-bottom-space",
12
+ "description": "Bottom block padding for the nav rail.",
13
+ "values": []
14
+ },
15
+ {
16
+ "name": "--m3e-nav-rail-compact-width",
17
+ "description": "Width of the nav rail in compact mode.",
18
+ "values": []
19
+ },
20
+ {
21
+ "name": "--m3e-nav-rail-expanded-inline-padding",
22
+ "description": "Inline padding for expanded nav rail.",
23
+ "values": []
24
+ },
25
+ {
26
+ "name": "--m3e-nav-rail-expanded-min-width",
27
+ "description": "Minimum width of the nav rail in expanded mode.",
28
+ "values": []
29
+ },
30
+ {
31
+ "name": "--m3e-nav-rail-expanded-max-width",
32
+ "description": "Maximum width of the nav rail in expanded mode.",
33
+ "values": []
34
+ },
35
+ {
36
+ "name": "--m3e-nav-rail-expanded-item-height",
37
+ "description": "Height of nav items in expanded mode.",
38
+ "values": []
39
+ },
40
+ {
41
+ "name": "--m3e-nav-rail-button-item-space",
42
+ "description": "Space below icon buttons and FABs.",
43
+ "values": []
44
+ },
45
+ {
46
+ "name": "--m3e-nav-rail-expanded-icon-button-inset",
47
+ "description": "Inset for icon buttons in expanded mode.",
48
+ "values": []
49
+ }
50
+ ],
51
+ "pseudoElements": []
52
+ }
@@ -0,0 +1,260 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/index.ts",
8
+ "declarations": [],
9
+ "exports": [
10
+ {
11
+ "kind": "js",
12
+ "name": "*",
13
+ "declaration": {
14
+ "name": "*",
15
+ "package": "\"./NavRailElement\""
16
+ }
17
+ },
18
+ {
19
+ "kind": "js",
20
+ "name": "*",
21
+ "declaration": {
22
+ "name": "*",
23
+ "package": "\"./NavRailToggleElement\""
24
+ }
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "kind": "javascript-module",
30
+ "path": "src/NavRailElement.ts",
31
+ "declarations": [
32
+ {
33
+ "kind": "class",
34
+ "description": "",
35
+ "name": "M3eNavRailElement",
36
+ "cssProperties": [
37
+ {
38
+ "description": "Top block padding for the nav rail.",
39
+ "name": "--m3e-nav-rail-top-space"
40
+ },
41
+ {
42
+ "description": "Bottom block padding for the nav rail.",
43
+ "name": "--m3e-nav-rail-bottom-space"
44
+ },
45
+ {
46
+ "description": "Width of the nav rail in compact mode.",
47
+ "name": "--m3e-nav-rail-compact-width"
48
+ },
49
+ {
50
+ "description": "Inline padding for expanded nav rail.",
51
+ "name": "--m3e-nav-rail-expanded-inline-padding"
52
+ },
53
+ {
54
+ "description": "Minimum width of the nav rail in expanded mode.",
55
+ "name": "--m3e-nav-rail-expanded-min-width"
56
+ },
57
+ {
58
+ "description": "Maximum width of the nav rail in expanded mode.",
59
+ "name": "--m3e-nav-rail-expanded-max-width"
60
+ },
61
+ {
62
+ "description": "Height of nav items in expanded mode.",
63
+ "name": "--m3e-nav-rail-expanded-item-height"
64
+ },
65
+ {
66
+ "description": "Space below icon buttons and FABs.",
67
+ "name": "--m3e-nav-rail-button-item-space"
68
+ },
69
+ {
70
+ "description": "Inset for icon buttons in expanded mode.",
71
+ "name": "--m3e-nav-rail-expanded-icon-button-inset"
72
+ }
73
+ ],
74
+ "members": [
75
+ {
76
+ "kind": "field",
77
+ "name": "#focusKeyManager",
78
+ "privacy": "private"
79
+ },
80
+ {
81
+ "kind": "field",
82
+ "name": "#keyDownHandler",
83
+ "privacy": "private",
84
+ "readonly": true
85
+ },
86
+ {
87
+ "kind": "method",
88
+ "name": "#handleKeyDown",
89
+ "privacy": "private",
90
+ "return": {
91
+ "type": {
92
+ "text": "void"
93
+ }
94
+ },
95
+ "parameters": [
96
+ {
97
+ "name": "e",
98
+ "type": {
99
+ "text": "KeyboardEvent"
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ ],
105
+ "events": [
106
+ {
107
+ "description": "Emitted when the selected state of an item changes.",
108
+ "name": "change"
109
+ }
110
+ ],
111
+ "attributes": [
112
+ {
113
+ "description": "The mode in which items in the rail are presented.",
114
+ "name": "mode"
115
+ }
116
+ ],
117
+ "superclass": {
118
+ "name": "M3eNavBarElement",
119
+ "package": "@m3e/nav-bar"
120
+ },
121
+ "tagName": "m3e-nav-rail",
122
+ "customElement": true,
123
+ "summary": "A vertical bar, typically used on larger devices, that allows a user to switch between views."
124
+ }
125
+ ],
126
+ "exports": [
127
+ {
128
+ "kind": "js",
129
+ "name": "M3eNavRailElement",
130
+ "declaration": {
131
+ "name": "M3eNavRailElement",
132
+ "module": "src/NavRailElement.ts"
133
+ }
134
+ },
135
+ {
136
+ "kind": "custom-element-definition",
137
+ "name": "m3e-nav-rail",
138
+ "declaration": {
139
+ "name": "M3eNavRailElement",
140
+ "module": "src/NavRailElement.ts"
141
+ }
142
+ }
143
+ ]
144
+ },
145
+ {
146
+ "kind": "javascript-module",
147
+ "path": "src/NavRailToggleElement.ts",
148
+ "declarations": [
149
+ {
150
+ "kind": "class",
151
+ "description": "An element, nested within a clickable element, used to toggle the expanded state of a navigation rail.",
152
+ "name": "M3eNavRailToggleElement",
153
+ "members": [
154
+ {
155
+ "kind": "field",
156
+ "name": "#clickHandler",
157
+ "privacy": "private",
158
+ "readonly": true
159
+ },
160
+ {
161
+ "kind": "field",
162
+ "name": "#mutationController",
163
+ "privacy": "private",
164
+ "readonly": true,
165
+ "default": "new MutationController(this, { target: null, config: { attributeFilter: [\"class\"] }, callback: () => this.#updateToggle(), })"
166
+ },
167
+ {
168
+ "kind": "method",
169
+ "name": "attach",
170
+ "return": {
171
+ "type": {
172
+ "text": "void"
173
+ }
174
+ },
175
+ "parameters": [
176
+ {
177
+ "name": "control",
178
+ "type": {
179
+ "text": "HTMLElement"
180
+ }
181
+ }
182
+ ]
183
+ },
184
+ {
185
+ "kind": "method",
186
+ "name": "detach",
187
+ "return": {
188
+ "type": {
189
+ "text": "void"
190
+ }
191
+ }
192
+ },
193
+ {
194
+ "kind": "method",
195
+ "name": "#handleClick",
196
+ "privacy": "private",
197
+ "return": {
198
+ "type": {
199
+ "text": "void"
200
+ }
201
+ },
202
+ "parameters": [
203
+ {
204
+ "name": "e",
205
+ "type": {
206
+ "text": "Event"
207
+ }
208
+ }
209
+ ]
210
+ },
211
+ {
212
+ "kind": "method",
213
+ "name": "#updateToggle",
214
+ "privacy": "private",
215
+ "return": {
216
+ "type": {
217
+ "text": "void"
218
+ }
219
+ }
220
+ }
221
+ ],
222
+ "mixins": [
223
+ {
224
+ "name": "HtmlFor",
225
+ "package": "@m3e/core"
226
+ },
227
+ {
228
+ "name": "Role",
229
+ "package": "@m3e/core"
230
+ }
231
+ ],
232
+ "superclass": {
233
+ "name": "LitElement",
234
+ "package": "lit"
235
+ },
236
+ "tagName": "m3e-nav-rail-toggle",
237
+ "customElement": true
238
+ }
239
+ ],
240
+ "exports": [
241
+ {
242
+ "kind": "js",
243
+ "name": "M3eNavRailToggleElement",
244
+ "declaration": {
245
+ "name": "M3eNavRailToggleElement",
246
+ "module": "src/NavRailToggleElement.ts"
247
+ }
248
+ },
249
+ {
250
+ "kind": "custom-element-definition",
251
+ "name": "m3e-nav-rail-toggle",
252
+ "declaration": {
253
+ "name": "M3eNavRailToggleElement",
254
+ "module": "src/NavRailToggleElement.ts"
255
+ }
256
+ }
257
+ ]
258
+ }
259
+ ]
260
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-html-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "tags": [
5
+ {
6
+ "name": "m3e-nav-rail",
7
+ "description": "A vertical bar, typically used on larger devices, that allows a user to switch between views.\n---\n\n\n### **Events:**\n - **change** - Emitted when the selected state of an item changes.\n\n### **CSS Properties:**\n - **--m3e-nav-rail-top-space** - Top block padding for the nav rail. _(default: undefined)_\n- **--m3e-nav-rail-bottom-space** - Bottom block padding for the nav rail. _(default: undefined)_\n- **--m3e-nav-rail-compact-width** - Width of the nav rail in compact mode. _(default: undefined)_\n- **--m3e-nav-rail-expanded-inline-padding** - Inline padding for expanded nav rail. _(default: undefined)_\n- **--m3e-nav-rail-expanded-min-width** - Minimum width of the nav rail in expanded mode. _(default: undefined)_\n- **--m3e-nav-rail-expanded-max-width** - Maximum width of the nav rail in expanded mode. _(default: undefined)_\n- **--m3e-nav-rail-expanded-item-height** - Height of nav items in expanded mode. _(default: undefined)_\n- **--m3e-nav-rail-button-item-space** - Space below icon buttons and FABs. _(default: undefined)_\n- **--m3e-nav-rail-expanded-icon-button-inset** - Inset for icon buttons in expanded mode. _(default: undefined)_",
8
+ "attributes": [
9
+ {
10
+ "name": "mode",
11
+ "description": "The mode in which items in the rail are presented.",
12
+ "values": []
13
+ }
14
+ ],
15
+ "references": []
16
+ },
17
+ {
18
+ "name": "m3e-nav-rail-toggle",
19
+ "description": "An element, nested within a clickable element, used to toggle the expanded state of a navigation rail.\n---\n",
20
+ "attributes": [],
21
+ "references": []
22
+ }
23
+ ]
24
+ }