@watermarkinsights/ripple 3.3.0-0 → 3.3.0-2

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 (176) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/{functions-8fb310fe.js → functions-653e695c.js} +442 -442
  3. package/dist/cjs/{global-9bd085c7.js → global-45888f19.js} +65 -65
  4. package/dist/cjs/{http-service-9e8c4dd5.js → http-service-494d81de.js} +49 -49
  5. package/dist/cjs/{interfaces-30a74c1f.js → interfaces-a3338581.js} +29 -29
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/cjs/priv-chart-popover.cjs.entry.js +78 -78
  8. package/dist/cjs/priv-datepicker.cjs.entry.js +661 -661
  9. package/dist/cjs/priv-navigator-button.cjs.entry.js +18 -18
  10. package/dist/cjs/priv-navigator-item.cjs.entry.js +23 -23
  11. package/dist/cjs/ripple.cjs.js +2 -2
  12. package/dist/cjs/wm-action-menu_2.cjs.entry.js +340 -313
  13. package/dist/cjs/wm-button.cjs.entry.js +218 -219
  14. package/dist/cjs/wm-chart-slice.cjs.entry.js +13 -13
  15. package/dist/cjs/wm-chart.cjs.entry.js +514 -505
  16. package/dist/cjs/wm-datepicker.cjs.entry.js +256 -256
  17. package/dist/cjs/wm-input.cjs.entry.js +125 -125
  18. package/dist/cjs/wm-modal-footer.cjs.entry.js +31 -31
  19. package/dist/cjs/wm-modal-header.cjs.entry.js +34 -34
  20. package/dist/cjs/wm-modal.cjs.entry.js +161 -161
  21. package/dist/cjs/wm-navigator.cjs.entry.js +268 -268
  22. package/dist/cjs/wm-network-uploader.cjs.entry.js +420 -420
  23. package/dist/cjs/wm-option_2.cjs.entry.js +497 -469
  24. package/dist/cjs/wm-pagination.cjs.entry.js +167 -167
  25. package/dist/cjs/wm-search.cjs.entry.js +231 -231
  26. package/dist/cjs/wm-snackbar.cjs.entry.js +170 -170
  27. package/dist/cjs/wm-tab-item_3.cjs.entry.js +300 -300
  28. package/dist/cjs/wm-tag-input.cjs.entry.js +556 -556
  29. package/dist/cjs/wm-timepicker.cjs.entry.js +386 -381
  30. package/dist/cjs/wm-toggletip.cjs.entry.js +124 -124
  31. package/dist/cjs/wm-uploader.cjs.entry.js +346 -346
  32. package/dist/cjs/wm-wrapper.cjs.entry.js +12 -12
  33. package/dist/collection/components/wm-action-menu/wm-action-menu.js +465 -435
  34. package/dist/collection/components/wm-button/wm-button.js +485 -486
  35. package/dist/collection/components/wm-chart/priv-chart-popover/priv-chart-popover.js +232 -232
  36. package/dist/collection/components/wm-chart/wm-chart-slice.js +64 -64
  37. package/dist/collection/components/wm-chart/wm-chart.css +13 -0
  38. package/dist/collection/components/wm-chart/wm-chart.js +761 -734
  39. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.js +1003 -1003
  40. package/dist/collection/components/wm-datepicker/wm-datepicker.js +462 -462
  41. package/dist/collection/components/wm-input/wm-input.js +415 -415
  42. package/dist/collection/components/wm-menuitem/wm-menuitem.js +444 -411
  43. package/dist/collection/components/wm-modal/wm-modal-footer.js +141 -141
  44. package/dist/collection/components/wm-modal/wm-modal-header.js +92 -92
  45. package/dist/collection/components/wm-modal/wm-modal.js +459 -459
  46. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.js +97 -97
  47. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.js +114 -114
  48. package/dist/collection/components/wm-navigator/wm-navigator.js +468 -468
  49. package/dist/collection/components/wm-option/wm-option.js +422 -394
  50. package/dist/collection/components/wm-pagination/wm-pagination.js +368 -368
  51. package/dist/collection/components/wm-search/wm-search.js +479 -479
  52. package/dist/collection/components/wm-select/wm-select.js +728 -692
  53. package/dist/collection/components/wm-snackbar/wm-snackbar.js +297 -297
  54. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.js +219 -219
  55. package/dist/collection/components/wm-tabs/wm-tab-list/wm-tab-list.js +331 -331
  56. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.js +104 -104
  57. package/dist/collection/components/wm-tag-input/wm-tag-input.js +787 -787
  58. package/dist/collection/components/wm-timepicker/wm-timepicker.js +598 -587
  59. package/dist/collection/components/wm-toggletip/wm-toggletip.js +241 -241
  60. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.js +753 -753
  61. package/dist/collection/components/wm-uploader/wm-uploader.js +748 -748
  62. package/dist/collection/components/wm-wrapper/wm-wrapper.js +27 -27
  63. package/dist/collection/dev/scripts.js +20 -20
  64. package/dist/collection/global/__mocks__/functions.js +6 -5
  65. package/dist/collection/global/functions.js +445 -445
  66. package/dist/collection/global/global.js +72 -72
  67. package/dist/collection/global/interfaces.js +49 -49
  68. package/dist/collection/global/services/__mocks__/http-service.js +130 -130
  69. package/dist/collection/global/services/http-service.js +50 -50
  70. package/dist/collection/lang/lang.js +5 -5
  71. package/dist/collection/lang/piglatin.js +93 -93
  72. package/dist/esm/{functions-c315390d.js → functions-e528c934.js} +442 -442
  73. package/dist/esm/{global-11e6d295.js → global-1e13ed17.js} +65 -65
  74. package/dist/esm/{http-service-5d037e16.js → http-service-3dc3b3e7.js} +49 -49
  75. package/dist/esm/{interfaces-61c6305b.js → interfaces-2b97fab2.js} +29 -29
  76. package/dist/esm/loader.js +2 -2
  77. package/dist/esm/polyfills/core-js.js +0 -0
  78. package/dist/esm/polyfills/dom.js +0 -0
  79. package/dist/esm/polyfills/es5-html-element.js +0 -0
  80. package/dist/esm/polyfills/index.js +0 -0
  81. package/dist/esm/polyfills/system.js +0 -0
  82. package/dist/esm/priv-chart-popover.entry.js +78 -78
  83. package/dist/esm/priv-datepicker.entry.js +661 -661
  84. package/dist/esm/priv-navigator-button.entry.js +18 -18
  85. package/dist/esm/priv-navigator-item.entry.js +23 -23
  86. package/dist/esm/ripple.js +2 -2
  87. package/dist/esm/wm-action-menu_2.entry.js +340 -313
  88. package/dist/esm/wm-button.entry.js +218 -219
  89. package/dist/esm/wm-chart-slice.entry.js +13 -13
  90. package/dist/esm/wm-chart.entry.js +514 -505
  91. package/dist/esm/wm-datepicker.entry.js +256 -256
  92. package/dist/esm/wm-input.entry.js +125 -125
  93. package/dist/esm/wm-modal-footer.entry.js +31 -31
  94. package/dist/esm/wm-modal-header.entry.js +34 -34
  95. package/dist/esm/wm-modal.entry.js +161 -161
  96. package/dist/esm/wm-navigator.entry.js +268 -268
  97. package/dist/esm/wm-network-uploader.entry.js +420 -420
  98. package/dist/esm/wm-option_2.entry.js +497 -469
  99. package/dist/esm/wm-pagination.entry.js +167 -167
  100. package/dist/esm/wm-search.entry.js +231 -231
  101. package/dist/esm/wm-snackbar.entry.js +170 -170
  102. package/dist/esm/wm-tab-item_3.entry.js +300 -300
  103. package/dist/esm/wm-tag-input.entry.js +556 -556
  104. package/dist/esm/wm-timepicker.entry.js +386 -381
  105. package/dist/esm/wm-toggletip.entry.js +124 -124
  106. package/dist/esm/wm-uploader.entry.js +346 -346
  107. package/dist/esm/wm-wrapper.entry.js +12 -12
  108. package/dist/ripple/{p-c5e44367.entry.js → p-092b01f3.entry.js} +1 -1
  109. package/dist/ripple/p-0d138e91.entry.js +1 -0
  110. package/dist/ripple/{p-5ffa983b.entry.js → p-1e0c41a9.entry.js} +1 -1
  111. package/dist/ripple/{p-d5fafa9c.entry.js → p-3003d26d.entry.js} +1 -1
  112. package/dist/ripple/p-301b67a3.entry.js +1 -0
  113. package/dist/ripple/{p-374b4fa6.entry.js → p-33524565.entry.js} +1 -1
  114. package/dist/ripple/{p-73ebc395.js → p-40d42d65.js} +1 -1
  115. package/dist/ripple/{p-888bec42.js → p-43f1298b.js} +0 -0
  116. package/dist/ripple/{p-dea72d46.entry.js → p-4cc71463.entry.js} +1 -1
  117. package/dist/ripple/{p-e60fe2f5.js → p-588b4475.js} +0 -0
  118. package/dist/ripple/p-65e3a656.entry.js +1 -0
  119. package/dist/ripple/p-6b96b3d4.entry.js +1 -0
  120. package/dist/ripple/{p-7bbd123c.entry.js → p-8923b7d0.entry.js} +1 -1
  121. package/dist/ripple/{p-ba9d3069.entry.js → p-8cd1396e.entry.js} +1 -1
  122. package/dist/ripple/{p-e574fb73.entry.js → p-aa973691.entry.js} +1 -1
  123. package/dist/ripple/{p-b4a8c8d3.entry.js → p-b3d5ea85.entry.js} +1 -1
  124. package/dist/ripple/{p-27d5255f.entry.js → p-cd58a15c.entry.js} +1 -1
  125. package/dist/ripple/{p-589f8195.entry.js → p-d613130d.entry.js} +1 -1
  126. package/dist/ripple/{p-2689c3ff.entry.js → p-dc7ba72a.entry.js} +1 -1
  127. package/dist/ripple/{p-41f39509.entry.js → p-dc9c9fda.entry.js} +1 -1
  128. package/dist/ripple/p-df6da757.entry.js +1 -0
  129. package/dist/ripple/{p-36da5d4a.entry.js → p-e9e8334e.entry.js} +1 -1
  130. package/dist/ripple/p-ec9697db.entry.js +1 -0
  131. package/dist/ripple/{p-a6d6eae7.js → p-fd8070fb.js} +0 -0
  132. package/dist/ripple/ripple.esm.js +1 -1
  133. package/dist/types/components/wm-action-menu/wm-action-menu.d.ts +48 -46
  134. package/dist/types/components/wm-button/wm-button.d.ts +44 -43
  135. package/dist/types/components/wm-chart/priv-chart-popover/priv-chart-popover.d.ts +23 -23
  136. package/dist/types/components/wm-chart/wm-chart-slice.d.ts +8 -8
  137. package/dist/types/components/wm-chart/wm-chart.d.ts +80 -79
  138. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +75 -75
  139. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +41 -41
  140. package/dist/types/components/wm-input/wm-input.d.ts +45 -45
  141. package/dist/types/components/wm-menuitem/wm-menuitem.d.ts +34 -30
  142. package/dist/types/components/wm-modal/wm-modal-footer.d.ts +15 -15
  143. package/dist/types/components/wm-modal/wm-modal-header.d.ts +12 -12
  144. package/dist/types/components/wm-modal/wm-modal.d.ts +41 -41
  145. package/dist/types/components/wm-navigator/priv-navigator-button/priv-navigator-button.d.ts +10 -10
  146. package/dist/types/components/wm-navigator/priv-navigator-item/priv-navigator-item.d.ts +13 -13
  147. package/dist/types/components/wm-navigator/wm-navigator.d.ts +61 -61
  148. package/dist/types/components/wm-option/wm-option.d.ts +32 -28
  149. package/dist/types/components/wm-pagination/wm-pagination.d.ts +32 -32
  150. package/dist/types/components/wm-search/wm-search.d.ts +86 -86
  151. package/dist/types/components/wm-select/wm-select.d.ts +67 -64
  152. package/dist/types/components/wm-snackbar/wm-snackbar.d.ts +35 -35
  153. package/dist/types/components/wm-tabs/wm-tab-item/wm-tab-item.d.ts +38 -38
  154. package/dist/types/components/wm-tabs/wm-tab-list/wm-tab-list.d.ts +53 -53
  155. package/dist/types/components/wm-tabs/wm-tab-panel/wm-tab-panel.d.ts +20 -20
  156. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts +91 -91
  157. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +63 -62
  158. package/dist/types/components/wm-toggletip/wm-toggletip.d.ts +27 -27
  159. package/dist/types/components/wm-uploader/wm-network-uploader/wm-network-uploader.d.ts +85 -85
  160. package/dist/types/components/wm-uploader/wm-uploader.d.ts +80 -80
  161. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -7
  162. package/dist/types/components.d.ts +28 -24
  163. package/dist/types/global/__mocks__/functions.d.ts +6 -5
  164. package/dist/types/global/functions.d.ts +40 -40
  165. package/dist/types/global/global.d.ts +1 -1
  166. package/dist/types/global/interfaces.d.ts +34 -34
  167. package/dist/types/global/services/__mocks__/http-service.d.ts +6 -6
  168. package/dist/types/global/services/http-service.d.ts +4 -4
  169. package/dist/types/lang/lang.d.ts +5 -5
  170. package/package.json +46 -46
  171. package/dist/ripple/p-14b37f79.entry.js +0 -1
  172. package/dist/ripple/p-27c6abf9.entry.js +0 -1
  173. package/dist/ripple/p-336c0ed7.entry.js +0 -1
  174. package/dist/ripple/p-6933edc6.entry.js +0 -1
  175. package/dist/ripple/p-c31c4d52.entry.js +0 -1
  176. package/dist/ripple/p-d079df21.entry.js +0 -1
