@3t-transform/threeteeui 0.2.97 → 0.2.98
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/dist/cjs/tttx-form.cjs.entry.js +97 -29
- package/dist/cjs/tttx-icon.cjs.entry.js +6 -1
- package/dist/cjs/tttx-standalone-input.cjs.entry.js +1 -1
- package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +6 -1
- package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +1 -1
- package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +8 -1
- package/dist/collection/components/molecules/tttx-form/lib/setErrorState.js +2 -0
- package/dist/collection/components/molecules/tttx-form/lib/validityCheck.js +10 -5
- package/dist/collection/components/molecules/tttx-form/tttx-form.css +7 -0
- package/dist/collection/components/molecules/tttx-form/tttx-form.js +84 -23
- package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +126 -3
- package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.css +7 -0
- package/dist/components/tttx-form.js +97 -29
- package/dist/components/tttx-icon2.js +6 -1
- package/dist/components/tttx-standalone-input2.js +1 -1
- package/dist/esm/tttx-form.entry.js +97 -29
- package/dist/esm/tttx-icon.entry.js +6 -1
- package/dist/esm/tttx-standalone-input.entry.js +1 -1
- package/dist/tttx/{p-93e63568.entry.js → p-6e0fac85.entry.js} +1 -1
- package/dist/tttx/p-73bb7a06.entry.js +1 -0
- package/dist/tttx/p-bcf3844e.entry.js +1 -0
- package/dist/tttx/tttx.esm.js +1 -1
- package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +10 -1
- package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +12 -0
- package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +110 -0
- package/package.json +2 -2
- package/dist/tttx/p-a94f7efc.entry.js +0 -1
- package/dist/tttx/p-feea36cb.entry.js +0 -1
|
@@ -38,6 +38,16 @@ function validityCheck(event) {
|
|
|
38
38
|
// target.setCustomValidity('custom error!');
|
|
39
39
|
// and cleared with
|
|
40
40
|
// target.setCustomValidity('');
|
|
41
|
+
//handle whitespace-only input
|
|
42
|
+
if (target.value.length && !target.value.replace(/\s/g, '').length) {
|
|
43
|
+
errorMessage = 'This field cannot be left blank';
|
|
44
|
+
target.setCustomValidity(errorMessage);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
errorMessage = '';
|
|
48
|
+
if (target.setCustomValidity) // tests are dumb as a brick
|
|
49
|
+
target.setCustomValidity('');
|
|
50
|
+
}
|
|
41
51
|
// Check the validity of the input field and set an error message if needed
|
|
42
52
|
switch (true) {
|
|
43
53
|
// The field is required, but has no value
|
|
@@ -65,11 +75,6 @@ function validityCheck(event) {
|
|
|
65
75
|
default:
|
|
66
76
|
hasError = false;
|
|
67
77
|
}
|
|
68
|
-
//handle whitespace-only input
|
|
69
|
-
if (!target.value.replace(/\s/g, '').length && target.value.length !== 0) {
|
|
70
|
-
errorMessage = 'Whitespace-only not allowed';
|
|
71
|
-
hasError = true;
|
|
72
|
-
}
|
|
73
78
|
// Return the error state
|
|
74
79
|
return { target, hasError, errorMessage };
|
|
75
80
|
}
|
|
@@ -99,6 +104,8 @@ function setErrorState(target, hasError, errorMessage, parent = undefined) {
|
|
|
99
104
|
errorBubble = target.parentElement.parentElement.querySelector('.errorBubble');
|
|
100
105
|
}
|
|
101
106
|
}
|
|
107
|
+
if (!errorBubble)
|
|
108
|
+
return;
|
|
102
109
|
// If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
|
|
103
110
|
if (hasError) {
|
|
104
111
|
target.classList.add('invalid');
|
|
@@ -122,7 +129,7 @@ function setErrorState(target, hasError, errorMessage, parent = undefined) {
|
|
|
122
129
|
}
|
|
123
130
|
}
|
|
124
131
|
|
|
125
|
-
const tttxFormCss = ".material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}label{font-weight:500;font-size:16px;line-height:19px;color:#212121}label .optional{color:#757575;font-weight:normal}label .outer-container{position:relative}label .outer-container .left-icons,label .outer-container .right-icons{display:flex;position:absolute;height:24px;gap:8px}label .outer-container .left-icons tttx-icon,label .outer-container .right-icons tttx-icon{height:24px;width:24px}label .outer-container .left-icons{left:8px}label .outer-container .right-icons{right:8px}label .outer-container input{color:#212121;box-sizing:border-box;border:1px solid #d5d5d5;border-radius:4px;padding:0;padding-left:16px;padding-right:16px;margin-top:4px;}label .outer-container input.has-input-icon{padding-left:40px}label .outer-container input.has-input-icon.has-left-icon{padding-left:72px}label .outer-container input.has-left-icon{padding-left:40px}label .outer-container input.has-right-icon{padding-right:40px}label .outer-container input.invalid{border:1px solid #dc0000}label .outer-container input:not([type=submit]){font-family:\"Roboto\", serif;width:100%;height:36px;font-size:16px;line-height:19px}label .outer-container input[type=date]{background:white;display:block;min-width:calc(100% - 18px);line-height:37px}label .outer-container input[readonly]{cursor:default;pointer-events:none;user-select:none;color:gray}label .outer-container input:focus{border-color:#1479c6}label .outer-container input:focus-visible{outline:none}label .outer-container.inputBlock{display:flex;align-items:center;line-height:21px}label .outer-container.inputBlock .left-icons,label .outer-container.inputBlock .right-icons{margin-top:4px}label .outer-container.inputBlock.readonly{pointer-events:none;user-select:none;color:gray}label .outer-container.inputInline{display:flex;white-space:nowrap;align-items:center;margin:0}label .outer-container.inputInline input{margin-top:0}label .secondarylabel{color:#757575;font-size:14px;line-height:16px;font-weight:normal;display:flex;margin-top:4px}label .errorBubble{position:relative;font-size:14px;line-height:16px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center;margin-top:4px}label .errorBubble:not(.visible){display:none}label .errorBubble span{color:#dc0000;font-size:16px;margin-right:4px}.material-symbols-rounded{font-family:\"Material Symbols Rounded\", sans-serif;font-weight:400;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;color:#9e9e9e}button{cursor:pointer}.button{font-family:Roboto, serif;box-sizing:border-box;height:36px;min-width:36px;padding:0;margin:0;background:transparent;color:#212121;border:1px solid #c8c8c8;border-radius:4px;text-transform:uppercase;display:flex;justify-content:left;align-items:center;font-size:14px;font-weight:500}.button-content{display:block;padding:0 16px}.icon-left,.icon-right{margin-top:4px}.iconleft{padding-left:8px}.iconleft .button-content{padding-left:4px}.iconright{padding-right:8px}.iconright .button-content{padding-right:4px}.notext{padding:0 6px}.button:active{background:rgba(17, 17, 17, 0.2);border:1px solid #d5d5d5}.primary{background:#1479c6;border:1px solid #1479c6;color:white}.primary:active{background:#1464a2;border:1px solid #1464a2}.borderless{background:transparent;border:none;color:#212121}.borderless:active{background:rgba(17, 17, 17, 0.2);border:none}.borderless-circle{background:transparent;border:none;color:#212121;border-radius:50%}.borderless-circle:active{border:none}.borderless-circle:focus{border-color:transparent}.danger{background:#dc0000;border:1px solid #dc0000;color:white}.danger:active{background:#b00000;border:1px solid #b00000}.disabled{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}.disabled:active{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}@media (hover: hover){.button:hover{background:rgba(17, 17, 17, 0.1);border:1px solid #d5d5d5}.primary:hover{background:#146eb3;border:1px solid #146eb3}.borderless:hover{background:rgba(17, 17, 17, 0.1);border:none}.borderless-circle:hover{background:rgba(17, 17, 17, 0.1);border:none}.danger:hover{background:#c60000;border:1px solid #c60000}.disabled:hover{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}}:host{display:block}fieldset{margin:0;padding:0;border:none}label{display:block;position:relative;margin-bottom:16px}.inlineLabel{font-weight:400;display:inline-block;vertical-align:top;padding-top:4px}input[type=checkbox]{width:18px;height:18px}input~label{font-weight:400}select{font-family:\"Roboto\", serif;box-sizing:border-box;width:100%;height:36px;padding:0 16px;font-size:16px;border:1px solid #d5d5d5;border-radius:4px;margin-top:4px}.placeholder{color:#9e9e9e}.placeholder option{color:initial}select.invalid:invalid{border:1px solid #dc0000}select~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center}select~.errorBubble:not(.visible){visibility:hidden}select~.errorBubble span{color:#dc0000;font-size:16px;margin-right:4px;height:16px}select.invalid:invalid~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;visibility:visible}select:focus{border-color:#1479c6}select:focus-visible{outline:none}.button{padding:0 16px}.footer{display:flex;gap:16px;flex-direction:row-reverse}";
|
|
132
|
+
const tttxFormCss = ".material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}label{font-weight:500;font-size:16px;line-height:19px;color:#212121}label .optional{color:#757575;font-weight:normal}label .outer-container{position:relative}label .outer-container .left-icons,label .outer-container .right-icons{display:flex;position:absolute;height:24px;gap:8px}label .outer-container .left-icons tttx-icon,label .outer-container .right-icons tttx-icon{height:24px;width:24px}label .outer-container .left-icons{left:8px}label .outer-container .right-icons{right:8px}label .outer-container input{color:#212121;box-sizing:border-box;border:1px solid #d5d5d5;border-radius:4px;padding:0;padding-left:16px;padding-right:16px;margin-top:4px;}label .outer-container input.has-input-icon{padding-left:40px}label .outer-container input.has-input-icon.has-left-icon{padding-left:72px}label .outer-container input.has-left-icon{padding-left:40px}label .outer-container input.has-right-icon{padding-right:40px}label .outer-container input.invalid{border:1px solid #dc0000}label .outer-container input:not([type=submit]){font-family:\"Roboto\", serif;width:100%;height:36px;font-size:16px;line-height:19px}label .outer-container input[type=radio]{width:20px;height:20px}label .outer-container input[type=date]{background:white;display:block;min-width:calc(100% - 18px);line-height:37px}label .outer-container input[readonly]{cursor:default;pointer-events:none;user-select:none;color:gray}label .outer-container input:focus{border-color:#1479c6}label .outer-container input:focus-visible{outline:none}label .outer-container.inputBlock{display:flex;align-items:center;line-height:21px}label .outer-container.inputBlock .left-icons,label .outer-container.inputBlock .right-icons{margin-top:4px}label .outer-container.inputBlock.readonly{pointer-events:none;user-select:none;color:gray}label .outer-container.inputBlock.radioBlock{display:block}label .outer-container.inputInline{display:flex;white-space:nowrap;align-items:center;margin:0}label .outer-container.inputInline input{margin-top:0}label .secondarylabel{color:#757575;font-size:14px;line-height:16px;font-weight:normal;display:flex;margin-top:4px}label .errorBubble{position:relative;font-size:14px;line-height:16px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center;margin-top:4px}label .errorBubble:not(.visible){display:none}label .errorBubble span{color:#dc0000;font-size:16px;margin-right:4px}.material-symbols-rounded{font-family:\"Material Symbols Rounded\", sans-serif;font-weight:400;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;color:#9e9e9e}button{cursor:pointer}.button{font-family:Roboto, serif;box-sizing:border-box;height:36px;min-width:36px;padding:0;margin:0;background:transparent;color:#212121;border:1px solid #c8c8c8;border-radius:4px;text-transform:uppercase;display:flex;justify-content:left;align-items:center;font-size:14px;font-weight:500}.button-content{display:block;padding:0 16px}.icon-left,.icon-right{margin-top:4px}.iconleft{padding-left:8px}.iconleft .button-content{padding-left:4px}.iconright{padding-right:8px}.iconright .button-content{padding-right:4px}.notext{padding:0 6px}.button:active{background:rgba(17, 17, 17, 0.2);border:1px solid #d5d5d5}.primary{background:#1479c6;border:1px solid #1479c6;color:white}.primary:active{background:#1464a2;border:1px solid #1464a2}.borderless{background:transparent;border:none;color:#212121}.borderless:active{background:rgba(17, 17, 17, 0.2);border:none}.borderless-circle{background:transparent;border:none;color:#212121;border-radius:50%}.borderless-circle:active{border:none}.borderless-circle:focus{border-color:transparent}.danger{background:#dc0000;border:1px solid #dc0000;color:white}.danger:active{background:#b00000;border:1px solid #b00000}.disabled{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}.disabled:active{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}@media (hover: hover){.button:hover{background:rgba(17, 17, 17, 0.1);border:1px solid #d5d5d5}.primary:hover{background:#146eb3;border:1px solid #146eb3}.borderless:hover{background:rgba(17, 17, 17, 0.1);border:none}.borderless-circle:hover{background:rgba(17, 17, 17, 0.1);border:none}.danger:hover{background:#c60000;border:1px solid #c60000}.disabled:hover{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}}:host{display:block}fieldset{margin:0;padding:0;border:none}label{display:block;position:relative;margin-bottom:16px}.inlineLabel{font-weight:400;display:inline-block;vertical-align:top;padding-top:4px}input[type=checkbox]{width:18px;height:18px}input~label{font-weight:400}select{font-family:\"Roboto\", serif;box-sizing:border-box;width:100%;height:36px;padding:0 16px;font-size:16px;border:1px solid #d5d5d5;border-radius:4px;margin-top:4px}.placeholder{color:#9e9e9e}.placeholder option{color:initial}select.invalid:invalid{border:1px solid #dc0000}select~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center}select~.errorBubble:not(.visible){visibility:hidden}select~.errorBubble span{color:#dc0000;font-size:16px;margin-right:4px;height:16px}select.invalid:invalid~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;visibility:visible}select:focus{border-color:#1479c6}select:focus-visible{outline:none}.button{padding:0 16px}.footer{display:flex;gap:16px;flex-direction:row-reverse}";
|
|
126
133
|
|
|
127
134
|
const TttxForm = class {
|
|
128
135
|
constructor(hostRef) {
|
|
@@ -379,17 +386,21 @@ const TttxForm = class {
|
|
|
379
386
|
*/
|
|
380
387
|
createLabel(formProperties, input, errorBubble) {
|
|
381
388
|
const outerContainer = document.createElement('div');
|
|
382
|
-
|
|
389
|
+
let outerContainerClassName = 'outer-container inputBlock';
|
|
383
390
|
// Create a new <label> element with the "inputBlock" class and the specified text
|
|
384
391
|
const label = document.createElement('label');
|
|
385
392
|
label.innerText = formProperties.label;
|
|
386
393
|
// If the form property has no validation object, add an "optional" span element to the label
|
|
387
|
-
if (!formProperties.validation) {
|
|
394
|
+
if (!formProperties.validation && formProperties.label) {
|
|
388
395
|
const optionalSpan = document.createElement('span');
|
|
389
396
|
optionalSpan.className = 'optional';
|
|
390
397
|
optionalSpan.innerHTML = ' (optional)';
|
|
391
398
|
label.appendChild(optionalSpan);
|
|
392
399
|
}
|
|
400
|
+
if (formProperties.type === 'radio') {
|
|
401
|
+
outerContainerClassName += ' radioBlock';
|
|
402
|
+
}
|
|
403
|
+
outerContainer.className = outerContainerClassName;
|
|
393
404
|
if (formProperties.readonly) {
|
|
394
405
|
label.classList.add('readonly');
|
|
395
406
|
}
|
|
@@ -407,6 +418,38 @@ const TttxForm = class {
|
|
|
407
418
|
// Return the label element
|
|
408
419
|
return label;
|
|
409
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Creates a new radio input with a set of options.
|
|
423
|
+
*
|
|
424
|
+
* @param {string} formKey - The name of the dropdown field, as specified in the form schema.
|
|
425
|
+
* @param {Object} formProperties - An object containing additional properties, such as the field type and options properties.
|
|
426
|
+
* @param {'radio'} formProperties.type - The type of form field. In this case, it will always be "radio".
|
|
427
|
+
* @param {Object} formProperties.validation - A set of validation rules for the field.
|
|
428
|
+
* @param {Object[]} formProperties.options - A list of properties to pass to the select options.
|
|
429
|
+
* @param {string} formProperties.options.label - The visible value of the option.
|
|
430
|
+
* @param {string} formProperties.options.value - The actual value of the option.
|
|
431
|
+
*/
|
|
432
|
+
createRadio(formKey, formProperties) {
|
|
433
|
+
var _a, _b;
|
|
434
|
+
const fragment = new DocumentFragment();
|
|
435
|
+
for (const optionProperties of formProperties.options) {
|
|
436
|
+
// Create a new <input> element with the specified name and type
|
|
437
|
+
const input = document.createElement('input');
|
|
438
|
+
input.type = 'radio';
|
|
439
|
+
input.name = formKey;
|
|
440
|
+
input.value = optionProperties.value;
|
|
441
|
+
if ((_a = formProperties === null || formProperties === void 0 ? void 0 : formProperties.validation) === null || _a === void 0 ? void 0 : _a.required) {
|
|
442
|
+
input.setAttribute('required', 'required');
|
|
443
|
+
input.setAttribute('data-required', (_b = formProperties.validation.required.message) !== null && _b !== void 0 ? _b : '');
|
|
444
|
+
}
|
|
445
|
+
const span = document.createElement('span');
|
|
446
|
+
span.innerText = optionProperties.label;
|
|
447
|
+
fragment.appendChild(input);
|
|
448
|
+
fragment.appendChild(span);
|
|
449
|
+
fragment.appendChild(document.createElement('br'));
|
|
450
|
+
}
|
|
451
|
+
return fragment;
|
|
452
|
+
}
|
|
410
453
|
/**
|
|
411
454
|
* Populates the form template with input fields and labels based on the properties of the
|
|
412
455
|
* current form schema. For each property in the schema, it creates an input element, applies
|
|
@@ -426,9 +469,19 @@ const TttxForm = class {
|
|
|
426
469
|
propertyKeys.forEach(formKey => {
|
|
427
470
|
const formItem = properties[formKey];
|
|
428
471
|
const formProperties = formItem.form;
|
|
429
|
-
|
|
472
|
+
let input;
|
|
473
|
+
switch (formProperties.type) {
|
|
474
|
+
case 'select':
|
|
475
|
+
input = this.createSelect(formKey, formProperties);
|
|
476
|
+
break;
|
|
477
|
+
case 'radio':
|
|
478
|
+
input = this.createRadio(formKey, formProperties);
|
|
479
|
+
break;
|
|
480
|
+
default:
|
|
481
|
+
input = this.createInput(formKey, formProperties);
|
|
482
|
+
}
|
|
430
483
|
// If the form property has validation, apply it to the input
|
|
431
|
-
if (formProperties.validation) {
|
|
484
|
+
if (formProperties.validation && formProperties.type !== 'radio') {
|
|
432
485
|
this.applyValidation(input, formProperties.validation);
|
|
433
486
|
}
|
|
434
487
|
// Create an error bubble and label element for the input
|
|
@@ -459,25 +512,40 @@ const TttxForm = class {
|
|
|
459
512
|
const propertyKeys = Object.keys(properties);
|
|
460
513
|
propertyKeys.forEach(formKey => {
|
|
461
514
|
var _a, _b;
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
515
|
+
const formInputs = formItems.querySelectorAll(`[name=${formKey}]`);
|
|
516
|
+
for (const formInput of formInputs) {
|
|
517
|
+
// Bind events to form input elements
|
|
518
|
+
formInput.oninvalid = this.validityCheckWrapper.bind(this);
|
|
519
|
+
formInput.onblur = this.validityCheckWrapper.bind(this);
|
|
520
|
+
formInput.onkeyup = this.fieldChanged.bind(this);
|
|
521
|
+
formInput.onchange = this.fieldChanged.bind(this);
|
|
522
|
+
if ((_a = this._data) === null || _a === void 0 ? void 0 : _a[formKey]) {
|
|
523
|
+
switch (formInput.type) {
|
|
524
|
+
case 'checkbox':
|
|
525
|
+
if (this._data[formKey] === 'on') {
|
|
526
|
+
formInput.checked = true;
|
|
527
|
+
}
|
|
528
|
+
break;
|
|
529
|
+
case 'radio':
|
|
530
|
+
if (formInput.value === this._data[formKey]) {
|
|
531
|
+
formInput.checked = true;
|
|
532
|
+
}
|
|
533
|
+
break;
|
|
534
|
+
default:
|
|
535
|
+
formInput.value = this._data[formKey];
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
// If explicitly setting input as invalid, set invalid state and error message on render
|
|
539
|
+
if ((_b = properties[formKey].form.validation) === null || _b === void 0 ? void 0 : _b.invalid) {
|
|
540
|
+
const errorMessage = properties[formKey].form.validation.invalid.message;
|
|
541
|
+
formInput.setCustomValidity(errorMessage); // Prevents the invalid styling from resetting on blur
|
|
542
|
+
setErrorState(formInput, true, errorMessage);
|
|
543
|
+
}
|
|
544
|
+
if (properties[formKey].form.type === 'select' && formInput.classList.contains('placeholder')) {
|
|
545
|
+
formInput.addEventListener('change', () => {
|
|
546
|
+
formInput.classList.remove('placeholder');
|
|
547
|
+
});
|
|
548
|
+
}
|
|
481
549
|
}
|
|
482
550
|
});
|
|
483
551
|
// Append the cloned form elements to the fieldset
|
|
@@ -13,7 +13,12 @@ const TttxIcon = class {
|
|
|
13
13
|
this.color = 'grey';
|
|
14
14
|
}
|
|
15
15
|
render() {
|
|
16
|
-
|
|
16
|
+
if (this.color.startsWith('#')) {
|
|
17
|
+
return (index.h(index.Host, null, index.h("span", { class: 'material-symbols-rounded', style: { color: this.color } }, this.icon)));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return (index.h(index.Host, null, index.h("span", { class: `material-symbols-rounded ${this.color}` }, this.icon)));
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
};
|
|
19
24
|
TttxIcon.style = tttxIconCss;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-992a9fb3.js');
|
|
6
6
|
|
|
7
|
-
const tttxStandaloneInputCss = ".material-symbols-rounded.sc-tttx-standalone-input{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded.sc-tttx-standalone-input{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}label.sc-tttx-standalone-input{font-weight:500;font-size:16px;line-height:19px;color:#212121}label.sc-tttx-standalone-input .optional.sc-tttx-standalone-input{color:#757575;font-weight:normal}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input{position:relative}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input,label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input{display:flex;position:absolute;height:24px;gap:8px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input tttx-icon.sc-tttx-standalone-input,label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input tttx-icon.sc-tttx-standalone-input{height:24px;width:24px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input{left:8px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input{right:8px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input{color:#212121;box-sizing:border-box;border:1px solid #d5d5d5;border-radius:4px;padding:0;padding-left:16px;padding-right:16px;margin-top:4px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-input-icon.sc-tttx-standalone-input{padding-left:40px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-input-icon.has-left-icon.sc-tttx-standalone-input{padding-left:72px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-left-icon.sc-tttx-standalone-input{padding-left:40px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-right-icon.sc-tttx-standalone-input{padding-right:40px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.invalid.sc-tttx-standalone-input{border:1px solid #dc0000}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input:not([type=submit]){font-family:\"Roboto\", serif;width:100%;height:36px;font-size:16px;line-height:19px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input[type=date].sc-tttx-standalone-input{background:white;display:block;min-width:calc(100% - 18px);line-height:37px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input[readonly].sc-tttx-standalone-input{cursor:default;pointer-events:none;user-select:none;color:gray}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input:focus{border-color:#1479c6}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input:focus-visible{outline:none}label.sc-tttx-standalone-input .outer-container.inputBlock.sc-tttx-standalone-input{display:flex;align-items:center;line-height:21px}label.sc-tttx-standalone-input .outer-container.inputBlock.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input,label.sc-tttx-standalone-input .outer-container.inputBlock.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input{margin-top:4px}label.sc-tttx-standalone-input .outer-container.inputBlock.readonly.sc-tttx-standalone-input{pointer-events:none;user-select:none;color:gray}label.sc-tttx-standalone-input .outer-container.inputInline.sc-tttx-standalone-input{display:flex;white-space:nowrap;align-items:center;margin:0}label.sc-tttx-standalone-input .outer-container.inputInline.sc-tttx-standalone-input input.sc-tttx-standalone-input{margin-top:0}label.sc-tttx-standalone-input .secondarylabel.sc-tttx-standalone-input{color:#757575;font-size:14px;line-height:16px;font-weight:normal;display:flex;margin-top:4px}label.sc-tttx-standalone-input .errorBubble.sc-tttx-standalone-input{position:relative;font-size:14px;line-height:16px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center;margin-top:4px}label.sc-tttx-standalone-input .errorBubble.sc-tttx-standalone-input:not(.visible){display:none}label.sc-tttx-standalone-input .errorBubble.sc-tttx-standalone-input span.sc-tttx-standalone-input{color:#dc0000;font-size:16px;margin-right:4px}.material-symbols-rounded.sc-tttx-standalone-input{font-family:\"Material Symbols Rounded\", sans-serif;font-weight:400;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;color:#9e9e9e}.sc-tttx-standalone-input-h{display:block}";
|
|
7
|
+
const tttxStandaloneInputCss = ".material-symbols-rounded.sc-tttx-standalone-input{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded.sc-tttx-standalone-input{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}label.sc-tttx-standalone-input{font-weight:500;font-size:16px;line-height:19px;color:#212121}label.sc-tttx-standalone-input .optional.sc-tttx-standalone-input{color:#757575;font-weight:normal}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input{position:relative}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input,label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input{display:flex;position:absolute;height:24px;gap:8px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input tttx-icon.sc-tttx-standalone-input,label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input tttx-icon.sc-tttx-standalone-input{height:24px;width:24px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input{left:8px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input{right:8px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input{color:#212121;box-sizing:border-box;border:1px solid #d5d5d5;border-radius:4px;padding:0;padding-left:16px;padding-right:16px;margin-top:4px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-input-icon.sc-tttx-standalone-input{padding-left:40px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-input-icon.has-left-icon.sc-tttx-standalone-input{padding-left:72px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-left-icon.sc-tttx-standalone-input{padding-left:40px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.has-right-icon.sc-tttx-standalone-input{padding-right:40px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.invalid.sc-tttx-standalone-input{border:1px solid #dc0000}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input:not([type=submit]){font-family:\"Roboto\", serif;width:100%;height:36px;font-size:16px;line-height:19px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input[type=radio].sc-tttx-standalone-input{width:20px;height:20px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input[type=date].sc-tttx-standalone-input{background:white;display:block;min-width:calc(100% - 18px);line-height:37px}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input[readonly].sc-tttx-standalone-input{cursor:default;pointer-events:none;user-select:none;color:gray}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input:focus{border-color:#1479c6}label.sc-tttx-standalone-input .outer-container.sc-tttx-standalone-input input.sc-tttx-standalone-input:focus-visible{outline:none}label.sc-tttx-standalone-input .outer-container.inputBlock.sc-tttx-standalone-input{display:flex;align-items:center;line-height:21px}label.sc-tttx-standalone-input .outer-container.inputBlock.sc-tttx-standalone-input .left-icons.sc-tttx-standalone-input,label.sc-tttx-standalone-input .outer-container.inputBlock.sc-tttx-standalone-input .right-icons.sc-tttx-standalone-input{margin-top:4px}label.sc-tttx-standalone-input .outer-container.inputBlock.readonly.sc-tttx-standalone-input{pointer-events:none;user-select:none;color:gray}label.sc-tttx-standalone-input .outer-container.inputBlock.radioBlock.sc-tttx-standalone-input{display:block}label.sc-tttx-standalone-input .outer-container.inputInline.sc-tttx-standalone-input{display:flex;white-space:nowrap;align-items:center;margin:0}label.sc-tttx-standalone-input .outer-container.inputInline.sc-tttx-standalone-input input.sc-tttx-standalone-input{margin-top:0}label.sc-tttx-standalone-input .secondarylabel.sc-tttx-standalone-input{color:#757575;font-size:14px;line-height:16px;font-weight:normal;display:flex;margin-top:4px}label.sc-tttx-standalone-input .errorBubble.sc-tttx-standalone-input{position:relative;font-size:14px;line-height:16px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center;margin-top:4px}label.sc-tttx-standalone-input .errorBubble.sc-tttx-standalone-input:not(.visible){display:none}label.sc-tttx-standalone-input .errorBubble.sc-tttx-standalone-input span.sc-tttx-standalone-input{color:#dc0000;font-size:16px;margin-right:4px}.material-symbols-rounded.sc-tttx-standalone-input{font-family:\"Material Symbols Rounded\", sans-serif;font-weight:400;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;color:#9e9e9e}.sc-tttx-standalone-input-h{display:block}";
|
|
8
8
|
|
|
9
9
|
const TttxInput = class {
|
|
10
10
|
constructor(hostRef) {
|
|
@@ -5,7 +5,12 @@ export class TttxIcon {
|
|
|
5
5
|
this.color = 'grey';
|
|
6
6
|
}
|
|
7
7
|
render() {
|
|
8
|
-
|
|
8
|
+
if (this.color.startsWith('#')) {
|
|
9
|
+
return (h(Host, null, h("span", { class: 'material-symbols-rounded', style: { color: this.color } }, this.icon)));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return (h(Host, null, h("span", { class: `material-symbols-rounded ${this.color}` }, this.icon)));
|
|
13
|
+
}
|
|
9
14
|
}
|
|
10
15
|
static get is() { return "tttx-icon"; }
|
|
11
16
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import icons from './../../../icons';
|
|
2
|
-
const colors = ['red', 'blue', 'black', 'white', 'gray', 'green', 'orange', 'darkred'];
|
|
2
|
+
const colors = ['red', 'blue', 'black', 'white', 'gray', 'green', 'orange', 'darkred', '#397A4C', '#FF00BB'];
|
|
3
3
|
export default {
|
|
4
4
|
title: 'Atoms/Icons',
|
|
5
5
|
component: 'tttx-icon',
|
package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js
CHANGED
|
@@ -13,5 +13,12 @@ export default {
|
|
|
13
13
|
};
|
|
14
14
|
export const Example = args => {
|
|
15
15
|
const size = args.size || 'large';
|
|
16
|
-
return `<tttx-loading-spinner ${args.loadingMessage ? 'loading-message' : ''} size='${size}' />`;
|
|
16
|
+
return `<tttx-loading-spinner data-chromatic="ignore" ${args.loadingMessage ? 'loading-message' : ''} size='${size}' />`;
|
|
17
|
+
};
|
|
18
|
+
Example.parameters = {
|
|
19
|
+
chromatic: {
|
|
20
|
+
pauseAnimationAtEnd: true,
|
|
21
|
+
delay: 5000,
|
|
22
|
+
disableSnapshot: true
|
|
23
|
+
},
|
|
17
24
|
};
|
|
@@ -23,6 +23,8 @@ function setErrorState(target, hasError, errorMessage, parent = undefined) {
|
|
|
23
23
|
errorBubble = target.parentElement.parentElement.querySelector('.errorBubble');
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
if (!errorBubble)
|
|
27
|
+
return;
|
|
26
28
|
// If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
|
|
27
29
|
if (hasError) {
|
|
28
30
|
target.classList.add('invalid');
|
|
@@ -30,6 +30,16 @@ function validityCheck(event) {
|
|
|
30
30
|
// target.setCustomValidity('custom error!');
|
|
31
31
|
// and cleared with
|
|
32
32
|
// target.setCustomValidity('');
|
|
33
|
+
//handle whitespace-only input
|
|
34
|
+
if (target.value.length && !target.value.replace(/\s/g, '').length) {
|
|
35
|
+
errorMessage = 'This field cannot be left blank';
|
|
36
|
+
target.setCustomValidity(errorMessage);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
errorMessage = '';
|
|
40
|
+
if (target.setCustomValidity) // tests are dumb as a brick
|
|
41
|
+
target.setCustomValidity('');
|
|
42
|
+
}
|
|
33
43
|
// Check the validity of the input field and set an error message if needed
|
|
34
44
|
switch (true) {
|
|
35
45
|
// The field is required, but has no value
|
|
@@ -57,11 +67,6 @@ function validityCheck(event) {
|
|
|
57
67
|
default:
|
|
58
68
|
hasError = false;
|
|
59
69
|
}
|
|
60
|
-
//handle whitespace-only input
|
|
61
|
-
if (!target.value.replace(/\s/g, '').length && target.value.length !== 0) {
|
|
62
|
-
errorMessage = 'Whitespace-only not allowed';
|
|
63
|
-
hasError = true;
|
|
64
|
-
}
|
|
65
70
|
// Return the error state
|
|
66
71
|
return { target, hasError, errorMessage };
|
|
67
72
|
}
|
|
@@ -70,6 +70,10 @@ label .outer-container input:not([type=submit]) {
|
|
|
70
70
|
font-size: 16px;
|
|
71
71
|
line-height: 19px;
|
|
72
72
|
}
|
|
73
|
+
label .outer-container input[type=radio] {
|
|
74
|
+
width: 20px;
|
|
75
|
+
height: 20px;
|
|
76
|
+
}
|
|
73
77
|
label .outer-container input[type=date] {
|
|
74
78
|
background: white;
|
|
75
79
|
display: block;
|
|
@@ -102,6 +106,9 @@ label .outer-container.inputBlock.readonly {
|
|
|
102
106
|
user-select: none;
|
|
103
107
|
color: gray;
|
|
104
108
|
}
|
|
109
|
+
label .outer-container.inputBlock.radioBlock {
|
|
110
|
+
display: block;
|
|
111
|
+
}
|
|
105
112
|
label .outer-container.inputInline {
|
|
106
113
|
display: flex;
|
|
107
114
|
white-space: nowrap;
|
|
@@ -258,17 +258,21 @@ export class TttxForm {
|
|
|
258
258
|
*/
|
|
259
259
|
createLabel(formProperties, input, errorBubble) {
|
|
260
260
|
const outerContainer = document.createElement('div');
|
|
261
|
-
|
|
261
|
+
let outerContainerClassName = 'outer-container inputBlock';
|
|
262
262
|
// Create a new <label> element with the "inputBlock" class and the specified text
|
|
263
263
|
const label = document.createElement('label');
|
|
264
264
|
label.innerText = formProperties.label;
|
|
265
265
|
// If the form property has no validation object, add an "optional" span element to the label
|
|
266
|
-
if (!formProperties.validation) {
|
|
266
|
+
if (!formProperties.validation && formProperties.label) {
|
|
267
267
|
const optionalSpan = document.createElement('span');
|
|
268
268
|
optionalSpan.className = 'optional';
|
|
269
269
|
optionalSpan.innerHTML = ' (optional)';
|
|
270
270
|
label.appendChild(optionalSpan);
|
|
271
271
|
}
|
|
272
|
+
if (formProperties.type === 'radio') {
|
|
273
|
+
outerContainerClassName += ' radioBlock';
|
|
274
|
+
}
|
|
275
|
+
outerContainer.className = outerContainerClassName;
|
|
272
276
|
if (formProperties.readonly) {
|
|
273
277
|
label.classList.add('readonly');
|
|
274
278
|
}
|
|
@@ -286,6 +290,38 @@ export class TttxForm {
|
|
|
286
290
|
// Return the label element
|
|
287
291
|
return label;
|
|
288
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Creates a new radio input with a set of options.
|
|
295
|
+
*
|
|
296
|
+
* @param {string} formKey - The name of the dropdown field, as specified in the form schema.
|
|
297
|
+
* @param {Object} formProperties - An object containing additional properties, such as the field type and options properties.
|
|
298
|
+
* @param {'radio'} formProperties.type - The type of form field. In this case, it will always be "radio".
|
|
299
|
+
* @param {Object} formProperties.validation - A set of validation rules for the field.
|
|
300
|
+
* @param {Object[]} formProperties.options - A list of properties to pass to the select options.
|
|
301
|
+
* @param {string} formProperties.options.label - The visible value of the option.
|
|
302
|
+
* @param {string} formProperties.options.value - The actual value of the option.
|
|
303
|
+
*/
|
|
304
|
+
createRadio(formKey, formProperties) {
|
|
305
|
+
var _a, _b;
|
|
306
|
+
const fragment = new DocumentFragment();
|
|
307
|
+
for (const optionProperties of formProperties.options) {
|
|
308
|
+
// Create a new <input> element with the specified name and type
|
|
309
|
+
const input = document.createElement('input');
|
|
310
|
+
input.type = 'radio';
|
|
311
|
+
input.name = formKey;
|
|
312
|
+
input.value = optionProperties.value;
|
|
313
|
+
if ((_a = formProperties === null || formProperties === void 0 ? void 0 : formProperties.validation) === null || _a === void 0 ? void 0 : _a.required) {
|
|
314
|
+
input.setAttribute('required', 'required');
|
|
315
|
+
input.setAttribute('data-required', (_b = formProperties.validation.required.message) !== null && _b !== void 0 ? _b : '');
|
|
316
|
+
}
|
|
317
|
+
const span = document.createElement('span');
|
|
318
|
+
span.innerText = optionProperties.label;
|
|
319
|
+
fragment.appendChild(input);
|
|
320
|
+
fragment.appendChild(span);
|
|
321
|
+
fragment.appendChild(document.createElement('br'));
|
|
322
|
+
}
|
|
323
|
+
return fragment;
|
|
324
|
+
}
|
|
289
325
|
/**
|
|
290
326
|
* Populates the form template with input fields and labels based on the properties of the
|
|
291
327
|
* current form schema. For each property in the schema, it creates an input element, applies
|
|
@@ -305,9 +341,19 @@ export class TttxForm {
|
|
|
305
341
|
propertyKeys.forEach(formKey => {
|
|
306
342
|
const formItem = properties[formKey];
|
|
307
343
|
const formProperties = formItem.form;
|
|
308
|
-
|
|
344
|
+
let input;
|
|
345
|
+
switch (formProperties.type) {
|
|
346
|
+
case 'select':
|
|
347
|
+
input = this.createSelect(formKey, formProperties);
|
|
348
|
+
break;
|
|
349
|
+
case 'radio':
|
|
350
|
+
input = this.createRadio(formKey, formProperties);
|
|
351
|
+
break;
|
|
352
|
+
default:
|
|
353
|
+
input = this.createInput(formKey, formProperties);
|
|
354
|
+
}
|
|
309
355
|
// If the form property has validation, apply it to the input
|
|
310
|
-
if (formProperties.validation) {
|
|
356
|
+
if (formProperties.validation && formProperties.type !== 'radio') {
|
|
311
357
|
this.applyValidation(input, formProperties.validation);
|
|
312
358
|
}
|
|
313
359
|
// Create an error bubble and label element for the input
|
|
@@ -338,25 +384,40 @@ export class TttxForm {
|
|
|
338
384
|
const propertyKeys = Object.keys(properties);
|
|
339
385
|
propertyKeys.forEach(formKey => {
|
|
340
386
|
var _a, _b;
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
387
|
+
const formInputs = formItems.querySelectorAll(`[name=${formKey}]`);
|
|
388
|
+
for (const formInput of formInputs) {
|
|
389
|
+
// Bind events to form input elements
|
|
390
|
+
formInput.oninvalid = this.validityCheckWrapper.bind(this);
|
|
391
|
+
formInput.onblur = this.validityCheckWrapper.bind(this);
|
|
392
|
+
formInput.onkeyup = this.fieldChanged.bind(this);
|
|
393
|
+
formInput.onchange = this.fieldChanged.bind(this);
|
|
394
|
+
if ((_a = this._data) === null || _a === void 0 ? void 0 : _a[formKey]) {
|
|
395
|
+
switch (formInput.type) {
|
|
396
|
+
case 'checkbox':
|
|
397
|
+
if (this._data[formKey] === 'on') {
|
|
398
|
+
formInput.checked = true;
|
|
399
|
+
}
|
|
400
|
+
break;
|
|
401
|
+
case 'radio':
|
|
402
|
+
if (formInput.value === this._data[formKey]) {
|
|
403
|
+
formInput.checked = true;
|
|
404
|
+
}
|
|
405
|
+
break;
|
|
406
|
+
default:
|
|
407
|
+
formInput.value = this._data[formKey];
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
// If explicitly setting input as invalid, set invalid state and error message on render
|
|
411
|
+
if ((_b = properties[formKey].form.validation) === null || _b === void 0 ? void 0 : _b.invalid) {
|
|
412
|
+
const errorMessage = properties[formKey].form.validation.invalid.message;
|
|
413
|
+
formInput.setCustomValidity(errorMessage); // Prevents the invalid styling from resetting on blur
|
|
414
|
+
setErrorState(formInput, true, errorMessage);
|
|
415
|
+
}
|
|
416
|
+
if (properties[formKey].form.type === 'select' && formInput.classList.contains('placeholder')) {
|
|
417
|
+
formInput.addEventListener('change', () => {
|
|
418
|
+
formInput.classList.remove('placeholder');
|
|
419
|
+
});
|
|
420
|
+
}
|
|
360
421
|
}
|
|
361
422
|
});
|
|
362
423
|
// Append the cloned form elements to the fieldset
|
|
@@ -110,9 +110,9 @@ const formSchema = {
|
|
|
110
110
|
label: 'Food category',
|
|
111
111
|
options: [
|
|
112
112
|
{ label: 'Choose an option', value: '', placeholder: true },
|
|
113
|
-
{ label: 'Poultry', value: '
|
|
114
|
-
{ label: 'Fish', value: '
|
|
115
|
-
{ label: 'Veg', value: '
|
|
113
|
+
{ label: 'Poultry', value: 'chicken' },
|
|
114
|
+
{ label: 'Fish', value: 'salmon' },
|
|
115
|
+
{ label: 'Veg', value: 'lettuce' },
|
|
116
116
|
],
|
|
117
117
|
validation: {
|
|
118
118
|
required: {
|
|
@@ -271,6 +271,52 @@ const formSchemaWithReadonly = {
|
|
|
271
271
|
},
|
|
272
272
|
},
|
|
273
273
|
},
|
|
274
|
+
dropdown: {
|
|
275
|
+
form: {
|
|
276
|
+
type: 'select',
|
|
277
|
+
blankDefault: true,
|
|
278
|
+
label: 'Food category',
|
|
279
|
+
options: [
|
|
280
|
+
{ label: 'Choose an option', value: '', placeholder: true },
|
|
281
|
+
{ label: 'Poultry', value: 'chicken' },
|
|
282
|
+
{ label: 'Fish', value: 'salmon' },
|
|
283
|
+
{ label: 'Veg', value: 'lettuce' },
|
|
284
|
+
],
|
|
285
|
+
validation: {
|
|
286
|
+
required: {
|
|
287
|
+
message: 'Must select a value',
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
permissions: {
|
|
293
|
+
form: {
|
|
294
|
+
type: 'checkbox',
|
|
295
|
+
label: 'Permissions',
|
|
296
|
+
inlineLabel: 'Please grant permissions to use data',
|
|
297
|
+
validation: {
|
|
298
|
+
required: {
|
|
299
|
+
message: 'Please grant permissions to use data',
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
expiration: {
|
|
305
|
+
type: 'radio',
|
|
306
|
+
form: {
|
|
307
|
+
type: 'radio',
|
|
308
|
+
label: 'Expiration',
|
|
309
|
+
options: [
|
|
310
|
+
{ label: 'Never expires', value: 'neverExpires' },
|
|
311
|
+
{ label: 'Will expire', value: 'willExpire' },
|
|
312
|
+
],
|
|
313
|
+
validation: {
|
|
314
|
+
required: {
|
|
315
|
+
message: 'Please select validity',
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
274
320
|
},
|
|
275
321
|
};
|
|
276
322
|
const data = {
|
|
@@ -280,6 +326,9 @@ const data = {
|
|
|
280
326
|
postcode: 'AB10',
|
|
281
327
|
age: '50',
|
|
282
328
|
dob: '1973-06-02',
|
|
329
|
+
dropdown: 'chicken',
|
|
330
|
+
permissions: 'on',
|
|
331
|
+
expiration: 'willExpire'
|
|
283
332
|
};
|
|
284
333
|
export const PrePopulateForm = args => `<tttx-form id='form' formSchema='${JSON.stringify(args.formSchema)}' data='${JSON.stringify(args.data)}'></tttx-form>
|
|
285
334
|
<hr/>
|
|
@@ -302,3 +351,77 @@ PrePopulateForm.args = {
|
|
|
302
351
|
data,
|
|
303
352
|
formSchema: formSchemaWithReadonly,
|
|
304
353
|
};
|
|
354
|
+
const radioFormSchema = {
|
|
355
|
+
properties: {
|
|
356
|
+
name: {
|
|
357
|
+
type: 'string',
|
|
358
|
+
format: 'string',
|
|
359
|
+
form: {
|
|
360
|
+
type: 'text',
|
|
361
|
+
placeholder: 'Enter a name',
|
|
362
|
+
label: 'Name',
|
|
363
|
+
validation: {
|
|
364
|
+
required: {
|
|
365
|
+
message: 'Please enter name',
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
requiresEvidence: {
|
|
371
|
+
type: 'checkbox',
|
|
372
|
+
form: {
|
|
373
|
+
type: 'checkbox',
|
|
374
|
+
label: '',
|
|
375
|
+
inlineLabel: 'Requires Evidence',
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
validity: {
|
|
379
|
+
type: 'radio',
|
|
380
|
+
form: {
|
|
381
|
+
type: 'radio',
|
|
382
|
+
label: 'Validity',
|
|
383
|
+
options: [
|
|
384
|
+
{ label: 'Never expires', value: 'neverExpires' },
|
|
385
|
+
{ label: 'Validity duration', value: 'validityDuration' },
|
|
386
|
+
],
|
|
387
|
+
validation: {
|
|
388
|
+
required: {
|
|
389
|
+
message: 'Please select validity',
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
option2: {
|
|
395
|
+
type: 'radio',
|
|
396
|
+
form: {
|
|
397
|
+
type: 'radio',
|
|
398
|
+
label: 'Option 2',
|
|
399
|
+
options: [
|
|
400
|
+
{ label: 'Opt 2a', value: 'opt2a' },
|
|
401
|
+
{ label: 'Opt 2b', value: 'opt2b' },
|
|
402
|
+
{ label: 'Opt 2c', value: 'opt2c' },
|
|
403
|
+
],
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
export const FormWithRadio = args => `<tttx-form id='form' formSchema='${JSON.stringify(args.formSchema)}'></tttx-form>
|
|
409
|
+
<hr/>
|
|
410
|
+
<button type='button' id='button'>Submit Form</button>
|
|
411
|
+
<script>
|
|
412
|
+
if (window['tttxform'] === undefined && window['submitButton'] === undefined) {
|
|
413
|
+
let tttxform = document.getElementById('form');
|
|
414
|
+
tttxform.addEventListener('dataSubmitted', (event) => {
|
|
415
|
+
for(var entry of event.detail.entries()) {
|
|
416
|
+
console.log(entry[0], entry[1]);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
let submitButton = document.getElementById('button');
|
|
420
|
+
submitButton.onclick = () => {
|
|
421
|
+
tttxform.submit();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
</script>`;
|
|
425
|
+
FormWithRadio.args = {
|
|
426
|
+
formSchema: radioFormSchema,
|
|
427
|
+
};
|