material-inspired-component-library 3.1.0 → 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 +12 -5
- 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 +1 -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 +8 -3
- package/components/checkbox/index.scss +2 -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/menu/README.md +7 -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 +2 -0
- 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/stepper/README.md +190 -0
- package/components/stepper/index.scss +93 -14
- package/components/stepper/index.ts +138 -120
- 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 -40
- package/dist/alert.css +1 -1
- 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/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 +3 -8
- package/docs/bottomsheet.html +2 -2
- package/docs/button.html +2 -2
- package/docs/card.html +7 -7
- package/docs/checkbox.html +2 -2
- 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 +1 -3
- package/package.json +3 -1
- package/styles.scss +1 -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
|
@@ -33,7 +33,6 @@ interface ComponentEntry<T extends HTMLElement> {
|
|
|
33
33
|
component: {
|
|
34
34
|
initialize?: (element: T) => void,
|
|
35
35
|
input? : (event: Event) => void,
|
|
36
|
-
invalid? : (event: Event) => void,
|
|
37
36
|
keydown? : (event: Event) => void,
|
|
38
37
|
cleanup? : (element: T) => void
|
|
39
38
|
};
|
|
@@ -120,7 +119,7 @@ export default (() =>
|
|
|
120
119
|
if (
|
|
121
120
|
(event.target as Element).matches(selector)
|
|
122
121
|
&& event.target instanceof type
|
|
123
|
-
&& ['input', '
|
|
122
|
+
&& ['input', 'keydown'].includes(event.type)
|
|
124
123
|
&& typeof component[event.type as ComponentKey] === 'function'
|
|
125
124
|
) {
|
|
126
125
|
component[event.type as ComponentKey]?.(event);
|
|
@@ -165,7 +164,6 @@ export default (() =>
|
|
|
165
164
|
// Delegated Event Handlers
|
|
166
165
|
document.addEventListener('input', handleEvent);
|
|
167
166
|
document.addEventListener('keydown', handleEvent);
|
|
168
|
-
document.addEventListener('invalid', handleEvent, true);
|
|
169
167
|
};
|
|
170
168
|
|
|
171
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
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;
|