@m3e/badge 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,135 @@
1
+ # @m3e/badge
2
+
3
+ The `m3e-badge` component is a compact visual indicator used to label content. Designed according to Material Design 3 guidelines, it can display counts, presence, or semantic emphasis, and is attachable to icons, buttons, or other components. Badges support dynamic sizing, color, and shape, ensuring clarity and accessibility while maintaining a consistent, expressive appearance across surfaces.
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/badge
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/badge`, 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/badge/dist/html-custom-data.json"],
27
+ "css.customData": ["./node_modules/@m3e/badge/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/badge/dist/index.js"></script>
37
+ ```
38
+
39
+ 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.
40
+
41
+ ```html
42
+ <script type="importmap">
43
+ {
44
+ "imports": {
45
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
46
+ "@m3e/core": "/node_modules/@m3e/core/dist/index.js",
47
+ "@m3e/core/bidi": "/node_modules/@m3e/core/dist/bidi.js",
48
+ "@m3e/core/anchoring": "/node_modules/@m3e/core/dist/anchoring.js"
49
+ }
50
+ }
51
+ </script>
52
+ ```
53
+
54
+ > For production, use index.min.js, bidi.min.js, and anchoring.min.js for faster load times.
55
+
56
+ ## ๐Ÿ—‚๏ธ Elements
57
+
58
+ - `m3e-badge` โ€” A visual indicator used to label content.
59
+
60
+ ## ๐Ÿงช Examples
61
+
62
+ The following example illustrates attaching a `m3e-badge` to another element using the `for` attribute.
63
+
64
+ ```html
65
+ <m3e-button id="button">Button</m3e-button><m3e-badge for="button">10</m3e-badge>
66
+ ```
67
+
68
+ ## ๐Ÿ“– API Reference
69
+
70
+ This section details the attributes, slots and CSS custom properties available for the `m3e-badge` component.
71
+
72
+ ### โš™๏ธ Attributes
73
+
74
+ | Attribute | Type | Default | Description |
75
+ | ---------- | ----------------------------------------------------------------------------------------------------------------- | --------------- | ------------------------------------------------------------ |
76
+ | `size` | `"small" \| "medium" \| "large"` | `"medium"` | The size of the badge. |
77
+ | `position` | `"above-after" \| "above-before" \| "below-before" \| "below-after" \| "before" \| "after" \| "above" \| "below"` | `"above-after"` | The position of the badge, when attached to another element. |
78
+
79
+ ### ๐Ÿงฉ Slots
80
+
81
+ | Slot | Description |
82
+ | ----------- | --------------------------------- |
83
+ | _(default)_ | Renders the content of the badge. |
84
+
85
+ ### ๐ŸŽ›๏ธ CSS Custom Properties
86
+
87
+ The `m3e-badge` element supports scoped CSS custom properties for shape, color, sizing, and typography across badge sizes. These tokens enable consistent theming, semantic clarity, and expressive control.
88
+
89
+ #### ๐Ÿงฑ Global Properties
90
+
91
+ | Property | Description |
92
+ | ----------------------------- | ---------------------------------------- |
93
+ | `--m3e-badge-shape` | Corner radius of the badge container. |
94
+ | `--m3e-badge-color` | Foreground color of badge content. |
95
+ | `--m3e-badge-container-color` | Background color of the badge container. |
96
+
97
+ #### ๐ŸŸข Small Badge
98
+
99
+ Used for minimal indicators such as presence dots or unread markers.
100
+
101
+ | Property | Description |
102
+ | ------------------------ | --------------------------------- |
103
+ | `--m3e-badge-small-size` | Fixed dimensions for small badge. |
104
+
105
+ #### ๐ŸŸก Medium Badge
106
+
107
+ Used for numeric counts or short labels.
108
+
109
+ | Property | Description |
110
+ | -------------------------------- | -------------------------------------- |
111
+ | `--m3e-badge-medium-size` | Height and minimum width of the badge. |
112
+ | `--m3e-badge-medium-font-size` | Font size for badge label. |
113
+ | `--m3e-badge-medium-font-weight` | Font weight for badge label. |
114
+ | `--m3e-badge-medium-line-height` | Line height for badge label. |
115
+ | `--m3e-badge-medium-tracking` | Letter spacing for badge label. |
116
+
117
+ #### ๐Ÿ”ต Large Badge
118
+
119
+ Used for longer labels or emphasis in dense layouts.
120
+
121
+ | Property | Description |
122
+ | ------------------------------- | -------------------------------------- |
123
+ | `--m3e-badge-large-size` | Height and minimum width of the badge. |
124
+ | `--m3e-badge-large-font-size` | Font size for badge label. |
125
+ | `--m3e-badge-large-font-weight` | Font weight for badge label. |
126
+ | `--m3e-badge-large-line-height` | Line height for badge label. |
127
+ | `--m3e-badge-large-tracking` | Letter spacing for badge label. |
128
+
129
+ ## ๐Ÿค Contributing
130
+
131
+ See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
132
+
133
+ ## ๐Ÿ“„ License
134
+
135
+ 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,60 @@
1
+ <!doctype html>
2
+ <html lang="en" style="overflow-y: auto">
3
+ <head>
4
+ <title>Badge for M3E</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="description" content="Badge 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/anchoring": "../../core/dist/anchoring.min.js",
25
+ "@m3e/core/bidi": "../../core/dist/bidi.min.js"
26
+ }
27
+ }
28
+ </script>
29
+ <script type="module" src="../../button/dist/index.min.js"></script>
30
+ <script type="module" src="../../theme/dist/index.min.js"></script>
31
+ <script type="module" src="../dist/index.min.js"></script>
32
+ <style>
33
+ body {
34
+ font-family: "Roboto";
35
+ }
36
+ *:not(:defined) {
37
+ display: none;
38
+ }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <m3e-theme strong-focus>
43
+ <m3e-badge size="small">10</m3e-badge>
44
+ <m3e-badge size="medium">10</m3e-badge>
45
+ <m3e-badge size="large">10</m3e-badge>
46
+ <br /><br />
47
+ <m3e-badge>999+</m3e-badge>
48
+ <br /><br />
49
+ <m3e-button id="btn1" variant="tonal">Top Right</m3e-button>
50
+ <m3e-badge for="btn1">10</m3e-badge>
51
+ <m3e-button id="btn2" variant="tonal">Bottom Right</m3e-button>
52
+ <m3e-badge for="btn2" position="below-after">10</m3e-badge>
53
+ &nbsp;&nbsp;&nbsp;&nbsp;
54
+ <m3e-button id="btn3" variant="tonal">Bottom Left</m3e-button>
55
+ <m3e-badge for="btn3" position="below-before">10</m3e-badge>
56
+ <m3e-button id="btn4" variant="tonal">Top Left</m3e-button>
57
+ <m3e-badge for="btn4" position="above-before">10</m3e-badge>
58
+ </m3e-theme>
59
+ </body>
60
+ </html>
@@ -0,0 +1,77 @@
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-badge-shape",
7
+ "description": "Corner radius of the badge.",
8
+ "values": []
9
+ },
10
+ {
11
+ "name": "--m3e-badge-color",
12
+ "description": "Foreground color of badge content.",
13
+ "values": []
14
+ },
15
+ {
16
+ "name": "--m3e-badge-container-color",
17
+ "description": "Background color of the badge.",
18
+ "values": []
19
+ },
20
+ {
21
+ "name": "--m3e-badge-small-size",
22
+ "description": "Fixed dimensions for small badge. Used for minimal indicators (e.g. dot).",
23
+ "values": []
24
+ },
25
+ {
26
+ "name": "--m3e-badge-medium-size",
27
+ "description": "Height and min-width for medium badge.",
28
+ "values": []
29
+ },
30
+ {
31
+ "name": "--m3e-badge-medium-font-size",
32
+ "description": "Font size for medium badge label.",
33
+ "values": []
34
+ },
35
+ {
36
+ "name": "--m3e-badge-medium-font-weight",
37
+ "description": "Font weight for medium badge label.",
38
+ "values": []
39
+ },
40
+ {
41
+ "name": "--m3e-badge-medium-line-height",
42
+ "description": "Line height for medium badge label.",
43
+ "values": []
44
+ },
45
+ {
46
+ "name": "--m3e-badge-medium-tracking",
47
+ "description": "Letter spacing for medium badge label.",
48
+ "values": []
49
+ },
50
+ {
51
+ "name": "--m3e-badge-large-size",
52
+ "description": "Height and min-width for large badge.",
53
+ "values": []
54
+ },
55
+ {
56
+ "name": "--m3e-badge-large-font-size",
57
+ "description": "Font size for large badge label.",
58
+ "values": []
59
+ },
60
+ {
61
+ "name": "--m3e-badge-large-font-weight",
62
+ "description": "Font weight for large badge label.",
63
+ "values": []
64
+ },
65
+ {
66
+ "name": "--m3e-badge-large-line-height",
67
+ "description": "Line height for large badge label.",
68
+ "values": []
69
+ },
70
+ {
71
+ "name": "--m3e-badge-large-tracking",
72
+ "description": "Letter spacing for large badge label.",
73
+ "values": []
74
+ }
75
+ ],
76
+ "pseudoElements": []
77
+ }
@@ -0,0 +1,240 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/BadgeElement.ts",
8
+ "declarations": [
9
+ {
10
+ "kind": "class",
11
+ "description": "",
12
+ "name": "M3eBadgeElement",
13
+ "cssProperties": [
14
+ {
15
+ "description": "Corner radius of the badge.",
16
+ "name": "--m3e-badge-shape"
17
+ },
18
+ {
19
+ "description": "Foreground color of badge content.",
20
+ "name": "--m3e-badge-color"
21
+ },
22
+ {
23
+ "description": "Background color of the badge.",
24
+ "name": "--m3e-badge-container-color"
25
+ },
26
+ {
27
+ "description": "Fixed dimensions for small badge. Used for minimal indicators (e.g. dot).",
28
+ "name": "--m3e-badge-small-size"
29
+ },
30
+ {
31
+ "description": "Height and min-width for medium badge.",
32
+ "name": "--m3e-badge-medium-size"
33
+ },
34
+ {
35
+ "description": "Font size for medium badge label.",
36
+ "name": "--m3e-badge-medium-font-size"
37
+ },
38
+ {
39
+ "description": "Font weight for medium badge label.",
40
+ "name": "--m3e-badge-medium-font-weight"
41
+ },
42
+ {
43
+ "description": "Line height for medium badge label.",
44
+ "name": "--m3e-badge-medium-line-height"
45
+ },
46
+ {
47
+ "description": "Letter spacing for medium badge label.",
48
+ "name": "--m3e-badge-medium-tracking"
49
+ },
50
+ {
51
+ "description": "Height and min-width for large badge.",
52
+ "name": "--m3e-badge-large-size"
53
+ },
54
+ {
55
+ "description": "Font size for large badge label.",
56
+ "name": "--m3e-badge-large-font-size"
57
+ },
58
+ {
59
+ "description": "Font weight for large badge label.",
60
+ "name": "--m3e-badge-large-font-weight"
61
+ },
62
+ {
63
+ "description": "Line height for large badge label.",
64
+ "name": "--m3e-badge-large-line-height"
65
+ },
66
+ {
67
+ "description": "Letter spacing for large badge label.",
68
+ "name": "--m3e-badge-large-tracking"
69
+ }
70
+ ],
71
+ "slots": [
72
+ {
73
+ "description": "Renders the content of the badge.",
74
+ "name": ""
75
+ }
76
+ ],
77
+ "members": [
78
+ {
79
+ "kind": "field",
80
+ "name": "#directionalitySubscription",
81
+ "privacy": "private",
82
+ "type": {
83
+ "text": "() => void | undefined"
84
+ }
85
+ },
86
+ {
87
+ "kind": "field",
88
+ "name": "#anchorCleanup",
89
+ "privacy": "private",
90
+ "type": {
91
+ "text": "() => void | undefined"
92
+ }
93
+ },
94
+ {
95
+ "kind": "field",
96
+ "name": "size",
97
+ "type": {
98
+ "text": "BadgeSize"
99
+ },
100
+ "default": "\"medium\"",
101
+ "description": "The size of the badge.",
102
+ "attribute": "size",
103
+ "reflects": true
104
+ },
105
+ {
106
+ "kind": "field",
107
+ "name": "position",
108
+ "type": {
109
+ "text": "BadgePosition"
110
+ },
111
+ "default": "\"above-after\"",
112
+ "description": "The position of the badge, when attached to another element.",
113
+ "attribute": "position",
114
+ "reflects": true
115
+ },
116
+ {
117
+ "kind": "method",
118
+ "name": "detach",
119
+ "return": {
120
+ "type": {
121
+ "text": "void"
122
+ }
123
+ }
124
+ },
125
+ {
126
+ "kind": "method",
127
+ "name": "#detach",
128
+ "privacy": "private",
129
+ "return": {
130
+ "type": {
131
+ "text": "void"
132
+ }
133
+ }
134
+ },
135
+ {
136
+ "kind": "method",
137
+ "name": "#attach",
138
+ "privacy": "private",
139
+ "return": {
140
+ "type": {
141
+ "text": "Promise<void>"
142
+ }
143
+ }
144
+ }
145
+ ],
146
+ "attributes": [
147
+ {
148
+ "description": "The size of the badge.",
149
+ "name": "size",
150
+ "type": {
151
+ "text": "BadgeSize"
152
+ },
153
+ "default": "\"medium\"",
154
+ "fieldName": "size"
155
+ },
156
+ {
157
+ "name": "position",
158
+ "type": {
159
+ "text": "BadgePosition"
160
+ },
161
+ "default": "\"above-after\"",
162
+ "description": "The position of the badge, when attached to another element.",
163
+ "fieldName": "position"
164
+ }
165
+ ],
166
+ "mixins": [
167
+ {
168
+ "name": "HtmlFor",
169
+ "package": "@m3e/core"
170
+ },
171
+ {
172
+ "name": "Role",
173
+ "package": "@m3e/core"
174
+ }
175
+ ],
176
+ "superclass": {
177
+ "name": "LitElement",
178
+ "package": "lit"
179
+ },
180
+ "tagName": "m3e-badge",
181
+ "customElement": true,
182
+ "summary": "A visual indicator used to label content."
183
+ }
184
+ ],
185
+ "exports": [
186
+ {
187
+ "kind": "js",
188
+ "name": "M3eBadgeElement",
189
+ "declaration": {
190
+ "name": "M3eBadgeElement",
191
+ "module": "src/BadgeElement.ts"
192
+ }
193
+ },
194
+ {
195
+ "kind": "custom-element-definition",
196
+ "name": "m3e-badge",
197
+ "declaration": {
198
+ "name": "M3eBadgeElement",
199
+ "module": "src/BadgeElement.ts"
200
+ }
201
+ }
202
+ ]
203
+ },
204
+ {
205
+ "kind": "javascript-module",
206
+ "path": "src/BadgePosition.ts",
207
+ "declarations": [],
208
+ "exports": []
209
+ },
210
+ {
211
+ "kind": "javascript-module",
212
+ "path": "src/BadgeSize.ts",
213
+ "declarations": [],
214
+ "exports": []
215
+ },
216
+ {
217
+ "kind": "javascript-module",
218
+ "path": "src/index.ts",
219
+ "declarations": [],
220
+ "exports": [
221
+ {
222
+ "kind": "js",
223
+ "name": "*",
224
+ "declaration": {
225
+ "name": "*",
226
+ "package": "\"./BadgeElement\""
227
+ }
228
+ },
229
+ {
230
+ "kind": "js",
231
+ "name": "*",
232
+ "declaration": {
233
+ "name": "*",
234
+ "package": "\"./BadgeSize\""
235
+ }
236
+ }
237
+ ]
238
+ }
239
+ ]
240
+ }
@@ -0,0 +1,23 @@
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-badge",
7
+ "description": "A visual indicator used to label content.\n---\n\n\n### **Slots:**\n - _default_ - Renders the content of the badge.\n\n### **CSS Properties:**\n - **--m3e-badge-shape** - Corner radius of the badge. _(default: undefined)_\n- **--m3e-badge-color** - Foreground color of badge content. _(default: undefined)_\n- **--m3e-badge-container-color** - Background color of the badge. _(default: undefined)_\n- **--m3e-badge-small-size** - Fixed dimensions for small badge. Used for minimal indicators (e.g. dot). _(default: undefined)_\n- **--m3e-badge-medium-size** - Height and min-width for medium badge. _(default: undefined)_\n- **--m3e-badge-medium-font-size** - Font size for medium badge label. _(default: undefined)_\n- **--m3e-badge-medium-font-weight** - Font weight for medium badge label. _(default: undefined)_\n- **--m3e-badge-medium-line-height** - Line height for medium badge label. _(default: undefined)_\n- **--m3e-badge-medium-tracking** - Letter spacing for medium badge label. _(default: undefined)_\n- **--m3e-badge-large-size** - Height and min-width for large badge. _(default: undefined)_\n- **--m3e-badge-large-font-size** - Font size for large badge label. _(default: undefined)_\n- **--m3e-badge-large-font-weight** - Font weight for large badge label. _(default: undefined)_\n- **--m3e-badge-large-line-height** - Line height for large badge label. _(default: undefined)_\n- **--m3e-badge-large-tracking** - Letter spacing for large badge label. _(default: undefined)_",
8
+ "attributes": [
9
+ {
10
+ "name": "size",
11
+ "description": "The size of the badge.",
12
+ "values": [{ "name": "BadgeSize" }]
13
+ },
14
+ {
15
+ "name": "position",
16
+ "description": "The position of the badge, when attached to another element.",
17
+ "values": [{ "name": "BadgePosition" }]
18
+ }
19
+ ],
20
+ "references": []
21
+ }
22
+ ]
23
+ }