@massimo-cassandro/minimo 1.26.0 → 1.27.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/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { ValidationError } from './src/utilities/validation-error-class.js';
|
|
|
20
20
|
|
|
21
21
|
// domBuilder helpers
|
|
22
22
|
export { buildPictureTag } from './src/utilities/dom-builder-helpers/picture-tag.js';
|
|
23
|
-
export { buildInput, buildCheckbox, buildTextarea, buildFakeField, buildSelect } from './src/utilities/dom-builder-helpers/form-tags.js';
|
|
23
|
+
export { buildInput, buildCheckbox, buildTextarea, buildFakeField, buildSelect, buildButton } from './src/utilities/dom-builder-helpers/form-tags.js';
|
|
24
24
|
|
|
25
25
|
// components
|
|
26
26
|
export { dismissAlerts } from './src/components/dismiss-alerts.js';
|
package/package.json
CHANGED
|
@@ -50,10 +50,12 @@ function buildFormGroup({
|
|
|
50
50
|
* @param {string | number | null} args.value - input `value` attribute.
|
|
51
51
|
* @param {string | null} [args.type='text'] - input `type` attribute.
|
|
52
52
|
* @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
|
|
53
|
-
* @param {string | null} [args.
|
|
53
|
+
* @param {string | null} [args.class=null] - optional class to be added to the `input`.
|
|
54
|
+
* @param {string | null} [args.classname=null] - Alias for `class`.
|
|
55
|
+
* @param {string | null} [args.className=null] - Alias for `class`.
|
|
54
56
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
55
57
|
* @param {string | HTMLElement | null} args.help - Optional help text.
|
|
56
|
-
* @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
|
|
58
|
+
* @param {(function(HTMLElement|Text): void) | null} args.callback - Optional callback function.
|
|
57
59
|
* @param {Record<string, any> | null} [args.attrs={}] - Optional attributes object.
|
|
58
60
|
* @returns {DomBuilderItem|null} The `input` domBuilder item, or `null` when `condition` is false.
|
|
59
61
|
*/
|
|
@@ -64,13 +66,17 @@ export function buildInput({
|
|
|
64
66
|
value = null,
|
|
65
67
|
type = 'text',
|
|
66
68
|
wrapperClass = null,
|
|
67
|
-
|
|
69
|
+
class: classArg = null,
|
|
70
|
+
classname: classnameArg = null,
|
|
71
|
+
className: classNameArg = null,
|
|
68
72
|
condition = true,
|
|
69
73
|
help = null,
|
|
70
74
|
attrs = {},
|
|
71
75
|
callback = null
|
|
72
76
|
}){
|
|
73
77
|
|
|
78
|
+
const className = classArg ?? classnameArg ?? classNameArg;
|
|
79
|
+
|
|
74
80
|
id = id || randomId();
|
|
75
81
|
|
|
76
82
|
return buildFormGroup({
|
|
@@ -108,11 +114,13 @@ export function buildInput({
|
|
|
108
114
|
* as an array of objects `[{somekey: value, somekey2: text},...]` objects, or as a single `{value: text, ...}` object
|
|
109
115
|
* @param {boolean} [args.addEmptyOption=true] - When true, and empty option tag is added at top
|
|
110
116
|
* @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
|
|
111
|
-
* @param {string | null} [args.
|
|
117
|
+
* @param {string | null} [args.class=null] - optional class to be added to the `input`.
|
|
118
|
+
* @param {string | null} [args.classname=null] - Alias for `class`.
|
|
119
|
+
* @param {string | null} [args.className=null] - Alias for `class`.
|
|
112
120
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
113
121
|
* @param {boolean} [args.useBsClass=false] - When true, uses BS5 class (`form-select`) instead of `form-control`
|
|
114
122
|
* @param {string | HTMLElement | null} args.help - Optional help text.
|
|
115
|
-
* @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
|
|
123
|
+
* @param {(function(HTMLElement|Text): void) | null} args.callback - Optional callback function.
|
|
116
124
|
* @param {Record<string, any> | null} [args.attrs={}] - Optional attributes object.
|
|
117
125
|
* @returns {DomBuilderItem|null} The `input` domBuilder item, or `null` when `condition` is false.
|
|
118
126
|
*/
|
|
@@ -124,7 +132,9 @@ export function buildSelect({
|
|
|
124
132
|
options = null,
|
|
125
133
|
addEmptyOption = true,
|
|
126
134
|
wrapperClass = null,
|
|
127
|
-
|
|
135
|
+
class: classArg = null,
|
|
136
|
+
classname: classnameArg = null,
|
|
137
|
+
className: classNameArg = null,
|
|
128
138
|
useBsClass = false,
|
|
129
139
|
condition = true,
|
|
130
140
|
help = null,
|
|
@@ -132,6 +142,8 @@ export function buildSelect({
|
|
|
132
142
|
callback = null
|
|
133
143
|
}){
|
|
134
144
|
|
|
145
|
+
const className = classArg ?? classnameArg ?? classNameArg;
|
|
146
|
+
|
|
135
147
|
id = id || randomId();
|
|
136
148
|
|
|
137
149
|
// normalizing options as an array of [value, text] pairs
|
|
@@ -200,7 +212,7 @@ export function buildSelect({
|
|
|
200
212
|
* @param {boolean} [args.addFormGroup=true] - When true, wraps the checkbox in a `.form-group` element.
|
|
201
213
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
202
214
|
* @param {string | HTMLElement | null} args.help - Optional help text.
|
|
203
|
-
* @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
|
|
215
|
+
* @param {(function(HTMLElement|Text): void) | null} args.callback - Optional callback function.
|
|
204
216
|
* @param {Record<string, any> | null} [args.attrs={}] - Optional attributes object.
|
|
205
217
|
* @returns {DomBuilderItem|null} The `.form-check` (or `.form-group`-wrapped) domBuilder item, or `null` when `condition` is false.
|
|
206
218
|
*/
|
|
@@ -286,10 +298,12 @@ export function buildCheckbox({
|
|
|
286
298
|
* @param {string | number | null} args.value - textarea content.
|
|
287
299
|
* @param {boolean} [args.autosize=true] - adds `autosize` class
|
|
288
300
|
* @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
|
|
289
|
-
* @param {string | null} [args.
|
|
301
|
+
* @param {string | null} [args.class=null] - optional class to be added to the textarea element.
|
|
302
|
+
* @param {string | null} [args.classname=null] - Alias for `class`.
|
|
303
|
+
* @param {string | null} [args.className=null] - Alias for `class`.
|
|
290
304
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
291
305
|
* @param {string | HTMLElement | null} args.help - Optional help text.
|
|
292
|
-
* @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
|
|
306
|
+
* @param {(function(HTMLElement|Text): void) | null} args.callback - Optional callback function.
|
|
293
307
|
* @param {Record<string, any> | null} [args.attrs={}] - Optional attributes object.
|
|
294
308
|
* @returns {DomBuilderItem|null} The `textarea` domBuilder item, or `null` when `condition` is false.
|
|
295
309
|
*/
|
|
@@ -299,7 +313,9 @@ export function buildTextarea({
|
|
|
299
313
|
id = null,
|
|
300
314
|
value = null,
|
|
301
315
|
wrapperClass = null,
|
|
302
|
-
|
|
316
|
+
class: classArg = null,
|
|
317
|
+
classname: classnameArg = null,
|
|
318
|
+
className: classNameArg = null,
|
|
303
319
|
condition = true,
|
|
304
320
|
help = null,
|
|
305
321
|
callback = null,
|
|
@@ -307,6 +323,8 @@ export function buildTextarea({
|
|
|
307
323
|
autosize = true
|
|
308
324
|
}) {
|
|
309
325
|
|
|
326
|
+
const className = classArg ?? classnameArg ?? classNameArg;
|
|
327
|
+
|
|
310
328
|
id = id || randomId();
|
|
311
329
|
|
|
312
330
|
return buildFormGroup({
|
|
@@ -338,10 +356,12 @@ export function buildTextarea({
|
|
|
338
356
|
* @param {string | number | null} args.value - text content.
|
|
339
357
|
* @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
|
|
340
358
|
* @param {boolean} [args.noBorder=true] - adds `no-border` class.
|
|
341
|
-
* @param {string | null} [args.
|
|
359
|
+
* @param {string | null} [args.class=null] - optional class to be added to the fake field.
|
|
360
|
+
* @param {string | null} [args.classname=null] - Alias for `class`.
|
|
361
|
+
* @param {string | null} [args.className=null] - Alias for `class`.
|
|
342
362
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
343
363
|
* @param {string | HTMLElement | null} args.help - Optional help text.
|
|
344
|
-
* @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
|
|
364
|
+
* @param {(function(HTMLElement|Text): void) | null} args.callback - Optional callback function.
|
|
345
365
|
* @param {Record<string, any> | null} [args.attrs={}] - Optional attributes object.
|
|
346
366
|
* @returns {DomBuilderItem|null} The fake field domBuilder item, or `null` when `condition` is false.
|
|
347
367
|
*/
|
|
@@ -349,7 +369,9 @@ export function buildFakeField({
|
|
|
349
369
|
label,
|
|
350
370
|
value = null,
|
|
351
371
|
wrapperClass = null,
|
|
352
|
-
|
|
372
|
+
class: classArg = null,
|
|
373
|
+
classname: classnameArg = null,
|
|
374
|
+
className: classNameArg = null,
|
|
353
375
|
condition = true,
|
|
354
376
|
help = null,
|
|
355
377
|
callback = null,
|
|
@@ -357,6 +379,7 @@ export function buildFakeField({
|
|
|
357
379
|
noBorder = true
|
|
358
380
|
}) {
|
|
359
381
|
|
|
382
|
+
const className = classArg ?? classnameArg ?? classNameArg;
|
|
360
383
|
|
|
361
384
|
return buildFormGroup({
|
|
362
385
|
condition,
|
|
@@ -368,7 +391,6 @@ export function buildFakeField({
|
|
|
368
391
|
className: classnames('form-control-static', className, attrs?.class, noBorder && 'no-border'),
|
|
369
392
|
attrs: {
|
|
370
393
|
...(attrs??{}),
|
|
371
|
-
name: name,
|
|
372
394
|
},
|
|
373
395
|
content: value,
|
|
374
396
|
callback: callback
|
|
@@ -376,3 +398,55 @@ export function buildFakeField({
|
|
|
376
398
|
]
|
|
377
399
|
});
|
|
378
400
|
}
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* button tag builder
|
|
406
|
+
*
|
|
407
|
+
* @param {Object} args
|
|
408
|
+
* @param {string|HTMLElement|Array<DomBuilderItem>} args.content - button content. When an array of
|
|
409
|
+
* domBuilder items is passed, it is rendered via `children` instead of `content`.
|
|
410
|
+
* @param {string} [args.type=button] - button type.
|
|
411
|
+
* @param {string | null} args.id - `id` attribute.
|
|
412
|
+
* @param {string | number | null} [args.value=null] - button `value` attribute.
|
|
413
|
+
* @param {string | null} [args.class=null] - optional class to be added to the button element.
|
|
414
|
+
* @param {string | null} [args.classname=null] - Alias for `class`.
|
|
415
|
+
* @param {string | null} [args.className=null] - Alias for `class`.
|
|
416
|
+
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
417
|
+
* @param {(function(HTMLElement|Text): void) | null} args.callback - Optional callback function.
|
|
418
|
+
* @param {Record<string, any> | null} [args.attrs={}] - Optional attributes object.
|
|
419
|
+
* @returns {DomBuilderItem|null} The `button` domBuilder item, or `null` when `condition` is false.
|
|
420
|
+
*/
|
|
421
|
+
export function buildButton({
|
|
422
|
+
content,
|
|
423
|
+
type = 'button',
|
|
424
|
+
id = null,
|
|
425
|
+
value = null,
|
|
426
|
+
class: classArg = null,
|
|
427
|
+
classname: classnameArg = null,
|
|
428
|
+
className: classNameArg = null,
|
|
429
|
+
condition = true,
|
|
430
|
+
callback = null,
|
|
431
|
+
attrs = {},
|
|
432
|
+
}) {
|
|
433
|
+
|
|
434
|
+
const className = classArg ?? classnameArg ?? classNameArg;
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
condition: condition,
|
|
438
|
+
tag: 'button',
|
|
439
|
+
className: classnames(className, attrs?.class),
|
|
440
|
+
id: id,
|
|
441
|
+
attrs: {
|
|
442
|
+
...(attrs??{}),
|
|
443
|
+
type: type,
|
|
444
|
+
value: value
|
|
445
|
+
},
|
|
446
|
+
...(Array.isArray(content)
|
|
447
|
+
? { children: content }
|
|
448
|
+
: { content: content }
|
|
449
|
+
),
|
|
450
|
+
callback: callback
|
|
451
|
+
};
|
|
452
|
+
}
|