@3t-transform/threeteeui 0.1.5 → 0.1.7

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 (167) hide show
  1. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  2. package/dist/cjs/css-shim-211819bc.js +6 -0
  3. package/dist/cjs/dom-9deb26c8.js +75 -0
  4. package/dist/cjs/index-11cfdabe.js +3297 -0
  5. package/dist/cjs/{index-906c2757.js → index-451f61dd.js} +3 -102
  6. package/dist/cjs/loader.cjs.js +19 -4
  7. package/dist/cjs/shadow-css-bf3843d2.js +389 -0
  8. package/dist/cjs/{tttx-button_2.cjs.entry.js → tttx-button.cjs.entry.js} +24 -50
  9. package/dist/cjs/tttx-form.cjs.entry.js +364 -364
  10. package/dist/cjs/tttx-icon.cjs.entry.js +21 -0
  11. package/dist/cjs/tttx-keyvalue-block.cjs.entry.js +57 -57
  12. package/dist/cjs/tttx-list.cjs.entry.js +76 -46
  13. package/dist/cjs/tttx-loading-spinner.cjs.entry.js +16 -16
  14. package/dist/cjs/tttx-standalone-input.cjs.entry.js +61 -58
  15. package/dist/cjs/tttx-toolbar.cjs.entry.js +20 -0
  16. package/dist/cjs/tttx.cjs.js +117 -9
  17. package/dist/collection/collection-manifest.json +4 -3
  18. package/dist/collection/components/atoms/tttx-button/test/tttx-button.e2e.js +9 -0
  19. package/dist/collection/components/atoms/tttx-button/test/tttx-button.spec.js +83 -0
  20. package/dist/collection/components/atoms/tttx-button/tttx-button.js +110 -116
  21. package/dist/collection/components/atoms/tttx-button/tttx-button.stories.js +14 -14
  22. package/dist/collection/components/atoms/tttx-icon/test/tttx-icon.e2e.js +9 -0
  23. package/dist/collection/components/atoms/tttx-icon/test/tttx-icon.spec.js +16 -0
  24. package/dist/collection/components/atoms/tttx-icon/tttx-icon.css +4 -0
  25. package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +62 -62
  26. package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +22 -22
  27. package/dist/collection/components/atoms/tttx-keyvalue-block/test/tttx-keyvalue-block.spec.js +216 -0
  28. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.js +107 -107
  29. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.js +38 -38
  30. package/dist/collection/components/atoms/tttx-loading-spinner/Test/tttx-loading-spinner.spec.js +64 -0
  31. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.js +67 -67
  32. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +17 -17
  33. package/dist/collection/components/molecules/tttx-form/lib/setErrorState.js +35 -35
  34. package/dist/collection/components/molecules/tttx-form/lib/setErrorState.spec.js +38 -0
  35. package/dist/collection/components/molecules/tttx-form/lib/validityCheck.js +58 -58
  36. package/dist/collection/components/molecules/tttx-form/lib/validityCheck.spec.js +214 -0
  37. package/dist/collection/components/molecules/tttx-form/test/tttx-form.e2e.js +9 -0
  38. package/dist/collection/components/molecules/tttx-form/test/tttx-form.spec.js +232 -0
  39. package/dist/collection/components/molecules/tttx-form/tttx-form.css +32 -3
  40. package/dist/collection/components/molecules/tttx-form/tttx-form.js +364 -364
  41. package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +127 -127
  42. package/dist/collection/components/molecules/tttx-list/test/ttttx-list.spec.e2e.js +26 -0
  43. package/dist/collection/components/molecules/tttx-list/test/tttx-list.spec.js +183 -0
  44. package/dist/collection/components/molecules/tttx-list/tttx-list.js +105 -105
  45. package/dist/collection/components/molecules/tttx-list/tttx-list.stories.js +43 -43
  46. package/dist/collection/components/molecules/tttx-standalone-input/test/tttx-standalone-input.e2e.js +9 -0
  47. package/dist/collection/components/molecules/tttx-standalone-input/test/tttx-standalone-input.spec.js +219 -0
  48. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.css +32 -3
  49. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.js +627 -572
  50. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.js +148 -135
  51. package/dist/collection/components/molecules/tttx-toolbar/test/tttx-toolbar.test.js +0 -0
  52. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.css +30 -0
  53. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.js +44 -0
  54. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.stories.js +20 -0
  55. package/dist/collection/components/palette.stories.js +7 -7
  56. package/dist/collection/docs/gettingstarted-developer.stories.js +5 -5
  57. package/dist/collection/icons.js +2838 -2838
  58. package/dist/collection/index.js +1 -1
  59. package/dist/collection/shared/domsanitiser.options.js +14 -14
  60. package/dist/collection/shared/test/domsanitiser.options.spec.js +23 -0
  61. package/dist/components/index.d.ts +1 -9
  62. package/dist/components/index.js +6 -1
  63. package/dist/components/tttx-button.js +48 -59
  64. package/dist/components/tttx-form.js +381 -381
  65. package/dist/components/tttx-icon2.js +29 -29
  66. package/dist/components/tttx-keyvalue-block.js +74 -74
  67. package/dist/components/tttx-list.js +98 -68
  68. package/dist/components/tttx-loading-spinner.js +33 -33
  69. package/dist/components/tttx-standalone-input.js +108 -102
  70. package/dist/components/tttx-toolbar.d.ts +11 -0
  71. package/dist/components/tttx-toolbar.js +36 -0
  72. package/dist/esm/app-globals-0f993ce5.js +3 -0
  73. package/dist/esm/css-shim-9d54a2f2.js +4 -0
  74. package/dist/esm/dom-6be6f662.js +73 -0
  75. package/dist/esm/{index-4010ad69.js → index-0350f122.js} +4 -101
  76. package/dist/esm/index-dbe25028.js +3262 -0
  77. package/dist/esm/loader.js +19 -4
  78. package/dist/esm/polyfills/core-js.js +0 -0
  79. package/dist/esm/polyfills/css-shim.js +1 -1
  80. package/dist/esm/polyfills/dom.js +0 -0
  81. package/dist/esm/polyfills/es5-html-element.js +0 -0
  82. package/dist/esm/polyfills/index.js +0 -0
  83. package/dist/esm/polyfills/system.js +0 -0
  84. package/dist/esm/shadow-css-ed4599f8.js +387 -0
  85. package/dist/esm/{tttx-button_2.entry.js → tttx-button.entry.js} +25 -50
  86. package/dist/esm/tttx-form.entry.js +364 -364
  87. package/dist/esm/tttx-icon.entry.js +17 -0
  88. package/dist/esm/tttx-keyvalue-block.entry.js +57 -57
  89. package/dist/esm/tttx-list.entry.js +76 -46
  90. package/dist/esm/tttx-loading-spinner.entry.js +16 -16
  91. package/dist/esm/tttx-standalone-input.entry.js +61 -58
  92. package/dist/esm/tttx-toolbar.entry.js +16 -0
  93. package/dist/esm/tttx.js +117 -6
  94. package/dist/tttx/app-globals-0f993ce5.js +3 -0
  95. package/dist/tttx/css-shim-9d54a2f2.js +4 -0
  96. package/dist/tttx/dom-6be6f662.js +73 -0
  97. package/dist/tttx/index-dbe25028.js +3262 -0
  98. package/dist/tttx/index.esm.js +1 -0
  99. package/dist/tttx/p-0a85dda4.entry.js +1 -0
  100. package/dist/tttx/{p-3281444a.entry.js → p-1b015a9d.entry.js} +1 -1
  101. package/dist/tttx/p-4f3958fa.entry.js +1 -0
  102. package/dist/tttx/p-5cae1beb.entry.js +1 -0
  103. package/dist/tttx/p-62869344.js +2 -0
  104. package/dist/tttx/p-92465671.entry.js +1 -0
  105. package/dist/tttx/{p-dab7ee1b.entry.js → p-a0179cb1.entry.js} +1 -1
  106. package/dist/tttx/p-cc6644c9.entry.js +1 -0
  107. package/dist/tttx/p-cd1565e0.entry.js +3 -0
  108. package/dist/tttx/shadow-css-ed4599f8.js +387 -0
  109. package/dist/tttx/tttx-button.entry.js +30 -0
  110. package/dist/tttx/tttx-form.entry.js +373 -0
  111. package/dist/tttx/tttx-icon.entry.js +17 -0
  112. package/dist/tttx/tttx-keyvalue-block.entry.js +63 -0
  113. package/dist/tttx/tttx-list.entry.js +1730 -0
  114. package/dist/tttx/tttx-loading-spinner.entry.js +22 -0
  115. package/dist/tttx/tttx-standalone-input.entry.js +66 -0
  116. package/dist/tttx/tttx-toolbar.entry.js +16 -0
  117. package/dist/tttx/tttx.esm.js +129 -1
  118. package/dist/types/components/atoms/tttx-button/test/tttx-button.e2e.d.ts +1 -0
  119. package/dist/types/components/atoms/tttx-button/test/tttx-button.spec.d.ts +1 -0
  120. package/dist/types/components/atoms/tttx-button/tttx-button.d.ts +10 -13
  121. package/dist/types/components/atoms/tttx-button/tttx-button.stories.d.ts +10 -10
  122. package/dist/types/components/atoms/tttx-icon/test/tttx-icon.e2e.d.ts +1 -0
  123. package/dist/types/components/atoms/tttx-icon/test/tttx-icon.spec.d.ts +1 -0
  124. package/dist/types/components/atoms/tttx-icon/tttx-icon.d.ts +5 -5
  125. package/dist/types/components/atoms/tttx-icon/tttx-icon.stories.d.ts +20 -20
  126. package/dist/types/components/atoms/tttx-keyvalue-block/test/tttx-keyvalue-block.spec.d.ts +1 -0
  127. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.d.ts +7 -7
  128. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.d.ts +9 -9
  129. package/dist/types/components/atoms/tttx-loading-spinner/Test/tttx-loading-spinner.spec.d.ts +1 -0
  130. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.d.ts +6 -6
  131. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +17 -17
  132. package/dist/types/components/molecules/tttx-form/lib/setErrorState.d.ts +13 -13
  133. package/dist/types/components/molecules/tttx-form/lib/setErrorState.spec.d.ts +1 -0
  134. package/dist/types/components/molecules/tttx-form/lib/validityCheck.d.ts +17 -17
  135. package/dist/types/components/molecules/tttx-form/lib/validityCheck.spec.d.ts +1 -0
  136. package/dist/types/components/molecules/tttx-form/test/tttx-form.e2e.d.ts +1 -0
  137. package/dist/types/components/molecules/tttx-form/test/tttx-form.spec.d.ts +1 -0
  138. package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +114 -114
  139. package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +13 -13
  140. package/dist/types/components/molecules/tttx-list/test/ttttx-list.spec.e2e.d.ts +1 -0
  141. package/dist/types/components/molecules/tttx-list/test/tttx-list.spec.d.ts +1 -0
  142. package/dist/types/components/molecules/tttx-list/tttx-list.d.ts +11 -11
  143. package/dist/types/components/molecules/tttx-list/tttx-list.stories.d.ts +14 -14
  144. package/dist/types/components/molecules/tttx-standalone-input/test/tttx-standalone-input.e2e.d.ts +1 -0
  145. package/dist/types/components/molecules/tttx-standalone-input/test/tttx-standalone-input.spec.d.ts +1 -0
  146. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.d.ts +56 -53
  147. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.d.ts +122 -106
  148. package/dist/types/components/molecules/tttx-toolbar/test/tttx-toolbar.test.d.ts +0 -0
  149. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.d.ts +4 -0
  150. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.stories.d.ts +13 -0
  151. package/dist/types/components/palette.stories.d.ts +6 -6
  152. package/dist/types/components.d.ts +21 -0
  153. package/dist/types/docs/gettingstarted-developer.stories.d.ts +5 -5
  154. package/dist/types/icons.d.ts +2 -2
  155. package/dist/types/index.d.ts +1 -1
  156. package/dist/types/shared/domsanitiser.options.d.ts +10 -10
  157. package/dist/types/shared/test/domsanitiser.options.spec.d.ts +1 -0
  158. package/dist/types/stencil-public-runtime.d.ts +3 -59
  159. package/loader/index.d.ts +0 -9
  160. package/package.json +1 -1
  161. package/dist/collection/transform-tag-name.js +0 -5
  162. package/dist/tttx/p-083eeedc.entry.js +0 -1
  163. package/dist/tttx/p-5687f4ad.js +0 -2
  164. package/dist/tttx/p-5c9a1626.entry.js +0 -3
  165. package/dist/tttx/p-931e42c9.entry.js +0 -1
  166. package/dist/tttx/p-b5c1dd86.entry.js +0 -1
  167. package/dist/types/transform-tag-name.d.ts +0 -1
