@m3e/radio-group 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 +22 -0
- package/README.md +151 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +78 -0
- package/dist/css-custom-data.json +82 -0
- package/dist/custom-elements.json +472 -0
- package/dist/html-custom-data.json +50 -0
- package/dist/index.js +448 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +141 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/RadioElement.d.ts +79 -0
- package/dist/src/RadioElement.d.ts.map +1 -0
- package/dist/src/RadioGroupElement.d.ts +72 -0
- package/dist/src/RadioGroupElement.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +49 -0
- package/rollup.config.js +32 -0
- package/src/RadioElement.ts +257 -0
- package/src/RadioGroupElement.ts +170 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +9 -0
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,151 @@
|
|
|
1
|
+
# @m3e/radio-group
|
|
2
|
+
|
|
3
|
+
The `m3e-radio-group` and `m3e-radio` components enable single-choice selection within a set of mutually exclusive options. They support accessible state transitions, semantic grouping, and expressive styling across interaction states.
|
|
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/radio-group
|
|
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/radio-group`, 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/radio-group/dist/html-custom-data.json"],
|
|
27
|
+
"css.customData": ["./node_modules/@m3e/radio-group/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/radio-group/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/a11y": "/node_modules/@m3e/core/dist/a11y.js"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
> For production, use index.min.js and a11y.min.js for faster load times.
|
|
54
|
+
|
|
55
|
+
## ๐๏ธ Elements
|
|
56
|
+
|
|
57
|
+
- `m3e-radio-group` โ A container for a set of radio buttons that enforces single selection.
|
|
58
|
+
- `m3e-radio` โ A radio button that allows a user to select one option from a set of options.
|
|
59
|
+
|
|
60
|
+
## ๐งช Example
|
|
61
|
+
|
|
62
|
+
The following example illustrates using `m3e-radio-group` and `m3e-radio` to present a group of options.
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<label for="rdg1">Radio group</label>
|
|
66
|
+
<br />
|
|
67
|
+
<m3e-radio-group id="rdg1">
|
|
68
|
+
<label><m3e-radio value="1"></m3e-radio> Value 1</label>
|
|
69
|
+
<label><m3e-radio value="2"></m3e-radio> Value 2</label>
|
|
70
|
+
<label><m3e-radio value="3"></m3e-radio> Value 3</label>
|
|
71
|
+
<label><m3e-radio value="4"></m3e-radio> Value 4</label>
|
|
72
|
+
</m3e-radio-group>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## ๐ API Reference
|
|
76
|
+
|
|
77
|
+
### ๐๏ธ m3e-radio-group
|
|
78
|
+
|
|
79
|
+
This section details the attributes, slots, events and CSS custom properties available for the `m3e-radio-group` component.
|
|
80
|
+
|
|
81
|
+
#### โ๏ธ Attributes
|
|
82
|
+
|
|
83
|
+
| Attribute | Type | Default | Description |
|
|
84
|
+
| ---------- | --------- | ------- | --------------------------------------------- |
|
|
85
|
+
| `checked` | `boolean` | `false` | Whether the element is checked. |
|
|
86
|
+
| `disabled` | `boolean` | `false` | Whether the element is disabled. |
|
|
87
|
+
| `value` | `string` | `""` | A string representing the value of the radio. |
|
|
88
|
+
|
|
89
|
+
#### ๐ Events
|
|
90
|
+
|
|
91
|
+
| Event | Description |
|
|
92
|
+
| -------- | --------------------------------------------------------- |
|
|
93
|
+
| `change` | Emitted when the checked state of a radio button changes. |
|
|
94
|
+
|
|
95
|
+
#### ๐งฉ Slots
|
|
96
|
+
|
|
97
|
+
| Slot | Description |
|
|
98
|
+
| ----------- | --------------------------------------- |
|
|
99
|
+
| _(default)_ | Renders the radio buttons of the group. |
|
|
100
|
+
|
|
101
|
+
#### ๐๏ธ CSS Custom Properties
|
|
102
|
+
|
|
103
|
+
| Property | Description |
|
|
104
|
+
| -------------------------------- | ----------------------------------------------------------------- |
|
|
105
|
+
| `--m3e-radio-error-hover-color` | Fallback hover color used when the radio is invalid and touched. |
|
|
106
|
+
| `--m3e-radio-error-focus-color` | Fallback focus color used when the radio is invalid and touched. |
|
|
107
|
+
| `--m3e-radio-error-ripple-color` | Fallback ripple color used when the radio is invalid and touched. |
|
|
108
|
+
| `--m3e-radio-error-icon-color` | Fallback icon color used when the radio is invalid and touched. |
|
|
109
|
+
|
|
110
|
+
### ๐๏ธ m3e-radio
|
|
111
|
+
|
|
112
|
+
This section details the attributes, events and CSS custom properties available for the `m3e-radio` component.
|
|
113
|
+
|
|
114
|
+
#### โ๏ธ Attributes
|
|
115
|
+
|
|
116
|
+
| Attribute | Type | Default | Description |
|
|
117
|
+
| ---------- | --------- | ------- | --------------------------------------------- |
|
|
118
|
+
| `checked` | `boolean` | `false` | Whether the element is checked. |
|
|
119
|
+
| `disabled` | `boolean` | `false` | Whether the element is disabled. |
|
|
120
|
+
| `value` | `string` | `""` | A string representing the value of the radio. |
|
|
121
|
+
|
|
122
|
+
#### ๐ Events
|
|
123
|
+
|
|
124
|
+
| Event | Description |
|
|
125
|
+
| -------- | --------------------------------------- |
|
|
126
|
+
| `input` | Emitted when the checked state changes. |
|
|
127
|
+
| `change` | Emitted when the checked state changes. |
|
|
128
|
+
|
|
129
|
+
#### ๐๏ธ CSS Custom Properties
|
|
130
|
+
|
|
131
|
+
| Property | Description |
|
|
132
|
+
| ------------------------------------- | --------------------------------------------------- |
|
|
133
|
+
| `--m3e-radio-container-size` | Base size of the radio button container. |
|
|
134
|
+
| `--m3e-radio-icon-size` | Size of the radio icon inside the wrapper. |
|
|
135
|
+
| `--m3e-radio-unselected-hover-color` | Hover state layer color when radio is not selected. |
|
|
136
|
+
| `--m3e-radio-unselected-focus-color` | Focus state layer color when radio is not selected. |
|
|
137
|
+
| `--m3e-radio-unselected-ripple-color` | Ripple color when radio is not selected. |
|
|
138
|
+
| `--m3e-radio-unselected-icon-color` | Icon color when radio is not selected. |
|
|
139
|
+
| `--m3e-radio-selected-hover-color` | Hover state layer color when radio is selected. |
|
|
140
|
+
| `--m3e-radio-selected-focus-color` | Focus state layer color when radio is selected. |
|
|
141
|
+
| `--m3e-radio-selected-ripple-color` | Ripple color when radio is selected. |
|
|
142
|
+
| `--m3e-radio-selected-icon-color` | Icon color when radio is selected. |
|
|
143
|
+
| `--m3e-radio-disabled-icon-color` | Icon color when radio is disabled. |
|
|
144
|
+
|
|
145
|
+
## ๐ค Contributing
|
|
146
|
+
|
|
147
|
+
See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
|
|
148
|
+
|
|
149
|
+
## ๐ License
|
|
150
|
+
|
|
151
|
+
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
|
+
};
|
package/demo/index.html
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" style="overflow-y: auto">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Radio Group for M3E</title>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<meta name="description" content="Radio Group 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
|
+
}
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
<script type="module" src="../../theme/dist/index.min.js"></script>
|
|
29
|
+
<script type="module" src="../dist/index.min.js"></script>
|
|
30
|
+
<style>
|
|
31
|
+
body {
|
|
32
|
+
font-family: "Roboto";
|
|
33
|
+
}
|
|
34
|
+
*:not(:defined) {
|
|
35
|
+
display: none;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
<m3e-theme strong-focus>
|
|
41
|
+
<label for="rdg1">Radio group</label>
|
|
42
|
+
<br />
|
|
43
|
+
<m3e-radio-group id="rdg1">
|
|
44
|
+
<label><m3e-radio value="1"></m3e-radio> Value 1</label>
|
|
45
|
+
<label><m3e-radio value="2"></m3e-radio> Value 2</label>
|
|
46
|
+
<label><m3e-radio value="3"></m3e-radio> Value 3</label>
|
|
47
|
+
<label><m3e-radio value="4"></m3e-radio> Value 4</label>
|
|
48
|
+
</m3e-radio-group>
|
|
49
|
+
<br />
|
|
50
|
+
<label for="rdg2">Disabled radio group</label>
|
|
51
|
+
<br />
|
|
52
|
+
<m3e-radio-group id="rdg2" disabled>
|
|
53
|
+
<label><m3e-radio value="1"></m3e-radio> Value 1</label>
|
|
54
|
+
<label><m3e-radio value="2"></m3e-radio> Value 2</label>
|
|
55
|
+
<label><m3e-radio value="3"></m3e-radio> Value 3</label>
|
|
56
|
+
<label><m3e-radio value="4"></m3e-radio> Value 4</label>
|
|
57
|
+
</m3e-radio-group>
|
|
58
|
+
<br />
|
|
59
|
+
<label for="rdg3">Radio group w/ disabled option</label>
|
|
60
|
+
<br />
|
|
61
|
+
<m3e-radio-group id="rdg3">
|
|
62
|
+
<label><m3e-radio value="1" disabled></m3e-radio> Value 1</label>
|
|
63
|
+
<label><m3e-radio value="2"></m3e-radio> Value 2</label>
|
|
64
|
+
<label><m3e-radio value="3"></m3e-radio> Value 3</label>
|
|
65
|
+
<label><m3e-radio value="4"></m3e-radio> Value 4</label>
|
|
66
|
+
</m3e-radio-group>
|
|
67
|
+
<br />
|
|
68
|
+
<label for="rdg4">Required radio group</label>
|
|
69
|
+
<br />
|
|
70
|
+
<m3e-radio-group id="rdg4" required>
|
|
71
|
+
<label><m3e-radio value="1"></m3e-radio> Value 1</label>
|
|
72
|
+
<label><m3e-radio value="2"></m3e-radio> Value 2</label>
|
|
73
|
+
<label><m3e-radio value="3"></m3e-radio> Value 3</label>
|
|
74
|
+
<label><m3e-radio value="4"></m3e-radio> Value 4</label>
|
|
75
|
+
</m3e-radio-group>
|
|
76
|
+
</m3e-theme>
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
@@ -0,0 +1,82 @@
|
|
|
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-radio-container-size",
|
|
7
|
+
"description": "Base size of the radio button container.",
|
|
8
|
+
"values": []
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "--m3e-radio-icon-size",
|
|
12
|
+
"description": "Size of the radio icon inside the wrapper.",
|
|
13
|
+
"values": []
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "--m3e-radio-unselected-hover-color",
|
|
17
|
+
"description": "Hover state layer color when radio is not selected.",
|
|
18
|
+
"values": []
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "--m3e-radio-unselected-focus-color",
|
|
22
|
+
"description": "Focus state layer color when radio is not selected.",
|
|
23
|
+
"values": []
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "--m3e-radio-unselected-ripple-color",
|
|
27
|
+
"description": "Ripple color when radio is not selected.",
|
|
28
|
+
"values": []
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "--m3e-radio-unselected-icon-color",
|
|
32
|
+
"description": "Icon color when radio is not selected.",
|
|
33
|
+
"values": []
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "--m3e-radio-selected-hover-color",
|
|
37
|
+
"description": "Hover state layer color when radio is selected.",
|
|
38
|
+
"values": []
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "--m3e-radio-selected-focus-color",
|
|
42
|
+
"description": "Focus state layer color when radio is selected.",
|
|
43
|
+
"values": []
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "--m3e-radio-selected-ripple-color",
|
|
47
|
+
"description": "Ripple color when radio is selected.",
|
|
48
|
+
"values": []
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "--m3e-radio-selected-icon-color",
|
|
52
|
+
"description": "Icon color when radio is selected.",
|
|
53
|
+
"values": []
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "--m3e-radio-disabled-icon-color",
|
|
57
|
+
"description": "Icon color when radio is disabled.",
|
|
58
|
+
"values": []
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "--m3e-radio-error-hover-color",
|
|
62
|
+
"description": "Fallback hover color used when the radio is invalid and touched.",
|
|
63
|
+
"values": []
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "--m3e-radio-error-focus-color",
|
|
67
|
+
"description": "Fallback focus color used when the radio is invalid and touched.",
|
|
68
|
+
"values": []
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "--m3e-radio-error-ripple-color",
|
|
72
|
+
"description": "Fallback ripple color used when the radio is invalid and touched.",
|
|
73
|
+
"values": []
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "--m3e-radio-error-icon-color",
|
|
77
|
+
"description": "Fallback icon color used when the radio is invalid and touched.",
|
|
78
|
+
"values": []
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"pseudoElements": []
|
|
82
|
+
}
|