@3t-transform/threeteeui 0.2.107 → 0.2.108
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-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/tttx-form.cjs.entry.js +184 -28
- package/dist/collection/components/atoms/tttx-checkbox/tttx-checkbox.js +1 -1
- package/dist/collection/components/molecules/tttx-form/lib/validityCheck.js +3 -1
- package/dist/collection/components/molecules/tttx-form/tttx-form.css +19 -0
- package/dist/collection/components/molecules/tttx-form/tttx-form.js +180 -26
- package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +64 -10
- package/dist/components/tttx-checkbox.js +1 -1
- package/dist/components/tttx-form.js +184 -28
- package/dist/esm/tttx-checkbox.entry.js +1 -1
- package/dist/esm/tttx-form.entry.js +184 -28
- package/dist/tttx/{p-61ef7773.entry.js → p-69e15a92.entry.js} +1 -1
- package/dist/tttx/p-91cf9bd4.entry.js +1 -0
- package/dist/tttx/tttx.esm.js +1 -1
- package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +14 -0
- package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +64 -8
- package/package.json +4 -4
- package/dist/tttx/p-b2cfa283.entry.js +0 -1
|
@@ -12,7 +12,9 @@ import './_commonjsHelpers-9943807e.js';
|
|
|
12
12
|
*/
|
|
13
13
|
function validityCheck(event) {
|
|
14
14
|
var _a, _b, _c, _d;
|
|
15
|
-
event.preventDefault
|
|
15
|
+
if (event.preventDefault) {
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
}
|
|
16
18
|
const target = event.target;
|
|
17
19
|
let hasError = true;
|
|
18
20
|
let errorMessage = '';
|
|
@@ -125,7 +127,7 @@ function setErrorState(target, hasError, errorMessage, parent = undefined) {
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
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}";
|
|
130
|
+
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}label.flex-label{display:flex;flex-direction:column;width:300px;box-sizing:border-box}label.flex-label input[type=date]{flex-grow:1;min-width:auto}label.flex-label input[type=time]{min-width:auto;text-align:center;width:180px;margin-left:16px}";
|
|
129
131
|
|
|
130
132
|
const TttxForm = class {
|
|
131
133
|
constructor(hostRef) {
|
|
@@ -295,6 +297,59 @@ const TttxForm = class {
|
|
|
295
297
|
// Return the input element
|
|
296
298
|
return input;
|
|
297
299
|
}
|
|
300
|
+
createStartEndDateComponent(formKey, formProperties) {
|
|
301
|
+
const startDate = document.createElement('input');
|
|
302
|
+
const endDate = document.createElement('input');
|
|
303
|
+
startDate.type = endDate.type = 'date';
|
|
304
|
+
startDate.name = `${formKey}-startdate`;
|
|
305
|
+
endDate.name = `${formKey}-enddate`;
|
|
306
|
+
startDate.setAttribute('data-formkey', formKey);
|
|
307
|
+
endDate.setAttribute('data-formkey', formKey);
|
|
308
|
+
if (formProperties.readonly) {
|
|
309
|
+
startDate.readOnly = true;
|
|
310
|
+
endDate.readOnly = true;
|
|
311
|
+
}
|
|
312
|
+
this.applyValidation(startDate, { required: { message: 'Please enter a start date' }, dateCompare: { to: endDate.name } });
|
|
313
|
+
this.applyValidation(endDate, { required: { message: 'Please enter an end date' }, dateCompare: { with: startDate.name, message: 'End date cannot be before the start date' } });
|
|
314
|
+
let startTime;
|
|
315
|
+
let endTime;
|
|
316
|
+
if (formProperties.includeTime) {
|
|
317
|
+
startTime = document.createElement('input');
|
|
318
|
+
endTime = document.createElement('input');
|
|
319
|
+
startTime.type = endTime.type = 'time';
|
|
320
|
+
startTime.name = `${formKey}-starttime`;
|
|
321
|
+
endTime.name = `${formKey}-endtime`;
|
|
322
|
+
startTime.setAttribute('data-formkey', formKey);
|
|
323
|
+
endTime.setAttribute('data-formkey', formKey);
|
|
324
|
+
if (formProperties.readonly) {
|
|
325
|
+
startTime.readOnly = true;
|
|
326
|
+
endTime.readOnly = true;
|
|
327
|
+
}
|
|
328
|
+
this.applyValidation(startTime, { required: { message: 'Please enter a start time' } });
|
|
329
|
+
this.applyValidation(endTime, { required: { message: 'Please enter an end time' } });
|
|
330
|
+
}
|
|
331
|
+
const startLabel = document.createElement('label');
|
|
332
|
+
startLabel.innerText = 'Start date';
|
|
333
|
+
const endLabel = document.createElement('label');
|
|
334
|
+
endLabel.innerText = 'End date';
|
|
335
|
+
const startContainer = document.createElement('div');
|
|
336
|
+
const endContainer = document.createElement('div');
|
|
337
|
+
startContainer.className = endContainer.className = 'outer-container inputBlock';
|
|
338
|
+
startLabel.className = endLabel.className = 'flex-label';
|
|
339
|
+
startContainer.append(startDate);
|
|
340
|
+
if (startTime) {
|
|
341
|
+
startContainer.append(startTime);
|
|
342
|
+
}
|
|
343
|
+
startLabel.append(startContainer);
|
|
344
|
+
startLabel.append(this.createErrorBubble());
|
|
345
|
+
endContainer.append(endDate);
|
|
346
|
+
if (endTime) {
|
|
347
|
+
endContainer.append(endTime);
|
|
348
|
+
}
|
|
349
|
+
endLabel.append(endContainer);
|
|
350
|
+
endLabel.append(this.createErrorBubble());
|
|
351
|
+
return { start: startLabel, end: endLabel };
|
|
352
|
+
}
|
|
298
353
|
/**
|
|
299
354
|
* Applies validation attributes to an input element based on the specified validation object.
|
|
300
355
|
* If a certain property is present in the object, it will set the corresponding attribute on
|
|
@@ -315,6 +370,7 @@ const TttxForm = class {
|
|
|
315
370
|
* @param {string} [validation.minmax.max]
|
|
316
371
|
* @param {string} [validation.minmax.message]
|
|
317
372
|
* @param {string} [validation.maxlength] - The maximum length of the input field.
|
|
373
|
+
* @param {string} [validation.datecompare] - To compare start and end date fields.
|
|
318
374
|
* @return {void}
|
|
319
375
|
*/
|
|
320
376
|
applyValidation(input, validation) {
|
|
@@ -347,6 +403,16 @@ const TttxForm = class {
|
|
|
347
403
|
if (validation.maxlength) {
|
|
348
404
|
input.setAttribute('maxlength', validation.maxlength);
|
|
349
405
|
}
|
|
406
|
+
// Custom validation parameters for start date and end date comparison
|
|
407
|
+
if (validation.dateCompare) {
|
|
408
|
+
if (validation.dateCompare.message && validation.dateCompare.with) {
|
|
409
|
+
input.setAttribute('data-compare', validation.dateCompare.message);
|
|
410
|
+
input.setAttribute('data-compare-with', validation.dateCompare.with);
|
|
411
|
+
}
|
|
412
|
+
if (validation.dateCompare.to) {
|
|
413
|
+
input.setAttribute('data-compare-to', validation.dateCompare.to);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
350
416
|
}
|
|
351
417
|
// Create a new error bubble element
|
|
352
418
|
createErrorBubble() {
|
|
@@ -463,6 +529,7 @@ const TttxForm = class {
|
|
|
463
529
|
* @return {void}
|
|
464
530
|
*/
|
|
465
531
|
populateFormFromSchema() {
|
|
532
|
+
var _a;
|
|
466
533
|
// If there is no form schema, return early
|
|
467
534
|
if (!this._formSchema)
|
|
468
535
|
return;
|
|
@@ -470,9 +537,17 @@ const TttxForm = class {
|
|
|
470
537
|
const properties = this._formSchema.properties;
|
|
471
538
|
const propertyKeys = Object.keys(properties);
|
|
472
539
|
// Loop through each property key and create an input, label, and error bubble for it
|
|
473
|
-
|
|
540
|
+
for (const formKey of propertyKeys) {
|
|
474
541
|
const formItem = properties[formKey];
|
|
475
542
|
const formProperties = formItem.form;
|
|
543
|
+
// complex form types which require
|
|
544
|
+
// custom HTML should be done here
|
|
545
|
+
if (formProperties.type === 'startenddate') {
|
|
546
|
+
const { start, end } = this.createStartEndDateComponent(formKey, formProperties);
|
|
547
|
+
this.template.content.append(start);
|
|
548
|
+
this.template.content.append(end);
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
476
551
|
let input;
|
|
477
552
|
switch (formProperties.type) {
|
|
478
553
|
case 'select':
|
|
@@ -485,15 +560,22 @@ const TttxForm = class {
|
|
|
485
560
|
input = this.createInput(formKey, formProperties);
|
|
486
561
|
}
|
|
487
562
|
// If the form property has validation, apply it to the input
|
|
488
|
-
if (formProperties.validation &&
|
|
563
|
+
if (formProperties.validation &&
|
|
564
|
+
formProperties.type !== 'radio') {
|
|
489
565
|
this.applyValidation(input, formProperties.validation);
|
|
490
566
|
}
|
|
491
567
|
// Create an error bubble and label element for the input
|
|
492
568
|
const errorBubble = this.createErrorBubble();
|
|
493
569
|
const label = this.createLabel(formProperties, input, errorBubble);
|
|
570
|
+
// If explicitly setting input as invalid, set invalid state and error message on render
|
|
571
|
+
if ((_a = formProperties.validation) === null || _a === void 0 ? void 0 : _a.invalid) {
|
|
572
|
+
const errorMessage = formProperties.validation.invalid.message;
|
|
573
|
+
input.setCustomValidity(errorMessage); // Prevents the invalid styling from resetting on blur
|
|
574
|
+
setErrorState(input, true, errorMessage);
|
|
575
|
+
}
|
|
494
576
|
// Append the label element to the form template
|
|
495
577
|
this.template.content.append(label);
|
|
496
|
-
}
|
|
578
|
+
}
|
|
497
579
|
}
|
|
498
580
|
/**
|
|
499
581
|
* Clones the form template and binds event listeners to its input elements. First, it checks if
|
|
@@ -514,47 +596,121 @@ const TttxForm = class {
|
|
|
514
596
|
// Bind event listeners to form elements
|
|
515
597
|
const properties = this._formSchema.properties;
|
|
516
598
|
const propertyKeys = Object.keys(properties);
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const
|
|
520
|
-
for (const formInput of formInputs) {
|
|
599
|
+
for (const formKey of propertyKeys) {
|
|
600
|
+
const formItemsByKey = formItems.querySelectorAll(`[name^=${formKey}]`);
|
|
601
|
+
for (const formInput of formItemsByKey) {
|
|
521
602
|
// Bind events to form input elements
|
|
522
603
|
formInput.oninvalid = this.validityCheckWrapper.bind(this);
|
|
523
604
|
formInput.onblur = this.validityCheckWrapper.bind(this);
|
|
524
605
|
formInput.onkeyup = this.fieldChanged.bind(this);
|
|
525
606
|
formInput.onchange = this.fieldChanged.bind(this);
|
|
526
|
-
if (
|
|
527
|
-
|
|
607
|
+
if (properties[formKey].form.type === 'select' && formInput.classList.contains('placeholder')) {
|
|
608
|
+
formInput.addEventListener('change', () => {
|
|
609
|
+
formInput.classList.remove('placeholder');
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
if (properties[formKey].form.type === 'startenddate' && formInput.hasAttribute('data-compare-with')) {
|
|
613
|
+
formInput.oninvalid = this.endDateComparisonValidator.bind(this);
|
|
614
|
+
formInput.onblur = this.endDateComparisonValidator.bind(this);
|
|
615
|
+
}
|
|
616
|
+
if (properties[formKey].form.type === 'startenddate' && formInput.type === 'time') {
|
|
617
|
+
formInput.oninvalid = this.startEndTimeComparitor.bind(this);
|
|
618
|
+
formInput.onblur = this.startEndTimeComparitor.bind(this);
|
|
619
|
+
}
|
|
620
|
+
if (properties[formKey].form.type === 'startenddate' && formInput.hasAttribute('data-compare-to')) {
|
|
621
|
+
formInput.oninvalid = this.startDateComparisonValidator.bind(this);
|
|
622
|
+
formInput.onblur = this.startDateComparisonValidator.bind(this);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
// populate with existing form data if available
|
|
627
|
+
if (this._data && Object.keys(this._data).length > 0) {
|
|
628
|
+
const dataKeys = Object.keys(this._data);
|
|
629
|
+
for (const key of dataKeys) {
|
|
630
|
+
const formItemsByKey = formItems.querySelectorAll(`[name=${key}]`);
|
|
631
|
+
for (const formItem of formItemsByKey) {
|
|
632
|
+
switch (formItem.type) {
|
|
528
633
|
case 'checkbox':
|
|
529
|
-
if (this._data[
|
|
530
|
-
|
|
634
|
+
if (this._data[key] === 'on') {
|
|
635
|
+
formItem.checked = true;
|
|
531
636
|
}
|
|
532
637
|
break;
|
|
533
638
|
case 'radio':
|
|
534
|
-
if (
|
|
535
|
-
|
|
639
|
+
if (formItem.value === this._data[key]) {
|
|
640
|
+
formItem.checked = true;
|
|
536
641
|
}
|
|
537
642
|
break;
|
|
538
643
|
default:
|
|
539
|
-
|
|
644
|
+
formItem.value = this._data[key];
|
|
540
645
|
}
|
|
541
646
|
}
|
|
542
|
-
// If explicitly setting input as invalid, set invalid state and error message on render
|
|
543
|
-
if ((_b = properties[formKey].form.validation) === null || _b === void 0 ? void 0 : _b.invalid) {
|
|
544
|
-
const errorMessage = properties[formKey].form.validation.invalid.message;
|
|
545
|
-
formInput.setCustomValidity(errorMessage); // Prevents the invalid styling from resetting on blur
|
|
546
|
-
setErrorState(formInput, true, errorMessage);
|
|
547
|
-
}
|
|
548
|
-
if (properties[formKey].form.type === 'select' && formInput.classList.contains('placeholder')) {
|
|
549
|
-
formInput.addEventListener('change', () => {
|
|
550
|
-
formInput.classList.remove('placeholder');
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
647
|
}
|
|
554
|
-
}
|
|
648
|
+
}
|
|
555
649
|
// Append the cloned form elements to the fieldset
|
|
556
650
|
this.fieldset.replaceChildren(formItems);
|
|
557
651
|
}
|
|
652
|
+
startEndTimeComparitor(event) {
|
|
653
|
+
var _a, _b;
|
|
654
|
+
const target = event.target;
|
|
655
|
+
const formKey = target.getAttribute('data-formkey');
|
|
656
|
+
const timeFields = Array.from(target.parentElement.parentElement.parentElement.querySelectorAll(`[data-formkey=${formKey}]`));
|
|
657
|
+
if (timeFields.length === 4) {
|
|
658
|
+
const startTime = timeFields.find(t => t.name.endsWith('starttime'));
|
|
659
|
+
const endTime = timeFields.find(t => t.name.endsWith('endtime'));
|
|
660
|
+
const startDate = timeFields.find(t => t.name.endsWith('startdate'));
|
|
661
|
+
const endDate = timeFields.find(t => t.name.endsWith('enddate'));
|
|
662
|
+
if (startTime.valueAsNumber >= endTime.valueAsNumber && ((_a = startDate.valueAsDate) === null || _a === void 0 ? void 0 : _a.valueOf()) === ((_b = endDate.valueAsDate) === null || _b === void 0 ? void 0 : _b.valueOf())) {
|
|
663
|
+
setErrorState(endTime, true, 'End time cannot be the same or before the start time');
|
|
664
|
+
if (target.name.endsWith('starttime')) {
|
|
665
|
+
this.validityCheckWrapper(event);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
// clear any end time comparitor errors and perform the standard validity check on the event
|
|
670
|
+
endTime.setCustomValidity('');
|
|
671
|
+
setErrorState(endTime, false, null);
|
|
672
|
+
this.validityCheckWrapper(event);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
clearTimeComparitor(event) {
|
|
677
|
+
const target = event.target;
|
|
678
|
+
const formKey = target.getAttribute('data-formkey');
|
|
679
|
+
const timeFields = Array.from(target.parentElement.parentElement.parentElement.querySelectorAll(`[type=time][data-formkey=${formKey}]`));
|
|
680
|
+
if (timeFields.length) {
|
|
681
|
+
const endTime = timeFields.find(t => t.name.endsWith('endtime'));
|
|
682
|
+
endTime.setCustomValidity('');
|
|
683
|
+
setErrorState(endTime, false, null);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
startDateComparisonValidator(event) {
|
|
687
|
+
const startDate = event.target;
|
|
688
|
+
const compareToName = startDate.getAttribute('data-compare-to');
|
|
689
|
+
const endDate = startDate.parentElement.parentElement.parentElement.querySelector(`[name=${compareToName}]`);
|
|
690
|
+
this.endDateComparisonValidator({ target: endDate }, true);
|
|
691
|
+
this.validityCheckWrapper(event);
|
|
692
|
+
}
|
|
693
|
+
endDateComparisonValidator(event, triggeredByStartDate = false) {
|
|
694
|
+
var _a, _b, _c, _d;
|
|
695
|
+
const endDate = event.target;
|
|
696
|
+
if (!endDate.value && triggeredByStartDate)
|
|
697
|
+
return;
|
|
698
|
+
const compareWithName = endDate.getAttribute('data-compare-with');
|
|
699
|
+
const startDate = endDate.parentElement.parentElement.parentElement.querySelector(`[name=${compareWithName}]`);
|
|
700
|
+
if (((_a = endDate.valueAsDate) === null || _a === void 0 ? void 0 : _a.valueOf()) < ((_b = startDate.valueAsDate) === null || _b === void 0 ? void 0 : _b.valueOf())) {
|
|
701
|
+
endDate.setCustomValidity(endDate.getAttribute('data-compare'));
|
|
702
|
+
setErrorState(endDate, true, endDate.getAttribute('data-compare'));
|
|
703
|
+
}
|
|
704
|
+
else if (((_c = endDate.valueAsDate) === null || _c === void 0 ? void 0 : _c.valueOf()) === ((_d = startDate.valueAsDate) === null || _d === void 0 ? void 0 : _d.valueOf())) {
|
|
705
|
+
endDate.setCustomValidity('');
|
|
706
|
+
this.validityCheckWrapper(event);
|
|
707
|
+
this.startEndTimeComparitor(event);
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
this.clearTimeComparitor(event);
|
|
711
|
+
this.validityCheckWrapper(event);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
558
714
|
validityCheckWrapper(event) {
|
|
559
715
|
const { target, hasError, errorMessage } = validityCheck(event);
|
|
560
716
|
setErrorState(target, hasError, errorMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t,c as e,h as i,H as n}from"./p-65bb4035.js";const c=class{constructor(i){t(this,i),this.checkboxChangeEvent=e(this,"checkboxChangeEvent",3),this.checkboxId=void 0,this.label=void 0,this.inline=!1,this.indeterminate=!1,this.checked=void 0}watchIndeterminateChange(t){this.checkbox.indeterminate=t}onClick(){const{checked:t,indeterminate:e}=this;this.checkboxChangeEvent.emit({indeterminate:e,checked:t})}componentDidLoad(){this.checkbox.indeterminate=this.indeterminate}render(){const t=this.indeterminate?"indeterminate_check_box":this.checked?"check_box":"check_box_outline_blank";return i(n,null,i("label",{class:"tttx-checkbox "+(this.inline?"--inline":"")},i("input",{class:"tttx-checkbox__input",type:"checkbox",id:this.checkboxId,checked:this.checked,ref:t=>this.checkbox=t}),i("tttx-icon",{color:this.checked?"blue":
|
|
1
|
+
import{r as t,c as e,h as i,H as n}from"./p-65bb4035.js";const c=class{constructor(i){t(this,i),this.checkboxChangeEvent=e(this,"checkboxChangeEvent",3),this.checkboxId=void 0,this.label=void 0,this.inline=!1,this.indeterminate=!1,this.checked=void 0}watchIndeterminateChange(t){this.checkbox.indeterminate=t}onClick(){const{checked:t,indeterminate:e}=this;this.checkboxChangeEvent.emit({indeterminate:e,checked:t})}componentDidLoad(){this.checkbox.indeterminate=this.indeterminate}render(){const t=this.indeterminate?"indeterminate_check_box":this.checked?"check_box":"check_box_outline_blank";return i(n,null,i("label",{class:"tttx-checkbox "+(this.inline?"--inline":"")},i("input",{class:"tttx-checkbox__input",type:"checkbox",id:this.checkboxId,checked:this.checked,ref:t=>this.checkbox=t}),i("tttx-icon",{color:this.checked?"blue":"grey",icon:t,onClick:this.onClick.bind(this)}),i("span",{class:"tttx-checkbox__label"},this.label)))}static get watchers(){return{indeterminate:["watchIndeterminateChange"]}}};c.style='.material-symbols-rounded{font-variation-settings:"FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24}.tttx-checkbox{padding:8px;display:flex;justify-content:flex-start;font-size:16px;align-items:center;font-weight:normal;line-height:19px}.tttx-checkbox tttx-icon{height:24px}.tttx-checkbox.--inline{display:inline-flex}.tttx-checkbox__input{display:none}.tttx-checkbox__label{margin-left:8px;padding-right:0;color:#212121;font-weight:normal}';export{c as tttx_checkbox}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,c as t,h as o,H as i}from"./p-65bb4035.js";import{p as n,d as r}from"./p-88ee2406.js";import"./p-112455b1.js";function a(e,t,o,i){let n;if(n=void 0!==i?i.querySelector(".errorBubble"):"label"===e.parentElement.nodeName.toLowerCase()?e.parentElement.querySelector(".errorBubble"):e.parentElement.parentElement.querySelector(".errorBubble"),n)if(t){e.classList.add("invalid"),n.classList.add("visible");const t=document.createElement("span");t.className="material-symbols-rounded",t.textContent="warning",n.innerHTML="",n.append(t),n.append(o)}else n.classList.remove("visible"),e.classList.remove("invalid"),n.innerHTML=""}const l=class{constructor(o){e(this,o),this.dataSubmitted=t(this,"dataSubmitted",7),this.dataChanged=t(this,"dataChanged",7),this.template=document.createElement("template"),this.formschema=void 0,this.data=void 0}onFormSchemaChange(e){if(!this.data&&this.form&&this._formSchema){const e=new FormData(this.form);this._data=Object.fromEntries(Object.keys(this._formSchema.properties).map((t=>[t,e.get(t)])))}this._formSchema="string"==typeof e?JSON.parse(e):e}onDataChange(e){this._data="string"==typeof e?JSON.parse(e):e}fieldChanged(e){this.dataChanged.emit({name:e.target.name,value:e.target.value})}async submit(){this.submitButton.click()}doSubmit(e){e.preventDefault();const t=new FormData(e.target),o=this._formSchema.properties;for(const e of Object.keys(o))"checkbox"!==o[e].form.type||t.has(e)||t.append(e,"off");this.dataSubmitted.emit(t)}componentWillLoad(){this.onFormSchemaChange(this.formschema),this.data&&this.onDataChange(this.data)}componentWillRender(){this.template=document.createElement("template"),this.populateFormFromSchema()}createSelect(e,t){var o;const i=document.createElement("select");return i.setAttribute("name",e),t.options.forEach((e=>{this.appendOption(i,e)})),(null===(o=this._data)||void 0===o?void 0:o[e])&&i.classList.remove("placeholder"),i}appendOption(e,t){const o=document.createElement("option");o.setAttribute("value",t.value),t.placeholder&&(o.setAttribute("disabled",""),o.setAttribute("selected",""),o.setAttribute("hidden",""),e.classList.add("placeholder")),t.label&&(o.innerHTML=n.sanitize(t.label,r)),e.appendChild(o)}createInput(e,t){var o;const i=document.createElement("input");return i.name=e,i.type=t.type,i.placeholder=null!==(o=t.placeholder)&&void 0!==o?o:"",i.autocomplete="off",i.autocapitalize="off",t.readonly&&(i.readOnly=!0),i}createStartEndDateComponent(e,t){const o=document.createElement("input"),i=document.createElement("input");let n,r;o.type=i.type="date",o.name=`${e}-startdate`,i.name=`${e}-enddate`,o.setAttribute("data-formkey",e),i.setAttribute("data-formkey",e),t.readonly&&(o.readOnly=!0,i.readOnly=!0),this.applyValidation(o,{required:{message:"Please enter a start date"},dateCompare:{to:i.name}}),this.applyValidation(i,{required:{message:"Please enter an end date"},dateCompare:{with:o.name,message:"End date cannot be before the start date"}}),t.includeTime&&(n=document.createElement("input"),r=document.createElement("input"),n.type=r.type="time",n.name=`${e}-starttime`,r.name=`${e}-endtime`,n.setAttribute("data-formkey",e),r.setAttribute("data-formkey",e),t.readonly&&(n.readOnly=!0,r.readOnly=!0),this.applyValidation(n,{required:{message:"Please enter a start time"}}),this.applyValidation(r,{required:{message:"Please enter an end time"}}));const a=document.createElement("label");a.innerText="Start date";const l=document.createElement("label");l.innerText="End date";const s=document.createElement("div"),d=document.createElement("div");return s.className=d.className="outer-container inputBlock",a.className=l.className="flex-label",s.append(o),n&&s.append(n),a.append(s),a.append(this.createErrorBubble()),d.append(i),r&&d.append(r),l.append(d),l.append(this.createErrorBubble()),{start:a,end:l}}applyValidation(e,t){var o,i;t.required&&(e.setAttribute("required",""),e.setAttribute("data-required",null!==(o=t.required.message)&&void 0!==o?o:"")),t.pattern&&(e.setAttribute("pattern",t.pattern.pattern),e.setAttribute("data-pattern",null!==(i=t.pattern.message)&&void 0!==i?i:"")),t.badInput&&e.setAttribute("data-badinput",t.badInput.message),t.minmax&&(e.setAttribute("min",t.minmax.min),e.setAttribute("max",t.minmax.max),e.setAttribute("data-range",t.minmax.message)),t.maxlength&&e.setAttribute("maxlength",t.maxlength),t.dateCompare&&(t.dateCompare.message&&t.dateCompare.with&&(e.setAttribute("data-compare",t.dateCompare.message),e.setAttribute("data-compare-with",t.dateCompare.with)),t.dateCompare.to&&e.setAttribute("data-compare-to",t.dateCompare.to))}createErrorBubble(){const e=document.createElement("div");return e.className="errorBubble",e}appendCheckboxInput(e,t,o){if(e.label){const e=document.createElement("br");o.appendChild(e)}if(o.appendChild(t),!e.inlineLabel)return;const i=document.createElement("span");i.className="inlineLabel",i.textContent=e.inlineLabel,o.appendChild(i)}createLabel(e,t,o){var i;const n=document.createElement("div");let r="outer-container inputBlock";const a=document.createElement("label");if(a.innerText=e.label,!(null===(i=e.validation)||void 0===i?void 0:i.required)&&e.label){const e=document.createElement("span");e.className="optional",e.innerHTML=" (optional)",a.appendChild(e)}return"radio"===e.type&&(r+=" radioBlock"),n.className=r,e.readonly&&a.classList.add("readonly"),"checkbox"===e.type?this.appendCheckboxInput(e,t,a):n.appendChild(t),"checkbox"!==e.type&&a.appendChild(n),a.appendChild(o),a}createRadio(e,t){var o,i;const n=new DocumentFragment;for(const r of t.options){const a=document.createElement("input");a.type="radio",a.name=e,a.value=r.value,(null===(o=null==t?void 0:t.validation)||void 0===o?void 0:o.required)&&(a.setAttribute("required","required"),a.setAttribute("data-required",null!==(i=t.validation.required.message)&&void 0!==i?i:""));const l=document.createElement("span");l.innerText=r.label,n.appendChild(a),n.appendChild(l),n.appendChild(document.createElement("br"))}return n}populateFormFromSchema(){var e;if(!this._formSchema)return;const t=this._formSchema.properties,o=Object.keys(t);for(const i of o){const o=t[i].form;if("startenddate"===o.type){const{start:e,end:t}=this.createStartEndDateComponent(i,o);this.template.content.append(e),this.template.content.append(t);continue}let n;switch(o.type){case"select":n=this.createSelect(i,o);break;case"radio":n=this.createRadio(i,o);break;default:n=this.createInput(i,o)}o.validation&&"radio"!==o.type&&this.applyValidation(n,o.validation);const r=this.createErrorBubble(),l=this.createLabel(o,n,r);if(null===(e=o.validation)||void 0===e?void 0:e.invalid){const e=o.validation.invalid.message;n.setCustomValidity(e),a(n,!0,e)}this.template.content.append(l)}}componentDidRender(){if(!this._formSchema)return;const e=this.template.content.cloneNode(!0),t=this._formSchema.properties,o=Object.keys(t);for(const i of o){const o=e.querySelectorAll(`[name^=${i}]`);for(const e of o)e.oninvalid=this.validityCheckWrapper.bind(this),e.onblur=this.validityCheckWrapper.bind(this),e.onkeyup=this.fieldChanged.bind(this),e.onchange=this.fieldChanged.bind(this),"select"===t[i].form.type&&e.classList.contains("placeholder")&&e.addEventListener("change",(()=>{e.classList.remove("placeholder")})),"startenddate"===t[i].form.type&&e.hasAttribute("data-compare-with")&&(e.oninvalid=this.endDateComparisonValidator.bind(this),e.onblur=this.endDateComparisonValidator.bind(this)),"startenddate"===t[i].form.type&&"time"===e.type&&(e.oninvalid=this.startEndTimeComparitor.bind(this),e.onblur=this.startEndTimeComparitor.bind(this)),"startenddate"===t[i].form.type&&e.hasAttribute("data-compare-to")&&(e.oninvalid=this.startDateComparisonValidator.bind(this),e.onblur=this.startDateComparisonValidator.bind(this))}if(this._data&&Object.keys(this._data).length>0){const t=Object.keys(this._data);for(const o of t){const t=e.querySelectorAll(`[name=${o}]`);for(const e of t)switch(e.type){case"checkbox":"on"===this._data[o]&&(e.checked=!0);break;case"radio":e.value===this._data[o]&&(e.checked=!0);break;default:e.value=this._data[o]}}}this.fieldset.replaceChildren(e)}startEndTimeComparitor(e){var t,o;const i=e.target,n=i.getAttribute("data-formkey"),r=Array.from(i.parentElement.parentElement.parentElement.querySelectorAll(`[data-formkey=${n}]`));if(4===r.length){const n=r.find((e=>e.name.endsWith("starttime"))),l=r.find((e=>e.name.endsWith("endtime"))),s=r.find((e=>e.name.endsWith("startdate"))),d=r.find((e=>e.name.endsWith("enddate")));n.valueAsNumber>=l.valueAsNumber&&(null===(t=s.valueAsDate)||void 0===t?void 0:t.valueOf())===(null===(o=d.valueAsDate)||void 0===o?void 0:o.valueOf())?(a(l,!0,"End time cannot be the same or before the start time"),i.name.endsWith("starttime")&&this.validityCheckWrapper(e)):(l.setCustomValidity(""),a(l,!1,null),this.validityCheckWrapper(e))}}clearTimeComparitor(e){const t=e.target,o=t.getAttribute("data-formkey"),i=Array.from(t.parentElement.parentElement.parentElement.querySelectorAll(`[type=time][data-formkey=${o}]`));if(i.length){const e=i.find((e=>e.name.endsWith("endtime")));e.setCustomValidity(""),a(e,!1,null)}}startDateComparisonValidator(e){const t=e.target,o=t.getAttribute("data-compare-to"),i=t.parentElement.parentElement.parentElement.querySelector(`[name=${o}]`);this.endDateComparisonValidator({target:i},!0),this.validityCheckWrapper(e)}endDateComparisonValidator(e,t=!1){var o,i,n,r;const l=e.target;if(!l.value&&t)return;const s=l.getAttribute("data-compare-with"),d=l.parentElement.parentElement.parentElement.querySelector(`[name=${s}]`);(null===(o=l.valueAsDate)||void 0===o?void 0:o.valueOf())<(null===(i=d.valueAsDate)||void 0===i?void 0:i.valueOf())?(l.setCustomValidity(l.getAttribute("data-compare")),a(l,!0,l.getAttribute("data-compare"))):(null===(n=l.valueAsDate)||void 0===n?void 0:n.valueOf())===(null===(r=d.valueAsDate)||void 0===r?void 0:r.valueOf())?(l.setCustomValidity(""),this.validityCheckWrapper(e),this.startEndTimeComparitor(e)):(this.clearTimeComparitor(e),this.validityCheckWrapper(e))}validityCheckWrapper(e){const{target:t,hasError:o,errorMessage:i}=function(e){var t,o,i,n;e.preventDefault&&e.preventDefault();const r=e.target;let a=!0,l="";switch(r.value.length&&!r.value.replace(/\s/g,"").length?(l="This field cannot be left blank",r.setCustomValidity(l)):(l="",r.setCustomValidity&&r.setCustomValidity("")),!0){case r.validity.valueMissing:l=null!==(t=r.dataset.required)&&void 0!==t?t:"This field is required";break;case r.validity.patternMismatch:l=null!==(o=r.dataset.pattern)&&void 0!==o?o:"Incorrect format";break;case r.validity.badInput:l=null!==(i=r.dataset.badinput)&&void 0!==i?i:"Wrong input type";break;case r.validity.rangeOverflow||r.validity.rangeUnderflow:l=null!==(n=r.dataset.range)&&void 0!==n?n:"Invalid value";break;case r.validity.customError:l=r.validationMessage;break;default:a=!1}return{target:r,hasError:a,errorMessage:l}}(e);a(t,o,i)}render(){return o(i,null,o("form",{ref:e=>this.form=e,onSubmit:this.doSubmit.bind(this)},o("fieldset",{ref:e=>this.fieldset=e}),o("input",{type:"submit",ref:e=>this.submitButton=e,style:{display:"none"}})))}static get watchers(){return{formschema:["onFormSchemaChange"],data:["onDataChange"]}}};l.style='.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}label.flex-label{display:flex;flex-direction:column;width:300px;box-sizing:border-box}label.flex-label input[type=date]{flex-grow:1;min-width:auto}label.flex-label input[type=time]{min-width:auto;text-align:center;width:180px;margin-left:16px}';export{l as tttx_form}
|
package/dist/tttx/tttx.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as e,b as t}from"./p-65bb4035.js";export{s as setNonce}from"./p-65bb4035.js";(()=>{const t=import.meta.url,o={};return""!==t&&(o.resourcesUrl=new URL(".",t).href),e(o)})().then((e=>t([["p-7f1452fb",[[1,"tttx-data-pattern",{data:[1],sorteroptions:[1],filteroptions:[1],filterheader:[1]}]]],["p-f8c7f162",[[1,"tttx-multiselect-box",{optionsData:[1,"options-data"],label:[1],inline:[4],placeholder:[1],searchEnabled:[4,"search-enabled"],htmlVisibleValue:[4,"html-visible-value"],visibleValue:[1,"visible-value"],open:[32],unsavedSelectedItems:[32],searchTerm:[32]},[[0,"closeSelectBox","handleCloseSelectBox"],[0,"blur","handleBlur"]]]]],["p-c476e635",[[1,"tttx-dialog-box",{data:[1025],size:[1],open:[1028],allowOverflow:[4,"allow-overflow"],elementSize:[32]},[[9,"resize","handleResize"]]]]],["p-aa7f5822",[[1,"tttx-select-box",{optionsData:[1,"options-data"],label:[1],inline:[4],placeholder:[1],searchEnabled:[4,"search-enabled"],selectedValue:[1,"selected-value"],open:[32],selectedItem:[32],searchTerm:[32]},[[0,"closeSelectBox","handleCloseSelectBox"],[0,"blur","handleBlur"]]]]],["p-888fb9ee",[[1,"tttx-tree-view",{data:[1040],firstSelected:[1028,"first-selected"],treeData:[32],selectedId:[32]}]]],["p-
|
|
1
|
+
import{p as e,b as t}from"./p-65bb4035.js";export{s as setNonce}from"./p-65bb4035.js";(()=>{const t=import.meta.url,o={};return""!==t&&(o.resourcesUrl=new URL(".",t).href),e(o)})().then((e=>t([["p-7f1452fb",[[1,"tttx-data-pattern",{data:[1],sorteroptions:[1],filteroptions:[1],filterheader:[1]}]]],["p-f8c7f162",[[1,"tttx-multiselect-box",{optionsData:[1,"options-data"],label:[1],inline:[4],placeholder:[1],searchEnabled:[4,"search-enabled"],htmlVisibleValue:[4,"html-visible-value"],visibleValue:[1,"visible-value"],open:[32],unsavedSelectedItems:[32],searchTerm:[32]},[[0,"closeSelectBox","handleCloseSelectBox"],[0,"blur","handleBlur"]]]]],["p-c476e635",[[1,"tttx-dialog-box",{data:[1025],size:[1],open:[1028],allowOverflow:[4,"allow-overflow"],elementSize:[32]},[[9,"resize","handleResize"]]]]],["p-aa7f5822",[[1,"tttx-select-box",{optionsData:[1,"options-data"],label:[1],inline:[4],placeholder:[1],searchEnabled:[4,"search-enabled"],selectedValue:[1,"selected-value"],open:[32],selectedItem:[32],searchTerm:[32]},[[0,"closeSelectBox","handleCloseSelectBox"],[0,"blur","handleBlur"]]]]],["p-888fb9ee",[[1,"tttx-tree-view",{data:[1040],firstSelected:[1028,"first-selected"],treeData:[32],selectedId:[32]}]]],["p-69e15a92",[[0,"tttx-checkbox",{checkboxId:[1,"checkbox-id"],label:[1],inline:[4],indeterminate:[4],checked:[4]}]]],["p-20d3d8fb",[[1,"tttx-dialog",{header:[1],type:[1],size:[1],open:[4],allowOverflow:[4,"allow-overflow"],closeEnabled:[4,"close-enabled"],elementSize:[32]},[[9,"resize","handleResize"]]]]],["p-87b6e5a9",[[1,"tttx-expander",{name:[1],open:[4],lefticon:[1],lefticoncolor:[1],isExpanded:[32]}]]],["p-562eafbd",[[2,"tttx-tabs",{tabsName:[1,"tabs-name"],navigation:[4],wide:[4],tabs:[1],_tabs:[32]},[[0,"keydown","handleKeyDown"]]]]],["p-67f24d17",[[1,"tttx-checkbox-group"]]],["p-a64c9910",[[4,"tttx-checkbox-group-caption"]]],["p-80e3bd36",[[4,"tttx-checkbox-group-heading"]]],["p-91cf9bd4",[[1,"tttx-form",{formschema:[1025],data:[1032],submit:[64]}]]],["p-15b7a577",[[1,"tttx-keyvalue-block",{keyvalues:[1],horizontal:[4],spacedout:[4],_elements:[32]}]]],["p-fe6c321b",[[1,"tttx-loading-spinner",{loadingMessage:[1028,"loading-message"],size:[1025]}]]],["p-be16cf2d",[[2,"tttx-percentage-bar",{percentage:[8],thresholds:[1],color:[1],min:[1],labelid:[1],_percentage:[32],_ranges:[32],_min:[32]}]]],["p-69642b71",[[1,"tttx-qrcode",{link:[1025],size:[1026]}]]],["p-e7b7d2e2",[[1,"tttx-tag",{text:[1],color:[1],textColor:[1,"text-color"]}]]],["p-34f328f9",[[2,"tttx-textarea",{label:[1],secondarylabel:[1],showerrormsg:[4],showerrorbubble:[4],errormsg:[1],rows:[2],textareaautofocus:[4],inputkeyhint:[1],inputindex:[8],inputtitle:[1],disabled:[4],maxlength:[8],name:[1],placeholder:[1],readonly:[8],required:[4],value:[1032]}]]],["p-bcf3844e",[[1,"tttx-icon",{icon:[1],color:[1]}]]],["p-6e0fac85",[[2,"tttx-standalone-input",{label:[1],secondarylabel:[1],showerrormsg:[4],showerrorbubble:[4],errormsg:[1],iconleft:[1],iconleftcolor:[1],iconright:[1],iconrightcolor:[1],inputicon:[1],inputiconcolor:[1],inline:[4],inputautocapitalize:[1],inputautofocus:[4],inputkeyhint:[1],inputindex:[8],inputtitle:[1],autocomplete:[1],checked:[4],disabled:[4],max:[8],maxlength:[8],min:[8],minlength:[8],name:[1],pattern:[1],placeholder:[1],readonly:[8],required:[4],step:[8],type:[1],value:[1032]}]]],["p-f27adb48",[[1,"tttx-filter",{filterKey:[1,"filter-key"],filterOptions:[1,"filter-options"],showSelectAll:[4,"show-select-all"],showSearchField:[4,"show-search-field"],showOptionIcons:[4,"show-option-icons"],filterButtonStyle:[1,"filter-button-style"],filterHeader:[1,"filter-header"],defaultFilterOptions:[1,"default-filter-options"],popoverWidth:[1,"popover-width"],showPopover:[32],displayedFilterSettings:[32],selectedFilters:[32],filterSearchTerm:[32],allSelected:[32]},[[0,"closeFilter","handleCloseFilter"]]],[1,"tttx-list",{data:[1025],name:[1],_data:[32]}],[1,"tttx-sorter",{sorterKey:[1,"sorter-key"],defaultSortDirection:[1,"default-sort-direction"],fieldOptionsData:[1,"field-options-data"],defaultOption:[1,"default-option"],selectedField:[32],sortDirection:[32],dropdownExpand:[32],dropdownOptions:[32]},[[0,"closeSorter","handleCloseSorter"]]],[1,"tttx-toolbar",{border:[4],viewSize:[32]},[[9,"resize","handleResize"]]]]],["p-61741832",[[1,"tttx-button",{notext:[4],icon:[1],iconposition:[1],iconcolor:[1025],design:[1]}]]]],e)));
|
|
@@ -86,6 +86,10 @@ export declare class TttxForm {
|
|
|
86
86
|
* @return {HTMLInputElement} - The new input element.
|
|
87
87
|
*/
|
|
88
88
|
createInput(formKey: string, formProperties: Record<string, any>): HTMLInputElement;
|
|
89
|
+
createStartEndDateComponent(formKey: string, formProperties: Record<string, any>): {
|
|
90
|
+
start: HTMLLabelElement;
|
|
91
|
+
end: HTMLLabelElement;
|
|
92
|
+
};
|
|
89
93
|
/**
|
|
90
94
|
* Applies validation attributes to an input element based on the specified validation object.
|
|
91
95
|
* If a certain property is present in the object, it will set the corresponding attribute on
|
|
@@ -106,6 +110,7 @@ export declare class TttxForm {
|
|
|
106
110
|
* @param {string} [validation.minmax.max]
|
|
107
111
|
* @param {string} [validation.minmax.message]
|
|
108
112
|
* @param {string} [validation.maxlength] - The maximum length of the input field.
|
|
113
|
+
* @param {string} [validation.datecompare] - To compare start and end date fields.
|
|
109
114
|
* @return {void}
|
|
110
115
|
*/
|
|
111
116
|
applyValidation(input: FormField, validation: {
|
|
@@ -125,6 +130,11 @@ export declare class TttxForm {
|
|
|
125
130
|
message?: string;
|
|
126
131
|
};
|
|
127
132
|
maxlength?: string;
|
|
133
|
+
dateCompare?: {
|
|
134
|
+
to?: string;
|
|
135
|
+
with?: string;
|
|
136
|
+
message?: string;
|
|
137
|
+
};
|
|
128
138
|
}): void;
|
|
129
139
|
createErrorBubble(): HTMLDivElement;
|
|
130
140
|
/**
|
|
@@ -177,6 +187,10 @@ export declare class TttxForm {
|
|
|
177
187
|
* @return {void}
|
|
178
188
|
*/
|
|
179
189
|
componentDidRender(): void;
|
|
190
|
+
startEndTimeComparitor(event: Event | FocusEvent): void;
|
|
191
|
+
clearTimeComparitor(event: Event | FocusEvent): void;
|
|
192
|
+
startDateComparisonValidator(event: Event | FocusEvent): void;
|
|
193
|
+
endDateComparisonValidator(event: Event | FocusEvent, triggeredByStartDate?: boolean): void;
|
|
180
194
|
validityCheckWrapper(event: Event | FocusEvent): void;
|
|
181
195
|
/**
|
|
182
196
|
* Renders the component's template as a form element with a fieldset container. The form's
|
|
@@ -21,6 +21,9 @@ export declare const SingleFormItem: {
|
|
|
21
21
|
type: string;
|
|
22
22
|
label: string;
|
|
23
23
|
validation: {
|
|
24
|
+
invalid: {
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
24
27
|
required: {
|
|
25
28
|
message: string;
|
|
26
29
|
};
|
|
@@ -31,6 +34,23 @@ export declare const SingleFormItem: {
|
|
|
31
34
|
};
|
|
32
35
|
};
|
|
33
36
|
};
|
|
37
|
+
export declare const StartAndEndDateWithoutTime: {
|
|
38
|
+
(args: any): string;
|
|
39
|
+
args: {
|
|
40
|
+
formSchema: {
|
|
41
|
+
properties: {
|
|
42
|
+
startend: {
|
|
43
|
+
type: string;
|
|
44
|
+
format: string;
|
|
45
|
+
form: {
|
|
46
|
+
type: string;
|
|
47
|
+
includeTime: boolean;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
34
54
|
export declare const ExampleFormFromJSON: {
|
|
35
55
|
(args: any): string;
|
|
36
56
|
args: {
|
|
@@ -149,6 +169,30 @@ export declare const ExampleFormFromJSON: {
|
|
|
149
169
|
};
|
|
150
170
|
};
|
|
151
171
|
};
|
|
172
|
+
startend: {
|
|
173
|
+
type: string;
|
|
174
|
+
format: string;
|
|
175
|
+
form: {
|
|
176
|
+
type: string;
|
|
177
|
+
includeTime: boolean;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
expiration: {
|
|
181
|
+
type: string;
|
|
182
|
+
form: {
|
|
183
|
+
type: string;
|
|
184
|
+
label: string;
|
|
185
|
+
options: {
|
|
186
|
+
label: string;
|
|
187
|
+
value: string;
|
|
188
|
+
}[];
|
|
189
|
+
validation: {
|
|
190
|
+
required: {
|
|
191
|
+
message: string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
};
|
|
152
196
|
permissions: {
|
|
153
197
|
form: {
|
|
154
198
|
type: string;
|
|
@@ -178,6 +222,10 @@ export declare const PrePopulateForm: {
|
|
|
178
222
|
dropdown: string;
|
|
179
223
|
permissions: string;
|
|
180
224
|
expiration: string;
|
|
225
|
+
'startend-startdate': string;
|
|
226
|
+
'startend-starttime': string;
|
|
227
|
+
'startend-enddate': string;
|
|
228
|
+
'startend-endtime': string;
|
|
181
229
|
};
|
|
182
230
|
formSchema: {
|
|
183
231
|
properties: {
|
|
@@ -296,16 +344,12 @@ export declare const PrePopulateForm: {
|
|
|
296
344
|
};
|
|
297
345
|
};
|
|
298
346
|
};
|
|
299
|
-
|
|
347
|
+
startend: {
|
|
348
|
+
type: string;
|
|
349
|
+
format: string;
|
|
300
350
|
form: {
|
|
301
351
|
type: string;
|
|
302
|
-
|
|
303
|
-
inlineLabel: string;
|
|
304
|
-
validation: {
|
|
305
|
-
required: {
|
|
306
|
-
message: string;
|
|
307
|
-
};
|
|
308
|
-
};
|
|
352
|
+
includeTime: boolean;
|
|
309
353
|
};
|
|
310
354
|
};
|
|
311
355
|
expiration: {
|
|
@@ -324,6 +368,18 @@ export declare const PrePopulateForm: {
|
|
|
324
368
|
};
|
|
325
369
|
};
|
|
326
370
|
};
|
|
371
|
+
permissions: {
|
|
372
|
+
form: {
|
|
373
|
+
type: string;
|
|
374
|
+
label: string;
|
|
375
|
+
inlineLabel: string;
|
|
376
|
+
validation: {
|
|
377
|
+
required: {
|
|
378
|
+
message: string;
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
};
|
|
327
383
|
};
|
|
328
384
|
};
|
|
329
385
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3t-transform/threeteeui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.108",
|
|
4
4
|
"description": "3t Design System",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@types/react-dom": "^18.0.5",
|
|
40
40
|
"@types/react-redux": "^7.1.24",
|
|
41
41
|
"@types/react-router-dom": "^5.3.3",
|
|
42
|
-
"string-width":"4.2.3",
|
|
43
|
-
"cliui":"8.0.1"
|
|
42
|
+
"string-width": "4.2.3",
|
|
43
|
+
"cliui": "8.0.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@babel/core": "^7.18.10",
|
|
@@ -82,4 +82,4 @@
|
|
|
82
82
|
"dompurify": "^3.0.3",
|
|
83
83
|
"ts-qrcode": "^0.0.4"
|
|
84
84
|
}
|
|
85
|
-
}
|
|
85
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e,c as t,h as o,H as i}from"./p-65bb4035.js";import{p as n,d as r}from"./p-88ee2406.js";import"./p-112455b1.js";function a(e,t,o,i){let n;if(n=void 0!==i?i.querySelector(".errorBubble"):"label"===e.parentElement.nodeName.toLowerCase()?e.parentElement.querySelector(".errorBubble"):e.parentElement.parentElement.querySelector(".errorBubble"),n)if(t){e.classList.add("invalid"),n.classList.add("visible");const t=document.createElement("span");t.className="material-symbols-rounded",t.textContent="warning",n.innerHTML="",n.append(t),n.append(o)}else n.classList.remove("visible"),e.classList.remove("invalid"),n.innerHTML=""}const l=class{constructor(o){e(this,o),this.dataSubmitted=t(this,"dataSubmitted",7),this.dataChanged=t(this,"dataChanged",7),this.template=document.createElement("template"),this.formschema=void 0,this.data=void 0}onFormSchemaChange(e){if(!this.data&&this.form&&this._formSchema){const e=new FormData(this.form);this._data=Object.fromEntries(Object.keys(this._formSchema.properties).map((t=>[t,e.get(t)])))}this._formSchema="string"==typeof e?JSON.parse(e):e}onDataChange(e){this._data="string"==typeof e?JSON.parse(e):e}fieldChanged(e){this.dataChanged.emit({name:e.target.name,value:e.target.value})}async submit(){this.submitButton.click()}doSubmit(e){e.preventDefault();const t=new FormData(e.target),o=this._formSchema.properties;for(const e of Object.keys(o))"checkbox"!==o[e].form.type||t.has(e)||t.append(e,"off");this.dataSubmitted.emit(t)}componentWillLoad(){this.onFormSchemaChange(this.formschema),this.data&&this.onDataChange(this.data)}componentWillRender(){this.template=document.createElement("template"),this.populateFormFromSchema()}createSelect(e,t){var o;const i=document.createElement("select");return i.setAttribute("name",e),t.options.forEach((e=>{this.appendOption(i,e)})),(null===(o=this._data)||void 0===o?void 0:o[e])&&i.classList.remove("placeholder"),i}appendOption(e,t){const o=document.createElement("option");o.setAttribute("value",t.value),t.placeholder&&(o.setAttribute("disabled",""),o.setAttribute("selected",""),o.setAttribute("hidden",""),e.classList.add("placeholder")),t.label&&(o.innerHTML=n.sanitize(t.label,r)),e.appendChild(o)}createInput(e,t){var o;const i=document.createElement("input");return i.name=e,i.type=t.type,i.placeholder=null!==(o=t.placeholder)&&void 0!==o?o:"",i.autocomplete="off",i.autocapitalize="off",t.readonly&&(i.readOnly=!0),i}applyValidation(e,t){var o,i;t.required&&(e.setAttribute("required",""),e.setAttribute("data-required",null!==(o=t.required.message)&&void 0!==o?o:"")),t.pattern&&(e.setAttribute("pattern",t.pattern.pattern),e.setAttribute("data-pattern",null!==(i=t.pattern.message)&&void 0!==i?i:"")),t.badInput&&e.setAttribute("data-badinput",t.badInput.message),t.minmax&&(e.setAttribute("min",t.minmax.min),e.setAttribute("max",t.minmax.max),e.setAttribute("data-range",t.minmax.message)),t.maxlength&&e.setAttribute("maxlength",t.maxlength)}createErrorBubble(){const e=document.createElement("div");return e.className="errorBubble",e}appendCheckboxInput(e,t,o){if(e.label){const e=document.createElement("br");o.appendChild(e)}if(o.appendChild(t),!e.inlineLabel)return;const i=document.createElement("span");i.className="inlineLabel",i.textContent=e.inlineLabel,o.appendChild(i)}createLabel(e,t,o){var i;const n=document.createElement("div");let r="outer-container inputBlock";const a=document.createElement("label");if(a.innerText=e.label,!(null===(i=e.validation)||void 0===i?void 0:i.required)&&e.label){const e=document.createElement("span");e.className="optional",e.innerHTML=" (optional)",a.appendChild(e)}return"radio"===e.type&&(r+=" radioBlock"),n.className=r,e.readonly&&a.classList.add("readonly"),"checkbox"===e.type?this.appendCheckboxInput(e,t,a):n.appendChild(t),"checkbox"!==e.type&&a.appendChild(n),a.appendChild(o),a}createRadio(e,t){var o,i;const n=new DocumentFragment;for(const r of t.options){const a=document.createElement("input");a.type="radio",a.name=e,a.value=r.value,(null===(o=null==t?void 0:t.validation)||void 0===o?void 0:o.required)&&(a.setAttribute("required","required"),a.setAttribute("data-required",null!==(i=t.validation.required.message)&&void 0!==i?i:""));const l=document.createElement("span");l.innerText=r.label,n.appendChild(a),n.appendChild(l),n.appendChild(document.createElement("br"))}return n}populateFormFromSchema(){if(!this._formSchema)return;const e=this._formSchema.properties;Object.keys(e).forEach((t=>{const o=e[t].form;let i;switch(o.type){case"select":i=this.createSelect(t,o);break;case"radio":i=this.createRadio(t,o);break;default:i=this.createInput(t,o)}o.validation&&"radio"!==o.type&&this.applyValidation(i,o.validation);const n=this.createErrorBubble(),r=this.createLabel(o,i,n);this.template.content.append(r)}))}componentDidRender(){if(!this._formSchema)return;const e=this.template.content.cloneNode(!0),t=this._formSchema.properties;Object.keys(t).forEach((o=>{var i,n;const r=e.querySelectorAll(`[name=${o}]`);for(const e of r){if(e.oninvalid=this.validityCheckWrapper.bind(this),e.onblur=this.validityCheckWrapper.bind(this),e.onkeyup=this.fieldChanged.bind(this),e.onchange=this.fieldChanged.bind(this),null===(i=this._data)||void 0===i?void 0:i[o])switch(e.type){case"checkbox":"on"===this._data[o]&&(e.checked=!0);break;case"radio":e.value===this._data[o]&&(e.checked=!0);break;default:e.value=this._data[o]}if(null===(n=t[o].form.validation)||void 0===n?void 0:n.invalid){const i=t[o].form.validation.invalid.message;e.setCustomValidity(i),a(e,!0,i)}"select"===t[o].form.type&&e.classList.contains("placeholder")&&e.addEventListener("change",(()=>{e.classList.remove("placeholder")}))}})),this.fieldset.replaceChildren(e)}validityCheckWrapper(e){const{target:t,hasError:o,errorMessage:i}=function(e){var t,o,i,n;e.preventDefault();const r=e.target;let a=!0,l="";switch(r.value.length&&!r.value.replace(/\s/g,"").length?(l="This field cannot be left blank",r.setCustomValidity(l)):(l="",r.setCustomValidity&&r.setCustomValidity("")),!0){case r.validity.valueMissing:l=null!==(t=r.dataset.required)&&void 0!==t?t:"This field is required";break;case r.validity.patternMismatch:l=null!==(o=r.dataset.pattern)&&void 0!==o?o:"Incorrect format";break;case r.validity.badInput:l=null!==(i=r.dataset.badinput)&&void 0!==i?i:"Wrong input type";break;case r.validity.rangeOverflow||r.validity.rangeUnderflow:l=null!==(n=r.dataset.range)&&void 0!==n?n:"Invalid value";break;case r.validity.customError:l=r.validationMessage;break;default:a=!1}return{target:r,hasError:a,errorMessage:l}}(e);a(t,o,i)}render(){return o(i,null,o("form",{ref:e=>this.form=e,onSubmit:this.doSubmit.bind(this)},o("fieldset",{ref:e=>this.fieldset=e}),o("input",{type:"submit",ref:e=>this.submitButton=e,style:{display:"none"}})))}static get watchers(){return{formschema:["onFormSchemaChange"],data:["onDataChange"]}}};l.style='.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}';export{l as tttx_form}
|