@@ -0,0 +1,64 @@
1
+ import { newSpecPage } from '@stencil/core/testing';
2
+ import { TttxLoadingSpinner } from '../tttx-loading-spinner';
3
+ describe('tttx-loading-spinner', () => {
4
+ it('renders the loading text when the loading message prop is set to true', async () => {
5
+ const page = await newSpecPage({
6
+ components: [TttxLoadingSpinner],
7
+ html: '<tttx-loading-spinner></tttx-loading-spinner>',
8
+ });
9
+ page.rootInstance.loadingMessage = true;
10
+ await page.waitForChanges();
11
+ expect(page.root).toEqualHtml(`
12
+ <tttx-loading-spinner>
13
+ <mock:shadow-root>
14
+ <div class='spinner-container'><div class="loading-box"><span class='spinner large'></span></div><div class='loading-text'>Loading, please wait...</div></div>
15
+ </mock:shadow-root>
16
+ </tttx-loading-spinner>
17
+ `);
18
+ });
19
+ it('renders without the loading text when the loading message prop is set to false', async () => {
20
+ const page = await newSpecPage({
21
+ components: [TttxLoadingSpinner],
22
+ html: '<tttx-loading-spinner></tttx-loading-spinner>',
23
+ });
24
+ page.rootInstance.loadingMessage = false;
25
+ await page.waitForChanges();
26
+ expect(page.root).toEqualHtml(`
27
+ <tttx-loading-spinner>
28
+ <mock:shadow-root>
29
+ <div class='spinner-container'><div class="loading-box"><span class='spinner large'></span></div></div>
30
+ </mock:shadow-root>
31
+ </tttx-loading-spinner>
32
+ `);
33
+ });
34
+ it('renders the small spinner when the size prop is set to small', async () => {
35
+ const page = await newSpecPage({
36
+ components: [TttxLoadingSpinner],
37
+ html: '<tttx-loading-spinner></tttx-loading-spinner>',
38
+ });
39
+ page.rootInstance.size = 'small';
40
+ await page.waitForChanges();
41
+ expect(page.root).toEqualHtml(`
42
+ <tttx-loading-spinner>
43
+ <mock:shadow-root>
44
+ <div class='spinner-container'><div class="loading-box"><span class='spinner small'></span></div></div>
45
+ </mock:shadow-root>
46
+ </tttx-loading-spinner>
47
+ `);
48
+ });
49
+ it('renders the large spinner when the size prop is set to large', async () => {
50
+ const page = await newSpecPage({
51
+ components: [TttxLoadingSpinner],
52
+ html: '<tttx-loading-spinner></tttx-loading-spinner>',
53
+ });
54
+ page.rootInstance.size = 'large';
55
+ await page.waitForChanges();
56
+ expect(page.root).toEqualHtml(`
57
+ <tttx-loading-spinner>
58
+ <mock:shadow-root>
59
+ <div class='spinner-container'><div class="loading-box"><span class='spinner large'></span></div></div>
60
+ </mock:shadow-root>
61
+ </tttx-loading-spinner>
62
+ `);
63
+ });
64
+ });
@@ -1,67 +1,67 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { h } from '@stencil/core';
3
- export class TttxLoadingSpinner {
4
- constructor() {
5
- this.loadingMessage = undefined;
6
- this.size = 'large';
7
- }
8
- renderLoadingMessage() {
9
- if (!this.loadingMessage)
10
- return '';
11
- return h("div", { class: "loading-text" }, "Loading, please wait...");
12
- }
13
- render() {
14
- return (h("div", { class: "spinner-container" }, h("div", { class: "loading-box" }, h("span", { class: `spinner ${this.size}` })), this.renderLoadingMessage()));
15
- }
16
- static get is() { return "tttx-loading-spinner"; }
17
- static get encapsulation() { return "shadow"; }
18
- static get originalStyleUrls() {
19
- return {
20
- "$": ["tttx-loading-spinner.scss"]
21
- };
22
- }
23
- static get styleUrls() {
24
- return {
25
- "$": ["tttx-loading-spinner.css"]
26
- };
27
- }
28
- static get properties() {
29
- return {
30
- "loadingMessage": {
31
- "type": "boolean",
32
- "mutable": true,
33
- "complexType": {
34
- "original": "boolean",
35
- "resolved": "boolean",
36
- "references": {}
37
- },
38
- "required": false,
39
- "optional": false,
40
- "docs": {
41
- "tags": [],
42
- "text": ""
43
- },
44
- "attribute": "loading-message",
45
- "reflect": false
46
- },
47
- "size": {
48
- "type": "string",
49
- "mutable": true,
50
- "complexType": {
51
- "original": "'small' | 'large'",
52
- "resolved": "\"large\" | \"small\"",
53
- "references": {}
54
- },
55
- "required": false,
56
- "optional": false,
57
- "docs": {
58
- "tags": [],
59
- "text": ""
60
- },
61
- "attribute": "size",
62
- "reflect": false,
63
- "defaultValue": "'large'"
64
- }
65
- };
66
- }
67
- }
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { h } from '@stencil/core';
3
+ export class TttxLoadingSpinner {
4
+ constructor() {
5
+ this.loadingMessage = undefined;
6
+ this.size = 'large';
7
+ }
8
+ renderLoadingMessage() {
9
+ if (!this.loadingMessage)
10
+ return '';
11
+ return h("div", { class: "loading-text" }, "Loading, please wait...");
12
+ }
13
+ render() {
14
+ return (h("div", { class: "spinner-container" }, h("div", { class: "loading-box" }, h("span", { class: `spinner ${this.size}` })), this.renderLoadingMessage()));
15
+ }
16
+ static get is() { return "tttx-loading-spinner"; }
17
+ static get encapsulation() { return "shadow"; }
18
+ static get originalStyleUrls() {
19
+ return {
20
+ "$": ["tttx-loading-spinner.scss"]
21
+ };
22
+ }
23
+ static get styleUrls() {
24
+ return {
25
+ "$": ["tttx-loading-spinner.css"]
26
+ };
27
+ }
28
+ static get properties() {
29
+ return {
30
+ "loadingMessage": {
31
+ "type": "boolean",
32
+ "mutable": true,
33
+ "complexType": {
34
+ "original": "boolean",
35
+ "resolved": "boolean",
36
+ "references": {}
37
+ },
38
+ "required": false,
39
+ "optional": false,
40
+ "docs": {
41
+ "tags": [],
42
+ "text": ""
43
+ },
44
+ "attribute": "loading-message",
45
+ "reflect": false
46
+ },
47
+ "size": {
48
+ "type": "string",
49
+ "mutable": true,
50
+ "complexType": {
51
+ "original": "'small' | 'large'",
52
+ "resolved": "\"large\" | \"small\"",
53
+ "references": {}
54
+ },
55
+ "required": false,
56
+ "optional": false,
57
+ "docs": {
58
+ "tags": [],
59
+ "text": ""
60
+ },
61
+ "attribute": "size",
62
+ "reflect": false,
63
+ "defaultValue": "'large'"
64
+ }
65
+ };
66
+ }
67
+ }
@@ -1,17 +1,17 @@
1
- export default {
2
- title: 'atoms/Loading Spinner',
3
- component: 'tttx-loading-spinner',
4
- argTypes: {
5
- loadingMessage: {
6
- control: 'boolean',
7
- },
8
- size: {
9
- control: { type: 'radio' },
10
- options: ['small', 'large'],
11
- },
12
- },
13
- };
14
- export const Example = args => {
15
- const size = args.size || 'large';
16
- return `<tttx-loading-spinner ${args.loadingMessage ? 'loading-message' : ''} size='${size}' />`;
17
- };
1
+ export default {
2
+ title: 'atoms/Loading Spinner',
3
+ component: 'tttx-loading-spinner',
4
+ argTypes: {
5
+ loadingMessage: {
6
+ control: 'boolean',
7
+ },
8
+ size: {
9
+ control: { type: 'radio' },
10
+ options: ['small', 'large'],
11
+ },
12
+ },
13
+ };
14
+ export const Example = args => {
15
+ const size = args.size || 'large';
16
+ return `<tttx-loading-spinner ${args.loadingMessage ? 'loading-message' : ''} size='${size}' />`;
17
+ };
@@ -1,35 +1,35 @@
1
- /**
2
- * Sets the error state of an input field by updating its class and error message.
3
- * If an error was detected, it sets the input field's class to "invalid" and
4
- * displays the error message in an error bubble. If no error was detected,
5
- * it removes the "invalid" class from the input field and clears the error bubble.
6
- *
7
- * @param {HTMLInputElement} target - The input field to update.
8
- * @param {boolean} hasError - Whether an error was detected in the field.
9
- * @param {string} errorMessage - The error message to display (if any).
10
- * @return {void}
11
- */
12
- function setErrorState(target, hasError, errorMessage) {
13
- // Find the error bubble element for the input field
14
- const errorBubble = target.parentElement.querySelector('.errorBubble');
15
- // If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
16
- if (hasError) {
17
- target.className = 'invalid';
18
- const errorIcon = document.createElement('span');
19
- // Set the class of the error icon to a pre-defined CSS class that specifies the icon's appearance
20
- errorIcon.className = 'material-symbols-rounded';
21
- // Set the text content of the error icon to the word "warning"
22
- errorIcon.textContent = 'warning';
23
- // errorBubble.replaceChildren cannot be used here because the tests don't support this new feature :(
24
- errorBubble.innerHTML = '';
25
- errorBubble.append(errorIcon);
26
- errorBubble.append(errorMessage);
27
- // errorBubble.replaceChildren(errorIcon, errorMessage);
28
- }
29
- // If no error was detected, remove the "invalid" class from the input field and clear the error bubble
30
- else {
31
- target.className = '';
32
- errorBubble.innerHTML = '';
33
- }
34
- }
35
- export default setErrorState;
1
+ /**
2
+ * Sets the error state of an input field by updating its class and error message.
3
+ * If an error was detected, it sets the input field's class to "invalid" and
4
+ * displays the error message in an error bubble. If no error was detected,
5
+ * it removes the "invalid" class from the input field and clears the error bubble.
6
+ *
7
+ * @param {HTMLInputElement} target - The input field to update.
8
+ * @param {boolean} hasError - Whether an error was detected in the field.
9
+ * @param {string} errorMessage - The error message to display (if any).
10
+ * @return {void}
11
+ */
12
+ function setErrorState(target, hasError, errorMessage) {
13
+ // Find the error bubble element for the input field
14
+ const errorBubble = target.parentElement.querySelector('.errorBubble');
15
+ // If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
16
+ if (hasError) {
17
+ target.className = 'invalid';
18
+ const errorIcon = document.createElement('span');
19
+ // Set the class of the error icon to a pre-defined CSS class that specifies the icon's appearance
20
+ errorIcon.className = 'material-symbols-rounded';
21
+ // Set the text content of the error icon to the word "warning"
22
+ errorIcon.textContent = 'warning';
23
+ // errorBubble.replaceChildren cannot be used here because the tests don't support this new feature :(
24
+ errorBubble.innerHTML = '';
25
+ errorBubble.append(errorIcon);
26
+ errorBubble.append(errorMessage);
27
+ // errorBubble.replaceChildren(errorIcon, errorMessage);
28
+ }
29
+ // If no error was detected, remove the "invalid" class from the input field and clear the error bubble
30
+ else {
31
+ target.className = '';
32
+ errorBubble.innerHTML = '';
33
+ }
34
+ }
35
+ export default setErrorState;
@@ -0,0 +1,38 @@
1
+ import setErrorState from './setErrorState';
2
+ describe('setErrorState', () => {
3
+ let target;
4
+ let errorBubble;
5
+ beforeEach(() => {
6
+ target = document.createElement('input');
7
+ errorBubble = document.createElement('div');
8
+ errorBubble.className = 'errorBubble';
9
+ target.parentElement = document.createElement('div');
10
+ target.parentElement.appendChild(errorBubble);
11
+ });
12
+ afterEach(() => {
13
+ target = null;
14
+ errorBubble = null;
15
+ });
16
+ test('should set error state correctly when hasError is true', () => {
17
+ setErrorState(target, true, 'Invalid value');
18
+ expect(target.className).toBe('invalid');
19
+ expect(errorBubble.innerHTML).toBe('<span class="material-symbols-rounded">warning</span>Invalid value');
20
+ });
21
+ test('should clear error state correctly when hasError is false', () => {
22
+ target.className = 'invalid';
23
+ errorBubble.innerHTML = '<span class="material-symbols-rounded">warning</span>Invalid value';
24
+ setErrorState(target, false, '');
25
+ expect(target.className).toBe('');
26
+ expect(errorBubble.innerHTML).toBe('');
27
+ });
28
+ test('should set error state correctly with custom error message', () => {
29
+ setErrorState(target, true, 'Custom error message');
30
+ expect(target.className).toBe('invalid');
31
+ expect(errorBubble.innerHTML).toBe('<span class="material-symbols-rounded">warning</span>Custom error message');
32
+ });
33
+ test('should set error state correctly with no error message', () => {
34
+ setErrorState(target, true, '');
35
+ expect(target.className).toBe('invalid');
36
+ expect(errorBubble.innerHTML).toBe('<span class="material-symbols-rounded">warning</span> ');
37
+ });
38
+ });
@@ -1,58 +1,58 @@
1
- /**
2
- * Validates the input field on focusout event by checking its validity state,
3
- * sets an error message if there's an issue, and emits a "dataChanged" event to
4
- * the parent component with the field name and its new value.
5
- *
6
- * @param {Event} event - The focusout event triggered by the input field.
7
- * @return {void}
8
- */
9
- function validityCheck(event) {
10
- var _a, _b, _c, _d;
11
- event.preventDefault();
12
- const target = event.target;
13
- let hasError = true;
14
- let errorMessage = '';
15
- // validity object on HTML5 inputs has the following options
16
- // badInput
17
- // customError
18
- // patternMismatch
19
- // rangeOverflow
20
- // rangeUnderflow
21
- // stepMismatch
22
- // tooLong
23
- // tooShort
24
- // typeMismatch
25
- // valid
26
- // valueMissing
27
- // customErrors can be set with
28
- // target.setCustomValidity('custom error!');
29
- // and cleared with
30
- // target.setCustomValidity('');
31
- // Check the validity of the input field and set an error message if needed
32
- switch (true) {
33
- // The field is required, but has no value
34
- case target.validity.valueMissing:
35
- errorMessage = (_a = target.dataset.required) !== null && _a !== void 0 ? _a : 'This field is required';
36
- break;
37
- // The field's value does not match the expected pattern
38
- case target.validity.patternMismatch:
39
- errorMessage = (_b = target.dataset.pattern) !== null && _b !== void 0 ? _b : 'Incorrect format';
40
- break;
41
- // The field's value is not of the correct input type
42
- case target.validity.badInput:
43
- // IE string in a number field
44
- errorMessage = (_c = target.dataset.badinput) !== null && _c !== void 0 ? _c : 'Wrong input type';
45
- break;
46
- // The field's value is above or below the range set in the "min" and "max" attributes
47
- case target.validity.rangeOverflow || target.validity.rangeUnderflow:
48
- // IE date or number is above or below value set in min or max tags
49
- errorMessage = (_d = target.dataset.range) !== null && _d !== void 0 ? _d : 'Invalid value';
50
- break;
51
- // No error detected
52
- default:
53
- hasError = false;
54
- }
55
- // Return the error state
56
- return { target, hasError, errorMessage };
57
- }
58
- export default validityCheck;
1
+ /**
2
+ * Validates the input field on focusout event by checking its validity state,
3
+ * sets an error message if there's an issue, and emits a "dataChanged" event to
4
+ * the parent component with the field name and its new value.
5
+ *
6
+ * @param {Event} event - The focusout event triggered by the input field.
7
+ * @return {void}
8
+ */
9
+ function validityCheck(event) {
10
+ var _a, _b, _c, _d;
11
+ event.preventDefault();
12
+ const target = event.target;
13
+ let hasError = true;
14
+ let errorMessage = '';
15
+ // validity object on HTML5 inputs has the following options
16
+ // badInput
17
+ // customError
18
+ // patternMismatch
19
+ // rangeOverflow
20
+ // rangeUnderflow
21
+ // stepMismatch
22
+ // tooLong
23
+ // tooShort
24
+ // typeMismatch
25
+ // valid
26
+ // valueMissing
27
+ // customErrors can be set with
28
+ // target.setCustomValidity('custom error!');
29
+ // and cleared with
30
+ // target.setCustomValidity('');
31
+ // Check the validity of the input field and set an error message if needed
32
+ switch (true) {
33
+ // The field is required, but has no value
34
+ case target.validity.valueMissing:
35
+ errorMessage = (_a = target.dataset.required) !== null && _a !== void 0 ? _a : 'This field is required';
36
+ break;
37
+ // The field's value does not match the expected pattern
38
+ case target.validity.patternMismatch:
39
+ errorMessage = (_b = target.dataset.pattern) !== null && _b !== void 0 ? _b : 'Incorrect format';
40
+ break;
41
+ // The field's value is not of the correct input type
42
+ case target.validity.badInput:
43
+ // IE string in a number field
44
+ errorMessage = (_c = target.dataset.badinput) !== null && _c !== void 0 ? _c : 'Wrong input type';
45
+ break;
46
+ // The field's value is above or below the range set in the "min" and "max" attributes
47
+ case target.validity.rangeOverflow || target.validity.rangeUnderflow:
48
+ // IE date or number is above or below value set in min or max tags
49
+ errorMessage = (_d = target.dataset.range) !== null && _d !== void 0 ? _d : 'Invalid value';
50
+ break;
51
+ // No error detected
52
+ default:
53
+ hasError = false;
54
+ }
55
+ // Return the error state
56
+ return { target, hasError, errorMessage };
57
+ }
58
+ export default validityCheck;
@@ -0,0 +1,214 @@
1
+ import validityCheck from './validityCheck';
2
+ // badInput
3
+ // customError
4
+ // patternMismatch
5
+ // rangeOverflow
6
+ // rangeUnderflow
7
+ // stepMismatch
8
+ // tooLong
9
+ // tooShort
10
+ // typeMismatch
11
+ // valid
12
+ // valueMissing
13
+ describe('validityCheck', () => {
14
+ it('should return a valid response when there are no validation issues', async () => {
15
+ const preventDefault = jest.fn();
16
+ const event = {
17
+ target: {
18
+ value: 'test',
19
+ validity: {
20
+ valid: true
21
+ },
22
+ dataset: {}
23
+ },
24
+ preventDefault
25
+ };
26
+ const result = validityCheck(event);
27
+ expect(preventDefault).toHaveBeenCalledTimes(1);
28
+ expect(result).toStrictEqual({
29
+ "errorMessage": "",
30
+ "hasError": false,
31
+ "target": event.target
32
+ });
33
+ });
34
+ it('should return the required property when there is a value missing', async () => {
35
+ const preventDefault = jest.fn();
36
+ const event = {
37
+ target: {
38
+ dataset: {
39
+ required: 'This is required'
40
+ },
41
+ value: 'test',
42
+ validity: {
43
+ valid: false,
44
+ valueMissing: true
45
+ }
46
+ },
47
+ preventDefault
48
+ };
49
+ const result = validityCheck(event);
50
+ expect(preventDefault).toHaveBeenCalledTimes(1);
51
+ expect(result).toStrictEqual({
52
+ "errorMessage": "This is required",
53
+ "hasError": true,
54
+ "target": event.target
55
+ });
56
+ });
57
+ it('should return a default error message property when there is a value missing', async () => {
58
+ const preventDefault = jest.fn();
59
+ const event = {
60
+ target: {
61
+ dataset: {},
62
+ value: 'test',
63
+ validity: {
64
+ valid: false,
65
+ valueMissing: true
66
+ }
67
+ },
68
+ preventDefault
69
+ };
70
+ const result = validityCheck(event);
71
+ expect(preventDefault).toHaveBeenCalledTimes(1);
72
+ expect(result).toStrictEqual({
73
+ "errorMessage": 'This field is required',
74
+ "hasError": true,
75
+ "target": event.target
76
+ });
77
+ });
78
+ it('should return the pattern property when there is a patternMismatch', async () => {
79
+ const preventDefault = jest.fn();
80
+ const event = {
81
+ target: {
82
+ dataset: {
83
+ pattern: 'Incorrect format CUSTOM'
84
+ },
85
+ value: 'test',
86
+ validity: {
87
+ valid: false,
88
+ patternMismatch: true
89
+ }
90
+ },
91
+ preventDefault
92
+ };
93
+ const result = validityCheck(event);
94
+ expect(preventDefault).toHaveBeenCalledTimes(1);
95
+ expect(result).toStrictEqual({
96
+ "errorMessage": "Incorrect format CUSTOM",
97
+ "hasError": true,
98
+ "target": event.target
99
+ });
100
+ });
101
+ it('should return the a default error message when there is a patternMismatch', async () => {
102
+ const preventDefault = jest.fn();
103
+ const event = {
104
+ target: {
105
+ dataset: {},
106
+ value: 'test',
107
+ validity: {
108
+ valid: false,
109
+ patternMismatch: true
110
+ }
111
+ },
112
+ preventDefault
113
+ };
114
+ const result = validityCheck(event);
115
+ expect(preventDefault).toHaveBeenCalledTimes(1);
116
+ expect(result).toStrictEqual({
117
+ "errorMessage": 'Incorrect format',
118
+ "hasError": true,
119
+ "target": event.target
120
+ });
121
+ });
122
+ it('should return the badinput error message property when there is a badInput', async () => {
123
+ const preventDefault = jest.fn();
124
+ const event = {
125
+ target: {
126
+ dataset: {
127
+ badinput: 'There is a bad input'
128
+ },
129
+ value: 'test',
130
+ validity: {
131
+ valid: false,
132
+ badInput: true
133
+ }
134
+ },
135
+ preventDefault
136
+ };
137
+ const result = validityCheck(event);
138
+ expect(preventDefault).toHaveBeenCalledTimes(1);
139
+ expect(result).toStrictEqual({
140
+ "errorMessage": "There is a bad input",
141
+ "hasError": true,
142
+ "target": event.target
143
+ });
144
+ });
145
+ it('should return a default error message property when there is a badInput', async () => {
146
+ const preventDefault = jest.fn();
147
+ const event = {
148
+ target: {
149
+ value: 'test',
150
+ validity: {
151
+ valid: false,
152
+ badInput: true
153
+ },
154
+ dataset: {}
155
+ },
156
+ preventDefault
157
+ };
158
+ const result = validityCheck(event);
159
+ expect(preventDefault).toHaveBeenCalledTimes(1);
160
+ expect(result).toStrictEqual({
161
+ "errorMessage": 'Wrong input type',
162
+ "hasError": true,
163
+ "target": event.target
164
+ });
165
+ });
166
+ it('should return a message for an item out of range (underflow) with custom message', async () => {
167
+ const preventDefault = jest.fn();
168
+ const event = {
169
+ target: {
170
+ value: '0',
171
+ validity: {
172
+ valid: false,
173
+ rangeOverflow: true
174
+ },
175
+ dataset: {
176
+ range: 'Value is out of range'
177
+ }
178
+ },
179
+ preventDefault
180
+ };
181
+ const result = validityCheck(event);
182
+ expect(preventDefault).toHaveBeenCalledTimes(1);
183
+ expect(result).toStrictEqual({
184
+ "errorMessage": "Value is out of range",
185
+ "hasError": true,
186
+ "target": event.target
187
+ });
188
+ });
189
+ it('should return a message for an item out of range (underflow)', async () => {
190
+ const preventDefault = jest.fn();
191
+ const event = {
192
+ target: {
193
+ value: '0',
194
+ validity: {
195
+ valid: false,
196
+ rangeOverflow: true
197
+ },
198
+ dataset: {}
199
+ },
200
+ preventDefault
201
+ };
202
+ const result = validityCheck(event);
203
+ expect(preventDefault).toHaveBeenCalledTimes(1);
204
+ expect(result).toStrictEqual({
205
+ "errorMessage": "Invalid value",
206
+ "hasError": true,
207
+ "target": event.target
208
+ });
209
+ });
210
+ // it('target.validity.rangeOverflow', async () => {
211
+ // });
212
+ // it('target.validity.rangeUnderflow', async () => {
213
+ // });
214
+ });