@m3e/fab 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 +181 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +80 -0
- package/dist/css-custom-data.json +1247 -0
- package/dist/custom-elements.json +1363 -0
- package/dist/html-custom-data.json +78 -0
- package/dist/index.js +1393 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +310 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/FabElement.d.ts +355 -0
- package/dist/src/FabElement.d.ts.map +1 -0
- package/dist/src/FabSize.d.ts +3 -0
- package/dist/src/FabSize.d.ts.map +1 -0
- package/dist/src/FabVariant.d.ts +3 -0
- package/dist/src/FabVariant.d.ts.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/styles/FabSizeStyle.d.ts +7 -0
- package/dist/src/styles/FabSizeStyle.d.ts.map +1 -0
- package/dist/src/styles/FabSizeToken.d.ts +25 -0
- package/dist/src/styles/FabSizeToken.d.ts.map +1 -0
- package/dist/src/styles/FabStyle.d.ts +7 -0
- package/dist/src/styles/FabStyle.d.ts.map +1 -0
- package/dist/src/styles/FabVariantStyle.d.ts +7 -0
- package/dist/src/styles/FabVariantStyle.d.ts.map +1 -0
- package/dist/src/styles/FabVariantToken.d.ts +52 -0
- package/dist/src/styles/FabVariantToken.d.ts.map +1 -0
- package/dist/src/styles/index.d.ts +4 -0
- package/dist/src/styles/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/FabElement.ts +448 -0
- package/src/FabSize.ts +2 -0
- package/src/FabVariant.ts +9 -0
- package/src/index.ts +3 -0
- package/src/styles/FabSizeStyle.ts +45 -0
- package/src/styles/FabSizeToken.ts +102 -0
- package/src/styles/FabStyle.ts +155 -0
- package/src/styles/FabVariantStyle.ts +95 -0
- package/src/styles/FabVariantToken.ts +1068 -0
- package/src/styles/index.ts +3 -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,181 @@
|
|
|
1
|
+
# @m3e/fab
|
|
2
|
+
|
|
3
|
+
The `m3e-fab` component is a prominent, expressive UI component that represents the primary action on a screen. Designed according to Material Design 3 guidelines, it supports seven visual variants, specified using the `variant` attribute—`primary`, `primary-container`, `secondary`, `secondary-container`, `tertiary`, `tertiary-container` and `surface`—each with dynamic elevation and adaptive color theming.
|
|
4
|
+
|
|
5
|
+
The component is accessible by default, with ARIA roles, contrast-safe color tokens, and strong focus indicators. It can be extended to display a label alongside its icon, and responds to interaction states (hover, focus, press, disabled) with smooth motion transitions, elevation changes, and adaptive color theming. It can also function as a link or be used to submit form data.
|
|
6
|
+
|
|
7
|
+
Native disabled `<button>` elements cannot receive focus. This can be problematic in some cases because it can prevent you from telling the user why the button is disabled. You can use the `disabled-interactive` attribute to style a `m3e-fab` as disabled but allow for it to receive focus. The button will have `aria-disabled="true"` for assistive technology.
|
|
8
|
+
|
|
9
|
+
> **Part of the [M3E](../../README.md) monorepo**
|
|
10
|
+
> This package is maintained within the unified M3E repository, which provides a suite of Material 3 web components.
|
|
11
|
+
|
|
12
|
+
## 📦 Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @m3e/fab
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 💻 Editor Integration
|
|
19
|
+
|
|
20
|
+
This package includes a [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest) to support enhanced editor tooling and developer experience.
|
|
21
|
+
|
|
22
|
+
### Visual Studio Code
|
|
23
|
+
|
|
24
|
+
To enable autocomplete and hover documentation for `@m3e/fab`, 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.
|
|
25
|
+
|
|
26
|
+
Alternately, you can explicitly reference the `html-custom-data.json` and `css-custom-data.json` in your workspace settings:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"html.customData": ["./node_modules/@m3e/fab/dist/html-custom-data.json"],
|
|
31
|
+
"css.customData": ["./node_modules/@m3e/fab/dist/css-custom-data.json"]
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 🚀 Browser Usage
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<script type="module" src="/node_modules/@m3e/fab/dist/index.js"></script>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
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.
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<script type="importmap">
|
|
47
|
+
{
|
|
48
|
+
"imports": {
|
|
49
|
+
"lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
|
|
50
|
+
"@m3e/core": "/node_modules/@m3e/core/dist/index.js"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> For production, use index.min.js for faster load times.
|
|
57
|
+
|
|
58
|
+
## 🗂️ Elements
|
|
59
|
+
|
|
60
|
+
- `m3e-fab` — A floating action button (FAB) used to present important actions.
|
|
61
|
+
|
|
62
|
+
## 🧪 Examples
|
|
63
|
+
|
|
64
|
+
The following example illustrates a basic floating action button.
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<m3e-fab>
|
|
68
|
+
<m3e-icon>add</m3e-icon>
|
|
69
|
+
</m3e-fab>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The next example illustrates an extended floating action button.
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<m3e-fab extended>
|
|
76
|
+
<m3e-icon>add</m3e-icon>
|
|
77
|
+
<span slot="label">Add</span>
|
|
78
|
+
</m3e-fab>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 📖 API Reference
|
|
82
|
+
|
|
83
|
+
This section details the attributes, slots and CSS custom properties available for the `m3e-fab` component.
|
|
84
|
+
|
|
85
|
+
### ⚙️ Attributes
|
|
86
|
+
|
|
87
|
+
| Attribute | Type | Default | Description |
|
|
88
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
89
|
+
| `variant` | `"primary" \| "primary-container" \| "secondary" \| "secondary-container" \| "tertiary" \| "tertiary-container" \| "surface"` | `"primary-container"` | The appearance variant of the FAB. |
|
|
90
|
+
| `size` | `"small" \| "medium" \| "large"` | `"medium"` | The size of the FAB. |
|
|
91
|
+
| `extended` | `boolean` | `false` | Whether the FAB is extended to show the label. |
|
|
92
|
+
| `lowered` | `boolean` | `false` | Whether to present a lowered elevation. |
|
|
93
|
+
| `disabled` | `boolean` | `false` | Whether the element is disabled. |
|
|
94
|
+
| `disabled-interactive` | `boolean` | `false` | Whether the element is disabled and interactive. |
|
|
95
|
+
| `type` | `"button" \| "submit" \| "reset"` | `"button"` | The type of the element. |
|
|
96
|
+
| `name` | `string` | | The name of the element, submitted as a pair with the element's value as part of form data, when the element is used to submit a form. |
|
|
97
|
+
| `value` | `string` | | The value associated with the element's name when it's submitted with form data. |
|
|
98
|
+
| `href` | `string` | | The URL to which the link FAB points. |
|
|
99
|
+
| `target` | `string` | | The target of the link FAB. |
|
|
100
|
+
| `rel` | `string` | | The relationship between the target of the link FAB and the document. |
|
|
101
|
+
| `download` | `string` | | A value indicating whether the target of the link FAB will be downloaded, optionally specifying the new name of the file. |
|
|
102
|
+
|
|
103
|
+
### 🧩 Slots
|
|
104
|
+
|
|
105
|
+
| Slot | Description |
|
|
106
|
+
| ------------ | ---------------------------------------------------- |
|
|
107
|
+
| _(default)_ | Renders the icon of the button. |
|
|
108
|
+
| `label` | Renders the label of an extended FAB. |
|
|
109
|
+
| `close-icon` | Renders the close icon when used to open a FAB menu. |
|
|
110
|
+
|
|
111
|
+
### 🎛️ CSS Custom Properties
|
|
112
|
+
|
|
113
|
+
#### 🧱 Size Properties
|
|
114
|
+
|
|
115
|
+
All size variants (`small`, `medium`, `large`) support:
|
|
116
|
+
|
|
117
|
+
| Property | Description |
|
|
118
|
+
| ----------------------------------------- | ---------------------------- |
|
|
119
|
+
| `--m3e-fab-[size]-container-height` | Height of the FAB container |
|
|
120
|
+
| `--m3e-fab-[size]-label-text-font-size` | Font size for label |
|
|
121
|
+
| `--m3e-fab-[size]-label-text-font-weight` | Font weight for label |
|
|
122
|
+
| `--m3e-fab-[size]-label-text-line-height` | Line height for label |
|
|
123
|
+
| `--m3e-fab-[size]-label-text-tracking` | Letter tracking for label |
|
|
124
|
+
| `--m3e-fab-[size]-icon-size` | Icon size |
|
|
125
|
+
| `--m3e-fab-[size]-shape` | Corner radius |
|
|
126
|
+
| `--m3e-fab-[size]-leading-space` | Space before icon/label |
|
|
127
|
+
| `--m3e-fab-[size]-trailing-space` | Space after icon/label |
|
|
128
|
+
| `--m3e-fab-[size]-icon-label-space` | Space between icon and label |
|
|
129
|
+
|
|
130
|
+
#### 🎨 Appearance Variant Properties
|
|
131
|
+
|
|
132
|
+
All appearance variants (`primary`, `primary-container`, `secondary`, `secondary-container`, `tertiary`, `tertiary-container`, `surface`) support:
|
|
133
|
+
|
|
134
|
+
| Property | Description |
|
|
135
|
+
| ------------------------------------------------- | -------------------------- |
|
|
136
|
+
| `--m3e-[variant]-fab-label-text-color` | Label color |
|
|
137
|
+
| `--m3e-[variant]-fab-icon-color` | Icon color |
|
|
138
|
+
| `--m3e-[variant]-fab-container-color` | Container background color |
|
|
139
|
+
| `--m3e-[variant]-fab-container-elevation` | Elevation |
|
|
140
|
+
| `--m3e-[variant]-fab-lowered-container-elevation` | Lowered elevation |
|
|
141
|
+
|
|
142
|
+
#### 🟫 State Properties
|
|
143
|
+
|
|
144
|
+
Each variant supports state properties for disabled, hover, focus, and pressed. For each variant, the following properties are available (replace `[variant]` with the variant name):
|
|
145
|
+
|
|
146
|
+
| Property | Description |
|
|
147
|
+
| ---------------------------------------------------------- | ------------------------------- |
|
|
148
|
+
| `--m3e-[variant]-fab-disabled-label-text-color` | Label color when disabled |
|
|
149
|
+
| `--m3e-[variant]-fab-disabled-label-text-opacity` | Label opacity when disabled |
|
|
150
|
+
| `--m3e-[variant]-fab-disabled-icon-color` | Icon color when disabled |
|
|
151
|
+
| `--m3e-[variant]-fab-disabled-icon-opacity` | Icon opacity when disabled |
|
|
152
|
+
| `--m3e-[variant]-fab-disabled-container-color` | Container color when disabled |
|
|
153
|
+
| `--m3e-[variant]-fab-disabled-container-opacity` | Container opacity when disabled |
|
|
154
|
+
| `--m3e-[variant]-fab-disabled-container-elevation` | Elevation when disabled |
|
|
155
|
+
| `--m3e-[variant]-fab-lowered-disabled-container-elevation` | Lowered elevation when disabled |
|
|
156
|
+
| `--m3e-[variant]-fab-hover-label-text-color` | Label color on hover |
|
|
157
|
+
| `--m3e-[variant]-fab-hover-icon-color` | Icon color on hover |
|
|
158
|
+
| `--m3e-[variant]-fab-hover-state-layer-color` | State layer color on hover |
|
|
159
|
+
| `--m3e-[variant]-fab-hover-state-layer-opacity` | State layer opacity on hover |
|
|
160
|
+
| `--m3e-[variant]-fab-hover-container-elevation` | Elevation on hover |
|
|
161
|
+
| `--m3e-[variant]-fab-lowered-hover-container-elevation` | Lowered elevation on hover |
|
|
162
|
+
| `--m3e-[variant]-fab-focus-label-text-color` | Label color on focus |
|
|
163
|
+
| `--m3e-[variant]-fab-focus-icon-color` | Icon color on focus |
|
|
164
|
+
| `--m3e-[variant]-fab-focus-state-layer-color` | State layer color on focus |
|
|
165
|
+
| `--m3e-[variant]-fab-focus-state-layer-opacity` | State layer opacity on focus |
|
|
166
|
+
| `--m3e-[variant]-fab-focus-container-elevation` | Elevation on focus |
|
|
167
|
+
| `--m3e-[variant]-fab-lowered-focus-container-elevation` | Lowered elevation on focus |
|
|
168
|
+
| `--m3e-[variant]-fab-pressed-label-text-color` | Label color on press |
|
|
169
|
+
| `--m3e-[variant]-fab-pressed-icon-color` | Icon color on press |
|
|
170
|
+
| `--m3e-[variant]-fab-pressed-state-layer-color` | State layer color on press |
|
|
171
|
+
| `--m3e-[variant]-fab-pressed-state-layer-opacity` | State layer opacity on press |
|
|
172
|
+
| `--m3e-[variant]-fab-pressed-container-elevation` | Elevation on press |
|
|
173
|
+
| `--m3e-[variant]-fab-lowered-pressed-container-elevation` | Lowered elevation on press |
|
|
174
|
+
|
|
175
|
+
## 🤝 Contributing
|
|
176
|
+
|
|
177
|
+
See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
|
|
178
|
+
|
|
179
|
+
## 📄 License
|
|
180
|
+
|
|
181
|
+
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,80 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" style="overflow-y: auto">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Floating Action Button for M3E</title>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<meta name="description" content="Floating Action Button 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="../../icon/dist/index.min.js"></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
|
+
<m3e-fab aria-label="Fab" variant="primary-container"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
42
|
+
<m3e-fab aria-label="Fab" variant="secondary-container"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
43
|
+
<m3e-fab aria-label="Fab" variant="tertiary-container"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
44
|
+
<m3e-fab aria-label="Fab" variant="primary"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
45
|
+
<m3e-fab aria-label="Fab" variant="secondary"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
46
|
+
<m3e-fab aria-label="Fab" variant="tertiary"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
47
|
+
<m3e-fab aria-label="Fab" variant="surface"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
48
|
+
<br /><br />
|
|
49
|
+
|
|
50
|
+
<m3e-fab size="small"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
51
|
+
<m3e-fab size="medium"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
52
|
+
<m3e-fab size="large"><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
53
|
+
<br /><br />
|
|
54
|
+
|
|
55
|
+
<m3e-fab>
|
|
56
|
+
<m3e-icon name="edit"></m3e-icon>
|
|
57
|
+
<span slot="label">Extended</span>
|
|
58
|
+
</m3e-fab>
|
|
59
|
+
<m3e-fab extended>
|
|
60
|
+
<span slot="label">Extended</span>
|
|
61
|
+
</m3e-fab>
|
|
62
|
+
<br /><br />
|
|
63
|
+
|
|
64
|
+
<m3e-fab href="https://m3.material.io/components/floating-action-button/overview" target="_blank" extended>
|
|
65
|
+
<m3e-icon name="edit"></m3e-icon>
|
|
66
|
+
<span slot="label">Link Button</span>
|
|
67
|
+
</m3e-fab>
|
|
68
|
+
<m3e-fab
|
|
69
|
+
href="https://m3.material.io/components/floating-action-button/overview"
|
|
70
|
+
target="_blank"
|
|
71
|
+
aria-label="Fab"
|
|
72
|
+
>
|
|
73
|
+
<m3e-icon name="edit"></m3e-icon>
|
|
74
|
+
</m3e-fab>
|
|
75
|
+
<br /><br />
|
|
76
|
+
<m3e-fab aria-label="Fab" disabled><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
77
|
+
<m3e-fab aria-label="Fab" disabled-interactive><m3e-icon name="edit"></m3e-icon></m3e-fab>
|
|
78
|
+
</m3e-theme>
|
|
79
|
+
</body>
|
|
80
|
+
</html>
|