@m3e/snackbar 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,139 @@
1
+ # @m3e/snackbar
2
+
3
+ The `@m3e/snackbar` package provides the `M3eSnackbar` global service on `window` (`globalThis`) used to present short updates about application processes at the bottom of the screen from anywhere in an application.
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/snackbar
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/snackbar`, 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/snackbar/dist/html-custom-data.json"],
27
+ "css.customData": ["./node_modules/@m3e/snackbar/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/snackbar/dist/index.js"></script>
37
+ ```
38
+
39
+ You also need a module script for `@m3e/button` and `@m3e/icon-button` due to being a dependency.
40
+
41
+ ```html
42
+ <script type="module" src="/node_modules/@m3e/button/dist/index.js"></script>
43
+ <script type="module" src="/node_modules/@m3e/icon-button/dist/index.js"></script>
44
+ ```
45
+
46
+ In addition, you must use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap) to include additional dependencies.
47
+
48
+ ```html
49
+ <script type="importmap">
50
+ {
51
+ "imports": {
52
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
53
+ "@m3e/core": "/node_modules/@m3e/core/dist/index.js"
54
+ }
55
+ }
56
+ </script>
57
+ ```
58
+
59
+ > For production, use index.min.js for faster load times.
60
+
61
+ ## ๐Ÿงช Examples
62
+
63
+ The following example illustrates basic usage.
64
+
65
+ ```js
66
+ M3eSnackbar.open("File deleted");
67
+ ```
68
+
69
+ The next example illustrates presenting a snackbar with an action and callback.
70
+
71
+ ```js
72
+ M3eSnackbar.open("File deleted", "Undo", {
73
+ actionCallback: () => {
74
+ // Undo logic here
75
+ },
76
+ });
77
+ ```
78
+
79
+ ## ๐Ÿ“– API Reference
80
+
81
+ ### ๐Ÿ› ๏ธ Snackbar Service
82
+
83
+ This section details the methods available for the `M3eSnackbar` service.
84
+
85
+ #### โš™๏ธ Methods
86
+
87
+ | Method | Signature | Description |
88
+ | --------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
89
+ | `open` | `open(message: string, options?: SnackbarOptions): void` | Opens a snackbar with a message.<br>- `message`: The message to show in the snackbar.<br>- `options`: (optional) Options that control the behavior of the snackbar. |
90
+ | `open` | `open(message: string, action: string, options?: SnackbarOptions): void` | Opens a snackbar with a message and action.<br>- `message`: The message to show in the snackbar.<br>- `action`: The label for the snackbar action.<br>- `options`: (optional) Options that control the behavior of the snackbar. |
91
+ | `open` | `open(message: string, action: string, dismissible: boolean, options?: SnackbarOptions): void` | Opens a snackbar with a message, action, and optional close affordance.<br>- `message`: The message to show in the snackbar.<br>- `action`: The label for the snackbar action.<br>- `dismissible`: Whether to present close affordance.<br>- `options`: (optional) Options that control the behavior of the snackbar. |
92
+ | `open` | `open(message: string, dismissible: boolean, options?: SnackbarOptions): void` | Opens a snackbar with a message and optional close affordance.<br>- `message`: The message to show in the snackbar.<br>- `dismissible`: Whether to present close affordance.<br>- `options`: (optional) Options that control the behavior of the snackbar. |
93
+ | `dismiss` | `dismiss(): void` | Dismisses the currently visible snackbar. |
94
+
95
+ ### ๐Ÿ—‚๏ธ Snackbar
96
+
97
+ This section details the attributes, slots and CSS custom properties available for the `m3e-snackbar` component.
98
+
99
+ #### โš™๏ธ Attributes
100
+
101
+ | Attribute | Type | Default | Description |
102
+ | ------------- | --------- | --------- | ------------------------------------------------------------------------------------------ |
103
+ | `action` | `string` | | The label of the snackbar's action. |
104
+ | `close-label` | `string` | `"Close"` | The accessible label given to the button used to dismiss the snackbar. |
105
+ | `dismissible` | `boolean` | `false` | Whether a button is presented that can be used to close the snackbar. |
106
+ | `duration` | `number` | `3000` | The length of time, in milliseconds, to wait before automatically dismissing the snackbar. |
107
+
108
+ #### ๐Ÿงฉ Slots
109
+
110
+ | Slot | Description |
111
+ | ------------ | -------------------------------------- |
112
+ | _(default)_ | Renders the content of the snackbar. |
113
+ | `close-icon` | Renders the icon for the close button. |
114
+
115
+ #### ๐ŸŽ›๏ธ CSS Custom Properties
116
+
117
+ | Property | Description |
118
+ | -------------------------------------------- | -------------------------------------------- |
119
+ | `--m3e-snackbar-margin` | Vertical offset from the bottom of viewport. |
120
+ | `--m3e-snackbar-container-shape` | Border radius of the snackbar container. |
121
+ | `--m3e-snackbar-container-color` | Background color of the snackbar. |
122
+ | `--m3e-snackbar-padding` | Internal spacing of the snackbar container. |
123
+ | `--m3e-snackbar-min-width` | Minimum width of the snackbar. |
124
+ | `--m3e-snackbar-max-width` | Maximum width of the snackbar. |
125
+ | `--m3e-snackbar-supporting-text-font-size` | Font size for supporting text. |
126
+ | `--m3e-snackbar-supporting-text-font-weight` | Font weight for supporting text. |
127
+ | `--m3e-snackbar-supporting-text-line-height` | Line height for supporting text. |
128
+ | `--m3e-snackbar-supporting-text-tracking` | Letter spacing for supporting text. |
129
+ | `--m3e-snackbar-supporting-text-color` | Color of supporting text. |
130
+ | `--m3e-snackbar-action-text-color` | Color of the action button text. |
131
+ | `--m3e-snackbar-close-icon-color` | Color of the close icon. |
132
+
133
+ ## ๐Ÿค Contributing
134
+
135
+ See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
136
+
137
+ ## ๐Ÿ“„ License
138
+
139
+ 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,49 @@
1
+ <!doctype html>
2
+ <html lang="en" style="overflow-y: auto">
3
+ <head>
4
+ <title>Snackbar for M3E</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="description" content="Snackbar 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
+ }
25
+ }
26
+ </script>
27
+ <script type="module" src="../../button/dist/index.min.js"></script>
28
+ <script type="module" src="../../icon-button/dist/index.min.js"></script>
29
+ <script type="module" src="../../theme/dist/index.min.js"></script>
30
+ <script type="module" src="../dist/index.min.js"></script>
31
+ <style>
32
+ body {
33
+ font-family: "Roboto";
34
+ }
35
+ *:not(:defined) {
36
+ display: none;
37
+ }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <m3e-theme strong-focus>
42
+ <m3e-button
43
+ onclick="M3eSnackbar.open('Test', 'Custom Action', true, { duration: 5000, actionCallback: () => console.log('Action Taken')})"
44
+ >
45
+ Open Snackbar
46
+ </m3e-button>
47
+ </m3e-theme>
48
+ </body>
49
+ </html>
@@ -0,0 +1,37 @@
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-snackbar-margin",
7
+ "description": "Vertical offset from the bottom of the viewport.",
8
+ "values": []
9
+ },
10
+ {
11
+ "name": "--m3e-snackbar-container-shape",
12
+ "description": "Border radius of the snackbar container.",
13
+ "values": []
14
+ },
15
+ {
16
+ "name": "--m3e-snackbar-container-color",
17
+ "description": "Background color of the snackbar.",
18
+ "values": []
19
+ },
20
+ {
21
+ "name": "--m3e-snackbar-padding",
22
+ "description": "Internal spacing of the snackbar container.",
23
+ "values": []
24
+ },
25
+ {
26
+ "name": "--m3e-snackbar-min-width",
27
+ "description": "Minimum width of the snackbar.",
28
+ "values": []
29
+ },
30
+ {
31
+ "name": "--m3e-snackbar-max-width",
32
+ "description": "Maximum width of the snackbar.",
33
+ "values": []
34
+ }
35
+ ],
36
+ "pseudoElements": []
37
+ }