@@ -1,415 +1,415 @@
1
- import { h, Component, Element, Event, Host, Prop, State, Watch } from "@stencil/core";
2
- import { intl, generateId, isRelatedTarget } from "../../global/functions";
3
- export class Input {
4
- constructor() {
5
- this.labelPosition = "top";
6
- this.value = "";
7
- this.disabled = false;
8
- this.placeholder = "";
9
- this.requiredField = false;
10
- this.type = "text";
11
- this.step = 1;
12
- this.announcement = "";
13
- this.previousBlurredValue = "";
14
- this.displayedErrorMessage = "";
15
- this.uid = "";
16
- this.requiredErrorMessage = intl.formatMessage({
17
- id: "global.requiredError",
18
- defaultMessage: "This field is required.",
19
- });
20
- this.numberErrorMessage = intl.formatMessage({
21
- id: "input.numberError",
22
- defaultMessage: "Please enter a valid number.",
23
- });
24
- }
25
- get charCount() {
26
- return this.value.length;
27
- }
28
- componentWillLoad() {
29
- this.uid = this.el.id ? this.el.id : generateId();
30
- this.el.focus = function () {
31
- if (!this.disabled) {
32
- this.shadowRoot.querySelector("input").focus();
33
- }
34
- };
35
- if (!this.label) {
36
- console.error("wm-input requires the label property");
37
- }
38
- }
39
- componentDidLoad() {
40
- if (this.value) {
41
- this.inputEl.value = this.value;
42
- this.previousBlurredValue = this.inputEl.value;
43
- }
44
- }
45
- handleErrorMessage() {
46
- this.displayedErrorMessage = this.validate();
47
- }
48
- handleKeyDown(ev) {
49
- // in most browsers, onInput doesn't fire if the input's maxLength is reached
50
- // to handle the case where a user continues to type after reaching the character limit, the keyDown event must be used
51
- const isModifierKey = ev.ctrlKey || ev.metaKey || ev.altKey;
52
- const isCharacter = /^.$/.test(ev.key) && !isModifierKey;
53
- const hasReachedCharacterLimit = isCharacter && this.characterLimit && this.inputEl.value.length >= this.characterLimit;
54
- if (hasReachedCharacterLimit) {
55
- this.announce(this.generateCharacterLimitWarning(this.charCount, this.characterLimit));
56
- }
57
- }
58
- handleBlur(ev) {
59
- if (this.value !== this.previousBlurredValue) {
60
- this.wmInputValueChanged.emit({ value: this.value });
61
- }
62
- this.previousBlurredValue = this.value;
63
- // do not validate if clicking to an element that should prevent validation (e.g. close button on modal)
64
- const shouldPreventValidation = this.preventValidation && isRelatedTarget(ev, this.preventValidation);
65
- if (!shouldPreventValidation) {
66
- this.displayedErrorMessage = this.validate();
67
- }
68
- this.inputWrapperEl.classList.remove("focus");
69
- }
70
- handleInput(ev) {
71
- this.value = ev.target.value;
72
- if (this.characterLimit && this.charCount >= this.characterLimit - 5) {
73
- this.announce(this.generateCharacterLimitWarning(this.charCount, this.characterLimit));
74
- }
75
- }
76
- handleFocus() {
77
- this.inputWrapperEl.classList.add("focus");
78
- }
79
- validate() {
80
- // These rules are in priority order
81
- // i.e. an input that is triggering both required and number errors will only show the number one but it's first
82
- const validationRules = [this.validateNumber.bind(this), this.validateRequired.bind(this)];
83
- if (this.errorMessage) {
84
- return this.errorMessage;
85
- }
86
- else {
87
- // sets newError to first rule that returns an error
88
- return validationRules.reduce((prev, current) => (prev ? prev : current()), "");
89
- }
90
- }
91
- validateRequired() {
92
- return this.requiredField && this.value === "" ? this.requiredErrorMessage : "";
93
- }
94
- validateNumber() {
95
- return this.type === "number" && this.inputEl.validity.badInput ? this.numberErrorMessage : "";
96
- }
97
- announce(message) {
98
- if (this.liveRegionEl.textContent === message) {
99
- message += "\u00A0";
100
- }
101
- this.announcement = message;
102
- }
103
- generateCharacterLimitWarning(charCount, charLimit) {
104
- const charactersEnteredMessage = intl.formatMessage({
105
- id: "input.charactersEntered",
106
- defaultMessage: "{x, number} of {y, number} characters entered.",
107
- }, { x: charCount, y: charLimit });
108
- const characterLimitReachedMessage = intl.formatMessage({
109
- id: "input.characterLimitReached",
110
- defaultMessage: "No additional characters will be entered.",
111
- });
112
- return `${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`;
113
- }
114
- renderErrorMessage() {
115
- return this.errorMessage || this.displayedErrorMessage;
116
- }
117
- render() {
118
- return (h(Host, { id: this.uid },
119
- h("div", { class: `wrapper label-${this.labelPosition} ${this.errorMessage || this.displayedErrorMessage ? "invalid" : ""}`, ref: (el) => (this.inputWrapperEl = el) },
120
- h("div", { class: "label-wrapper" }, this.labelPosition !== "none" && (h("label", { htmlFor: `inputfield-${this.uid}`, class: "label" },
121
- this.label,
122
- this.requiredField && (h("span", { class: "required", "aria-hidden": "true" }, "*"))))),
123
- h("div", { class: "inner-wrapper" },
124
- h("div", { class: "inputfield-wrapper" },
125
- h("input", { ref: (el) => (this.inputEl = el), id: `inputfield-${this.uid}`, disabled: this.disabled, "aria-label": this.label, "aria-describedby": `info-${this.uid} error-${this.uid}`, onInput: (ev) => this.handleInput(ev), onKeyDown: (ev) => this.handleKeyDown(ev), onBlur: (ev) => this.handleBlur(ev), onFocus: this.handleFocus.bind(this), placeholder: this.placeholder, autocomplete: "off", required: this.requiredField, maxLength: this.characterLimit || undefined, type: this.type, step: this.step, max: this.max, min: this.min }),
126
- this.characterLimit && typeof this.characterLimit === "number" ? (h("div", { class: "character-count" },
127
- this.charCount,
128
- "/",
129
- this.characterLimit)) : ("")),
130
- this.info && (h("div", { id: `info-${this.uid}`, class: "info" }, this.info)),
131
- h("div", { id: `error-${this.uid}`, "aria-live": "assertive", class: "error-message", "aria-atomic": "true" }, this.renderErrorMessage()),
132
- h("div", { class: "sr-only", "aria-live": "polite", "aria-atomic": "true", ref: (el) => (this.liveRegionEl = el) }, this.announcement)))));
133
- }
134
- static get is() { return "wm-input"; }
135
- static get encapsulation() { return "shadow"; }
136
- static get originalStyleUrls() { return {
137
- "$": ["wm-input.scss"]
138
- }; }
139
- static get styleUrls() { return {
140
- "$": ["wm-input.css"]
141
- }; }
142
- static get properties() { return {
143
- "label": {
144
- "type": "string",
145
- "mutable": false,
146
- "complexType": {
147
- "original": "string",
148
- "resolved": "string",
149
- "references": {}
150
- },
151
- "required": true,
152
- "optional": false,
153
- "docs": {
154
- "tags": [],
155
- "text": ""
156
- },
157
- "attribute": "label",
158
- "reflect": false
159
- },
160
- "labelPosition": {
161
- "type": "string",
162
- "mutable": false,
163
- "complexType": {
164
- "original": "\"top\" | \"left\" | \"none\"",
165
- "resolved": "\"left\" | \"none\" | \"top\"",
166
- "references": {}
167
- },
168
- "required": false,
169
- "optional": false,
170
- "docs": {
171
- "tags": [],
172
- "text": ""
173
- },
174
- "attribute": "label-position",
175
- "reflect": false,
176
- "defaultValue": "\"top\""
177
- },
178
- "value": {
179
- "type": "string",
180
- "mutable": true,
181
- "complexType": {
182
- "original": "string",
183
- "resolved": "string",
184
- "references": {}
185
- },
186
- "required": false,
187
- "optional": false,
188
- "docs": {
189
- "tags": [],
190
- "text": ""
191
- },
192
- "attribute": "value",
193
- "reflect": true,
194
- "defaultValue": "\"\""
195
- },
196
- "disabled": {
197
- "type": "boolean",
198
- "mutable": false,
199
- "complexType": {
200
- "original": "boolean",
201
- "resolved": "boolean",
202
- "references": {}
203
- },
204
- "required": false,
205
- "optional": false,
206
- "docs": {
207
- "tags": [],
208
- "text": ""
209
- },
210
- "attribute": "disabled",
211
- "reflect": true,
212
- "defaultValue": "false"
213
- },
214
- "info": {
215
- "type": "string",
216
- "mutable": false,
217
- "complexType": {
218
- "original": "string",
219
- "resolved": "string | undefined",
220
- "references": {}
221
- },
222
- "required": false,
223
- "optional": true,
224
- "docs": {
225
- "tags": [],
226
- "text": ""
227
- },
228
- "attribute": "info",
229
- "reflect": false
230
- },
231
- "placeholder": {
232
- "type": "string",
233
- "mutable": false,
234
- "complexType": {
235
- "original": "string",
236
- "resolved": "string",
237
- "references": {}
238
- },
239
- "required": false,
240
- "optional": false,
241
- "docs": {
242
- "tags": [],
243
- "text": ""
244
- },
245
- "attribute": "placeholder",
246
- "reflect": false,
247
- "defaultValue": "\"\""
248
- },
249
- "requiredField": {
250
- "type": "boolean",
251
- "mutable": false,
252
- "complexType": {
253
- "original": "boolean",
254
- "resolved": "boolean",
255
- "references": {}
256
- },
257
- "required": false,
258
- "optional": false,
259
- "docs": {
260
- "tags": [],
261
- "text": ""
262
- },
263
- "attribute": "required-field",
264
- "reflect": false,
265
- "defaultValue": "false"
266
- },
267
- "errorMessage": {
268
- "type": "string",
269
- "mutable": false,
270
- "complexType": {
271
- "original": "string",
272
- "resolved": "string | undefined",
273
- "references": {}
274
- },
275
- "required": false,
276
- "optional": true,
277
- "docs": {
278
- "tags": [],
279
- "text": ""
280
- },
281
- "attribute": "error-message",
282
- "reflect": false
283
- },
284
- "characterLimit": {
285
- "type": "number",
286
- "mutable": false,
287
- "complexType": {
288
- "original": "number",
289
- "resolved": "number | undefined",
290
- "references": {}
291
- },
292
- "required": false,
293
- "optional": true,
294
- "docs": {
295
- "tags": [],
296
- "text": ""
297
- },
298
- "attribute": "character-limit",
299
- "reflect": false
300
- },
301
- "preventValidation": {
302
- "type": "string",
303
- "mutable": false,
304
- "complexType": {
305
- "original": "string",
306
- "resolved": "string | undefined",
307
- "references": {}
308
- },
309
- "required": false,
310
- "optional": true,
311
- "docs": {
312
- "tags": [],
313
- "text": ""
314
- },
315
- "attribute": "prevent-validation",
316
- "reflect": false
317
- },
318
- "type": {
319
- "type": "string",
320
- "mutable": false,
321
- "complexType": {
322
- "original": "\"number\" | \"text\"",
323
- "resolved": "\"number\" | \"text\"",
324
- "references": {}
325
- },
326
- "required": false,
327
- "optional": false,
328
- "docs": {
329
- "tags": [],
330
- "text": ""
331
- },
332
- "attribute": "type",
333
- "reflect": false,
334
- "defaultValue": "\"text\""
335
- },
336
- "step": {
337
- "type": "number",
338
- "mutable": false,
339
- "complexType": {
340
- "original": "number",
341
- "resolved": "number | undefined",
342
- "references": {}
343
- },
344
- "required": false,
345
- "optional": true,
346
- "docs": {
347
- "tags": [],
348
- "text": ""
349
- },
350
- "attribute": "step",
351
- "reflect": false,
352
- "defaultValue": "1"
353
- },
354
- "min": {
355
- "type": "number",
356
- "mutable": false,
357
- "complexType": {
358
- "original": "number",
359
- "resolved": "number | undefined",
360
- "references": {}
361
- },
362
- "required": false,
363
- "optional": true,
364
- "docs": {
365
- "tags": [],
366
- "text": ""
367
- },
368
- "attribute": "min",
369
- "reflect": false
370
- },
371
- "max": {
372
- "type": "number",
373
- "mutable": false,
374
- "complexType": {
375
- "original": "number",
376
- "resolved": "number | undefined",
377
- "references": {}
378
- },
379
- "required": false,
380
- "optional": true,
381
- "docs": {
382
- "tags": [],
383
- "text": ""
384
- },
385
- "attribute": "max",
386
- "reflect": false
387
- }
388
- }; }
389
- static get states() { return {
390
- "announcement": {},
391
- "previousBlurredValue": {},
392
- "displayedErrorMessage": {}
393
- }; }
394
- static get events() { return [{
395
- "method": "wmInputValueChanged",
396
- "name": "wmInputValueChanged",
397
- "bubbles": true,
398
- "cancelable": true,
399
- "composed": true,
400
- "docs": {
401
- "tags": [],
402
- "text": ""
403
- },
404
- "complexType": {
405
- "original": "{ value: string }",
406
- "resolved": "{ value: string; }",
407
- "references": {}
408
- }
409
- }]; }
410
- static get elementRef() { return "el"; }
411
- static get watchers() { return [{
412
- "propName": "errorMessage",
413
- "methodName": "handleErrorMessage"
414
- }]; }
415
- }
1
+ import { h, Component, Element, Event, Host, Prop, State, Watch } from "@stencil/core";
2
+ import { intl, generateId, isRelatedTarget } from "../../global/functions";
3
+ export class Input {
4
+ constructor() {
5
+ this.labelPosition = "top";
6
+ this.value = "";
7
+ this.disabled = false;
8
+ this.placeholder = "";
9
+ this.requiredField = false;
10
+ this.type = "text";
11
+ this.step = 1;
12
+ this.announcement = "";
13
+ this.previousBlurredValue = "";
14
+ this.displayedErrorMessage = "";
15
+ this.uid = "";
16
+ this.requiredErrorMessage = intl.formatMessage({
17
+ id: "global.requiredError",
18
+ defaultMessage: "This field is required.",
19
+ });
20
+ this.numberErrorMessage = intl.formatMessage({
21
+ id: "input.numberError",
22
+ defaultMessage: "Please enter a valid number.",
23
+ });
24
+ }
25
+ get charCount() {
26
+ return this.value.length;
27
+ }
28
+ componentWillLoad() {
29
+ this.uid = this.el.id ? this.el.id : generateId();
30
+ this.el.focus = function () {
31
+ if (!this.disabled) {
32
+ this.shadowRoot.querySelector("input").focus();
33
+ }
34
+ };
35
+ if (!this.label) {
36
+ console.error("wm-input requires the label property");
37
+ }
38
+ }
39
+ componentDidLoad() {
40
+ if (this.value) {
41
+ this.inputEl.value = this.value;
42
+ this.previousBlurredValue = this.inputEl.value;
43
+ }
44
+ }
45
+ handleErrorMessage() {
46
+ this.displayedErrorMessage = this.validate();
47
+ }
48
+ handleKeyDown(ev) {
49
+ // in most browsers, onInput doesn't fire if the input's maxLength is reached
50
+ // to handle the case where a user continues to type after reaching the character limit, the keyDown event must be used
51
+ const isModifierKey = ev.ctrlKey || ev.metaKey || ev.altKey;
52
+ const isCharacter = /^.$/.test(ev.key) && !isModifierKey;
53
+ const hasReachedCharacterLimit = isCharacter && this.characterLimit && this.inputEl.value.length >= this.characterLimit;
54
+ if (hasReachedCharacterLimit) {
55
+ this.announce(this.generateCharacterLimitWarning(this.charCount, this.characterLimit));
56
+ }
57
+ }
58
+ handleBlur(ev) {
59
+ if (this.value !== this.previousBlurredValue) {
60
+ this.wmInputValueChanged.emit({ value: this.value });
61
+ }
62
+ this.previousBlurredValue = this.value;
63
+ // do not validate if clicking to an element that should prevent validation (e.g. close button on modal)
64
+ const shouldPreventValidation = this.preventValidation && isRelatedTarget(ev, this.preventValidation);
65
+ if (!shouldPreventValidation) {
66
+ this.displayedErrorMessage = this.validate();
67
+ }
68
+ this.inputWrapperEl.classList.remove("focus");
69
+ }
70
+ handleInput(ev) {
71
+ this.value = ev.target.value;
72
+ if (this.characterLimit && this.charCount >= this.characterLimit - 5) {
73
+ this.announce(this.generateCharacterLimitWarning(this.charCount, this.characterLimit));
74
+ }
75
+ }
76
+ handleFocus() {
77
+ this.inputWrapperEl.classList.add("focus");
78
+ }
79
+ validate() {
80
+ // These rules are in priority order
81
+ // i.e. an input that is triggering both required and number errors will only show the number one but it's first
82
+ const validationRules = [this.validateNumber.bind(this), this.validateRequired.bind(this)];
83
+ if (this.errorMessage) {
84
+ return this.errorMessage;
85
+ }
86
+ else {
87
+ // sets newError to first rule that returns an error
88
+ return validationRules.reduce((prev, current) => (prev ? prev : current()), "");
89
+ }
90
+ }
91
+ validateRequired() {
92
+ return this.requiredField && this.value === "" ? this.requiredErrorMessage : "";
93
+ }
94
+ validateNumber() {
95
+ return this.type === "number" && this.inputEl.validity.badInput ? this.numberErrorMessage : "";
96
+ }
97
+ announce(message) {
98
+ if (this.liveRegionEl.textContent === message) {
99
+ message += "\u00A0";
100
+ }
101
+ this.announcement = message;
102
+ }
103
+ generateCharacterLimitWarning(charCount, charLimit) {
104
+ const charactersEnteredMessage = intl.formatMessage({
105
+ id: "input.charactersEntered",
106
+ defaultMessage: "{x, number} of {y, number} characters entered.",
107
+ }, { x: charCount, y: charLimit });
108
+ const characterLimitReachedMessage = intl.formatMessage({
109
+ id: "input.characterLimitReached",
110
+ defaultMessage: "No additional characters will be entered.",
111
+ });
112
+ return `${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`;
113
+ }
114
+ renderErrorMessage() {
115
+ return this.errorMessage || this.displayedErrorMessage;
116
+ }
117
+ render() {
118
+ return (h(Host, { id: this.uid },
119
+ h("div", { class: `wrapper label-${this.labelPosition} ${this.errorMessage || this.displayedErrorMessage ? "invalid" : ""}`, ref: (el) => (this.inputWrapperEl = el) },
120
+ h("div", { class: "label-wrapper" }, this.labelPosition !== "none" && (h("label", { htmlFor: `inputfield-${this.uid}`, class: "label" },
121
+ this.label,
122
+ this.requiredField && (h("span", { class: "required", "aria-hidden": "true" }, "*"))))),
123
+ h("div", { class: "inner-wrapper" },
124
+ h("div", { class: "inputfield-wrapper" },
125
+ h("input", { ref: (el) => (this.inputEl = el), id: `inputfield-${this.uid}`, disabled: this.disabled, "aria-label": this.label, "aria-describedby": `info-${this.uid} error-${this.uid}`, onInput: (ev) => this.handleInput(ev), onKeyDown: (ev) => this.handleKeyDown(ev), onBlur: (ev) => this.handleBlur(ev), onFocus: this.handleFocus.bind(this), placeholder: this.placeholder, autocomplete: "off", required: this.requiredField, maxLength: this.characterLimit || undefined, type: this.type, step: this.step, max: this.max, min: this.min }),
126
+ this.characterLimit && typeof this.characterLimit === "number" ? (h("div", { class: "character-count" },
127
+ this.charCount,
128
+ "/",
129
+ this.characterLimit)) : ("")),
130
+ this.info && (h("div", { id: `info-${this.uid}`, class: "info" }, this.info)),
131
+ h("div", { id: `error-${this.uid}`, "aria-live": "assertive", class: "error-message", "aria-atomic": "true" }, this.renderErrorMessage()),
132
+ h("div", { class: "sr-only", "aria-live": "polite", "aria-atomic": "true", ref: (el) => (this.liveRegionEl = el) }, this.announcement)))));
133
+ }
134
+ static get is() { return "wm-input"; }
135
+ static get encapsulation() { return "shadow"; }
136
+ static get originalStyleUrls() { return {
137
+ "$": ["wm-input.scss"]
138
+ }; }
139
+ static get styleUrls() { return {
140
+ "$": ["wm-input.css"]
141
+ }; }
142
+ static get properties() { return {
143
+ "label": {
144
+ "type": "string",
145
+ "mutable": false,
146
+ "complexType": {
147
+ "original": "string",
148
+ "resolved": "string",
149
+ "references": {}
150
+ },
151
+ "required": true,
152
+ "optional": false,
153
+ "docs": {
154
+ "tags": [],
155
+ "text": ""
156
+ },
157
+ "attribute": "label",
158
+ "reflect": false
159
+ },
160
+ "labelPosition": {
161
+ "type": "string",
162
+ "mutable": false,
163
+ "complexType": {
164
+ "original": "\"top\" | \"left\" | \"none\"",
165
+ "resolved": "\"left\" | \"none\" | \"top\"",
166
+ "references": {}
167
+ },
168
+ "required": false,
169
+ "optional": false,
170
+ "docs": {
171
+ "tags": [],
172
+ "text": ""
173
+ },
174
+ "attribute": "label-position",
175
+ "reflect": false,
176
+ "defaultValue": "\"top\""
177
+ },
178
+ "value": {
179
+ "type": "string",
180
+ "mutable": true,
181
+ "complexType": {
182
+ "original": "string",
183
+ "resolved": "string",
184
+ "references": {}
185
+ },
186
+ "required": false,
187
+ "optional": false,
188
+ "docs": {
189
+ "tags": [],
190
+ "text": ""
191
+ },
192
+ "attribute": "value",
193
+ "reflect": true,
194
+ "defaultValue": "\"\""
195
+ },
196
+ "disabled": {
197
+ "type": "boolean",
198
+ "mutable": false,
199
+ "complexType": {
200
+ "original": "boolean",
201
+ "resolved": "boolean",
202
+ "references": {}
203
+ },
204
+ "required": false,
205
+ "optional": false,
206
+ "docs": {
207
+ "tags": [],
208
+ "text": ""
209
+ },
210
+ "attribute": "disabled",
211
+ "reflect": true,
212
+ "defaultValue": "false"
213
+ },
214
+ "info": {
215
+ "type": "string",
216
+ "mutable": false,
217
+ "complexType": {
218
+ "original": "string",
219
+ "resolved": "string | undefined",
220
+ "references": {}
221
+ },
222
+ "required": false,
223
+ "optional": true,
224
+ "docs": {
225
+ "tags": [],
226
+ "text": ""
227
+ },
228
+ "attribute": "info",
229
+ "reflect": false
230
+ },
231
+ "placeholder": {
232
+ "type": "string",
233
+ "mutable": false,
234
+ "complexType": {
235
+ "original": "string",
236
+ "resolved": "string",
237
+ "references": {}
238
+ },
239
+ "required": false,
240
+ "optional": false,
241
+ "docs": {
242
+ "tags": [],
243
+ "text": ""
244
+ },
245
+ "attribute": "placeholder",
246
+ "reflect": false,
247
+ "defaultValue": "\"\""
248
+ },
249
+ "requiredField": {
250
+ "type": "boolean",
251
+ "mutable": false,
252
+ "complexType": {
253
+ "original": "boolean",
254
+ "resolved": "boolean",
255
+ "references": {}
256
+ },
257
+ "required": false,
258
+ "optional": false,
259
+ "docs": {
260
+ "tags": [],
261
+ "text": ""
262
+ },
263
+ "attribute": "required-field",
264
+ "reflect": false,
265
+ "defaultValue": "false"
266
+ },
267
+ "errorMessage": {
268
+ "type": "string",
269
+ "mutable": false,
270
+ "complexType": {
271
+ "original": "string",
272
+ "resolved": "string | undefined",
273
+ "references": {}
274
+ },
275
+ "required": false,
276
+ "optional": true,
277
+ "docs": {
278
+ "tags": [],
279
+ "text": ""
280
+ },
281
+ "attribute": "error-message",
282
+ "reflect": false
283
+ },
284
+ "characterLimit": {
285
+ "type": "number",
286
+ "mutable": false,
287
+ "complexType": {
288
+ "original": "number",
289
+ "resolved": "number | undefined",
290
+ "references": {}
291
+ },
292
+ "required": false,
293
+ "optional": true,
294
+ "docs": {
295
+ "tags": [],
296
+ "text": ""
297
+ },
298
+ "attribute": "character-limit",
299
+ "reflect": false
300
+ },
301
+ "preventValidation": {
302
+ "type": "string",
303
+ "mutable": false,
304
+ "complexType": {
305
+ "original": "string",
306
+ "resolved": "string | undefined",
307
+ "references": {}
308
+ },
309
+ "required": false,
310
+ "optional": true,
311
+ "docs": {
312
+ "tags": [],
313
+ "text": ""
314
+ },
315
+ "attribute": "prevent-validation",
316
+ "reflect": false
317
+ },
318
+ "type": {
319
+ "type": "string",
320
+ "mutable": false,
321
+ "complexType": {
322
+ "original": "\"number\" | \"text\"",
323
+ "resolved": "\"number\" | \"text\"",
324
+ "references": {}
325
+ },
326
+ "required": false,
327
+ "optional": false,
328
+ "docs": {
329
+ "tags": [],
330
+ "text": ""
331
+ },
332
+ "attribute": "type",
333
+ "reflect": false,
334
+ "defaultValue": "\"text\""
335
+ },
336
+ "step": {
337
+ "type": "number",
338
+ "mutable": false,
339
+ "complexType": {
340
+ "original": "number",
341
+ "resolved": "number | undefined",
342
+ "references": {}
343
+ },
344
+ "required": false,
345
+ "optional": true,
346
+ "docs": {
347
+ "tags": [],
348
+ "text": ""
349
+ },
350
+ "attribute": "step",
351
+ "reflect": false,
352
+ "defaultValue": "1"
353
+ },
354
+ "min": {
355
+ "type": "number",
356
+ "mutable": false,
357
+ "complexType": {
358
+ "original": "number",
359
+ "resolved": "number | undefined",
360
+ "references": {}
361
+ },
362
+ "required": false,
363
+ "optional": true,
364
+ "docs": {
365
+ "tags": [],
366
+ "text": ""
367
+ },
368
+ "attribute": "min",
369
+ "reflect": false
370
+ },
371
+ "max": {
372
+ "type": "number",
373
+ "mutable": false,
374
+ "complexType": {
375
+ "original": "number",
376
+ "resolved": "number | undefined",
377
+ "references": {}
378
+ },
379
+ "required": false,
380
+ "optional": true,
381
+ "docs": {
382
+ "tags": [],
383
+ "text": ""
384
+ },
385
+ "attribute": "max",
386
+ "reflect": false
387
+ }
388
+ }; }
389
+ static get states() { return {
390
+ "announcement": {},
391
+ "previousBlurredValue": {},
392
+ "displayedErrorMessage": {}
393
+ }; }
394
+ static get events() { return [{
395
+ "method": "wmInputValueChanged",
396
+ "name": "wmInputValueChanged",
397
+ "bubbles": true,
398
+ "cancelable": true,
399
+ "composed": true,
400
+ "docs": {
401
+ "tags": [],
402
+ "text": ""
403
+ },
404
+ "complexType": {
405
+ "original": "{ value: string }",
406
+ "resolved": "{ value: string; }",
407
+ "references": {}
408
+ }
409
+ }]; }
410
+ static get elementRef() { return "el"; }
411
+ static get watchers() { return [{
412
+ "propName": "errorMessage",
413
+ "methodName": "handleErrorMessage"
414
+ }]; }
415
+ }