@3t-transform/threeteeui 0.0.15 → 0.0.16

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.
Files changed (132) hide show
  1. package/dist/cjs/index-864b7110.js +1531 -0
  2. package/dist/cjs/index.cjs.js +2 -0
  3. package/dist/cjs/loader.cjs.js +22 -0
  4. package/dist/cjs/tttx-button.cjs.entry.js +28 -0
  5. package/dist/cjs/tttx-checkbox.cjs.entry.js +28 -0
  6. package/dist/cjs/tttx-form.cjs.entry.js +374 -0
  7. package/dist/cjs/tttx-icon.cjs.entry.js +1863 -0
  8. package/dist/cjs/tttx-list.cjs.entry.js +198 -0
  9. package/dist/cjs/tttx-loading-spinner.cjs.entry.js +26 -0
  10. package/dist/cjs/tttx-popover-content.cjs.entry.js +23 -0
  11. package/dist/cjs/tttx-standalone-input.cjs.entry.js +136 -0
  12. package/dist/cjs/tttx-table.cjs.entry.js +60 -0
  13. package/dist/cjs/tttx.cjs.js +23 -0
  14. package/dist/collection/collection-manifest.json +20 -0
  15. package/dist/collection/components/atoms/tttx-button/tttx-button.css +62 -0
  16. package/dist/collection/components/atoms/tttx-button/tttx-button.js +93 -0
  17. package/dist/collection/components/atoms/tttx-button/tttx-button.stories.js +27 -0
  18. package/dist/collection/components/atoms/tttx-icon/tttx-icon.css +105 -0
  19. package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +116 -0
  20. package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +47 -0
  21. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.css +48 -0
  22. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.js +66 -0
  23. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +17 -0
  24. package/dist/collection/components/atoms/tttx-popover-content/tttx-popover-content.css +30 -0
  25. package/dist/collection/components/atoms/tttx-popover-content/tttx-popover-content.js +96 -0
  26. package/dist/collection/components/atoms/tttx-popover-content/tttx-popover-content.stories.js +23 -0
  27. package/dist/collection/components/atoms/ttx-checkbox/tttx-checkbox.css +181 -0
  28. package/dist/collection/components/atoms/ttx-checkbox/tttx-checkbox.js +101 -0
  29. package/dist/collection/components/atoms/ttx-checkbox/tttx-checkbox.stories.js +13 -0
  30. package/dist/collection/components/molecules/tttx-form/tttx-form.css +230 -0
  31. package/dist/collection/components/molecules/tttx-form/tttx-form.js +451 -0
  32. package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +109 -0
  33. package/dist/collection/components/molecules/tttx-list/tttx-list.css +56 -0
  34. package/dist/collection/components/molecules/tttx-list/tttx-list.js +311 -0
  35. package/dist/collection/components/molecules/tttx-list/tttx-list.stories.js +37 -0
  36. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.css +177 -0
  37. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.js +569 -0
  38. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.js +156 -0
  39. package/dist/collection/components/molecules/tttx-table/tttx-table.css +166 -0
  40. package/dist/collection/components/molecules/tttx-table/tttx-table.js +177 -0
  41. package/dist/collection/components/molecules/tttx-table/tttx-table.stories.js +81 -0
  42. package/dist/collection/components/palette.stories.js +88 -0
  43. package/dist/collection/docs/gettingstarted-developer.stories.js +9 -0
  44. package/dist/collection/icons.js +2838 -0
  45. package/dist/collection/index.js +1 -0
  46. package/dist/components/index.d.ts +39 -0
  47. package/dist/components/index.js +10 -0
  48. package/dist/components/tttx-button.d.ts +11 -0
  49. package/dist/components/tttx-button.js +45 -0
  50. package/dist/components/tttx-checkbox.d.ts +11 -0
  51. package/dist/components/tttx-checkbox.js +46 -0
  52. package/dist/components/tttx-form.d.ts +11 -0
  53. package/dist/components/tttx-form.js +391 -0
  54. package/dist/components/tttx-icon.d.ts +11 -0
  55. package/dist/components/tttx-icon.js +6 -0
  56. package/dist/components/tttx-icon2.js +1877 -0
  57. package/dist/components/tttx-list.d.ts +11 -0
  58. package/dist/components/tttx-list.js +225 -0
  59. package/dist/components/tttx-loading-spinner.d.ts +11 -0
  60. package/dist/components/tttx-loading-spinner.js +6 -0
  61. package/dist/components/tttx-loading-spinner2.js +40 -0
  62. package/dist/components/tttx-popover-content.d.ts +11 -0
  63. package/dist/components/tttx-popover-content.js +6 -0
  64. package/dist/components/tttx-popover-content2.js +39 -0
  65. package/dist/components/tttx-standalone-input.d.ts +11 -0
  66. package/dist/components/tttx-standalone-input.js +179 -0
  67. package/dist/components/tttx-table.d.ts +11 -0
  68. package/dist/components/tttx-table.js +91 -0
  69. package/dist/esm/index-232e347b.js +1502 -0
  70. package/dist/esm/index.js +1 -0
  71. package/dist/esm/loader.js +18 -0
  72. package/dist/esm/polyfills/core-js.js +11 -0
  73. package/dist/esm/polyfills/css-shim.js +1 -0
  74. package/dist/esm/polyfills/dom.js +79 -0
  75. package/dist/esm/polyfills/es5-html-element.js +1 -0
  76. package/dist/esm/polyfills/index.js +34 -0
  77. package/dist/esm/polyfills/system.js +6 -0
  78. package/dist/esm/tttx-button.entry.js +24 -0
  79. package/dist/esm/tttx-checkbox.entry.js +24 -0
  80. package/dist/esm/tttx-form.entry.js +370 -0
  81. package/dist/esm/tttx-icon.entry.js +1859 -0
  82. package/dist/esm/tttx-list.entry.js +194 -0
  83. package/dist/esm/tttx-loading-spinner.entry.js +22 -0
  84. package/dist/esm/tttx-popover-content.entry.js +19 -0
  85. package/dist/esm/tttx-standalone-input.entry.js +132 -0
  86. package/dist/esm/tttx-table.entry.js +56 -0
  87. package/dist/esm/tttx.js +18 -0
  88. package/dist/index.cjs.js +1 -0
  89. package/dist/index.js +1 -0
  90. package/dist/tttx/index.esm.js +0 -0
  91. package/dist/tttx/p-01e1894e.entry.js +1 -0
  92. package/dist/tttx/p-10316ff1.entry.js +1 -0
  93. package/dist/tttx/p-125f06b3.entry.js +1 -0
  94. package/dist/tttx/p-184c4fae.js +2 -0
  95. package/dist/tttx/p-3973b7dd.entry.js +1 -0
  96. package/dist/tttx/p-5ce1ba22.entry.js +1 -0
  97. package/dist/tttx/p-6828fe6f.entry.js +1 -0
  98. package/dist/tttx/p-b1c22f5f.entry.js +1 -0
  99. package/dist/tttx/p-c7f9be65.entry.js +1 -0
  100. package/dist/tttx/p-fe4c70b2.entry.js +1 -0
  101. package/dist/tttx/tttx.esm.js +1 -0
  102. package/dist/types/components/atoms/tttx-button/tttx-button.d.ts +9 -0
  103. package/dist/types/components/atoms/tttx-button/tttx-button.stories.d.ts +20 -0
  104. package/dist/types/components/atoms/tttx-icon/tttx-icon.d.ts +14 -0
  105. package/dist/types/components/atoms/tttx-icon/tttx-icon.stories.d.ts +21 -0
  106. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.d.ts +6 -0
  107. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +17 -0
  108. package/dist/types/components/atoms/tttx-popover-content/tttx-popover-content.d.ts +7 -0
  109. package/dist/types/components/atoms/tttx-popover-content/tttx-popover-content.stories.d.ts +18 -0
  110. package/dist/types/components/atoms/ttx-checkbox/tttx-checkbox.d.ts +9 -0
  111. package/dist/types/components/atoms/ttx-checkbox/tttx-checkbox.stories.d.ts +6 -0
  112. package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +134 -0
  113. package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +12 -0
  114. package/dist/types/components/molecules/tttx-list/tttx-list.d.ts +51 -0
  115. package/dist/types/components/molecules/tttx-list/tttx-list.stories.d.ts +13 -0
  116. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.d.ts +38 -0
  117. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.d.ts +106 -0
  118. package/dist/types/components/molecules/tttx-table/tttx-table.d.ts +15 -0
  119. package/dist/types/components/molecules/tttx-table/tttx-table.stories.d.ts +21 -0
  120. package/dist/types/components/palette.stories.d.ts +6 -0
  121. package/dist/types/components.d.ts +264 -0
  122. package/dist/types/docs/gettingstarted-developer.stories.d.ts +5 -0
  123. package/dist/types/icons.d.ts +2 -0
  124. package/dist/types/index.d.ts +1 -0
  125. package/dist/types/stencil-public-runtime.d.ts +1637 -0
  126. package/loader/cdn.js +3 -0
  127. package/loader/index.cjs.js +3 -0
  128. package/loader/index.d.ts +21 -0
  129. package/loader/index.es2017.js +3 -0
  130. package/loader/index.js +4 -0
  131. package/loader/package.json +11 -0
  132. package/package.json +1 -1
