material-inspired-component-library 3.0.2 → 4.0.0
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/README.md +16 -14
- package/components/README.md +1 -1
- package/components/accordion/README.md +8 -3
- package/components/alert/README.md +76 -0
- package/components/alert/index.scss +121 -0
- package/components/appbar/README.md +9 -4
- package/components/appbar/index.scss +1 -1
- package/components/badge/README.md +8 -3
- package/components/badge/index.scss +1 -0
- package/components/bottomsheet/README.md +8 -3
- package/components/button/README.md +8 -3
- package/components/button/index.scss +7 -0
- package/components/card/README.md +10 -4
- package/components/card/index.scss +1 -1
- package/components/checkbox/README.md +56 -13
- package/components/checkbox/index.scss +148 -183
- package/components/checkbox/index.ts +148 -0
- package/components/dialog/README.md +8 -3
- package/components/dialog/index.scss +1 -0
- package/components/divider/README.md +8 -3
- package/components/iconbutton/README.md +8 -3
- package/components/iconbutton/index.scss +3 -1
- package/components/list/README.md +8 -3
- package/components/list/index.scss +2 -0
- package/components/list/index.ts +2 -3
- package/components/menu/README.md +7 -2
- package/components/menu/index.ts +2 -2
- package/components/navigationrail/README.md +8 -3
- package/components/navigationrail/index.scss +1 -0
- package/components/radio/README.md +8 -3
- package/components/radio/index.scss +8 -24
- package/components/select/README.md +3 -3
- package/components/sidesheet/README.md +8 -3
- package/components/slider/README.md +8 -3
- package/components/slider/index.scss +1 -0
- package/components/slider/index.ts +9 -10
- package/components/stepper/README.md +190 -0
- package/components/stepper/index.scss +93 -14
- package/components/stepper/index.ts +169 -88
- package/components/switch/README.md +8 -3
- package/components/switch/index.scss +2 -0
- package/components/textfield/README.md +8 -3
- package/components/textfield/index.ts +8 -41
- package/dist/alert.css +1 -0
- package/dist/alert.js +1 -0
- package/dist/badge.css +1 -1
- package/dist/button.css +1 -1
- package/dist/card.css +1 -1
- package/dist/checkbox.css +1 -1
- package/dist/components/checkbox/index.d.ts +5 -0
- package/dist/components/textfield/index.d.ts +0 -1
- package/dist/dialog.css +1 -1
- package/dist/foundations/form/index.d.ts +5 -0
- package/dist/iconbutton.css +1 -1
- package/dist/list.css +1 -1
- package/dist/micl.css +1 -1
- package/dist/micl.js +1 -1
- package/dist/navigationrail.css +1 -1
- package/dist/radio.css +1 -1
- package/dist/slider.css +1 -1
- package/dist/stepper.css +1 -1
- package/dist/switch.css +1 -1
- package/docs/accordion.html +1 -1
- package/docs/alert.html +176 -0
- package/docs/bottomsheet.html +2 -2
- package/docs/button.html +2 -2
- package/docs/card.html +7 -7
- package/docs/checkbox.html +33 -9
- package/docs/dialog.html +2 -2
- package/docs/divider.html +8 -8
- package/docs/iconbutton.html +2 -2
- package/docs/index.html +43 -32
- package/docs/list.html +2 -2
- package/docs/menu.html +2 -2
- package/docs/micl.css +1 -1
- package/docs/micl.js +1 -1
- package/docs/radio.html +2 -2
- package/docs/select.html +2 -2
- package/docs/sidesheet.html +2 -2
- package/docs/slider.html +2 -2
- package/docs/stepper.html +318 -0
- package/docs/switch.html +8 -4
- package/docs/textfield.html +2 -2
- package/foundations/form/index.ts +174 -0
- package/{layout → foundations/layout}/README.md +5 -0
- package/{layout → foundations/layout}/index.scss +1 -1
- package/micl.ts +3 -3
- package/package.json +3 -1
- package/styles.scss +2 -1
- package/webpack.config.js +1 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2025 Hermana AS
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
|
|
22
|
+
export default (() =>
|
|
23
|
+
{
|
|
24
|
+
const isCVElement = (element: Element): element is
|
|
25
|
+
HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLFieldSetElement =>
|
|
26
|
+
'willValidate' in element;
|
|
27
|
+
|
|
28
|
+
const setErrorStateCheckbox = (element: HTMLInputElement): boolean =>
|
|
29
|
+
{
|
|
30
|
+
element.classList.toggle('micl-checkbox--error', !!element.validationMessage);
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const setErrorStateTextField = (textField: HTMLElement, message: string): boolean =>
|
|
36
|
+
{
|
|
37
|
+
textField.classList.toggle('micl-textfield--error', !!message);
|
|
38
|
+
|
|
39
|
+
const supporting = textField.querySelector(
|
|
40
|
+
'.micl-textfield__supporting-text'
|
|
41
|
+
) as HTMLElement;
|
|
42
|
+
|
|
43
|
+
if (supporting) {
|
|
44
|
+
if (!message) {
|
|
45
|
+
if ('micltext' in supporting.dataset) {
|
|
46
|
+
supporting.textContent = supporting.dataset.micltext || '';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (!supporting.dataset.micltext) {
|
|
51
|
+
supporting.dataset.micltext = supporting.textContent;
|
|
52
|
+
}
|
|
53
|
+
supporting.textContent = message;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return !!message && !!supporting;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const setErrorState = (element: HTMLElement): boolean =>
|
|
61
|
+
{
|
|
62
|
+
if (
|
|
63
|
+
!element.parentElement
|
|
64
|
+
|| !isCVElement(element)
|
|
65
|
+
) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
let reported = false;
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
element instanceof HTMLInputElement
|
|
72
|
+
&& (element.type === 'checkbox')
|
|
73
|
+
&& element.classList.contains('micl-checkbox')
|
|
74
|
+
) {
|
|
75
|
+
reported = setErrorStateCheckbox(element);
|
|
76
|
+
}
|
|
77
|
+
else if (
|
|
78
|
+
element.parentElement.classList.contains('micl-textfield-outlined')
|
|
79
|
+
|| element.parentElement.classList.contains('micl-textfield-filled')
|
|
80
|
+
) {
|
|
81
|
+
reported = setErrorStateTextField(element.parentElement, element.validationMessage);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return reported;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const clearCustomValidity = (event: Event): void =>
|
|
88
|
+
{
|
|
89
|
+
const element = event.target as Element;
|
|
90
|
+
if (isCVElement(element)) {
|
|
91
|
+
element.setCustomValidity('');
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const setCustomValidityFieldSet = (fieldset: HTMLFieldSetElement): void =>
|
|
96
|
+
{
|
|
97
|
+
const message = fieldset.dataset.miclvalidateMessage || '';
|
|
98
|
+
if (!message) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (fieldset.matches('[data-miclvalidate-checkboxes-name]')) {
|
|
103
|
+
const name = fieldset.dataset.miclvalidateCheckboxesName || '';
|
|
104
|
+
const countEqual = fieldset.dataset.miclvalidateCheckboxesCountEqual || '';
|
|
105
|
+
const countMax = fieldset.dataset.miclvalidateCheckboxesCountMax || '';
|
|
106
|
+
const countMin = fieldset.dataset.miclvalidateCheckboxesCountMin || '';
|
|
107
|
+
|
|
108
|
+
if (name && (countEqual || countMax || countMin)) {
|
|
109
|
+
const checkedCount = fieldset.querySelectorAll<HTMLInputElement>(
|
|
110
|
+
`input[type="checkbox"][name="${name}"]:checked`
|
|
111
|
+
).length;
|
|
112
|
+
const expectedCountEqual = parseInt(countEqual, 10);
|
|
113
|
+
const expectedCountMax = parseInt(countMax, 10);
|
|
114
|
+
const expectedCountMin = parseInt(countMin, 10);
|
|
115
|
+
|
|
116
|
+
let invalid = (!isNaN(expectedCountEqual) && (checkedCount != expectedCountEqual))
|
|
117
|
+
|| (!isNaN(expectedCountMax) && (checkedCount > expectedCountMax))
|
|
118
|
+
|| (!isNaN(expectedCountMin) && (checkedCount < expectedCountMin));
|
|
119
|
+
|
|
120
|
+
fieldset.setCustomValidity(invalid ? message : '');
|
|
121
|
+
|
|
122
|
+
const firstCheckbox = fieldset.querySelector<HTMLInputElement>(
|
|
123
|
+
`input[type="checkbox"][name="${name}"]`
|
|
124
|
+
);
|
|
125
|
+
if (firstCheckbox) {
|
|
126
|
+
firstCheckbox.setCustomValidity(invalid ? message : '');
|
|
127
|
+
if (invalid) {
|
|
128
|
+
firstCheckbox.addEventListener('change', clearCustomValidity);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
firstCheckbox.removeEventListener('change', clearCustomValidity);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const validity = (container: HTMLFormElement | HTMLFieldSetElement, doReport?: boolean): boolean =>
|
|
139
|
+
{
|
|
140
|
+
let invalid = false;
|
|
141
|
+
|
|
142
|
+
container.querySelectorAll<HTMLFieldSetElement>(
|
|
143
|
+
'fieldset'
|
|
144
|
+
).forEach(setCustomValidityFieldSet);
|
|
145
|
+
|
|
146
|
+
Array.from(container.elements).forEach(element =>
|
|
147
|
+
{
|
|
148
|
+
if (isCVElement(element) && element.willValidate) {
|
|
149
|
+
if (!element.checkValidity()) {
|
|
150
|
+
invalid = true;
|
|
151
|
+
}
|
|
152
|
+
let reported = setErrorState(element);
|
|
153
|
+
if (!reported && doReport) {
|
|
154
|
+
element.reportValidity();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return !invalid;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
validateFieldSet: (fieldset: HTMLFieldSetElement, doReport?: boolean): boolean =>
|
|
164
|
+
{
|
|
165
|
+
setCustomValidityFieldSet(fieldset);
|
|
166
|
+
return validity(fieldset, doReport);
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
validateForm: (form: HTMLFormElement, doReport?: boolean): boolean =>
|
|
170
|
+
{
|
|
171
|
+
return validity(form, doReport);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
})();
|
|
@@ -31,6 +31,11 @@ Import the layout styles into your project:
|
|
|
31
31
|
@use "material-inspired-component-library/dist/layout";
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
Or import all MICL styles:
|
|
35
|
+
```CSS
|
|
36
|
+
@use "material-inspired-component-library/styles";
|
|
37
|
+
```
|
|
38
|
+
|
|
34
39
|
## Layout Components Explained
|
|
35
40
|
|
|
36
41
|
### Window
|
package/micl.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
import _bottomsheet, { bottomsheetSelector } from './components/bottomsheet';
|
|
23
23
|
import _button, { buttonSelector } from './components/button';
|
|
24
|
+
import _checkboxgroup, { checkboxGroupSelector } from './components/checkbox';
|
|
24
25
|
import _list, { listSelector } from './components/list';
|
|
25
26
|
import _menu, { menuSelector } from './components/menu';
|
|
26
27
|
import _navigationrail, { navigationrailSelector } from './components/navigationrail';
|
|
@@ -32,7 +33,6 @@ interface ComponentEntry<T extends HTMLElement> {
|
|
|
32
33
|
component: {
|
|
33
34
|
initialize?: (element: T) => void,
|
|
34
35
|
input? : (event: Event) => void,
|
|
35
|
-
invalid? : (event: Event) => void,
|
|
36
36
|
keydown? : (event: Event) => void,
|
|
37
37
|
cleanup? : (element: T) => void
|
|
38
38
|
};
|
|
@@ -45,6 +45,7 @@ export default (() =>
|
|
|
45
45
|
const componentMap: Record<string, ComponentEntry<any>> = {
|
|
46
46
|
[bottomsheetSelector] : { component: _bottomsheet, type: HTMLDialogElement },
|
|
47
47
|
[buttonSelector] : { component: _button, type: HTMLButtonElement },
|
|
48
|
+
[checkboxGroupSelector] : { component: _checkboxgroup, type: HTMLElement },
|
|
48
49
|
[listSelector] : { component: _list, type: HTMLElement },
|
|
49
50
|
[menuSelector] : { component: _menu, type: HTMLElement },
|
|
50
51
|
[navigationrailSelector]: { component: _navigationrail, type: HTMLLabelElement },
|
|
@@ -118,7 +119,7 @@ export default (() =>
|
|
|
118
119
|
if (
|
|
119
120
|
(event.target as Element).matches(selector)
|
|
120
121
|
&& event.target instanceof type
|
|
121
|
-
&& ['input', '
|
|
122
|
+
&& ['input', 'keydown'].includes(event.type)
|
|
122
123
|
&& typeof component[event.type as ComponentKey] === 'function'
|
|
123
124
|
) {
|
|
124
125
|
component[event.type as ComponentKey]?.(event);
|
|
@@ -163,7 +164,6 @@ export default (() =>
|
|
|
163
164
|
// Delegated Event Handlers
|
|
164
165
|
document.addEventListener('input', handleEvent);
|
|
165
166
|
document.addEventListener('keydown', handleEvent);
|
|
166
|
-
document.addEventListener('invalid', handleEvent, true);
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
const loaded = () =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "material-inspired-component-library",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "The Material-Inspired Component Library (MICL) offers a collection of beautifully crafted components leveraging native HTML markup, designed to align with the Material Design 3 guidelines.",
|
|
5
5
|
"author": "MICL Hermana <micl.hermana@proton.me> (https://github.com/henkpb/micl)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"CSS",
|
|
15
15
|
"HTML",
|
|
16
16
|
"accordion",
|
|
17
|
+
"alert",
|
|
17
18
|
"app bar",
|
|
18
19
|
"badge",
|
|
19
20
|
"bottomsheet",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"select",
|
|
32
33
|
"sidesheet",
|
|
33
34
|
"slider",
|
|
35
|
+
"stepper",
|
|
34
36
|
"switch",
|
|
35
37
|
"textfield"
|
|
36
38
|
],
|
package/styles.scss
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
20
|
// SOFTWARE.
|
|
21
21
|
|
|
22
|
-
@use 'layout';
|
|
22
|
+
@use 'foundations/layout';
|
|
23
23
|
|
|
24
24
|
@use 'styles/typography';
|
|
25
25
|
@use 'styles/shapes';
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
@use 'styles/statelayer';
|
|
29
29
|
|
|
30
30
|
@use 'components/divider';
|
|
31
|
+
@use 'components/alert';
|
|
31
32
|
@use 'components/radio';
|
|
32
33
|
@use 'components/checkbox';
|
|
33
34
|
@use 'components/switch';
|
package/webpack.config.js
CHANGED
|
@@ -5,7 +5,7 @@ const miniCss = require('mini-css-extract-plugin');
|
|
|
5
5
|
const distDir = path.resolve(__dirname, 'dist');
|
|
6
6
|
const docsDir = path.resolve(__dirname, 'docs');
|
|
7
7
|
|
|
8
|
-
const scssFiles = glob.sync('{./
|
|
8
|
+
const scssFiles = glob.sync('{./foundations/**/*.scss,./components/**/*.scss}');
|
|
9
9
|
const scssEntries = scssFiles.reduce((entries, filePath) => {
|
|
10
10
|
const componentName = path.dirname(filePath).split('\\').pop();
|
|
11
11
|
entries[componentName] = './' + filePath;
|