material-inspired-component-library 3.0.1 → 3.1.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 +9 -14
- package/components/alert/index.scss +120 -0
- package/components/appbar/index.scss +2 -2
- package/components/badge/index.scss +22 -7
- package/components/button/index.scss +2 -2
- package/components/card/README.md +9 -5
- package/components/card/index.scss +49 -22
- package/components/checkbox/README.md +49 -11
- package/components/checkbox/index.scss +145 -182
- package/components/checkbox/index.ts +148 -0
- package/components/dialog/index.scss +3 -3
- package/components/divider/README.md +3 -3
- package/components/divider/index.scss +18 -27
- package/components/iconbutton/index.scss +2 -2
- package/components/list/index.scss +2 -2
- package/components/list/index.ts +2 -3
- package/components/menu/index.ts +2 -2
- package/components/navigationrail/index.scss +5 -3
- package/components/radio/README.md +1 -1
- package/components/radio/index.scss +6 -24
- package/components/select/index.scss +5 -2
- package/components/slider/index.scss +4 -4
- package/components/slider/index.ts +9 -10
- package/components/stepper/index.scss +85 -0
- package/components/stepper/index.ts +226 -0
- package/components/switch/README.md +26 -4
- package/components/switch/index.scss +24 -23
- package/components/textfield/index.scss +1 -0
- package/components/textfield/index.ts +56 -23
- package/dist/alert.css +1 -0
- package/dist/alert.js +1 -0
- package/dist/appbar.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/checkbox/index.d.ts +5 -0
- package/dist/components/stepper/index.d.ts +5 -0
- package/dist/components/textfield/index.d.ts +2 -1
- package/dist/dialog.css +1 -1
- package/dist/divider.css +1 -1
- package/dist/iconbutton.css +1 -1
- package/dist/layout.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/select.css +1 -1
- package/dist/slider.css +1 -1
- package/dist/stepper.css +1 -0
- package/dist/stepper.js +1 -0
- package/dist/switch.css +1 -1
- package/dist/textfield.css +1 -1
- package/docs/alert.html +181 -0
- package/docs/card.html +25 -7
- package/docs/checkbox.html +31 -7
- package/docs/divider.html +7 -1
- package/docs/index.html +9 -10
- package/docs/micl.css +1 -1
- package/docs/micl.js +1 -1
- package/docs/navigationrail.html +2 -3
- package/docs/radio.html +1 -1
- package/docs/switch.html +41 -26
- package/layout/index.scss +9 -2
- package/micl.ts +24 -26
- package/package.json +2 -1
- package/styles.scss +2 -0
|
@@ -308,8 +308,8 @@
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
.micl-list-item__icon {
|
|
311
|
-
min-width: 24px;
|
|
312
|
-
font-size: 24px;
|
|
311
|
+
min-width: var(--md-sys-layout-icon-size, 24px);
|
|
312
|
+
font-size: var(--md-sys-layout-icon-size, 24px);
|
|
313
313
|
font-variation-settings: 'FILL' 0;
|
|
314
314
|
color: var(--md-sys-color-on-surface-variant);
|
|
315
315
|
transition: font-variation-settings var(--md-sys-list-motion-duration) linear;
|
package/components/list/index.ts
CHANGED
|
@@ -23,9 +23,8 @@ export const listSelector = '.micl-list-item-one,.micl-list-item-two,.micl-list-
|
|
|
23
23
|
|
|
24
24
|
export default (() =>
|
|
25
25
|
{
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
isSelected = (item: HTMLElement | null): boolean => !!item && item.matches(':has(input[type=checkbox]:checked)');
|
|
26
|
+
const isDisabled = (item: HTMLElement | null): boolean => !!item && item.classList.contains('micl-list-item--disabled');
|
|
27
|
+
const isSelected = (item: HTMLElement | null): boolean => !!item && item.matches(':has(input[type=checkbox]:checked)');
|
|
29
28
|
|
|
30
29
|
return {
|
|
31
30
|
keydown: (event: Event) =>
|
package/components/menu/index.ts
CHANGED
|
@@ -25,8 +25,8 @@ export default (() =>
|
|
|
25
25
|
{
|
|
26
26
|
const getOrigin = (invoker: Element, popover: Element): string =>
|
|
27
27
|
{
|
|
28
|
-
const invokerRect = invoker.getBoundingClientRect()
|
|
29
|
-
|
|
28
|
+
const invokerRect = invoker.getBoundingClientRect();
|
|
29
|
+
const popoverRect = popover.getBoundingClientRect();
|
|
30
30
|
|
|
31
31
|
return ((invokerRect.x > popoverRect.x) ? 'right ' : 'left ') +
|
|
32
32
|
((invokerRect.y > popoverRect.y) ? 'bottom' : 'top');
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
--md-sys-navigationrail-motion-duration-reverse: #{motion.$md-sys-motion-expressive-default-spatial-duration};
|
|
44
44
|
--md-sys-navigationrail-morph-duration: #{motion.$md-sys-motion-expressive-fast-spatial-duration};
|
|
45
45
|
--md-sys-navigationrail-morph-duration-reverse: #{motion.$md-sys-motion-expressive-fast-spatial-duration};
|
|
46
|
+
--md-sys-badge-inline-offset: -16px;
|
|
47
|
+
--md-sys-badge-block-offset: 4px;
|
|
46
48
|
|
|
47
49
|
box-sizing: border-box;
|
|
48
50
|
display: flex;
|
|
@@ -91,6 +93,7 @@
|
|
|
91
93
|
|
|
92
94
|
box-sizing: border-box;
|
|
93
95
|
display: flex;
|
|
96
|
+
position: relative;
|
|
94
97
|
flex-direction: column;
|
|
95
98
|
align-items: center;
|
|
96
99
|
block-size: var(--md-sys-navigationrail-item-height);
|
|
@@ -115,8 +118,8 @@
|
|
|
115
118
|
&> .micl-navigationrail__icon {
|
|
116
119
|
--micl-ripple: 1;
|
|
117
120
|
|
|
118
|
-
font-size: 24px;
|
|
119
|
-
inline-size: 24px;
|
|
121
|
+
font-size: var(--md-sys-layout-icon-size, 24px);
|
|
122
|
+
inline-size: var(--md-sys-layout-icon-size, 24px);
|
|
120
123
|
margin: 0;
|
|
121
124
|
padding-block: 4px;
|
|
122
125
|
padding-inline: 16px;
|
|
@@ -173,7 +176,6 @@ nav.micl-navigationrail:has(> .micl-navigationrail__headline .micl-button--toggl
|
|
|
173
176
|
row-gap: 0px;
|
|
174
177
|
|
|
175
178
|
&> label.micl-navigationrail__item {
|
|
176
|
-
position: relative;
|
|
177
179
|
flex-direction: row;
|
|
178
180
|
inline-size: fit-content;
|
|
179
181
|
|
|
@@ -29,7 +29,7 @@ A radio button can be disabled by adding the `disabled` attribute to the `<input
|
|
|
29
29
|
|
|
30
30
|
The Radio Button component respects the `dir` global attribute, automatically adjusting its layout for right-to-left (RTL) languages when `dir="rtl"` is applied to an ancestor element.
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
The component applies `cursor: pointer` and the color role **on surface** to the `<label>` element immediately preceding or following an `<input type="radio">` with the `micl-radio` class. You are encouraged to customize these CSS settings to match your design system.
|
|
33
33
|
|
|
34
34
|
## Customizations
|
|
35
35
|
You can customize the appearance of the Radio Button component by overriding its global CSS variables. These variables are declared on the `:root` pseudo-class and can be changed on any appropriate parent element to affect its child radio buttons.
|
|
@@ -85,9 +85,10 @@ input[type=radio].micl-radio {
|
|
|
85
85
|
background-size 3000ms,
|
|
86
86
|
--statelayer-opacity var(--md-sys-radio-motion-duration) linear;
|
|
87
87
|
|
|
88
|
-
&:hover
|
|
88
|
+
&:hover,
|
|
89
|
+
&:focus-visible,
|
|
90
|
+
&:active {
|
|
89
91
|
--statelayer-color: var(--md-sys-color-on-surface);
|
|
90
|
-
--statelayer-opacity: var(--md-sys-state-hover-state-layer-opacity);
|
|
91
92
|
|
|
92
93
|
&:checked {
|
|
93
94
|
--statelayer-color: var(--md-sys-color-primary);
|
|
@@ -99,38 +100,19 @@ input[type=radio].micl-radio {
|
|
|
99
100
|
border-color: var(--md-sys-color-primary);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
103
|
+
&:hover {
|
|
104
|
+
--statelayer-opacity: var(--md-sys-state-hover-state-layer-opacity);
|
|
105
|
+
}
|
|
102
106
|
&:focus-visible {
|
|
103
|
-
--statelayer-color: var(--md-sys-color-on-surface);
|
|
104
107
|
--statelayer-opacity: var(--md-sys-state-focus-state-layer-opacity);
|
|
105
108
|
|
|
106
109
|
outline: var(--md-sys-state-focus-indicator-thickness) solid var(--md-sys-color-secondary);
|
|
107
|
-
|
|
108
|
-
&:checked {
|
|
109
|
-
--statelayer-color: var(--md-sys-color-primary);
|
|
110
|
-
}
|
|
111
|
-
&::after {
|
|
112
|
-
border-color: var(--md-sys-color-on-surface);
|
|
113
|
-
}
|
|
114
|
-
&:checked::after {
|
|
115
|
-
border-color: var(--md-sys-color-primary);
|
|
116
|
-
}
|
|
117
110
|
}
|
|
118
111
|
&:active {
|
|
119
|
-
--statelayer-color: var(--md-sys-color-on-surface);
|
|
120
112
|
--statelayer-opacity: var(--md-sys-state-pressed-state-layer-opacity);
|
|
121
113
|
|
|
122
114
|
background-size: 0%, 100%;
|
|
123
115
|
transition: background-size 0ms;
|
|
124
|
-
|
|
125
|
-
&:checked {
|
|
126
|
-
--statelayer-color: var(--md-sys-color-primary);
|
|
127
|
-
}
|
|
128
|
-
&::after {
|
|
129
|
-
border-color: var(--md-sys-color-on-surface);
|
|
130
|
-
}
|
|
131
|
-
&:checked::after {
|
|
132
|
-
border-color: var(--md-sys-color-primary);
|
|
133
|
-
}
|
|
134
116
|
}
|
|
135
117
|
}
|
|
136
118
|
&:disabled {
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
background-color: var(--md-sys-color-surface-container);
|
|
63
63
|
box-shadow: var(--md-sys-elevation-level2);
|
|
64
64
|
opacity: 0;
|
|
65
|
-
overflow: hidden;
|
|
65
|
+
overflow-x: hidden;
|
|
66
|
+
overflow-y: auto;
|
|
66
67
|
transform: scaleY(0);
|
|
67
68
|
transform-origin: var(--md-sys-select-picker-origin);
|
|
68
69
|
transition:
|
|
@@ -130,7 +131,9 @@
|
|
|
130
131
|
content: attr(aria-description);
|
|
131
132
|
display: block;
|
|
132
133
|
color: var(--md-sys-color-on-surface-variant);
|
|
133
|
-
|
|
134
|
+
overflow-x: hidden;
|
|
135
|
+
text-overflow: ellipsis;
|
|
136
|
+
white-space: nowrap;
|
|
134
137
|
}
|
|
135
138
|
&::checkmark {
|
|
136
139
|
color: var(--md-sys-color-on-surface-variant);
|
|
@@ -261,7 +261,7 @@ input[type=range].micl-slider-xl {
|
|
|
261
261
|
|
|
262
262
|
.micl-slider__container {
|
|
263
263
|
display: grid;
|
|
264
|
-
grid-template-areas: "
|
|
264
|
+
grid-template-areas: "slider-icon";
|
|
265
265
|
flex-shrink: 0;
|
|
266
266
|
align-items: center;
|
|
267
267
|
justify-items: flex-start;
|
|
@@ -269,16 +269,16 @@ input[type=range].micl-slider-xl {
|
|
|
269
269
|
|
|
270
270
|
&:has(> .micl-slider-m,> .micl-slider-l,> .micl-slider-xl) {
|
|
271
271
|
.micl-slider__icon {
|
|
272
|
-
grid-area:
|
|
272
|
+
grid-area: slider-icon;
|
|
273
273
|
inset: 0;
|
|
274
274
|
margin: 6px;
|
|
275
|
-
font-size: 24px;
|
|
275
|
+
font-size: var(--md-sys-layout-icon-size, 24px);
|
|
276
276
|
color: var(--md-sys-color-on-primary);
|
|
277
277
|
z-index: 1;
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
&> input[type=range] {
|
|
281
|
-
grid-area:
|
|
281
|
+
grid-area: slider-icon;
|
|
282
282
|
}
|
|
283
283
|
.micl-slider__icon:has(+ input[type=range].micl-slider-xl),
|
|
284
284
|
input[type=range].micl-slider-xl + .micl-slider__icon {
|
|
@@ -97,18 +97,17 @@ export default (() =>
|
|
|
97
97
|
setValue(element);
|
|
98
98
|
setVars(element);
|
|
99
99
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
100
|
+
const max = parseFloat(element.max);
|
|
101
|
+
const min = parseFloat(element.min);
|
|
102
|
+
const rect = element.getBoundingClientRect();
|
|
103
|
+
const percentages = getTickValues(element, max, min).sort((a, b) => a - b).map(value => {
|
|
104
|
+
return Math.round(100 * (value - min) / (max - min));
|
|
105
|
+
});
|
|
107
106
|
|
|
108
107
|
if (percentages.length > 0) {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
const canvas = document.createElement('canvas');
|
|
109
|
+
const ctx = canvas.getContext('2d');
|
|
110
|
+
|
|
112
111
|
if (ctx) {
|
|
113
112
|
ctx.font = window.getComputedStyle(element).getPropertyValue('font');
|
|
114
113
|
let blankWidth = ctx.measureText(blank).width,
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
@use '../../layout';
|
|
23
|
+
@use '../../styles/motion';
|
|
24
|
+
|
|
25
|
+
:root {
|
|
26
|
+
--md-sys-stepper-thickness: 1px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.micl-stepper {
|
|
30
|
+
--md-sys-stepper-motion-spatial: #{motion.$md-sys-motion-expressive-slow-spatial};
|
|
31
|
+
--md-sys-stepper-motion-duration: #{motion.$md-sys-motion-expressive-slow-spatial-duration};
|
|
32
|
+
--md-sys-stepper-motion-duration-reverse: #{motion.$md-sys-motion-expressive-default-spatial-duration};
|
|
33
|
+
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
row-gap: var(--md-sys-layout-padding-xl, 24px);
|
|
38
|
+
background-color: inherit;
|
|
39
|
+
|
|
40
|
+
.micl-stepper__steps {
|
|
41
|
+
display: grid;
|
|
42
|
+
grid-template-areas: "stepper-steps";
|
|
43
|
+
overflow-x: hidden;
|
|
44
|
+
background-color: inherit;
|
|
45
|
+
|
|
46
|
+
.micl-stepper__step {
|
|
47
|
+
grid-area: stepper-steps;
|
|
48
|
+
display: flex;
|
|
49
|
+
visibility: hidden;
|
|
50
|
+
flex-direction: column;
|
|
51
|
+
justify-content: space-between;
|
|
52
|
+
opacity: 0%;
|
|
53
|
+
background-color: inherit;
|
|
54
|
+
transform: translateX(100%);
|
|
55
|
+
transition:
|
|
56
|
+
opacity var(--md-sys-stepper-motion-duration) linear,
|
|
57
|
+
transform var(--md-sys-stepper-motion-duration) var(--md-sys-stepper-motion-spatial);
|
|
58
|
+
|
|
59
|
+
&:has(~ .micl-stepper__step--current) {
|
|
60
|
+
transform: translateX(-100%);
|
|
61
|
+
}
|
|
62
|
+
&.micl-stepper__step--tocurrent {
|
|
63
|
+
visibility: visible;
|
|
64
|
+
}
|
|
65
|
+
&.micl-stepper__step--current {
|
|
66
|
+
visibility: visible;
|
|
67
|
+
opacity: 100%;
|
|
68
|
+
transform: translateX(0%);
|
|
69
|
+
}
|
|
70
|
+
&.micl-stepper__step--fromcurrent {
|
|
71
|
+
visibility: visible;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.micl-stepper__content {
|
|
75
|
+
box-sizing: border-box;
|
|
76
|
+
padding-inline: var(--md-sys-stepper-padding-inline);
|
|
77
|
+
background-color: inherit;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
.micl-stepper__actions {
|
|
82
|
+
display: flex;
|
|
83
|
+
justify-content: space-between;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
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
|
+
type StepperAction = HTMLButtonElement & {
|
|
23
|
+
classList: { contains(token: string): boolean };
|
|
24
|
+
addEventListener(type: 'click', listener: (this: HTMLButtonElement, ev: MouseEvent) => any): void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type StepperStep = HTMLElement & {
|
|
28
|
+
dataset : { miclstep?: string };
|
|
29
|
+
nextElementSibling : Element | null;
|
|
30
|
+
previousElementSibling: Element | null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const stepperSelector = '.micl-stepper';
|
|
34
|
+
|
|
35
|
+
export default (() =>
|
|
36
|
+
{
|
|
37
|
+
const getCurrentStep = (stepper: HTMLElement): StepperStep | null =>
|
|
38
|
+
{
|
|
39
|
+
let step = stepper.querySelector('.micl-stepper__step--current') as StepperStep;
|
|
40
|
+
if (step) {
|
|
41
|
+
return step;
|
|
42
|
+
}
|
|
43
|
+
step = stepper.querySelector('.micl-stepper__step') as StepperStep;
|
|
44
|
+
if (step) {
|
|
45
|
+
step.classList.add('micl-stepper__step--current');
|
|
46
|
+
}
|
|
47
|
+
return step;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const endTransitionCurrent = (event: Event): void =>
|
|
51
|
+
{
|
|
52
|
+
const target = event.currentTarget as Element;
|
|
53
|
+
if ((event as TransitionEvent).propertyName !== 'transform' || !target) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
target.classList.remove(
|
|
57
|
+
'micl-stepper__step--fromcurrent',
|
|
58
|
+
'micl-stepper__step--tocurrent'
|
|
59
|
+
);
|
|
60
|
+
target.removeEventListener('transitionend', endTransitionCurrent);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const goToSibling = (currentStep: StepperStep, sibling: StepperStep): void =>
|
|
64
|
+
{
|
|
65
|
+
currentStep.addEventListener('transitionend', endTransitionCurrent);
|
|
66
|
+
currentStep.classList.add('micl-stepper__step--fromcurrent');
|
|
67
|
+
currentStep.offsetHeight;
|
|
68
|
+
|
|
69
|
+
sibling.addEventListener('transitionend', endTransitionCurrent);
|
|
70
|
+
sibling.classList.add('micl-stepper__step--tocurrent');
|
|
71
|
+
sibling.offsetHeight;
|
|
72
|
+
|
|
73
|
+
sibling.classList.add('micl-stepper__step--current');
|
|
74
|
+
currentStep.classList.remove('micl-stepper__step--current');
|
|
75
|
+
currentStep.offsetHeight;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const showHideActions = (actions: StepperAction[], step: StepperStep, back: boolean): void =>
|
|
79
|
+
{
|
|
80
|
+
actions.forEach(action =>
|
|
81
|
+
{
|
|
82
|
+
const siblingKey = back ? 'previousElementSibling' : 'nextElementSibling';
|
|
83
|
+
const hasSiblingStep = (step[siblingKey] as Element)?.classList.contains('micl-stepper__step');
|
|
84
|
+
|
|
85
|
+
action.classList.toggle('micl-hidden', !hasSiblingStep);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const showHideElements = (stepper: HTMLElement, step: StepperStep): void =>
|
|
90
|
+
{
|
|
91
|
+
const stepIdentifier = step.dataset.miclstep;
|
|
92
|
+
|
|
93
|
+
stepIdentifier && stepper.querySelectorAll<HTMLElement>('[data-step]').forEach(element =>
|
|
94
|
+
{
|
|
95
|
+
const shouldHide = element.dataset.step !== stepIdentifier;
|
|
96
|
+
element.classList.toggle('micl-hidden', shouldHide);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const checkGroupValidity= (parent: HTMLElement | null): boolean =>
|
|
101
|
+
{
|
|
102
|
+
if (!parent) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
const groups = parent.querySelectorAll<HTMLFieldSetElement>(
|
|
106
|
+
'fieldset.micl-checkbox-group[data-miclname]'
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
return Array.from(groups).every(fieldset =>
|
|
110
|
+
{
|
|
111
|
+
const name = fieldset.dataset.miclname;
|
|
112
|
+
if (!name) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const checkedCount = fieldset.querySelectorAll<HTMLInputElement>(
|
|
116
|
+
`input[type="checkbox"][name="${name}"]:checked`
|
|
117
|
+
).length;
|
|
118
|
+
|
|
119
|
+
return checkedCount > 0;
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const checkStepValidity = (stepper: HTMLElement): HTMLElement | null =>
|
|
124
|
+
{
|
|
125
|
+
const currentStep = getCurrentStep(stepper);
|
|
126
|
+
if (!currentStep) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
let isValid = true;
|
|
130
|
+
|
|
131
|
+
currentStep.querySelectorAll<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(
|
|
132
|
+
'input,select,textarea'
|
|
133
|
+
).forEach(element =>
|
|
134
|
+
{
|
|
135
|
+
if (!element.checkValidity()) {
|
|
136
|
+
isValid = false;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (!checkGroupValidity(currentStep)) {
|
|
141
|
+
isValid = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return isValid ? currentStep : null;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
initialize: (stepper: HTMLElement): void =>
|
|
149
|
+
{
|
|
150
|
+
if (!stepper.matches(stepperSelector) || stepper.dataset.miclinitialized) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
stepper.dataset.miclinitialized = '1';
|
|
154
|
+
|
|
155
|
+
stepper.querySelectorAll<HTMLElement>('.micl-stepper__step').forEach((step, index) =>
|
|
156
|
+
{
|
|
157
|
+
step.dataset.miclstep = `${index + 1}`;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const step = getCurrentStep(stepper);
|
|
161
|
+
const backActions = Array.from(stepper.querySelectorAll<StepperAction>(
|
|
162
|
+
'button.micl-stepper--goback'
|
|
163
|
+
));
|
|
164
|
+
const nextActions = Array.from(stepper.querySelectorAll<StepperAction>(
|
|
165
|
+
'button.micl-stepper--gonext'
|
|
166
|
+
));
|
|
167
|
+
|
|
168
|
+
if (step) {
|
|
169
|
+
showHideActions(backActions, step, true);
|
|
170
|
+
showHideActions(nextActions, step, false);
|
|
171
|
+
showHideElements(stepper, step);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
backActions.forEach(action =>
|
|
175
|
+
{
|
|
176
|
+
action.addEventListener('click', (event: Event) =>
|
|
177
|
+
{
|
|
178
|
+
const currentStep = getCurrentStep(stepper);
|
|
179
|
+
if (!currentStep) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const sibling = currentStep['previousElementSibling'] as StepperStep;
|
|
183
|
+
|
|
184
|
+
if (sibling?.classList.contains('micl-stepper__step')) {
|
|
185
|
+
goToSibling(currentStep, sibling);
|
|
186
|
+
showHideActions(backActions, sibling, true);
|
|
187
|
+
showHideElements(stepper, sibling);
|
|
188
|
+
}
|
|
189
|
+
}, true);
|
|
190
|
+
});
|
|
191
|
+
nextActions.forEach(action =>
|
|
192
|
+
{
|
|
193
|
+
action.addEventListener('click', (event: Event) =>
|
|
194
|
+
{
|
|
195
|
+
const currentStep = checkStepValidity(stepper);
|
|
196
|
+
if (!currentStep) {
|
|
197
|
+
event.stopImmediatePropagation();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const sibling = currentStep['nextElementSibling'] as StepperStep;
|
|
201
|
+
|
|
202
|
+
if (sibling?.classList.contains('micl-stepper__step')) {
|
|
203
|
+
goToSibling(currentStep, sibling);
|
|
204
|
+
showHideActions(nextActions, sibling, false);
|
|
205
|
+
showHideElements(stepper, sibling);
|
|
206
|
+
}
|
|
207
|
+
}, true);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (stepper instanceof HTMLFormElement) {
|
|
211
|
+
stepper.addEventListener('submit', (event: SubmitEvent) =>
|
|
212
|
+
{
|
|
213
|
+
if (!event.submitter?.classList.contains('micl-form--dosubmit')) {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const isValid = stepper.checkValidity() && checkGroupValidity(stepper);
|
|
218
|
+
if (!isValid) {
|
|
219
|
+
event.stopImmediatePropagation();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
}, true);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
})();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Switch
|
|
2
|
-
This component implements the the [Material Design 3 Expressive Switch](https://m3.material.io/components/switch/overview) design.
|
|
2
|
+
This component implements the the [Material Design 3 Expressive Switch](https://m3.material.io/components/switch/overview) design. Switches toggle the state of a single setting on or off.
|
|
3
3
|
|
|
4
4
|
## Basic Usage
|
|
5
5
|
|
|
@@ -41,9 +41,31 @@ To remove the icon in the selected state:
|
|
|
41
41
|
|
|
42
42
|
A switch can be disabled by adding the `disabled` attribute to the `<input>` element.
|
|
43
43
|
|
|
44
|
-
The
|
|
44
|
+
The Switch component respects the `dir` global attribute, automatically adjusting its layout for right-to-left (RTL) languages when `dir="rtl"` is applied to an ancestor element.
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
The component applies `cursor: pointer` and the color role **on surface** to the `<label>` element immediately preceding or following the `<input type="checkbox">` with the `micl-switch` class. You are encouraged to customize these CSS settings to match your design system.
|
|
47
|
+
|
|
48
|
+
## Customizations
|
|
49
|
+
You can customize the appearance of the Switch component by overriding its global CSS variables. These variables are declared on the `:root` pseudo-class and can be changed on any appropriate parent element to affect its child switches.
|
|
50
|
+
|
|
51
|
+
| Variable name | Default Value | Description |
|
|
52
|
+
| ------------- | ------------- | ----------- |
|
|
53
|
+
| --md-sys-switch-handle-size | 16px | The diameter of the handle when the switch is "off" |
|
|
54
|
+
| --md-sys-switch-handle-selected-size | 24px | The diameter of the handle when the switch is "on" |
|
|
55
|
+
| --md-sys-switch-handle-pressed-size | 28px | The diameter of the handle when the switch is pressed |
|
|
56
|
+
| --md-sys-switch-outline-width | 2px | The width of the border |
|
|
57
|
+
| --md-sys-switch-state-layer-size | 40px | Sets the size of the area that indicates the component's current state (e.g., hover, focus, press) |
|
|
58
|
+
| --md-sys-switch-target-height | 32px | The height of the track |
|
|
59
|
+
| --md-sys-switch-target-width | 52px | The width of the track |
|
|
60
|
+
|
|
61
|
+
**Example: Changing the width of the switch**
|
|
62
|
+
|
|
63
|
+
```HTML
|
|
64
|
+
<div style="--md-sys-switch-target-width:64px">
|
|
65
|
+
<input type="checkbox" id="myswitch" class="micl-switch" role="switch">
|
|
66
|
+
<label for="myswitch">Long switch</label>
|
|
67
|
+
</div>
|
|
68
|
+
```
|
|
47
69
|
|
|
48
70
|
## Compatibility
|
|
49
|
-
This component
|
|
71
|
+
This component utilizes relative RGB color values, which may not be fully supported in your browser. Please check [Browser compatibility](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#browser_compatibility) for details.
|