@massimo-cassandro/minimo 1.19.11 → 1.19.12

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.
@@ -172,13 +172,39 @@ export default {
172
172
  }
173
173
  },
174
174
  required: {
175
- 'flag-color': {
176
- $value: '#c00',
177
- $type: 'color'
175
+ label: {
176
+ padding: {
177
+ inline: {
178
+ start: {
179
+ $type: 'dimension',
180
+ $value: '{size.xxs}',
181
+ }
182
+ }
183
+ },
178
184
  },
179
- 'flag-content': {
180
- $value: '\'\\002A\'',
181
- $type: 'string'
185
+ flag: {
186
+ color: {
187
+ $type: 'color',
188
+ $value: '#c00',
189
+ },
190
+ content: {
191
+ $type: 'string',
192
+ $value: '\'\\002A\'',
193
+ },
194
+ top: {
195
+ $type: 'dimension',
196
+ $value: '-.15em',
197
+ },
198
+ left: {
199
+ $type: 'dimension',
200
+ $value: '0em',
201
+ },
202
+ font: {
203
+ size: {
204
+ $type: 'dimension',
205
+ $value: '2em',
206
+ }
207
+ }
182
208
  }
183
209
  },
184
210
  focus: {
@@ -168,13 +168,39 @@
168
168
  }
169
169
  },
170
170
  "required": {
171
- "flag-color": {
172
- "$type": "color",
173
- "$value": "#c00"
171
+ "label": {
172
+ "padding": {
173
+ "inline": {
174
+ "start": {
175
+ "$type": "dimension",
176
+ "$value": "{size.xxs}"
177
+ }
178
+ }
179
+ }
174
180
  },
175
- "flag-content": {
176
- "$type": "string",
177
- "$value": "'\\002A'"
181
+ "flag": {
182
+ "color": {
183
+ "$type": "color",
184
+ "$value": "#c00"
185
+ },
186
+ "content": {
187
+ "$type": "string",
188
+ "$value": "'\\002A'"
189
+ },
190
+ "top": {
191
+ "$type": "dimension",
192
+ "$value": "-.15em"
193
+ },
194
+ "left": {
195
+ "$type": "dimension",
196
+ "$value": "0em"
197
+ },
198
+ "font": {
199
+ "size": {
200
+ "$type": "dimension",
201
+ "$value": "2em"
202
+ }
203
+ }
178
204
  }
179
205
  },
180
206
  "focus": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.19.11",
3
+ "version": "1.19.12",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -4,20 +4,20 @@
4
4
  /* TODO classe grid specifica per i form ?? (.form-grid?) */
5
5
  /* TODO customizable select */
6
6
  /* TODO form-check: rifare come flex, separare? */
7
+ /* TODO abbreviare prefisso */
7
8
 
8
9
  .form-group:has([required]):not(:has([disabled])) {
9
10
 
10
11
  /* `>` excludes labels within form-collections */
11
12
  > .form-label {
12
13
  position: relative;
13
- padding-inline-start: var(--size-base);
14
+ padding-inline-start: var(--form-control-required-label-padding-inline-start);
14
15
  &::before {
15
16
  position: absolute;
16
- top: -.15em;
17
- left: 0;
17
+ top: var(--form-control-required-flag-top);
18
+ left: var(--form-control-required-flag-left);
18
19
  display: inline-block;
19
- padding-inline-end: var(--size-xxs);
20
- font-size: 2em;
20
+ font-size: var(--form-control-required-flag-font-size);
21
21
  color: var(--form-control-required-flag-color);
22
22
  content: var(--form-control-required-flag-content);
23
23
  }
@@ -162,6 +162,10 @@
162
162
  --form-control-readonly-opacity: 1;
163
163
  --form-control-required-flag-color: #c00;
164
164
  --form-control-required-flag-content: '\002A';
165
+ --form-control-required-flag-font-size: .125rem;
166
+ --form-control-required-flag-left: 0rem;
167
+ --form-control-required-flag-top: -.009375rem;
168
+ --form-control-required-label-padding-inline-start: var(--size-xxs);
165
169
  --form-control-select-trigger-icon: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20fill%3D%22none%22%20stroke%3D%22rgb(5%2C%2048%2C%2056)%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%20stroke-width%3D%222%22%20d%3D%22m2%205%206%206%206-6%22%2F%3E%3C%2Fsvg%3E');
166
170
  --form-control-sm-font-size: var(--font-size-sm);
167
171
  --form-control-sm-padding-block: var(--size-xxs);
@@ -18,7 +18,7 @@ import { parseDomString } from './parseDomString.js';
18
18
  * treated as markup: sanitized and inserted via the native Sanitizer API (`Element.setHTML`) where
19
19
  * supported, falling back to raw `innerHTML` on browsers without it.
20
20
  * @property {boolean} [condition=true] - When false, the element is skipped.
21
- * @property {function(HTMLElement): void} [callback] - Callback invoked after the element is created.
21
+ * @property {(function(HTMLElement): void) | null} [callback] - Callback invoked after the element is created.
22
22
  * @property {Array<DomBuilderItem|string>} [children] - Configuration array for child elements. Accepts strings (shorthand per `parseDomString`) and/or configuration objects.
23
23
  */
24
24
 
@@ -1,40 +1,93 @@
1
1
  import { classnames } from '../classnames.js';
2
2
  import { randomId } from '../random-id.js';
3
3
 
4
+ /**
5
+ * Shared `.form-group` wrapper for the tag builders below: handles the
6
+ * `condition` guard, `wrapperClass`, optional help text and `callback` in
7
+ * one place, so each builder only needs to provide its own `children`
8
+ * (typically the label + control).
9
+ *
10
+ * @param {Object} args
11
+ * @param {boolean} [args.condition=true] - When false, returns `null` without building anything.
12
+ * @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
13
+ * @param {string | HTMLElement | null} [args.help=null] - Optional help text.
14
+ * @param {Array} args.children - domBuilder children to render inside the `.form-group` (before the help text).
15
+ * @returns {DomBuilderItem|null} The `.form-group` domBuilder item, or `null` when `condition` is false.
16
+ */
17
+ function buildFormGroup({
18
+ condition = true,
19
+ wrapperClass = null,
20
+ help = null,
21
+ children
22
+ }) {
23
+
24
+ if(!condition) {
25
+ return null;
26
+ }
27
+
28
+ return {
29
+ className: classnames('form-group', wrapperClass),
30
+ children: [
31
+ ...children,
32
+ {
33
+ className: 'form-help-text',
34
+ condition: help != null,
35
+ content: help
36
+ }
37
+ ]
38
+ };
39
+ }
40
+
41
+
4
42
  /**
5
43
  * Input tag builder
6
44
  *
7
45
  * @param {Object} args
8
46
  * @param {string} args.label - input label.
9
47
  * @param {string | null} args.name - input `name` attribute.
10
- * @param {string | number | null} args.defaultValue - input `value` attribute.
48
+ * @param {string | number | null} args.value - input `value` attribute.
11
49
  * @param {string | null} [args.type='text'] - input `type` attribute.
12
50
  * @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
13
51
  * @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
52
+ * @param {string | HTMLElement | null} args.help - Optional help text.
53
+ * @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
54
+ * @param {object | null} [args.attrs={}] - Optional attributes object.
14
55
  * @returns {DomBuilderItem|null} The `input` domBuilder item, or `null` when `condition` is false.
15
56
  */
16
57
  export function buildInputTag({
17
58
  label,
18
59
  name,
19
- defaultValue,
60
+ value = null,
20
61
  type = 'text',
21
62
  wrapperClass = null,
22
- condition = true
63
+ condition = true,
64
+ help = null,
65
+ attrs = {},
66
+ callback = null
23
67
  }){
24
68
 
25
- if(!condition) {
26
- return null;
27
- }
28
-
29
69
  const id = randomId();
30
70
 
31
- return {
32
- className: classnames('form-group', wrapperClass),
71
+ return buildFormGroup({
72
+ condition,
73
+ wrapperClass,
74
+ help,
33
75
  children: [
34
76
  `label.form-label[for:${id}] ${label}`,
35
- `input#${id}.form-control[type: ${type}, name: ${name}, value: ${defaultValue}]`
77
+ {
78
+ tag: 'input',
79
+ className: 'form-control',
80
+ id: id,
81
+ attrs: {
82
+ ...(attrs??{}),
83
+ type: type,
84
+ name: name,
85
+ value: value
86
+ },
87
+ callback: callback
88
+ }
36
89
  ]
37
- };
90
+ });
38
91
  }
39
92
 
40
93
 
@@ -49,6 +102,9 @@ export function buildInputTag({
49
102
  * @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper (used only when `addFormGroup` is true).
50
103
  * @param {boolean} [args.addFormGroup=true] - When true, wraps the checkbox in a `.form-group` element.
51
104
  * @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
105
+ * @param {string | HTMLElement | null} args.help - Optional help text.
106
+ * @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
107
+ * @param {object | null} [args.attrs={}] - Optional attributes object.
52
108
  * @returns {DomBuilderItem|null} The `.form-check` (or `.form-group`-wrapped) domBuilder item, or `null` when `condition` is false.
53
109
  */
54
110
  export function buildCheckboxTag({
@@ -58,7 +114,10 @@ export function buildCheckboxTag({
58
114
  checked = false,
59
115
  wrapperClass = null,
60
116
  addFormGroup = true,
61
- condition = true
117
+ condition = true,
118
+ help = null,
119
+ attrs = {},
120
+ callback = null
62
121
  }) {
63
122
 
64
123
  if(!condition) {
@@ -76,32 +135,34 @@ export function buildCheckboxTag({
76
135
  const id = randomId();
77
136
 
78
137
  const tag = {
79
- className: classnames('form-check', !addFormGroup && wrapperClass),
138
+ className: classnames('form-check', !addFormGroup && !help && wrapperClass),
80
139
  children: [
81
140
  {
82
141
  tag: 'input',
83
142
  className: 'form-check-input',
84
143
  id: id,
85
144
  attrs: {
145
+ ...(attrs??{}),
86
146
  type: 'checkbox',
87
147
  value: value,
88
148
  name: name,
89
149
  checked: checked
90
- }
150
+ },
151
+ callback: callback
91
152
  },
92
153
  `label.form-label[for:${id}] ${label}`,
93
154
  ]
94
155
  };
95
156
 
96
157
  if(addFormGroup) {
97
- return {
98
- className: classnames('form-group', wrapperClass),
99
- children: [ tag ]
100
- };
158
+ return buildFormGroup({
159
+ wrapperClass,
160
+ help,
161
+ children: [tag]
162
+ });
101
163
 
102
164
  } else {
103
165
  return tag;
104
-
105
166
  }
106
167
 
107
168
  }
@@ -113,30 +174,44 @@ export function buildCheckboxTag({
113
174
  * @param {Object} args
114
175
  * @param {string} args.label - textarea label.
115
176
  * @param {string | null} args.name - textarea `name` attribute.
116
- * @param {string | number | null} args.defaultValue - textarea content.
177
+ * @param {string | number | null} args.value - textarea content.
117
178
  * @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
118
179
  * @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
180
+ * @param {string | HTMLElement | null} args.help - Optional help text.
181
+ * @param {(function(HTMLElement): void) | null} args.callback - Optional callback function.
182
+ * @param {object | null} [args.attrs={}] - Optional attributes object.
119
183
  * @returns {DomBuilderItem|null} The `textarea` domBuilder item, or `null` when `condition` is false.
120
184
  */
121
185
  export function buildTextareaTag({
122
186
  label,
123
187
  name,
124
- defaultValue,
188
+ value = null,
125
189
  wrapperClass = null,
126
- condition = true
190
+ condition = true,
191
+ help = null,
192
+ callback = null,
193
+ attrs = {}
127
194
  }) {
128
195
 
129
- if(!condition) {
130
- return null;
131
- }
132
-
133
196
  const id = randomId();
134
197
 
135
- return {
136
- className: classnames('form-group', wrapperClass),
198
+ return buildFormGroup({
199
+ condition,
200
+ wrapperClass,
201
+ help,
137
202
  children: [
138
203
  `label.form-label[for:${id}] ${label}`,
139
- `textarea#${id}.form-control[name: ${name}] ${defaultValue}`
204
+ {
205
+ tag: 'textarea',
206
+ className: 'form-control',
207
+ id: id,
208
+ attrs: {
209
+ ...(attrs??{}),
210
+ name: name,
211
+ value: value
212
+ },
213
+ callback: callback
214
+ }
140
215
  ]
141
- };
216
+ });
142
217
  }