material-inspired-component-library 3.0.0 → 3.0.2
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 +2 -2
- 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 +9 -0
- package/components/dialog/index.scss +3 -3
- package/components/divider/README.md +3 -3
- package/components/divider/index.scss +20 -29
- package/components/iconbutton/index.scss +2 -2
- package/components/list/README.md +4 -4
- package/components/list/index.scss +5 -5
- package/components/navigationrail/index.scss +5 -3
- package/components/radio/README.md +13 -4
- package/components/radio/index.scss +6 -4
- package/components/select/README.md +28 -6
- package/components/select/index.scss +60 -11
- package/components/slider/index.scss +4 -4
- package/components/stepper/index.scss +85 -0
- package/components/stepper/index.ts +163 -0
- package/components/switch/README.md +26 -4
- package/components/switch/index.scss +24 -23
- package/components/textfield/index.scss +4 -9
- package/components/textfield/index.ts +71 -30
- package/dist/appbar.css +1 -1
- package/dist/badge.css +1 -1
- package/dist/bottomsheet.css +1 -1
- package/dist/button.css +1 -1
- package/dist/card.css +1 -1
- package/dist/components/stepper/index.d.ts +5 -0
- package/dist/components/textfield/index.d.ts +3 -2
- package/dist/dialog.css +1 -1
- package/dist/divider.css +1 -1
- package/dist/iconbutton.css +1 -1
- package/dist/layout.css +1 -0
- package/dist/layout.js +1 -0
- package/dist/list.css +1 -1
- package/dist/menu.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/sidesheet.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/card.html +25 -7
- package/docs/checkbox.html +12 -16
- package/docs/divider.html +7 -1
- package/docs/index.html +14 -15
- package/docs/list.html +6 -6
- package/docs/micl.css +1 -1
- package/docs/micl.js +1 -1
- package/docs/navigationrail.html +2 -3
- package/docs/radio.html +13 -17
- package/docs/select.html +46 -6
- package/docs/switch.html +41 -26
- package/layout/index.scss +37 -29
- package/micl.ts +23 -27
- package/package.json +5 -1
- package/styles/shapes.scss +0 -2
- package/styles.scss +1 -0
- package/webpack.config.js +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Select
|
|
2
|
-
This component implements the the [Material Design 3 Expressive Select](https://m3.material.io/components/menus/guidelines#ee2f3664-c926-47ab-acbf-2ab675506932) design.
|
|
2
|
+
This component implements the the [Material Design 3 Expressive Select](https://m3.material.io/components/menus/guidelines#ee2f3664-c926-47ab-acbf-2ab675506932) design. A select component is used to offer the user with a set of options from which the user can select a single one.
|
|
3
3
|
|
|
4
4
|
## Basic Usage
|
|
5
5
|
|
|
@@ -11,10 +11,10 @@ The Select component is an extension of the [Text field](../textfield/README.md)
|
|
|
11
11
|
<label for="myselect">Country</label>
|
|
12
12
|
<select id="myselect">
|
|
13
13
|
<option class="micl-list-item-one" value="AR">
|
|
14
|
-
|
|
14
|
+
<span class="micl-list-item__text">Argentina</span>
|
|
15
15
|
</option>
|
|
16
16
|
<option class="micl-list-item-one" value="BO">
|
|
17
|
-
|
|
17
|
+
<span class="micl-list-item__text">Bolivia</span>
|
|
18
18
|
</option>
|
|
19
19
|
</select>
|
|
20
20
|
</div>
|
|
@@ -42,7 +42,29 @@ This will initialize any Select component, including those that will be added to
|
|
|
42
42
|
A live example of the [Select component](https://henkpb.github.io/micl/select.html) is available for you to interact with.
|
|
43
43
|
|
|
44
44
|
## Variants
|
|
45
|
-
|
|
45
|
+
A Select Component can be disabled by adding the `disabled` attribute to the `<select>` element. An option within the component can be disabled by adding the `disabled` attribute to the `<option>` element.
|
|
46
|
+
|
|
47
|
+
You can add [Dividers](../divider/README.md) into the list of options and they will appear as separators to help visually break up the options.
|
|
48
|
+
|
|
49
|
+
**Example: A select with a divider**
|
|
50
|
+
|
|
51
|
+
```HTML
|
|
52
|
+
<div class="micl-textfield-outlined">
|
|
53
|
+
<label for="myselect">Country</label>
|
|
54
|
+
<select id="myselect">
|
|
55
|
+
<option class="micl-list-item-two" value=""></option>
|
|
56
|
+
<option class="micl-list-item-two" value="AR">
|
|
57
|
+
<span class="micl-list-item__text">Argentina</span>
|
|
58
|
+
</option>
|
|
59
|
+
<hr class="micl-divider">
|
|
60
|
+
<option class="micl-list-item-two" value="BO">
|
|
61
|
+
<span class="micl-list-item__text">Bolivia</span>
|
|
62
|
+
</option>
|
|
63
|
+
</select>
|
|
64
|
+
</div>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
To display extra information for an option, add the `aria-description` attribute to its `<span class="micl-list-item__text">` element. In a two-line list item (`micl-list-item-two`), this displays the attribute's content as supporting text. Do not add a separate text element to the `<option>`, as this will change the text of the selected option.
|
|
46
68
|
|
|
47
69
|
**Example: A select with supporting text**
|
|
48
70
|
|
|
@@ -51,10 +73,10 @@ To display extra information for an option, add the `aria-description` attribute
|
|
|
51
73
|
<label for="myselect">Country</label>
|
|
52
74
|
<select id="myselect">
|
|
53
75
|
<option class="micl-list-item-two" value="AR">
|
|
54
|
-
|
|
76
|
+
<span class="micl-list-item__text" aria-description="Country code: AR">Argentina</span>
|
|
55
77
|
</option>
|
|
56
78
|
<option class="micl-list-item-two" value="BO">
|
|
57
|
-
|
|
79
|
+
<span class="micl-list-item__text" aria-description="Country code: BO">Bolivia</span>
|
|
58
80
|
</option>
|
|
59
81
|
</select>
|
|
60
82
|
</div>
|
|
@@ -25,15 +25,28 @@
|
|
|
25
25
|
@use '../../styles/statelayer';
|
|
26
26
|
@use '../../styles/typography';
|
|
27
27
|
|
|
28
|
+
.micl-textfield-filled > select {
|
|
29
|
+
--md-sys-select-line-height: calc(var(--md-sys-textfield-height) - 18px - 3px);
|
|
30
|
+
}
|
|
31
|
+
.micl-textfield-outlined > select {
|
|
32
|
+
--md-sys-select-line-height: var(--md-sys-textfield-height);
|
|
33
|
+
}
|
|
28
34
|
.micl-textfield-filled > select,
|
|
29
35
|
.micl-textfield-outlined > select {
|
|
36
|
+
--md-sys-divider-space: 8px;
|
|
30
37
|
--md-sys-list-motion-duration: #{motion.$md-sys-motion-expressive-default-effects-duration};
|
|
38
|
+
--md-sys-select-motion-spatial: #{motion.$md-sys-motion-expressive-default-spatial};
|
|
39
|
+
--md-sys-select-motion-duration: #{motion.$md-sys-motion-expressive-default-spatial-duration};
|
|
40
|
+
--md-sys-select-motion-duration-reverse: #{motion.$md-sys-motion-expressive-fast-spatial-duration};
|
|
41
|
+
--md-sys-select-picker-origin: left top;
|
|
31
42
|
|
|
32
43
|
appearance: base-select;
|
|
44
|
+
line-height: var(--md-sys-select-line-height);
|
|
33
45
|
|
|
34
46
|
&::picker-icon {
|
|
35
47
|
color: var(--md-sys-color-on-surface-variant);
|
|
36
|
-
transition:
|
|
48
|
+
transition: motion.$md-sys-motion-duration-medium4 rotate;
|
|
49
|
+
transform-origin: 50% calc((var(--md-sys-select-line-height) / 2) - 1px);
|
|
37
50
|
}
|
|
38
51
|
&:open::picker-icon {
|
|
39
52
|
rotate: 180deg;
|
|
@@ -42,12 +55,37 @@
|
|
|
42
55
|
appearance: base-select;
|
|
43
56
|
min-inline-size: max(anchor-size(self-inline), 112px);
|
|
44
57
|
max-inline-size: 280px;
|
|
45
|
-
|
|
46
|
-
padding
|
|
58
|
+
position-try: most-block-size flip-block;
|
|
59
|
+
padding: 8px 0;
|
|
47
60
|
border: none;
|
|
48
61
|
border-radius: var(--md-sys-shape-corner-extra-small);
|
|
49
62
|
background-color: var(--md-sys-color-surface-container);
|
|
50
63
|
box-shadow: var(--md-sys-elevation-level2);
|
|
64
|
+
opacity: 0;
|
|
65
|
+
overflow-x: hidden;
|
|
66
|
+
overflow-y: auto;
|
|
67
|
+
transform: scaleY(0);
|
|
68
|
+
transform-origin: var(--md-sys-select-picker-origin);
|
|
69
|
+
transition:
|
|
70
|
+
opacity var(--md-sys-select-motion-duration-reverse) linear,
|
|
71
|
+
transform var(--md-sys-select-motion-duration-reverse) var(--md-sys-select-motion-spatial),
|
|
72
|
+
overlay var(--md-sys-select-motion-duration-reverse) linear allow-discrete,
|
|
73
|
+
display var(--md-sys-select-motion-duration-reverse) linear allow-discrete;
|
|
74
|
+
|
|
75
|
+
&:popover-open {
|
|
76
|
+
opacity: 1;
|
|
77
|
+
transform: scaleY(1);
|
|
78
|
+
transition:
|
|
79
|
+
opacity var(--md-sys-select-motion-duration) motion.$md-sys-motion-easing-emphasized-decelerate,
|
|
80
|
+
transform var(--md-sys-select-motion-duration) var(--md-sys-select-motion-spatial),
|
|
81
|
+
overlay var(--md-sys-select-motion-duration) linear allow-discrete,
|
|
82
|
+
display var(--md-sys-select-motion-duration) linear allow-discrete;
|
|
83
|
+
|
|
84
|
+
@starting-style {
|
|
85
|
+
opacity: 0;
|
|
86
|
+
transform: scaleY(0);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
51
89
|
}
|
|
52
90
|
|
|
53
91
|
option {
|
|
@@ -59,7 +97,8 @@
|
|
|
59
97
|
--md-sys-list-item-padding-inline: 16px;
|
|
60
98
|
--md-sys-list-item-container-color: var(--md-sys-color-surface-container);
|
|
61
99
|
|
|
62
|
-
|
|
100
|
+
line-height: normal;
|
|
101
|
+
background-color: transparent;
|
|
63
102
|
|
|
64
103
|
&:not(:disabled) {
|
|
65
104
|
cursor: pointer;
|
|
@@ -84,6 +123,7 @@
|
|
|
84
123
|
@include typography.body-large;
|
|
85
124
|
|
|
86
125
|
color: var(--md-sys-color-on-surface);
|
|
126
|
+
white-space: normal;
|
|
87
127
|
}
|
|
88
128
|
.micl-list-item__text::after {
|
|
89
129
|
@include typography.body-medium;
|
|
@@ -91,10 +131,12 @@
|
|
|
91
131
|
content: attr(aria-description);
|
|
92
132
|
display: block;
|
|
93
133
|
color: var(--md-sys-color-on-surface-variant);
|
|
94
|
-
|
|
134
|
+
overflow-x: hidden;
|
|
135
|
+
text-overflow: ellipsis;
|
|
136
|
+
white-space: nowrap;
|
|
95
137
|
}
|
|
96
138
|
&::checkmark {
|
|
97
|
-
color: var(--md-sys-color-on-surface);
|
|
139
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
98
140
|
}
|
|
99
141
|
}
|
|
100
142
|
}
|
|
@@ -107,10 +149,17 @@ dialog.micl-dialog-fullscreen:has(.micl-textfield-outlined > select) {
|
|
|
107
149
|
inset-inline-start: 0;
|
|
108
150
|
margin: auto;
|
|
109
151
|
transform: scale(50%);
|
|
152
|
+
|
|
153
|
+
&:popover-open {
|
|
154
|
+
transform: scale(100%);
|
|
155
|
+
}
|
|
110
156
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
157
|
+
|
|
158
|
+
[dir=rtl] {
|
|
159
|
+
.micl-textfield-filled > select,
|
|
160
|
+
.micl-textfield-outlined > select {
|
|
161
|
+
&:open::picker-icon {
|
|
162
|
+
rotate: -180deg;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
116
165
|
}
|
|
@@ -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 {
|
|
@@ -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,163 @@
|
|
|
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 const stepperSelector = '.micl-stepper';
|
|
23
|
+
|
|
24
|
+
export default (() =>
|
|
25
|
+
{
|
|
26
|
+
const getCurrentStep = (stepper: HTMLElement): HTMLElement | null =>
|
|
27
|
+
{
|
|
28
|
+
let step = stepper.querySelector('.micl-stepper__step--current') as HTMLElement;
|
|
29
|
+
if (step) {
|
|
30
|
+
return step;
|
|
31
|
+
}
|
|
32
|
+
step = stepper.querySelector('.micl-stepper__step') as HTMLElement;
|
|
33
|
+
if (!step) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
step.classList.add('micl-stepper__step--current');
|
|
37
|
+
return step;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const endTransitionCurrent = (event: Event): void =>
|
|
41
|
+
{
|
|
42
|
+
if (!event.currentTarget || ((event as TransitionEvent).propertyName !== 'transform')) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
(event.currentTarget as Element).classList.remove(
|
|
46
|
+
'micl-stepper__step--fromcurrent',
|
|
47
|
+
'micl-stepper__step--tocurrent'
|
|
48
|
+
);
|
|
49
|
+
event.currentTarget.removeEventListener('transitionend', endTransitionCurrent);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const showHideActions = (actions: HTMLElement[], step: HTMLElement | null): void =>
|
|
53
|
+
{
|
|
54
|
+
step && actions.forEach(action =>
|
|
55
|
+
{
|
|
56
|
+
action.classList.toggle('micl-hidden', !step[
|
|
57
|
+
action.classList.contains('micl-stepper--gonext') ?
|
|
58
|
+
'nextElementSibling' : 'previousElementSibling'
|
|
59
|
+
]?.classList.contains('micl-stepper__step'));
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const showHideElements = (stepper: HTMLElement, step: HTMLElement): void =>
|
|
64
|
+
{
|
|
65
|
+
stepper.querySelectorAll<HTMLElement>('[data-step]').forEach(element =>
|
|
66
|
+
{
|
|
67
|
+
element.classList.toggle('micl-hidden', element.dataset.step !== step.dataset.miclstep);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const checkStepValidity = (stepper: HTMLElement): HTMLElement | null =>
|
|
72
|
+
{
|
|
73
|
+
let currentStep = getCurrentStep(stepper);
|
|
74
|
+
if (currentStep) {
|
|
75
|
+
currentStep.querySelectorAll<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(
|
|
76
|
+
'input:required,select:required,textarea:required'
|
|
77
|
+
).forEach(input =>
|
|
78
|
+
{
|
|
79
|
+
if (!input.checkValidity()) {
|
|
80
|
+
currentStep = null;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
currentStep?.querySelectorAll<HTMLFieldSetElement>(
|
|
85
|
+
'fieldset.micl-checkbox-group[data-miclname]'
|
|
86
|
+
).forEach(fieldset =>
|
|
87
|
+
{
|
|
88
|
+
let nrChecked = 0;
|
|
89
|
+
fieldset.querySelectorAll<HTMLInputElement>(
|
|
90
|
+
`.micl-checkbox[name="${fieldset.dataset.miclname}"]`
|
|
91
|
+
).forEach(checkbox =>
|
|
92
|
+
{
|
|
93
|
+
if (checkbox.checked) {
|
|
94
|
+
nrChecked++;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (nrChecked === 0) {
|
|
98
|
+
console.log("NOT ENGOUGH CHECKS");
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return currentStep;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
initialize: (stepper: HTMLElement): void =>
|
|
107
|
+
{
|
|
108
|
+
if (
|
|
109
|
+
!stepper.matches(stepperSelector)
|
|
110
|
+
|| stepper.dataset.miclinitialized
|
|
111
|
+
) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
stepper.dataset.miclinitialized = '1';
|
|
115
|
+
|
|
116
|
+
stepper.querySelectorAll<HTMLElement>('.micl-stepper__step').forEach((step, index) =>
|
|
117
|
+
{
|
|
118
|
+
step.dataset.miclstep = `${index + 1}`;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const
|
|
122
|
+
step = getCurrentStep(stepper),
|
|
123
|
+
actions = stepper.querySelectorAll<HTMLButtonElement>(
|
|
124
|
+
'button.micl-stepper--goback,button.micl-stepper--gonext'
|
|
125
|
+
);
|
|
126
|
+
showHideActions([...actions], step);
|
|
127
|
+
step && showHideElements(stepper, step);
|
|
128
|
+
|
|
129
|
+
actions.forEach(action =>
|
|
130
|
+
{
|
|
131
|
+
action.addEventListener('click', () =>
|
|
132
|
+
{
|
|
133
|
+
const currentStep = checkStepValidity(stepper);
|
|
134
|
+
if (!currentStep) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const
|
|
138
|
+
goNext = action.classList.contains('micl-stepper--gonext'),
|
|
139
|
+
sibling = currentStep[
|
|
140
|
+
goNext ? 'nextElementSibling' : 'previousElementSibling'
|
|
141
|
+
] as HTMLElement;
|
|
142
|
+
|
|
143
|
+
if (sibling?.classList.contains('micl-stepper__step')) {
|
|
144
|
+
currentStep.addEventListener('transitionend', endTransitionCurrent);
|
|
145
|
+
currentStep.classList.add('micl-stepper__step--fromcurrent');
|
|
146
|
+
currentStep.offsetHeight;
|
|
147
|
+
|
|
148
|
+
sibling.addEventListener('transitionend', endTransitionCurrent);
|
|
149
|
+
sibling.classList.add('micl-stepper__step--tocurrent');
|
|
150
|
+
sibling.offsetHeight;
|
|
151
|
+
|
|
152
|
+
sibling.classList.add('micl-stepper__step--current');
|
|
153
|
+
currentStep.classList.remove('micl-stepper__step--current');
|
|
154
|
+
currentStep.offsetHeight;
|
|
155
|
+
|
|
156
|
+
showHideActions([...actions], sibling);
|
|
157
|
+
showHideElements(stepper, sibling);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
})();
|
|
@@ -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.
|
|
@@ -24,24 +24,27 @@
|
|
|
24
24
|
@use '../../styles/statelayer';
|
|
25
25
|
@use '../../styles/typography';
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
--md-sys-switch-target-height: 32px;
|
|
29
|
-
--md-sys-switch-target-width: 52px;
|
|
30
|
-
--md-sys-switch-state-layer-size: 40px;
|
|
27
|
+
:root {
|
|
31
28
|
--md-sys-switch-handle-size: 16px;
|
|
32
29
|
--md-sys-switch-handle-selected-size: 24px;
|
|
33
30
|
--md-sys-switch-handle-pressed-size: 28px;
|
|
31
|
+
--md-sys-switch-outline-width: 2px;
|
|
32
|
+
--md-sys-switch-state-layer-size: 40px;
|
|
33
|
+
--md-sys-switch-target-height: 32px;
|
|
34
|
+
--md-sys-switch-target-width: 52px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
input[type=checkbox].micl-switch {
|
|
34
38
|
--md-sys-switch-unselected-icon: "+";
|
|
35
39
|
--md-sys-switch-selected-icon: "\AC";
|
|
36
|
-
--md-sys-switch-outline-width: 2px;
|
|
37
40
|
--md-sys-switch-motion-effects: #{motion.$md-sys-motion-expressive-slow-effects};
|
|
38
41
|
--md-sys-switch-motion-duration: #{motion.$md-sys-motion-expressive-slow-effects-duration};
|
|
39
42
|
--md-sys-switch-motion-duration-reverse: #{motion.$md-sys-motion-expressive-default-effects-duration};
|
|
40
43
|
|
|
41
44
|
appearance: none;
|
|
42
45
|
position: relative;
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
inline-size: var(--md-sys-switch-target-width);
|
|
47
|
+
block-size: var(--md-sys-target-size);
|
|
45
48
|
margin: 0;
|
|
46
49
|
border-radius: calc(var(--md-sys-switch-target-height) / 2);
|
|
47
50
|
outline: none;
|
|
@@ -50,8 +53,8 @@ input[type=checkbox].micl-switch {
|
|
|
50
53
|
content: "";
|
|
51
54
|
box-sizing: border-box;
|
|
52
55
|
display: block;
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
inline-size: var(--md-sys-switch-target-width);
|
|
57
|
+
block-size: var(--md-sys-switch-target-height);
|
|
55
58
|
margin-block: calc((var(--md-sys-target-size) - var(--md-sys-switch-target-height)) / 2);
|
|
56
59
|
border: var(--md-sys-switch-outline-width) solid var(--md-sys-color-outline);
|
|
57
60
|
border-radius: inherit;
|
|
@@ -62,12 +65,12 @@ input[type=checkbox].micl-switch {
|
|
|
62
65
|
content: var(--md-sys-switch-unselected-icon);
|
|
63
66
|
box-sizing: border-box;
|
|
64
67
|
position: absolute;
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
inline-size: var(--md-sys-switch-state-layer-size);
|
|
69
|
+
block-size: var(--md-sys-switch-state-layer-size);
|
|
67
70
|
inset: 0;
|
|
68
|
-
inset-inline-start: -
|
|
71
|
+
inset-inline-start: calc((var(--md-sys-target-size) - var(--md-sys-switch-state-layer-size) - 16px) / 2);
|
|
69
72
|
margin: auto 0;
|
|
70
|
-
font: 300
|
|
73
|
+
font: 300 16px / 1rem var(--md-ref-typeface-plain);
|
|
71
74
|
color: var(--md-sys-color-surface-container-highest);
|
|
72
75
|
text-align: center;
|
|
73
76
|
background-color: var(--md-sys-color-outline);
|
|
@@ -78,7 +81,6 @@ input[type=checkbox].micl-switch {
|
|
|
78
81
|
transition:
|
|
79
82
|
inset-inline-start var(--md-sys-switch-motion-duration) var(--md-sys-switch-motion-effects),
|
|
80
83
|
border-width var(--md-sys-switch-motion-duration) var(--md-sys-switch-motion-effects),
|
|
81
|
-
font-size var(--md-sys-switch-motion-duration) var(--md-sys-switch-motion-effects),
|
|
82
84
|
line-height var(--md-sys-switch-motion-duration) var(--md-sys-switch-motion-effects),
|
|
83
85
|
color var(--md-sys-switch-motion-duration) motion.$md-sys-motion-easing-emphasized,
|
|
84
86
|
border-color var(--md-sys-switch-motion-duration) motion.$md-sys-motion-easing-emphasized,
|
|
@@ -90,9 +92,10 @@ input[type=checkbox].micl-switch {
|
|
|
90
92
|
}
|
|
91
93
|
&::after {
|
|
92
94
|
content: var(--md-sys-switch-selected-icon);
|
|
93
|
-
inset-inline-start: 16px;
|
|
94
|
-
font-size:
|
|
95
|
-
line-height: 1.
|
|
95
|
+
inset-inline-start: calc(var(--md-sys-switch-target-width) - ((var(--md-sys-switch-state-layer-size) + var(--md-sys-target-size) - 16px) / 2));
|
|
96
|
+
font-size: 1.6rem;
|
|
97
|
+
line-height: 1.3rem;
|
|
98
|
+
letter-spacing: 0.1rem;
|
|
96
99
|
border: calc((var(--md-sys-switch-state-layer-size) - var(--md-sys-switch-handle-selected-size)) / 2) solid transparent;
|
|
97
100
|
color: var(--md-sys-color-on-primary-container);
|
|
98
101
|
background-color: var(--md-sys-color-on-primary);
|
|
@@ -129,19 +132,18 @@ input[type=checkbox].micl-switch {
|
|
|
129
132
|
}
|
|
130
133
|
&:active {
|
|
131
134
|
&::after {
|
|
132
|
-
font-size: 2rem;
|
|
133
135
|
line-height: 1.7rem;
|
|
134
136
|
border: calc((var(--md-sys-switch-state-layer-size) - var(--md-sys-switch-handle-pressed-size)) / 2) solid transparent;
|
|
135
137
|
background-color: var(--md-sys-color-on-surface-variant);
|
|
136
138
|
}
|
|
137
139
|
&:checked::after {
|
|
138
|
-
line-height: 1.
|
|
140
|
+
line-height: 1.6rem;
|
|
139
141
|
border-width: calc((var(--md-sys-switch-state-layer-size) - var(--md-sys-switch-handle-pressed-size)) / 2);
|
|
140
142
|
border-color: color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-pressed-state-layer-opacity), transparent);
|
|
141
143
|
background-color: var(--md-sys-color-primary-container);
|
|
142
144
|
}
|
|
143
145
|
&:not(:checked)::after {
|
|
144
|
-
inset-inline-start: -
|
|
146
|
+
inset-inline-start: calc((var(--md-sys-target-size) - var(--md-sys-switch-state-layer-size) - 16px) / 2);
|
|
145
147
|
border-color: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-pressed-state-layer-opacity), transparent);
|
|
146
148
|
}
|
|
147
149
|
}
|
|
@@ -154,15 +156,14 @@ input[type=checkbox].micl-switch {
|
|
|
154
156
|
}
|
|
155
157
|
&:checked::before {
|
|
156
158
|
background-color: var(--md-sys-color-on-surface);
|
|
157
|
-
opacity: 12%;
|
|
158
159
|
}
|
|
159
160
|
&::after {
|
|
160
|
-
color:
|
|
161
|
+
color: rgb(from var(--md-sys-color-surface-container-highest) r g b / 38%);
|
|
161
162
|
background-color: var(--md-sys-color-on-surface);
|
|
162
163
|
opacity: 38%;
|
|
163
164
|
}
|
|
164
165
|
&:checked::after {
|
|
165
|
-
color:
|
|
166
|
+
color: rgb(from var(--md-sys-color-on-surface) r g b / 38%);
|
|
166
167
|
background-color: var(--md-sys-color-surface);
|
|
167
168
|
opacity: 100%;
|
|
168
169
|
}
|