@massimo-cassandro/minimo 1.19.10 → 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.10",
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
  }
@@ -112,7 +112,7 @@ select.form-control {
112
112
 
113
113
  input[type='checkbox'] {
114
114
  color: var(--form-control-text-color);
115
- accent-color: var(--accent-color);
115
+ accent-color: var(--accent);
116
116
  transform-origin: center;
117
117
  scale: 1.3;
118
118
  }
@@ -8,7 +8,7 @@ html, body {
8
8
  font-style: var(--font-style-base);
9
9
  line-height: var(--line-height-base);
10
10
  color: var(--text-color);
11
- accent-color: var(--accent-color);
11
+ accent-color: var(--accent);
12
12
  background-color: var(--body-background-color);
13
13
 
14
14
  }
@@ -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
 
@@ -44,56 +97,72 @@ export function buildInputTag({
44
97
  * @param {Object} args
45
98
  * @param {string} args.label - checkbox label.
46
99
  * @param {string | null} args.name - checkbox `name` attribute.
47
- * @param {string | number | null} args.value - checkbox `value` attribute.
100
+ * @param {string | number | null} [args.value=1] - checkbox `value` attribute.
48
101
  * @param {boolean} [args.checked=false] - checkbox `checked` attribute.
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({
55
111
  label,
56
112
  name,
57
- value,
113
+ value = 1,
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) {
65
124
  return null;
66
125
  }
67
126
 
127
+ /*
128
+ <div class="form-group">
129
+ <div class="form-check">
130
+ <input type="checkbox" id="..." name="..." class="form-check-input" value="1">
131
+ <label for="..." class="form-label">...</label>
132
+ </div>
133
+ </div>
134
+ */
68
135
  const id = randomId();
69
136
 
70
137
  const tag = {
71
- className: classnames('form-check', !addFormGroup && wrapperClass),
138
+ className: classnames('form-check', !addFormGroup && !help && wrapperClass),
72
139
  children: [
73
- `label.form-label[for:${id}] ${label}`,
74
140
  {
75
141
  tag: 'input',
76
- className: 'form-control',
142
+ className: 'form-check-input',
77
143
  id: id,
78
144
  attrs: {
145
+ ...(attrs??{}),
79
146
  type: 'checkbox',
80
147
  value: value,
81
148
  name: name,
82
149
  checked: checked
83
- }
84
- }
150
+ },
151
+ callback: callback
152
+ },
153
+ `label.form-label[for:${id}] ${label}`,
85
154
  ]
86
155
  };
87
156
 
88
157
  if(addFormGroup) {
89
- return {
90
- className: classnames('form-group', wrapperClass),
91
- children: [ tag ]
92
- };
158
+ return buildFormGroup({
159
+ wrapperClass,
160
+ help,
161
+ children: [tag]
162
+ });
93
163
 
94
164
  } else {
95
165
  return tag;
96
-
97
166
  }
98
167
 
99
168
  }
@@ -105,30 +174,44 @@ export function buildCheckboxTag({
105
174
  * @param {Object} args
106
175
  * @param {string} args.label - textarea label.
107
176
  * @param {string | null} args.name - textarea `name` attribute.
108
- * @param {string | number | null} args.defaultValue - textarea content.
177
+ * @param {string | number | null} args.value - textarea content.
109
178
  * @param {string | null} [args.wrapperClass=null] - optional class to be added to the `.form-group` wrapper.
110
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.
111
183
  * @returns {DomBuilderItem|null} The `textarea` domBuilder item, or `null` when `condition` is false.
112
184
  */
113
185
  export function buildTextareaTag({
114
186
  label,
115
187
  name,
116
- defaultValue,
188
+ value = null,
117
189
  wrapperClass = null,
118
- condition = true
190
+ condition = true,
191
+ help = null,
192
+ callback = null,
193
+ attrs = {}
119
194
  }) {
120
195
 
121
- if(!condition) {
122
- return null;
123
- }
124
-
125
196
  const id = randomId();
126
197
 
127
- return {
128
- className: classnames('form-group', wrapperClass),
198
+ return buildFormGroup({
199
+ condition,
200
+ wrapperClass,
201
+ help,
129
202
  children: [
130
203
  `label.form-label[for:${id}] ${label}`,
131
- `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
+ }
132
215
  ]
133
- };
216
+ });
134
217
  }