semantic-forms 5.0.1 → 5.0.3
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 +28 -25
- package/dist/semantic-forms.cjs +5 -5
- package/dist/semantic-forms.cjs.map +1 -1
- package/dist/semantic-forms.css +21 -2
- package/dist/semantic-forms.css.map +1 -1
- package/dist/semantic-forms.js +5 -5
- package/dist/semantic-forms.js.map +1 -1
- package/dist/semantic-forms.min.js +1 -1
- package/dist/semantic-forms.min.js.map +1 -1
- package/dist/semantic-forms.min.mjs +1 -1
- package/dist/semantic-forms.min.mjs.map +1 -1
- package/dist/semantic-forms.mjs +5 -5
- package/dist/semantic-forms.mjs.map +1 -1
- package/package.json +5 -5
- package/semanticForms.js +25 -9
- package/semanticForms.scss +23 -2
package/semanticForms.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
const semanticForms = () => {
|
|
2
2
|
// do some feature detection so none of the JS executes if the browser is too old
|
|
3
3
|
if (typeof document.getElementsByClassName !== 'function' || typeof document.querySelector !== 'function' || !document.body.classList || !window.MutationObserver) return
|
|
4
4
|
|
|
5
5
|
const passwordShow = '<svg fill="none" height="256" viewBox="0 0 24 24" width="256" xmlns="http://www.w3.org/2000/svg"><g stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m1 12s4-8 11-8 11 8 11 8"/><path d="m1 12s4 8 11 8 11-8 11-8"/><circle cx="12" cy="12" r="3"/></g></svg>'
|
|
6
6
|
const passwordHide = '<svg fill="none" height="256" viewBox="0 0 24 24" width="256" xmlns="http://www.w3.org/2000/svg"><g stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m2 2 20 20"/><path d="m6.71277 6.7226c-3.04798 2.07267-4.71277 5.2774-4.71277 5.2774s3.63636 7 10 7c2.0503 0 3.8174-.7266 5.2711-1.7116m-6.2711-12.23018c.3254-.03809.6588-.05822 1-.05822 6.3636 0 10 7 10 7s-.6918 1.3317-2 2.8335"/><path d="m14 14.2362c-.5308.475-1.2316.7639-2 .7639-1.6569 0-3-1.3431-3-3 0-.8237.33193-1.5698.86932-2.11192"/></g></svg>'
|
|
7
|
+
const helpTextIcon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="14px" height="14px" viewBox="0 0 16 16" version="1.1"><rect width="16" height="16" fill="none"/><path fill="currentColor" d="M8,10.5c-0.552,0-1,0.448-1,1c0,0.552,0.448,1,1,1c0.552,0,1-0.448,1-1C9,10.948,8.552,10.5,8,10.5z M8,0 C3.582,0,0,3.582,0,8c0,4.418,3.582,8,8,8s8-3.582,8-8C16,3.582,12.418,0,8,0z M12.243,12.243C11.109,13.376,9.603,14,8,14 s-3.109-0.624-4.243-1.757C2.624,11.109,2,9.603,2,8s0.624-3.109,1.757-4.243C4.891,2.624,6.397,2,8,2s3.109,0.624,4.243,1.757 C13.376,4.891,14,6.397,14,8C14,9.603,13.376,11.109,12.243,12.243z M7.927,3.755c-2.248,0-2.76,1.695-2.802,2.906h1.571 c0.028-0.256,0.101-1.418,1.221-1.418c0.672,0,1.206,0.406,1.206,1.175c0,0.695-0.724,1.155-1.303,1.711 C7.241,8.685,7.168,9.325,7.168,9.824V10c0.146,0,1.615,0,1.615,0V9.824c0-1.256,1.967-1.594,1.967-3.541 C10.75,5.059,9.874,3.755,7.927,3.755z"/></svg>'
|
|
7
8
|
|
|
8
9
|
const nodeNameLookup = ['TEXTAREA', 'SELECT']
|
|
9
10
|
const inputTypeLookup = ['checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'image', 'month', 'number', 'password', 'radio', 'range', 'search', 'tel', 'text', 'time', 'url', 'week']
|
|
@@ -37,6 +38,7 @@ module.exports = () => {
|
|
|
37
38
|
input.classList.add('semanticform')
|
|
38
39
|
|
|
39
40
|
// #region create labels
|
|
41
|
+
|
|
40
42
|
if (type === 'checkbox' || type === 'radio') {
|
|
41
43
|
// recursively find <dd> element
|
|
42
44
|
let dd = input.parentNode
|
|
@@ -56,9 +58,16 @@ module.exports = () => {
|
|
|
56
58
|
|
|
57
59
|
newLabel.innerHTML = label.innerHTML
|
|
58
60
|
|
|
59
|
-
if (
|
|
61
|
+
if (label.hasAttribute('title') && label.getAttribute('data-show-help-icon') !== null && !label.querySelector('span.help')) {
|
|
62
|
+
const text = label.getAttribute('title')
|
|
63
|
+
label.innerHTML += ` <span title="${text}" class="help">${helpTextIcon}</span>`
|
|
64
|
+
newLabel.innerHTML += ` <span title="${text}" class="help">${helpTextIcon}</span>`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (dd.querySelector(':required') && label.getAttribute('data-no-asterisk') === null && !label.querySelector('span.required')) {
|
|
60
68
|
const text = label.getAttribute('data-asterisk-text') || 'This field is required.'
|
|
61
|
-
label.innerHTML +=
|
|
69
|
+
label.innerHTML += ` <span title="${text}" class="required">*</span>`
|
|
70
|
+
newLabel.innerHTML += ` <span title="${text}" class="required">*</span>`
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
if (!dd.querySelector('label')) dd.append(newLabel)
|
|
@@ -77,9 +86,14 @@ module.exports = () => {
|
|
|
77
86
|
|
|
78
87
|
newLabel.innerHTML = label.innerHTML
|
|
79
88
|
|
|
80
|
-
if (input.hasAttribute('
|
|
89
|
+
if (input.hasAttribute('title') && label.getAttribute('data-show-help-icon') !== null && !label.querySelector('span.help')) {
|
|
90
|
+
const text = input.getAttribute('title')
|
|
91
|
+
newLabel.innerHTML += ` <span title="${text}" class="help">${helpTextIcon}</span>`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (input.hasAttribute('required') && label.getAttribute('data-no-asterisk') === null && !label.querySelector('span.required')) {
|
|
81
95
|
const text = label.getAttribute('data-asterisk-text') || 'This field is required.'
|
|
82
|
-
newLabel.innerHTML += ` <span title="${text}">*</span>`
|
|
96
|
+
newLabel.innerHTML += ` <span title="${text}" class="required">*</span>`
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
label.setAttribute('hidden', 'hidden')
|
|
@@ -235,8 +249,8 @@ module.exports = () => {
|
|
|
235
249
|
let stop = false
|
|
236
250
|
for (const mutation of mutations) {
|
|
237
251
|
for (const node of mutation.addedNodes) {
|
|
238
|
-
if (node.nodeName === 'FORM') {
|
|
239
|
-
|
|
252
|
+
if (node.nodeName === 'FORM' || node?.querySelector('form')) {
|
|
253
|
+
semanticForms()
|
|
240
254
|
stop = true
|
|
241
255
|
}
|
|
242
256
|
}
|
|
@@ -246,8 +260,10 @@ module.exports = () => {
|
|
|
246
260
|
window.semanticFormsObserver.observe(document.body, { attributes: false, childList: true, characterData: false, subtree: true })
|
|
247
261
|
}
|
|
248
262
|
|
|
249
|
-
|
|
263
|
+
semanticForms.reinitialize = (form) => {
|
|
250
264
|
form.classList.remove('semanticFormsActive')
|
|
251
|
-
|
|
265
|
+
semanticForms()
|
|
252
266
|
}
|
|
253
267
|
}
|
|
268
|
+
|
|
269
|
+
module.exports = semanticForms
|
package/semanticForms.scss
CHANGED
|
@@ -100,7 +100,7 @@ form.semanticForms {
|
|
|
100
100
|
input:not([type='submit'], [type='reset'], [type='image'], [type=checkbox], [type=radio]),
|
|
101
101
|
select,
|
|
102
102
|
textarea {
|
|
103
|
-
background: var(--nestedInput);
|
|
103
|
+
background-color: var(--nestedInput);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -360,6 +360,17 @@ form.semanticForms {
|
|
|
360
360
|
// shift text down to match center
|
|
361
361
|
padding-top: 2px;
|
|
362
362
|
font-size: var(--inputFontSize);
|
|
363
|
+
|
|
364
|
+
span.required {
|
|
365
|
+
cursor: help;
|
|
366
|
+
pointer-events: auto;
|
|
367
|
+
color: red;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
span.help {
|
|
371
|
+
cursor: help;
|
|
372
|
+
pointer-events: auto;
|
|
373
|
+
}
|
|
363
374
|
}
|
|
364
375
|
|
|
365
376
|
.floatLabelForm {
|
|
@@ -462,11 +473,16 @@ form.semanticForms {
|
|
|
462
473
|
color: var(--placeholderColor);
|
|
463
474
|
touch-action: manipulation;
|
|
464
475
|
|
|
465
|
-
span {
|
|
476
|
+
span.required {
|
|
466
477
|
cursor: help;
|
|
467
478
|
pointer-events: auto;
|
|
468
479
|
color: red;
|
|
469
480
|
}
|
|
481
|
+
|
|
482
|
+
span.help {
|
|
483
|
+
cursor: help;
|
|
484
|
+
pointer-events: auto;
|
|
485
|
+
}
|
|
470
486
|
}
|
|
471
487
|
}
|
|
472
488
|
|
|
@@ -482,6 +498,11 @@ form.semanticForms {
|
|
|
482
498
|
transform: translateY(-100%) scale(0.7);
|
|
483
499
|
top: var(--inputTopMargin);
|
|
484
500
|
left: 10px;
|
|
501
|
+
|
|
502
|
+
span.help {
|
|
503
|
+
cursor: help;
|
|
504
|
+
pointer-events: auto;
|
|
505
|
+
}
|
|
485
506
|
}
|
|
486
507
|
}
|
|
487
508
|
|