@massimo-cassandro/minimo 1.22.0 → 1.22.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.
|
@@ -1,53 +1,56 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
height: {
|
|
9
|
-
$value: '1.25em',
|
|
10
|
-
$type: 'dimension'
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
thumb: {
|
|
14
|
-
inset: {
|
|
15
|
-
$value: '.125em',
|
|
2
|
+
form: {
|
|
3
|
+
|
|
4
|
+
switch: {
|
|
5
|
+
width: {
|
|
6
|
+
$value: '2.25em',
|
|
16
7
|
$type: 'dimension'
|
|
17
8
|
},
|
|
18
|
-
},
|
|
19
9
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
$
|
|
23
|
-
$type: 'duration'
|
|
10
|
+
height: {
|
|
11
|
+
$value: '1.25em',
|
|
12
|
+
$type: 'dimension'
|
|
24
13
|
},
|
|
25
|
-
},
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
thumb: {
|
|
16
|
+
inset: {
|
|
17
|
+
$value: '.125em',
|
|
18
|
+
$type: 'dimension'
|
|
19
|
+
},
|
|
20
|
+
},
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
$
|
|
38
|
-
|
|
39
|
-
}
|
|
22
|
+
transition: {
|
|
23
|
+
duration: {
|
|
24
|
+
$value: '.2s',
|
|
25
|
+
$type: 'duration'
|
|
26
|
+
},
|
|
40
27
|
},
|
|
41
|
-
},
|
|
42
28
|
|
|
43
|
-
checked: {
|
|
44
29
|
background: {
|
|
45
30
|
color: {
|
|
46
|
-
$value: '{
|
|
31
|
+
$value: '{neutral.100}',
|
|
47
32
|
$type: 'color'
|
|
48
33
|
}
|
|
49
34
|
},
|
|
50
|
-
}
|
|
51
35
|
|
|
36
|
+
cursor: {
|
|
37
|
+
background: {
|
|
38
|
+
color: {
|
|
39
|
+
$value: '{body.background.color}',
|
|
40
|
+
$type: 'color'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
checked: {
|
|
46
|
+
background: {
|
|
47
|
+
color: {
|
|
48
|
+
$value: '{primary.100}',
|
|
49
|
+
$type: 'color'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
};
|
package/package.json
CHANGED
package/src/css/forms/switch.css
CHANGED
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
/* TODO valutare versione con label a sinistra (form-check-reverse) */
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
|
-
Markup (
|
|
5
|
+
Markup (same as bootstrap 5, plus the native `switch` attribute):
|
|
6
6
|
|
|
7
7
|
<div class="form-check form-switch">
|
|
8
8
|
<input class="form-check-input" type="checkbox" role="switch" switch id="my-switch">
|
|
9
|
-
<label class="form-
|
|
9
|
+
<label class="form-label" for="my-switch">Enable notifications</label>
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`appearance: none`
|
|
12
|
+
The `switch` attribute (WebKit only for now) makes the browser render a real
|
|
13
|
+
native switch control, which can be styled through the `::track` and `::thumb`
|
|
14
|
+
pseudo-elements. Where it is not supported (or where the attribute is missing),
|
|
15
|
+
the `appearance: none` fallback is applied, with the thumb drawn as a
|
|
16
|
+
background-image.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
.form-switch {
|
|
19
20
|
|
|
20
|
-
--_switch-thumb-size: calc(var(--switch-height) - var(--switch-thumb-inset) * 2);
|
|
21
|
+
--_switch-thumb-size: calc(var(--form-switch-height) - var(--form-switch-thumb-inset) * 2);
|
|
21
22
|
|
|
22
23
|
/* annulla il layout con float di `.form-check` */
|
|
23
24
|
display: flex;
|
|
@@ -28,29 +29,30 @@ Dove non è supportato (o dove l'attributo è assente) si applica il fallback
|
|
|
28
29
|
.form-check-input {
|
|
29
30
|
float: none;
|
|
30
31
|
flex: none;
|
|
31
|
-
width: var(--switch-width);
|
|
32
|
-
height: var(--switch-height);
|
|
32
|
+
width: var(--form-switch-width);
|
|
33
|
+
height: var(--form-switch-height);
|
|
33
34
|
margin: 0;
|
|
34
35
|
appearance: none;
|
|
35
36
|
cursor: pointer;
|
|
36
|
-
background-color: var(--switch-background-color);
|
|
37
|
-
background-image:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
background-color: var(--form-switch-background-color);
|
|
38
|
+
background-image:
|
|
39
|
+
radial-gradient(
|
|
40
|
+
circle closest-side,
|
|
41
|
+
var(--form-switch-cursor-background-color) 98%,
|
|
42
|
+
transparent
|
|
43
|
+
);
|
|
42
44
|
background-repeat: no-repeat;
|
|
43
|
-
background-position: var(--switch-thumb-inset) center;
|
|
45
|
+
background-position: var(--form-switch-thumb-inset) center;
|
|
44
46
|
background-size: var(--_switch-thumb-size) var(--_switch-thumb-size);
|
|
45
47
|
border: none;
|
|
46
|
-
border-radius: var(--switch-height);
|
|
48
|
+
border-radius: var(--form-switch-height);
|
|
47
49
|
|
|
48
50
|
/* annulla lo `scale` applicato a tutti i checkbox */
|
|
49
51
|
scale: none;
|
|
50
52
|
|
|
51
53
|
&:checked {
|
|
52
|
-
background-color: var(--switch-checked-background-color);
|
|
53
|
-
background-position: calc(100% - var(--switch-thumb-inset)) center;
|
|
54
|
+
background-color: var(--form-switch-checked-background-color);
|
|
55
|
+
background-position: calc(100% - var(--form-switch-thumb-inset)) center;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
&:focus {
|
|
@@ -63,7 +65,7 @@ Dove non è supportato (o dove l'attributo è assente) si applica il fallback
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
.form-
|
|
68
|
+
.form-label {
|
|
67
69
|
cursor: pointer;
|
|
68
70
|
user-select: none;
|
|
69
71
|
}
|
|
@@ -71,7 +73,7 @@ Dove non è supportato (o dove l'attributo è assente) si applica il fallback
|
|
|
71
73
|
&:has(.form-check-input:disabled) {
|
|
72
74
|
opacity: var(--form-control-disabled-opacity);
|
|
73
75
|
|
|
74
|
-
.form-check-input, .form-
|
|
76
|
+
.form-check-input, .form-label {
|
|
75
77
|
cursor: not-allowed;
|
|
76
78
|
}
|
|
77
79
|
}
|
|
@@ -80,8 +82,8 @@ Dove non è supportato (o dove l'attributo è assente) si applica il fallback
|
|
|
80
82
|
@media (prefers-reduced-motion: no-preference) {
|
|
81
83
|
.form-switch .form-check-input {
|
|
82
84
|
transition:
|
|
83
|
-
background-color var(--switch-transition-duration) linear,
|
|
84
|
-
background-position var(--switch-transition-duration) ease-in-out;
|
|
85
|
+
background-color var(--form-switch-transition-duration) linear,
|
|
86
|
+
background-position var(--form-switch-transition-duration) ease-in-out;
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -95,15 +97,15 @@ Dove non è supportato (o dove l'attributo è assente) si applica il fallback
|
|
|
95
97
|
border-radius: 0; /* gestito da ::track */
|
|
96
98
|
|
|
97
99
|
&::track {
|
|
98
|
-
background-color: var(--switch-background-color);
|
|
100
|
+
background-color: var(--form-switch-background-color);
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
&::thumb {
|
|
102
|
-
background-color: var(--switch-cursor-background-color);
|
|
104
|
+
background-color: var(--form-switch-cursor-background-color);
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
&:checked::track {
|
|
106
|
-
background-color: var(--switch-checked-background-color);
|
|
108
|
+
background-color: var(--form-switch-checked-background-color);
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -193,6 +193,13 @@
|
|
|
193
193
|
--form-label-font-weight: var(--font-weight-semibold);
|
|
194
194
|
--form-legend-background-color: transparent;
|
|
195
195
|
--form-legend-color: var(--text-color);
|
|
196
|
+
--form-switch-background-color: var(--neutral-100);
|
|
197
|
+
--form-switch-checked-background-color: var(--primary-100);
|
|
198
|
+
--form-switch-cursor-background-color: var(--body-background-color);
|
|
199
|
+
--form-switch-height: 1.25em;
|
|
200
|
+
--form-switch-thumb-inset: .125em;
|
|
201
|
+
--form-switch-transition-duration: .2s;
|
|
202
|
+
--form-switch-width: 2.25em;
|
|
196
203
|
--form-user-info-color: var(--text-muted);
|
|
197
204
|
--form-user-info-font-size: var(--font-size-xs);
|
|
198
205
|
--form-validation-outline-offset: -3px;
|
|
@@ -380,14 +387,6 @@
|
|
|
380
387
|
--status-warning-color: #fc0;
|
|
381
388
|
--status-warning-fg: #4f2900;
|
|
382
389
|
|
|
383
|
-
--switch-background-color: var(--neutral-100);
|
|
384
|
-
--switch-checked-background-color: var(--primary-100);
|
|
385
|
-
--switch-cursor-background-color: var(--body-background-color);
|
|
386
|
-
--switch-height: 1.25em;
|
|
387
|
-
--switch-thumb-inset: .125em;
|
|
388
|
-
--switch-transition-duration: .2s;
|
|
389
|
-
--switch-width: 2.25em;
|
|
390
|
-
|
|
391
390
|
--table-body-border-width: 1px;
|
|
392
391
|
--table-body-tr-alt-bg-color: #efefef;
|
|
393
392
|
--table-body-tr-hover-bg-color: #cbcbcb;
|
|
@@ -132,12 +132,21 @@ export function buildSelect({
|
|
|
132
132
|
|
|
133
133
|
id = id || randomId();
|
|
134
134
|
|
|
135
|
-
// normalizing
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
// normalizing options as an array of [value, text] pairs
|
|
136
|
+
/** @type {Array<[string|number, string]>} */
|
|
137
|
+
let optionsList = [];
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
if(options) {
|
|
140
|
+
if(!Array.isArray(options)) {
|
|
141
|
+
optionsList = /** @type {Array<[string|number, string]>} */ (Object.entries(options));
|
|
142
|
+
|
|
143
|
+
} else if(!Array.isArray(options[0])) {
|
|
144
|
+
optionsList = /** @type {Array<Record<string, string>>} */ (options)
|
|
145
|
+
.map(o => /** @type {[string|number, string]} */ (Object.values(o)));
|
|
146
|
+
|
|
147
|
+
} else {
|
|
148
|
+
optionsList = /** @type {Array<[string|number, string]>} */ (options);
|
|
149
|
+
}
|
|
141
150
|
}
|
|
142
151
|
|
|
143
152
|
|
|
@@ -157,18 +166,15 @@ export function buildSelect({
|
|
|
157
166
|
},
|
|
158
167
|
children: [
|
|
159
168
|
...(addEmptyOption? ['option[value:]'] : []),
|
|
160
|
-
...(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}))
|
|
170
|
-
: []
|
|
171
|
-
)
|
|
169
|
+
...optionsList.map(([value, text]) => ({
|
|
170
|
+
tag: 'option',
|
|
171
|
+
attrs: {
|
|
172
|
+
value: value,
|
|
173
|
+
// eslint-disable-next-line eqeqeq
|
|
174
|
+
selected: value == selectedValue
|
|
175
|
+
},
|
|
176
|
+
content: text
|
|
177
|
+
}))
|
|
172
178
|
],
|
|
173
179
|
callback: callback
|
|
174
180
|
}
|
|
@@ -186,6 +192,8 @@ export function buildSelect({
|
|
|
186
192
|
* @param {string | null} args.id - `id` attribute.
|
|
187
193
|
* @param {string | number | null} [args.value=1] - checkbox `value` attribute.
|
|
188
194
|
* @param {boolean} [args.checked=false] - checkbox `checked` attribute.
|
|
195
|
+
* @param {boolean} [args.switch=false] - When true, the checkbox is rendered as a switch
|
|
196
|
+
* (`.form-switch` wrapper, `role="switch"` and the native `switch` attribute).
|
|
189
197
|
* @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper (used only when `addFormGroup` is true).
|
|
190
198
|
* @param {boolean} [args.addFormGroup=true] - When true, wraps the checkbox in a `.form-group` element.
|
|
191
199
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
@@ -200,6 +208,7 @@ export function buildCheckbox({
|
|
|
200
208
|
id = null,
|
|
201
209
|
value = 1,
|
|
202
210
|
checked = false,
|
|
211
|
+
switch: isSwitch = false,
|
|
203
212
|
wrapperClass = null,
|
|
204
213
|
addFormGroup = true,
|
|
205
214
|
condition = true,
|
|
@@ -213,17 +222,24 @@ export function buildCheckbox({
|
|
|
213
222
|
}
|
|
214
223
|
|
|
215
224
|
/*
|
|
216
|
-
<div class="form-group">
|
|
225
|
+
<div class="form-group"> <- optional
|
|
217
226
|
<div class="form-check">
|
|
218
227
|
<input type="checkbox" id="..." name="..." class="form-check-input" value="1">
|
|
219
228
|
<label for="..." class="form-label">...</label>
|
|
220
229
|
</div>
|
|
221
230
|
</div>
|
|
231
|
+
|
|
232
|
+
<div class="form-group"> <- optional
|
|
233
|
+
<div class="form-check form-switch">
|
|
234
|
+
<input class="form-check-input" type="checkbox" role="switch" switch id="my-switch">
|
|
235
|
+
<label class="form-label" for="my-switch">My label</label>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
222
238
|
*/
|
|
223
239
|
id = id || randomId();
|
|
224
240
|
|
|
225
241
|
const tag = {
|
|
226
|
-
className: classnames('form-check', !addFormGroup && !help && wrapperClass),
|
|
242
|
+
className: classnames('form-check', isSwitch && 'form-switch', !addFormGroup && !help && wrapperClass),
|
|
227
243
|
children: [
|
|
228
244
|
{
|
|
229
245
|
tag: 'input',
|
|
@@ -234,7 +250,9 @@ export function buildCheckbox({
|
|
|
234
250
|
type: 'checkbox',
|
|
235
251
|
value: value,
|
|
236
252
|
name: name,
|
|
237
|
-
checked: checked
|
|
253
|
+
checked: checked,
|
|
254
|
+
// native switch control (WebKit only for now), with the css fallback elsewhere
|
|
255
|
+
...(isSwitch? {role: 'switch', switch: ''} : {})
|
|
238
256
|
},
|
|
239
257
|
callback: callback
|
|
240
258
|
},
|