@@ -0,0 +1,451 @@
1
+ import { h, Host } from '@stencil/core';
2
+ export class TttxForm {
3
+ constructor() {
4
+ // Create a new template element using the HTMLTemplateElement interface.
5
+ this.template = document.createElement('template');
6
+ this.formschema = undefined;
7
+ this.submitValue = undefined;
8
+ }
9
+ // This method is called whenever the "formschema" property changes
10
+ onFormSchemaChange(newValue) {
11
+ // Check if the new value is a string, indicating that it needs to be parsed
12
+ if (typeof newValue === 'string') {
13
+ // Parse the string and set the "_formSchema" property
14
+ this._formSchema = JSON.parse(newValue);
15
+ }
16
+ else {
17
+ // If the new value is already an object, set the "_formSchema" property directly
18
+ this._formSchema = newValue;
19
+ }
20
+ }
21
+ /**
22
+ * Handles the focus event for a form field and emits a "dataChanged" event
23
+ * to the parent component with the field name and its new value.
24
+ *
25
+ * @param {FocusEvent} event - The focus event triggered by the field.
26
+ * @return {void}
27
+ */
28
+ fieldChanged(event) {
29
+ // Extract the name and value of the field from the event
30
+ const fieldName = event.target.name;
31
+ const fieldValue = event.target.value;
32
+ // Emit an event to signal that the field's data has changed
33
+ this.dataChanged.emit({ name: fieldName, value: fieldValue });
34
+ }
35
+ /**
36
+ * Validates the input field on focusout event by checking its validity state,
37
+ * sets an error message if there's an issue, and emits a "dataChanged" event to
38
+ * the parent component with the field name and its new value.
39
+ *
40
+ * @param {FocusEvent} event - The focusout event triggered by the input field.
41
+ * @return {void}
42
+ */
43
+ validityCheck(event) {
44
+ var _a, _b, _c, _d;
45
+ event.preventDefault();
46
+ const target = event.target;
47
+ let hasError = true;
48
+ let errorMessage = '';
49
+ // validity object on HTML5 inputs has the following options
50
+ // badInput
51
+ // customError
52
+ // patternMismatch
53
+ // rangeOverflow
54
+ // rangeUnderflow
55
+ // stepMismatch
56
+ // tooLong
57
+ // tooShort
58
+ // typeMismatch
59
+ // valid
60
+ // valueMissing
61
+ // customErrors can be set with
62
+ // target.setCustomValidity('custom error!');
63
+ // and cleared with
64
+ // target.setCustomValidity('');
65
+ // Check the validity of the input field and set an error message if needed
66
+ switch (true) {
67
+ // The field is required, but has no value
68
+ case target.validity.valueMissing:
69
+ errorMessage = (_a = target.dataset.required) !== null && _a !== void 0 ? _a : 'This field is required';
70
+ break;
71
+ // The field's value does not match the expected pattern
72
+ case target.validity.patternMismatch:
73
+ errorMessage = (_b = target.dataset.pattern) !== null && _b !== void 0 ? _b : 'Incorrect format';
74
+ break;
75
+ // The field's value is not of the correct input type
76
+ case target.validity.badInput:
77
+ // IE string in a number field
78
+ errorMessage = (_c = target.dataset.badinput) !== null && _c !== void 0 ? _c : 'Wrong input type';
79
+ break;
80
+ // The field's value is above or below the range set in the "min" and "max" attributes
81
+ case target.validity.rangeOverflow || target.validity.rangeUnderflow:
82
+ // IE date or number is above or below value set in min or max tags
83
+ errorMessage = (_d = target.dataset.range) !== null && _d !== void 0 ? _d : 'Invalid value';
84
+ break;
85
+ // No error detected
86
+ default:
87
+ hasError = false;
88
+ }
89
+ // Set the error state of the input field based on the error message and whether an error was detected
90
+ this.setErrorState(target, hasError, errorMessage);
91
+ }
92
+ /**
93
+ * Sets the error state of an input field by updating its class and error message.
94
+ * If an error was detected, it sets the input field's class to "invalid" and
95
+ * displays the error message in an error bubble. If no error was detected,
96
+ * it removes the "invalid" class from the input field and clears the error bubble.
97
+ *
98
+ * @param {HTMLInputElement} target - The input field to update.
99
+ * @param {boolean} hasError - Whether an error was detected in the field.
100
+ * @param {string} errorMessage - The error message to display (if any).
101
+ * @return {void}
102
+ */
103
+ setErrorState(target, hasError, errorMessage) {
104
+ // Find the error bubble element for the input field
105
+ const errorBubble = target.parentElement.querySelector('.errorBubble');
106
+ // If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
107
+ if (hasError) {
108
+ target.className = 'invalid';
109
+ const errorIcon = this.createErrorIcon();
110
+ errorBubble.replaceChildren(errorIcon, errorMessage);
111
+ }
112
+ // If no error was detected, remove the "invalid" class from the input field and clear the error bubble
113
+ else {
114
+ target.className = '';
115
+ errorBubble.replaceChildren();
116
+ }
117
+ }
118
+ // Create an error icon element to display in the error bubble of an input field
119
+ createErrorIcon() {
120
+ // Create a new <span> element to serve as the error icon
121
+ const errorIcon = document.createElement('span');
122
+ // Set the class of the error icon to a pre-defined CSS class that specifies the icon's appearance
123
+ errorIcon.className = 'material-symbols-rounded';
124
+ // Set the text content of the error icon to the word "warning"
125
+ errorIcon.textContent = 'warning';
126
+ // Return the error icon element
127
+ return errorIcon;
128
+ }
129
+ /**
130
+ * Submits the form data to the server.
131
+ *
132
+ * @param {SubmitEvent} event - The event object for the form submission.
133
+ * @returns {void}
134
+ *
135
+ * @example
136
+ * const form = document.getElementById('myForm');
137
+ * form.addEventListener('submit', (event) => {
138
+ * doSubmit(event);
139
+ * });
140
+ */
141
+ doSubmit(event) {
142
+ // prevent the form from submitting normally
143
+ event.preventDefault();
144
+ // create a new FormData object with the form data
145
+ const formData = new FormData(event.target);
146
+ // emit the form data through the `dataSubmitted` event
147
+ this.dataSubmitted.emit(formData);
148
+ }
149
+ // This method is called before the component is loaded into the DOM
150
+ componentWillLoad() {
151
+ // Initialize the form schema by calling the "onFormSchemaChange" method with the current "formschema" property
152
+ this.onFormSchemaChange(this.formschema);
153
+ }
154
+ // This method is called before the component is rendered
155
+ componentWillRender() {
156
+ // Clear the template to account for a potential re-render scenario
157
+ this.template = document.createElement('template');
158
+ // Populate the form from the form schema
159
+ this.populateFormFromSchema();
160
+ }
161
+ /**
162
+ * Creates a new HTMLInputElement with the specified name, type, and placeholder (if any),
163
+ * and sets its autocomplete and autocapitalization properties to off.
164
+ *
165
+ * @param {string} formKey - The name of the input field, as specified in the form schema.
166
+ * @param {Object} formProperties - An object containing additional properties for the input field, such as its type and placeholder value.
167
+ * @param {string} formProperties.type - The type of the input field (e.g., "text", "email", "number", etc.).
168
+ * @param {string} [formProperties.placeholder] - An optional placeholder value to display in the input field.
169
+ * @return {HTMLInputElement} - The new input element.
170
+ */
171
+ createInput(formKey, formProperties) {
172
+ var _a;
173
+ // Create a new <input> element with the specified name and type
174
+ const input = document.createElement('input');
175
+ input.name = formKey;
176
+ input.type = formProperties.type;
177
+ // Set the placeholder attribute to the specified value (if any)
178
+ input.placeholder = (_a = formProperties.placeholder) !== null && _a !== void 0 ? _a : '';
179
+ // Disable autocomplete and autocapitalization
180
+ input.autocomplete = 'off';
181
+ input.autocapitalize = 'off';
182
+ // Return the input element
183
+ return input;
184
+ }
185
+ /**
186
+ * Applies validation attributes to an input element based on the specified validation object.
187
+ * If a certain property is present in the object, it will set the corresponding attribute on
188
+ * the input element (e.g., "required" will set the "required" and "data-required" attributes,
189
+ * "pattern" will set the "pattern" and "data-pattern" attributes, etc.).
190
+ *
191
+ * @param {HTMLInputElement} input - The input element to apply validation attributes to.
192
+ * @param {Object} validation - An object containing the validation rules for the input field.
193
+ * @param {Object} [validation.required] - An object containing a "message" property to display if the field is required.
194
+ * @param {Object} [validation.pattern] - An object containing a "pattern" property to match against the field value, and a "message" property to display if the pattern doesn't match.
195
+ * @param {Object} [validation.badInput] - An object containing a "message" property to display if the field value is invalid.
196
+ * @param {Object} [validation.minmax] - An object containing "min" and "max" properties to validate the field value against, and a "message" property to display if the value is out of range.
197
+ * @param {string} [validation.maxlength] - The maximum length of the input field.
198
+ * @return {void}
199
+ */
200
+ applyValidation(input, validation) {
201
+ var _a, _b;
202
+ // If the "required" property is present, add the "required" attribute to the input element and
203
+ // set its "data-required" attribute to the specified message (if any)
204
+ if (validation.required) {
205
+ input.setAttribute('required', '');
206
+ input.setAttribute('data-required', (_a = validation.required.message) !== null && _a !== void 0 ? _a : '');
207
+ }
208
+ // If the "pattern" property is present, add the "pattern" attribute to the input element and set
209
+ // its "data-pattern" attribute to the specified message (if any)
210
+ if (validation.pattern) {
211
+ input.setAttribute('pattern', validation.pattern.pattern);
212
+ input.setAttribute('data-pattern', (_b = validation.pattern.message) !== null && _b !== void 0 ? _b : '');
213
+ }
214
+ // If the "badInput" property is present, set the input element's "data-badinput" attribute to
215
+ // the specified message
216
+ if (validation.badInput) {
217
+ input.setAttribute('data-badinput', validation.badInput.message);
218
+ }
219
+ // If the "minmax" property is present, add the "min" and "max" attributes to the input element
220
+ // and set its "data-range" attribute to the specified message (if any)
221
+ if (validation.minmax) {
222
+ input.setAttribute('min', validation.minmax.min);
223
+ input.setAttribute('max', validation.minmax.max);
224
+ input.setAttribute('data-range', validation.minmax.message);
225
+ }
226
+ // If the "maxlength" property is present, add the "maxlength" attribute to the input element
227
+ if (validation.maxlength) {
228
+ input.setAttribute('maxlength', validation.maxlength);
229
+ }
230
+ }
231
+ // Create a new error bubble element
232
+ createErrorBubble() {
233
+ // Create a new <div> element with the "errorBubble" class
234
+ const errorBubble = document.createElement('div');
235
+ errorBubble.className = 'errorBubble';
236
+ // Return the error bubble element
237
+ return errorBubble;
238
+ }
239
+ /**
240
+ * Creates a new <label> element with the "inputBlock" class and the specified label text,
241
+ * and appends the input element and error bubble element to it. If the form property has
242
+ * no validation object, it adds an "optional" span element to the label.
243
+ *
244
+ * @param {Object} formProperties - An object containing properties for the form field, including its label text and validation rules.
245
+ * @param {HTMLInputElement} input - The input element to associate with the label.
246
+ * @param {HTMLDivElement} errorBubble - The error bubble element to display error messages in.
247
+ * @return {HTMLLabelElement} - The new label element.
248
+ */
249
+ createLabel(formProperties, input, errorBubble) {
250
+ // Create a new <label> element with the "inputBlock" class and the specified text
251
+ const label = document.createElement('label');
252
+ label.className = 'inputBlock';
253
+ label.innerText = formProperties.label;
254
+ // If the form property has no validation object, add an "optional" span element to the label
255
+ if (!formProperties.validation) {
256
+ const optionalSpan = document.createElement('span');
257
+ optionalSpan.className = 'optional';
258
+ optionalSpan.innerHTML = '&nbsp;(optional)';
259
+ label.appendChild(optionalSpan);
260
+ }
261
+ // Append the input element and error bubble element to the label
262
+ label.appendChild(input);
263
+ label.appendChild(errorBubble);
264
+ // Return the label element
265
+ return label;
266
+ }
267
+ /**
268
+ * Creates a new <input> element with the "submit" type, the "primary-blue" class, and the
269
+ * specified label text (i.e., "Save" by default), and returns the new submit button element.
270
+ *
271
+ * @return {HTMLInputElement} - The new submit button element.
272
+ */
273
+ createSubmitButton() {
274
+ // Create a new <input> element with the "submit" type and the specified class and value
275
+ const submitButton = document.createElement('input');
276
+ submitButton.type = 'submit';
277
+ submitButton.className = 'button primary-blue';
278
+ submitButton.value = 'Save';
279
+ // Return the submit button element
280
+ return submitButton;
281
+ }
282
+ /**
283
+ * Populates the form template with input fields and labels based on the properties of the
284
+ * current form schema. For each property in the schema, it creates an input element, applies
285
+ * any validation rules to it, creates an error bubble and label element, and appends them
286
+ * to the form template. Finally, it creates and appends a submit button element to the form.
287
+ *
288
+ * @return {void}
289
+ */
290
+ populateFormFromSchema() {
291
+ // If there is no form schema, return early
292
+ if (!this._formSchema)
293
+ return;
294
+ // Get the properties of the form schema and their keys
295
+ const properties = this._formSchema.properties;
296
+ const propertyKeys = Object.keys(properties);
297
+ // Loop through each property key and create an input, label, and error bubble for it
298
+ propertyKeys.forEach(formKey => {
299
+ const formItem = properties[formKey];
300
+ const formProperties = formItem.form;
301
+ const input = this.createInput(formKey, formProperties);
302
+ // If the form property has validation, apply it to the input
303
+ if (formProperties.validation) {
304
+ this.applyValidation(input, formProperties.validation);
305
+ }
306
+ // Create an error bubble and label element for the input
307
+ const errorBubble = this.createErrorBubble();
308
+ const label = this.createLabel(formProperties, input, errorBubble);
309
+ // Append the label element to the form template
310
+ this.template.content.append(label);
311
+ });
312
+ // Create and append a submit button element to the form template
313
+ const submitButton = this.createSubmitButton();
314
+ this.template.content.append(submitButton);
315
+ }
316
+ /**
317
+ * Clones the form template and binds event listeners to its input elements. First, it checks if
318
+ * there is a form schema present. If so, it clones the template's content, binds events to form
319
+ * input elements, and appends the cloned form elements to the fieldset. The event listeners include
320
+ * "oninvalid" (to check input validity on submit), "onblur" (to check input validity on blur),
321
+ * "onkeyup" (to handle changes in input fields), and "onchange" (to handle changes in select fields).
322
+ *
323
+ * @return {void}
324
+ */
325
+ componentDidRender() {
326
+ // If there's no form schema, return
327
+ if (!this._formSchema) {
328
+ return;
329
+ }
330
+ // Clone the template's content and store it in a variable
331
+ const formItems = this.template.content.cloneNode(true);
332
+ // Bind event listeners to form elements
333
+ const properties = this._formSchema.properties;
334
+ const propertyKeys = Object.keys(properties);
335
+ propertyKeys.forEach((formKey) => {
336
+ const formInput = formItems.querySelector(`[name=${formKey}]`);
337
+ // Bind events to form input elements
338
+ formInput.oninvalid = this.validityCheck.bind(this);
339
+ formInput.onblur = this.validityCheck.bind(this);
340
+ formInput.onkeyup = this.fieldChanged.bind(this);
341
+ formInput.onchange = this.fieldChanged.bind(this);
342
+ });
343
+ // Append the cloned form elements to the fieldset
344
+ this.fieldset.appendChild(formItems);
345
+ }
346
+ /**
347
+ * Renders the component's template as a form element with a fieldset container. The form's
348
+ * "onSubmit" event is bound to the "doSubmit" function, which handles the form submission
349
+ * and emits a "dataSubmitted" event with the form data. The fieldset element is assigned
350
+ * to the "fieldset" instance variable using a ref, so it can be populated with form elements
351
+ * later on.
352
+ *
353
+ * @return {JSX.Element} - The rendered form template as a JSX element.
354
+ */
355
+ render() {
356
+ return (h(Host, null, h("form", { onSubmit: this.doSubmit.bind(this) }, h("fieldset", { ref: el => (this.fieldset = el) }))));
357
+ }
358
+ static get is() { return "tttx-form"; }
359
+ static get encapsulation() { return "shadow"; }
360
+ static get originalStyleUrls() {
361
+ return {
362
+ "$": ["tttx-form.scss"]
363
+ };
364
+ }
365
+ static get styleUrls() {
366
+ return {
367
+ "$": ["tttx-form.css"]
368
+ };
369
+ }
370
+ static get properties() {
371
+ return {
372
+ "formschema": {
373
+ "type": "any",
374
+ "mutable": false,
375
+ "complexType": {
376
+ "original": "any",
377
+ "resolved": "any",
378
+ "references": {}
379
+ },
380
+ "required": false,
381
+ "optional": false,
382
+ "docs": {
383
+ "tags": [],
384
+ "text": ""
385
+ },
386
+ "attribute": "formschema",
387
+ "reflect": false
388
+ },
389
+ "submitValue": {
390
+ "type": "any",
391
+ "mutable": false,
392
+ "complexType": {
393
+ "original": "any",
394
+ "resolved": "any",
395
+ "references": {}
396
+ },
397
+ "required": false,
398
+ "optional": false,
399
+ "docs": {
400
+ "tags": [],
401
+ "text": ""
402
+ },
403
+ "attribute": "submit-value",
404
+ "reflect": false
405
+ }
406
+ };
407
+ }
408
+ static get events() {
409
+ return [{
410
+ "method": "dataSubmitted",
411
+ "name": "dataSubmitted",
412
+ "bubbles": true,
413
+ "cancelable": true,
414
+ "composed": true,
415
+ "docs": {
416
+ "tags": [],
417
+ "text": ""
418
+ },
419
+ "complexType": {
420
+ "original": "FormData",
421
+ "resolved": "FormData",
422
+ "references": {
423
+ "FormData": {
424
+ "location": "global"
425
+ }
426
+ }
427
+ }
428
+ }, {
429
+ "method": "dataChanged",
430
+ "name": "dataChanged",
431
+ "bubbles": true,
432
+ "cancelable": true,
433
+ "composed": true,
434
+ "docs": {
435
+ "tags": [],
436
+ "text": ""
437
+ },
438
+ "complexType": {
439
+ "original": "{ name: string, value: any }",
440
+ "resolved": "{ name: string; value: any; }",
441
+ "references": {}
442
+ }
443
+ }];
444
+ }
445
+ static get watchers() {
446
+ return [{
447
+ "propName": "formschema",
448
+ "methodName": "onFormSchemaChange"
449
+ }];
450
+ }
451
+ }
@@ -0,0 +1,109 @@
1
+ import { withActions } from '@storybook/addon-actions/decorator';
2
+ export default {
3
+ title: 'molecules/Form',
4
+ component: 'tttx-form',
5
+ parameters: {
6
+ actions: {
7
+ handles: ['dataSubmitted', 'dataChanged'],
8
+ },
9
+ },
10
+ decorators: [withActions],
11
+ };
12
+ const formSchema = {
13
+ properties: {
14
+ title: {
15
+ type: 'string',
16
+ format: 'string',
17
+ form: {
18
+ type: 'text',
19
+ placeholder: 'Mr, Mrs, Dr, Hon Rev',
20
+ label: 'Title',
21
+ },
22
+ },
23
+ forename: {
24
+ type: 'string',
25
+ format: 'string',
26
+ form: {
27
+ type: 'text',
28
+ placeholder: 'John',
29
+ label: 'Forename',
30
+ validation: {
31
+ required: {
32
+ message: 'Please enter your forename',
33
+ },
34
+ },
35
+ },
36
+ },
37
+ surname: {
38
+ type: 'string',
39
+ format: 'string',
40
+ form: {
41
+ type: 'text',
42
+ placeholder: 'Doe',
43
+ label: 'Surname',
44
+ validation: {
45
+ required: {
46
+ message: 'Please enter your surname',
47
+ },
48
+ },
49
+ },
50
+ },
51
+ postcode: {
52
+ type: 'string',
53
+ format: 'string',
54
+ form: {
55
+ type: 'text',
56
+ placeholder: 'AB10',
57
+ label: 'Start of postcode',
58
+ validation: {
59
+ required: {
60
+ message: 'Please enter the beginning of your postcode',
61
+ },
62
+ pattern: {
63
+ pattern: '^([A-Za-z][0-9])$|^([A-Za-z][0-9]{2})$|^([A-Za-z]{2}[0-9])$|^([A-Za-z]{2}[0-9]{2})$|^([A-Za-z][0-9][A-Za-z])$|^([A-Za-z]{2}[0-9][A-Za-z])$|^(GIR|BF|BX|XX)$',
64
+ message: 'Please enter the first half of your postcode. EG: ZZ99',
65
+ },
66
+ maxlength: 4,
67
+ },
68
+ },
69
+ },
70
+ age: {
71
+ type: 'number',
72
+ format: 'number',
73
+ form: {
74
+ type: 'number',
75
+ placeholder: '',
76
+ label: 'Age',
77
+ validation: {
78
+ required: {
79
+ message: 'Please enter your age',
80
+ },
81
+ badInput: {
82
+ message: 'Please enter a number',
83
+ },
84
+ },
85
+ },
86
+ },
87
+ dob: {
88
+ type: 'string',
89
+ format: 'date-time',
90
+ form: {
91
+ type: 'date',
92
+ placeholder: '',
93
+ label: 'Date of birth',
94
+ validation: {
95
+ required: {
96
+ message: 'Please enter your date of birth',
97
+ },
98
+ minmax: {
99
+ min: '1900-01-01',
100
+ max: '2100-12-31',
101
+ message: 'Please enter a date between 1900 and 2100',
102
+ },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ };
108
+ const jsonFormSchema = JSON.stringify(formSchema);
109
+ export const ExampleFormFromJSON = () => `<tttx-form formSchema='${jsonFormSchema}'></tttx-form>`;
@@ -0,0 +1,56 @@
1
+ .material-symbols-rounded {
2
+ font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24;
3
+ }
4
+
5
+ .material-symbols-rounded {
6
+ font-family: "Material Symbols Rounded", sans-serif;
7
+ font-weight: 400;
8
+ font-style: normal;
9
+ font-size: 24px;
10
+ line-height: 1;
11
+ letter-spacing: normal;
12
+ text-transform: none;
13
+ display: inline-block;
14
+ white-space: nowrap;
15
+ word-wrap: normal;
16
+ direction: ltr;
17
+ text-rendering: optimizeLegibility;
18
+ -webkit-font-smoothing: antialiased;
19
+ color: #9e9e9e;
20
+ }
21
+
22
+ :host {
23
+ display: flex;
24
+ flex-direction: column;
25
+ }
26
+
27
+ .tttx-list__row {
28
+ min-height: 52px;
29
+ line-height: 36px;
30
+ padding: 8px;
31
+ display: flex;
32
+ flex-direction: row;
33
+ align-items: center;
34
+ cursor: pointer;
35
+ border-bottom: 1px solid #d5d5d5;
36
+ }
37
+ .tttx-list__row .generic-template__content {
38
+ width: 100%;
39
+ display: flex;
40
+ align-items: center;
41
+ gap: 8px;
42
+ }
43
+ .tttx-list__row:first-of-type {
44
+ border-top: 1px solid #d5d5d5;
45
+ }
46
+ .tttx-list__row:focus, .tttx-list__row:active {
47
+ background-color: #e6e6e6;
48
+ }
49
+ .tttx-list__row.selected {
50
+ background-color: #e7f1f9;
51
+ }
52
+
53
+ .load-indicator {
54
+ display: flex;
55
+ justify-content: center;
56
+ }