@aurodesignsystem/auro-formkit 2.0.0-beta.16 → 2.0.0-beta.18

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 (185) hide show
  1. package/.turbo/cache/000950e13093845f-meta.json +1 -1
  2. package/.turbo/cache/000950e13093845f.tar.zst +0 -0
  3. package/.turbo/cache/06ca4027e423c554-meta.json +1 -0
  4. package/.turbo/cache/06ca4027e423c554.tar.zst +0 -0
  5. package/.turbo/cache/2059bc724ac24519-meta.json +1 -1
  6. package/.turbo/cache/2059bc724ac24519.tar.zst +0 -0
  7. package/.turbo/cache/23b3a2fea223679d-meta.json +1 -1
  8. package/.turbo/cache/23b3a2fea223679d.tar.zst +0 -0
  9. package/.turbo/cache/26dbf393768f87cc-meta.json +1 -0
  10. package/.turbo/cache/26dbf393768f87cc.tar.zst +0 -0
  11. package/.turbo/cache/2c0d681132c153dd-meta.json +1 -1
  12. package/.turbo/cache/31bd5687f46c7eba-meta.json +1 -1
  13. package/.turbo/cache/32b28ddf2ebb2080-meta.json +1 -0
  14. package/.turbo/cache/32b28ddf2ebb2080.tar.zst +0 -0
  15. package/.turbo/cache/3488cff10dd06acd-meta.json +1 -1
  16. package/.turbo/cache/3488cff10dd06acd.tar.zst +0 -0
  17. package/.turbo/cache/4006a206400d5c7b-meta.json +1 -1
  18. package/.turbo/cache/43693504bf6e7c4c-meta.json +1 -1
  19. package/.turbo/cache/45cd32cd38eacbcb-meta.json +1 -1
  20. package/.turbo/cache/492dda333b8d15f1-meta.json +1 -1
  21. package/.turbo/cache/50cd7dcfc9f820c5-meta.json +1 -1
  22. package/.turbo/cache/51eaa58d5c167de8-meta.json +1 -1
  23. package/.turbo/cache/56f2745125fdd552-meta.json +1 -1
  24. package/.turbo/cache/56f2745125fdd552.tar.zst +0 -0
  25. package/.turbo/cache/5b57cc0e26e1fd5d-meta.json +1 -0
  26. package/.turbo/cache/5b57cc0e26e1fd5d.tar.zst +0 -0
  27. package/.turbo/cache/5f43911cbacf7df1-meta.json +1 -1
  28. package/.turbo/cache/5f43911cbacf7df1.tar.zst +0 -0
  29. package/.turbo/cache/60ad74320c682a2b-meta.json +1 -1
  30. package/.turbo/cache/61e218aba69cff58-meta.json +1 -1
  31. package/.turbo/cache/627be3e4a8af1d61-meta.json +1 -0
  32. package/.turbo/cache/627be3e4a8af1d61.tar.zst +0 -0
  33. package/.turbo/cache/631d441eebe7e4ac-meta.json +1 -0
  34. package/.turbo/cache/631d441eebe7e4ac.tar.zst +0 -0
  35. package/.turbo/cache/647bda3b31d82dc2-meta.json +1 -0
  36. package/.turbo/cache/647bda3b31d82dc2.tar.zst +0 -0
  37. package/.turbo/cache/6951c2a52e5ab5f7-meta.json +1 -1
  38. package/.turbo/cache/6951c2a52e5ab5f7.tar.zst +0 -0
  39. package/.turbo/cache/77da375a012de9d0-meta.json +1 -1
  40. package/.turbo/cache/78418f9089673a21-meta.json +1 -1
  41. package/.turbo/cache/7964d1656e9e702a-meta.json +1 -1
  42. package/.turbo/cache/7bf2b06a479d0b30-meta.json +1 -1
  43. package/.turbo/cache/7c9ca6163e61285c-meta.json +1 -1
  44. package/.turbo/cache/80ebd4b1fa5c1e3a-meta.json +1 -0
  45. package/.turbo/cache/80ebd4b1fa5c1e3a.tar.zst +0 -0
  46. package/.turbo/cache/876b8fa390c8ec81-meta.json +1 -1
  47. package/.turbo/cache/8bb856bd31b5b479-meta.json +1 -1
  48. package/.turbo/cache/8f287fd5d33579ae-meta.json +1 -1
  49. package/.turbo/cache/8f287fd5d33579ae.tar.zst +0 -0
  50. package/.turbo/cache/8f5fef3e04a6fcfa-meta.json +1 -1
  51. package/.turbo/cache/9d99fa3ab31d272f-meta.json +1 -0
  52. package/.turbo/cache/9d99fa3ab31d272f.tar.zst +0 -0
  53. package/.turbo/cache/9fd27f9b819a406a-meta.json +1 -0
  54. package/.turbo/cache/9fd27f9b819a406a.tar.zst +0 -0
  55. package/.turbo/cache/a227e8174447e364-meta.json +1 -0
  56. package/.turbo/cache/a227e8174447e364.tar.zst +0 -0
  57. package/.turbo/cache/a779ea8b78ce9d59-meta.json +1 -0
  58. package/.turbo/cache/a779ea8b78ce9d59.tar.zst +0 -0
  59. package/.turbo/cache/a9c36a3534c5496b-meta.json +1 -0
  60. package/.turbo/cache/a9c36a3534c5496b.tar.zst +0 -0
  61. package/.turbo/cache/b2313238e565c28e-meta.json +1 -0
  62. package/.turbo/cache/b2313238e565c28e.tar.zst +0 -0
  63. package/.turbo/cache/b5e6dc7fb9ae1a2f-meta.json +1 -1
  64. package/.turbo/cache/b6a202cc85cb61a0-meta.json +1 -1
  65. package/.turbo/cache/ba270a0ef147f2e5-meta.json +1 -1
  66. package/.turbo/cache/be0b95293ea517cc-meta.json +1 -1
  67. package/.turbo/cache/c03a12ff38ba1e02-meta.json +1 -1
  68. package/.turbo/cache/c1312c6f8c051461-meta.json +1 -1
  69. package/.turbo/cache/c1312c6f8c051461.tar.zst +0 -0
  70. package/.turbo/cache/c6c6411199b68170-meta.json +1 -1
  71. package/.turbo/cache/c6dbc49c3038946d-meta.json +1 -1
  72. package/.turbo/cache/cae7586c45bed13e-meta.json +1 -1
  73. package/.turbo/cache/cae7586c45bed13e.tar.zst +0 -0
  74. package/.turbo/cache/cf143eb1a55684db-meta.json +1 -1
  75. package/.turbo/cache/cf143eb1a55684db.tar.zst +0 -0
  76. package/.turbo/cache/d5b85352bc667f19-meta.json +1 -1
  77. package/.turbo/cache/d5b85352bc667f19.tar.zst +0 -0
  78. package/.turbo/cache/d5db503b2eaf239c-meta.json +1 -1
  79. package/.turbo/cache/d775555355d6b8fc-meta.json +1 -1
  80. package/.turbo/cache/d7c3007be148d2a1-meta.json +1 -1
  81. package/.turbo/cache/db5e65d819bfe66b-meta.json +1 -1
  82. package/.turbo/cache/dc597b3ea4f61ec8-meta.json +1 -1
  83. package/.turbo/cache/e62cfee068e3ef36-meta.json +1 -1
  84. package/.turbo/cache/f2913bf19939d840-meta.json +1 -1
  85. package/.turbo/cache/f2913bf19939d840.tar.zst +0 -0
  86. package/.turbo/cache/f86b28e5ea2c66fe-meta.json +1 -1
  87. package/CHANGELOG.md +20 -0
  88. package/components/checkbox/.turbo/turbo-build.log +3 -3
  89. package/components/checkbox/.turbo/turbo-bundler.log +3 -3
  90. package/components/checkbox/README.md +1 -1
  91. package/components/combobox/.turbo/turbo-build.log +3 -3
  92. package/components/combobox/README.md +4 -4
  93. package/components/counter/.turbo/turbo-build$colon$sass.log +37 -6
  94. package/components/counter/.turbo/turbo-build.log +47 -10
  95. package/components/counter/.turbo/turbo-bundler.log +9 -3
  96. package/components/counter/.turbo/turbo-sass$colon$render.log +7 -1
  97. package/components/counter/README.md +1 -1
  98. package/components/counter/demo/api.md +8 -7
  99. package/components/counter/demo/api.min.js +3304 -247
  100. package/components/counter/demo/index.md +16 -20
  101. package/components/counter/demo/index.min.js +3304 -247
  102. package/components/counter/dist/auro-counter-group.d.ts +27 -7
  103. package/components/counter/dist/auro-counter-group.d.ts.map +1 -1
  104. package/components/counter/dist/auro-counter-wrapper.d.ts +23 -0
  105. package/components/counter/dist/auro-counter-wrapper.d.ts.map +1 -0
  106. package/components/counter/dist/index.js +3304 -247
  107. package/components/counter/dist/styles/counter-wrapper-color-css.d.ts +3 -0
  108. package/components/counter/dist/styles/counter-wrapper-color-css.d.ts.map +1 -0
  109. package/components/counter/dist/styles/{counter-group-color-css.d.ts → counter-wrapper-css.d.ts} +1 -1
  110. package/components/counter/dist/styles/counter-wrapper-css.d.ts.map +1 -0
  111. package/components/counter/src/auro-counter-group.js +72 -19
  112. package/components/counter/src/auro-counter-wrapper.js +54 -0
  113. package/components/counter/src/styles/counter-group-css.js +1 -1
  114. package/components/counter/src/styles/counter-group.css +4 -8
  115. package/components/counter/src/styles/counter-group.scss +6 -10
  116. package/components/counter/src/styles/counter-wrapper-color-css.js +2 -0
  117. package/components/counter/src/styles/{counter-group-color.css → counter-wrapper-color.css} +1 -1
  118. package/components/counter/src/styles/{counter-group-color.scss → counter-wrapper-color.scss} +1 -1
  119. package/components/counter/src/styles/counter-wrapper-css.js +2 -0
  120. package/components/counter/src/styles/counter-wrapper.css +15 -0
  121. package/components/counter/src/styles/counter-wrapper.scss +29 -0
  122. package/components/datepicker/.turbo/turbo-build.log +3 -3
  123. package/components/datepicker/README.md +4 -4
  124. package/components/dropdown/.turbo/turbo-build.log +3 -3
  125. package/components/dropdown/.turbo/turbo-bundler.log +2 -2
  126. package/components/dropdown/README.md +1 -1
  127. package/components/form/.turbo/turbo-build.log +3 -3
  128. package/components/form/.turbo/turbo-bundler.log +3 -3
  129. package/components/form/README.md +1 -1
  130. package/components/form/demo/api.min.js +218 -70
  131. package/components/form/demo/index.min.js +218 -70
  132. package/components/form/demo/registerDemoDeps.js +3 -2
  133. package/components/form/demo/working.html +23 -1
  134. package/components/form/dist/auro-form.d.ts +60 -6
  135. package/components/form/dist/auro-form.d.ts.map +1 -1
  136. package/components/form/dist/index.js +218 -70
  137. package/components/form/src/auro-form.js +216 -68
  138. package/components/form/src/styles/style-css.js +1 -1
  139. package/components/form/src/styles/style.css +0 -8
  140. package/components/form/src/styles/style.scss +0 -10
  141. package/components/input/.turbo/turbo-build.log +2 -2
  142. package/components/input/.turbo/turbo-bundler.log +3 -3
  143. package/components/input/README.md +1 -1
  144. package/components/menu/.turbo/turbo-build.log +3 -3
  145. package/components/menu/.turbo/turbo-bundler.log +3 -3
  146. package/components/menu/README.md +1 -1
  147. package/components/radio/.turbo/turbo-build.log +3 -3
  148. package/components/radio/.turbo/turbo-bundler.log +3 -3
  149. package/components/radio/README.md +1 -1
  150. package/components/select/.turbo/turbo-build.log +3 -3
  151. package/components/select/README.md +3 -3
  152. package/package.json +1 -1
  153. package/.turbo/cache/02ee016619902665-meta.json +0 -1
  154. package/.turbo/cache/02ee016619902665.tar.zst +0 -0
  155. package/.turbo/cache/1b97859030a6d60b-meta.json +0 -1
  156. package/.turbo/cache/1b97859030a6d60b.tar.zst +0 -0
  157. package/.turbo/cache/1e855b2163b7c980-meta.json +0 -1
  158. package/.turbo/cache/1e855b2163b7c980.tar.zst +0 -0
  159. package/.turbo/cache/1f6653e2ed4c0087-meta.json +0 -1
  160. package/.turbo/cache/1f6653e2ed4c0087.tar.zst +0 -0
  161. package/.turbo/cache/3c8718d2ba6d3fe5-meta.json +0 -1
  162. package/.turbo/cache/3c8718d2ba6d3fe5.tar.zst +0 -0
  163. package/.turbo/cache/6081837e8943b62e-meta.json +0 -1
  164. package/.turbo/cache/6081837e8943b62e.tar.zst +0 -0
  165. package/.turbo/cache/80410f4b5990ab83-meta.json +0 -1
  166. package/.turbo/cache/80410f4b5990ab83.tar.zst +0 -0
  167. package/.turbo/cache/8fcce3ba8357be57-meta.json +0 -1
  168. package/.turbo/cache/8fcce3ba8357be57.tar.zst +0 -0
  169. package/.turbo/cache/9b5868be65819fdf-meta.json +0 -1
  170. package/.turbo/cache/9b5868be65819fdf.tar.zst +0 -0
  171. package/.turbo/cache/c3b2cc1b044a4135-meta.json +0 -1
  172. package/.turbo/cache/c3b2cc1b044a4135.tar.zst +0 -0
  173. package/.turbo/cache/dad3d78b33edd9e4-meta.json +0 -1
  174. package/.turbo/cache/dad3d78b33edd9e4.tar.zst +0 -0
  175. package/.turbo/cache/e392fe0927e4af23-meta.json +0 -1
  176. package/.turbo/cache/e392fe0927e4af23.tar.zst +0 -0
  177. package/.turbo/cache/e9e36823f6c98f07-meta.json +0 -1
  178. package/.turbo/cache/e9e36823f6c98f07.tar.zst +0 -0
  179. package/.turbo/cache/ea8dd91dba19ddee-meta.json +0 -1
  180. package/.turbo/cache/ea8dd91dba19ddee.tar.zst +0 -0
  181. package/components/counter/dist/formkit/auro-dropdownVersion.d.ts +0 -3
  182. package/components/counter/dist/formkit/auro-dropdownVersion.d.ts.map +0 -1
  183. package/components/counter/dist/styles/counter-group-color-css.d.ts.map +0 -1
  184. package/components/counter/src/formkit/auro-dropdownVersion.js +0 -1
  185. package/components/counter/src/styles/counter-group-color-css.js +0 -2
@@ -24,7 +24,7 @@ const t=globalThis,i$1=t.trustedTypes,s=i$1?i$1.createPolicy("lit-html",{createH
24
24
  * SPDX-License-Identifier: BSD-3-Clause
25
25
  */class r extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=undefined;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const s=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=B(s,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return T}}r._$litElement$=true,r["finalized"]=true,globalThis.litElementHydrateSupport?.({LitElement:r});const i=globalThis.litElementPolyfillSupport;i?.({LitElement:r});(globalThis.litElementVersions??=[]).push("4.1.1");
26
26
 
27
- var styleCss = i$3`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.testClass{display:inline-block;padding:var(--auro-text-body-size-default);border:1px solid var(--auro-color-border-error-on-light);color:var(--auro-color-border-error-on-light)}:focus-visible{background-color:var(--auro-color-border-error-on-light);color:var(--auro-color-base-white)}:host form{display:block;width:100%;padding:1rem;border:1px solid #2a2a2a;border-radius:1rem}`;
27
+ var styleCss = i$3`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.testClass{display:inline-block;padding:var(--auro-text-body-size-default);border:1px solid var(--auro-color-border-error-on-light);color:var(--auro-color-border-error-on-light)}:focus-visible{background-color:var(--auro-color-border-error-on-light);color:var(--auro-color-base-white)}`;
28
28
 
29
29
  // Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
30
30
  // See LICENSE in the project root for license information.
@@ -96,7 +96,7 @@ class AuroLibraryRuntimeUtils {
96
96
  }
97
97
  }
98
98
 
99
- /* eslint-disable no-underscore-dangle */
99
+ /* eslint-disable no-underscore-dangle,max-lines */
100
100
 
101
101
 
102
102
  /**
@@ -124,7 +124,12 @@ class AuroLibraryRuntimeUtils {
124
124
  class AuroForm extends r {
125
125
  static get properties() {
126
126
  return {
127
- _formState: { attribute: false },
127
+ formState: { attribute: false },
128
+ _validity: { attribute: false },
129
+ _isInitialState: { attribute: false },
130
+ _elements: { attribute: false },
131
+ _submitElements: { attribute: false },
132
+ _resetElements: { attribute: false },
128
133
  };
129
134
  }
130
135
 
@@ -132,7 +137,24 @@ class AuroForm extends r {
132
137
  super();
133
138
 
134
139
  /** @type {FormState} */
135
- this._formState = {};
140
+ this.formState = {};
141
+
142
+ /** @type {"valid" | "invalid" | null} */
143
+ this._validity = null;
144
+ this._isInitialState = true;
145
+
146
+ /** @type {(HTMLElement & {reset: () => void})[]} */
147
+ this._elements = [];
148
+
149
+ /** @type {HTMLButtonElement[]} */
150
+ this._submitelements = [];
151
+
152
+ /** @type {HTMLButtonElement[]} */
153
+ this._resetElements = [];
154
+
155
+ // Bind listeners
156
+ this.reset = this.reset.bind(this);
157
+ this.submit = this.submit.bind(this);
136
158
  }
137
159
 
138
160
  // Note: button is NOT considered a form element in this context
@@ -166,7 +188,7 @@ class AuroForm extends r {
166
188
  return this._isInElementCollection(AuroForm.formElementTags, element);
167
189
  }
168
190
 
169
- static get submitElementTags() {
191
+ static get buttonElementTags() {
170
192
  return [
171
193
  'button',
172
194
  'auro-button',
@@ -174,12 +196,12 @@ class AuroForm extends r {
174
196
  }
175
197
 
176
198
  /**
177
- * Check if the tag name is a submit element.
199
+ * Check if the tag name is a button element.
178
200
  * @param {HTMLElement} element - The element to check.
179
201
  * @returns {boolean}
180
202
  */
181
- isSubmitElement(element) {
182
- return this._isInElementCollection(AuroForm.submitElementTags, element);
203
+ isButtonElement(element) {
204
+ return this._isInElementCollection(AuroForm.buttonElementTags, element);
183
205
  }
184
206
 
185
207
  static get styles() {
@@ -196,45 +218,76 @@ class AuroForm extends r {
196
218
  * @returns {Record<string, string | number | boolean | string[] | null>} The form value.
197
219
  */
198
220
  get value() {
199
- return Object.keys(this._formState).reduce((acc, key) => {
200
- acc[key] = this._formState[key].value;
221
+ return Object.keys(this.formState).reduce((acc, key) => {
222
+ acc[key] = this.formState[key].value;
201
223
  return acc;
202
224
  }, {});
203
225
  }
204
226
 
227
+ /**
228
+ * Infer validity status based on current formState.
229
+ * @private
230
+ */
231
+ _calculateValidity() {
232
+ if (this.isInitialState) {
233
+ this._validity = null;
234
+ } else {
235
+ // go through validity states and return the first invalid state (if any)
236
+ const invalidKey = Object.keys(this.formState).
237
+ find((key) => {
238
+ const formKey = this.formState[key];
239
+ // these are NOT extra parens
240
+ // eslint-disable-next-line no-extra-parens
241
+ return (formKey.validity !== 'valid' && formKey.required) || (formKey.validity !== 'valid' && formKey.value !== null);
242
+ });
243
+ this._validity = invalidKey ? 'invalid' : 'valid';
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Current validity state of the form, based on form element events.
249
+ * @returns {"valid" | "invalid"}
250
+ */
205
251
  get validity() {
206
- // go through validity states and return the first invalid state (if any)
207
- const invalidKey = Object.keys(this._formState).
208
- find((key) => {
209
- const formKey = this._formState[key];
210
-
211
- // these are NOT extra :(
212
- // eslint-disable-next-line no-extra-parens
213
- return (formKey.validity !== 'valid' && formKey.required) || (formKey.validity !== 'valid' && formKey.value !== null);
214
- });
252
+ return this._validity;
253
+ }
254
+
255
+ _setInitialState() {
256
+ const anyTainted = Object.keys(this.formState).some((key) => this.formState[key].validity !== null || this.formState[key].value !== null);
215
257
 
216
- return invalidKey ? 'invalid' : 'valid';
258
+ this._isInitialState = !anyTainted;
259
+
260
+ this._resetElements.forEach((resetElement) => {
261
+ if (resetElement.hasAttribute("disabled")) {
262
+ resetElement.removeAttribute("disabled");
263
+ }
264
+ });
217
265
  }
218
266
 
219
- // Below is not implemented yet
267
+ /**
268
+ * Mostly internal way to determine if a form is in the initial state.
269
+ * @returns {boolean}
270
+ */
220
271
  get isInitialState() {
221
- const anyTainted = Object.keys(this._formState).some((key) => this._formState[key].validity !== null);
222
-
223
- return !anyTainted;
272
+ return this._isInitialState;
224
273
  }
225
274
 
226
- getSubmitFunction() {
227
- // We return an arrow function here to ensure that the `this` context points at this same AuroForm context.
228
- // Otherwise, submission tries to read `this.value` on the button element.
229
- return (event) => {
230
- event.preventDefault();
231
-
232
- this.dispatchEvent(new CustomEvent('submit', {
233
- detail: {
234
- value: this.value
235
- }
236
- }));
237
- };
275
+ setDisabledStateOnButtons() {
276
+ this._resetElements.forEach((element) => {
277
+ if (this.isInitialState) {
278
+ element.setAttribute("disabled", "");
279
+ } else {
280
+ element.removeAttribute("disabled");
281
+ }
282
+ });
283
+
284
+ this._submitelements.forEach((element) => {
285
+ if (this.isInitialState || this.validity !== "valid") {
286
+ element.setAttribute("disabled", "");
287
+ } else {
288
+ element.removeAttribute("disabled");
289
+ }
290
+ });
238
291
  }
239
292
 
240
293
  /**
@@ -242,16 +295,111 @@ class AuroForm extends r {
242
295
  * @returns {NodeList}
243
296
  */
244
297
  queryAuroElements() {
245
- const formElementQuery = AuroForm.formElementTags.map((tag) => `${tag}[name]`).join(',');
246
- const submitterQuery = AuroForm.submitElementTags.map((tag) => `${tag}[type=submit]`).join(',');
298
+ const queries = [
299
+ [
300
+ AuroForm.formElementTags,
301
+ '[name]'
302
+ ],
303
+ [
304
+ AuroForm.buttonElementTags,
305
+ '[type=submit]'
306
+ ],
307
+ [
308
+ AuroForm.buttonElementTags,
309
+ '[type=reset]'
310
+ ]
311
+ ];
247
312
 
248
- // Alternatively, for renamed components...
249
- const renamedFormElementQuery = AuroForm.formElementTags.map((tag) => `[${tag}][name]`).join(',');
250
- const renamedSubmitterQuery = AuroForm.formElementTags.map((tag) => `[${tag}][type=submit]`).join(',');
313
+ return this.querySelectorAll(queries.flatMap(([
314
+ tags,
315
+ extraAttributes
316
+ ]) => tags.map((tag) => `${tag}${extraAttributes}, [${tag}]${extraAttributes}`)).join(', '));
317
+ }
251
318
 
252
- const unifiedElementQuery = `${formElementQuery},${submitterQuery},${renamedFormElementQuery},${renamedSubmitterQuery}`;
319
+ /**
320
+ * Initialize (or reinitialize) the form state.
321
+ */
322
+ initializeState() {
323
+ this.formState = {};
324
+ this._submitelements = [];
325
+ this._resetElements = [];
326
+ this._elements = [];
327
+
328
+ this.queryAuroElements().forEach((element) => {
329
+ if (this.isFormElement(element)) {
330
+ this.formState[element.getAttribute('name')] = {
331
+ value: element.getAttribute('value'),
332
+ validity: element.getAttribute('validity'),
333
+ required: element.hasAttribute('required'),
334
+ // element
335
+ };
336
+
337
+ this._elements.push(element);
338
+ }
253
339
 
254
- return this.querySelectorAll(unifiedElementQuery);
340
+ if (this.isButtonElement(element) && element.getAttribute('type') === 'submit') {
341
+ element.removeEventListener('click', this.submit);
342
+ element.addEventListener('click', this.submit);
343
+
344
+ // Keep record of this element, so we can enable/disable as needed
345
+ this._submitelements.push(element);
346
+ }
347
+
348
+ if (this.isButtonElement(element) && element.getAttribute('type') === 'reset') {
349
+ // Keep record of this element, so we can enable/disable as needed
350
+ element.removeEventListener('click', this.reset);
351
+ element.addEventListener('click', this.reset);
352
+
353
+ this._resetElements.push(element);
354
+ }
355
+ });
356
+
357
+ // Set enabled/disabled states on buttons
358
+ this.setDisabledStateOnButtons();
359
+ }
360
+
361
+ reset() {
362
+ this._elements.forEach((element) => element.reset());
363
+
364
+ this.updateComplete.then(() => {
365
+ this.initializeState();
366
+ // Initial state must come first - validity can only be null if initial state is true
367
+ this._setInitialState();
368
+ this._calculateValidity();
369
+
370
+ // Wait for the above changes to run through, then disable submit/reset
371
+ this.updateComplete.then(() => {
372
+ this.setDisabledStateOnButtons();
373
+ });
374
+ });
375
+ }
376
+
377
+ /**
378
+ * Submit fires an event called `submit` - just as you would expect from a normal form.
379
+ *
380
+ * @example ```
381
+ * const form = document.querySelector('auro-
382
+ * ```
383
+ */
384
+ submit() {
385
+ // Steps required to get out of beta:
386
+ // 1. Submit triggers a forced validation on ALL elements
387
+ // 2. Wait for validation to complete (this.updateComplete.then or similar)
388
+ // 3. If still valid, go ahead with submit.
389
+ this._elements.forEach((element) => {
390
+ if (element.tagName.toLowerCase() !== "auro-datepicker") {
391
+ // Next line currently does NOT force
392
+ element.validate();
393
+ }
394
+ });
395
+
396
+ this.dispatchEvent(new CustomEvent('submit', {
397
+ bubbles: true,
398
+ composed: true,
399
+ detail: {
400
+ value: this.value
401
+ }
402
+ }));
255
403
  }
256
404
 
257
405
  /**
@@ -273,49 +421,49 @@ class AuroForm extends r {
273
421
 
274
422
  // Update the form state when a form element is detected
275
423
  slot.addEventListener('input', (event) => {
276
-
277
- /** @type {HTMLInputElement} */
278
- const eventTarget = event.target;
279
- if (this.isFormElement(eventTarget)) {
280
- this._formState[eventTarget.getAttribute("name")].value = eventTarget.value;
424
+ const targetName = event.target.getAttribute("name");
425
+ if (!this.isFormElement(event.target) || !targetName) {
426
+ return;
281
427
  }
428
+
429
+ this.formState[targetName].value = event.target.value;
430
+ this.requestUpdate('formState');
282
431
  });
283
432
 
284
433
  slot.addEventListener('auroFormElement-validated', (event) => {
285
- const oldValue = this._formState;
434
+ const targetName = event.target.getAttribute("name");
435
+ if (!this.isFormElement(event.target) || !targetName) {
436
+ return;
437
+ }
286
438
 
287
- this._formState[event.target.getAttribute("name")].validity = event.detail.validity;
288
- this.requestUpdate('formState', oldValue);
439
+ this.formState[targetName].validity = event.detail.validity;
440
+ this._calculateValidity();
289
441
  });
290
442
  }
291
443
 
292
- onSlotChange() {
293
- this._formState = {};
444
+ updated(_changedProperties) {
445
+ super.updated(_changedProperties);
294
446
 
295
- this.queryAuroElements().forEach((element) => {
296
- if (this.isFormElement(element)) {
297
- this._formState[element.getAttribute('name')] = {
298
- value: element.getAttribute('value'),
299
- validity: element.getAttribute('validity'),
300
- required: element.hasAttribute('required'),
301
- element
302
- };
303
- }
447
+ if (_changedProperties.has("formState")) {
448
+ this._setInitialState();
304
449
 
305
- if (this.isSubmitElement(element) && element.getAttribute('type') === 'submit') {
306
- element.removeEventListener('click', this.getSubmitFunction());
307
- element.addEventListener('click', this.getSubmitFunction());
308
- }
309
- });
450
+ // Automatically infer disabled state now
451
+ this.setDisabledStateOnButtons();
452
+ }
453
+
454
+ if (_changedProperties.has("_validity")) {
455
+ this._setInitialState();
456
+ }
457
+ }
458
+
459
+ onSlotChange() {
460
+ this.initializeState();
310
461
  }
311
462
 
312
463
  // function that renders the HTML and CSS into the scope of the component
313
464
  render() {
314
465
  return x`
315
466
  <form>
316
- <p>Value: ${JSON.stringify(this.value)}</p>
317
- <p>Validity: ${this.validity}</p>
318
- <h3>Auro form example</h3>
319
467
  <slot @slotchange="${this.onSlotChange}"></slot>
320
468
  </form>
321
469
  `;
@@ -1,5 +1,6 @@
1
- import {AuroInput} from "@auro-formkit/auro-input";
2
- import {AuroDatePicker} from "@auro-formkit/auro-datepicker";
1
+ import {AuroInput} from "@aurodesignsystem/auro-input";
2
+ import {AuroDatePicker} from "@aurodesignsystem/auro-datepicker";
3
3
 
4
4
  AuroInput.register();
5
+ AuroInput.register('auro-input-two');
5
6
  AuroDatePicker.register();
@@ -40,6 +40,14 @@
40
40
  .datepickerBlock {
41
41
  margin-top: 1rem;
42
42
  }
43
+
44
+ auro-form {
45
+ display: block;
46
+ width: 100%;
47
+ padding: 1rem;
48
+ border: 1px solid #2a2a2a;
49
+ border-radius: 1rem;
50
+ }
43
51
  </style>
44
52
 
45
53
  <h2>auro-form testing</h2>
@@ -60,6 +68,10 @@
60
68
  </div>
61
69
  </div>
62
70
 
71
+ <auro-input-two id="cool-fact" name="coolFact" required>
72
+ <span slot="label">Cool Fact</span>
73
+ </auro-input-two>
74
+
63
75
  <div class="datepickerBlock">
64
76
  <h4>Pick a cool date</h4>
65
77
  <auro-datepicker id="date-example" name="dateExample" required>
@@ -75,10 +87,20 @@
75
87
  </auro-form>
76
88
  </main>
77
89
 
78
- <script type="module" data-demo-script="true" src="./index.js"></script>
90
+ <!-- Form elements MUST be registered BEFORE form if custom names are used -->
79
91
  <script type="module" data-demo-script="true" src="./registerDemoDeps.js"></script>
92
+ <script type="module" data-demo-script="true" src="./index.js"></script>
80
93
  <!--<script type="module" data-demo-script="true" src="~@auro-formkit/auro-input/dist/index.min.js"></script>-->
81
94
 
95
+ <script>
96
+ const form = document.querySelector('auro-form');
97
+ form.addEventListener('submit', (event) => {
98
+ console.log(event)
99
+
100
+ console.log(event.target.value)
101
+ })
102
+ </script>
103
+
82
104
  <!-- If additional elements are needed for the demo, add them here. -->
83
105
  <script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
84
106
  <script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
@@ -16,12 +16,27 @@
16
16
  */
17
17
  export class AuroForm extends LitElement {
18
18
  static get properties(): {
19
- _formState: {
19
+ formState: {
20
+ attribute: boolean;
21
+ };
22
+ _validity: {
23
+ attribute: boolean;
24
+ };
25
+ _isInitialState: {
26
+ attribute: boolean;
27
+ };
28
+ _elements: {
29
+ attribute: boolean;
30
+ };
31
+ _submitElements: {
32
+ attribute: boolean;
33
+ };
34
+ _resetElements: {
20
35
  attribute: boolean;
21
36
  };
22
37
  };
23
38
  static get formElementTags(): string[];
24
- static get submitElementTags(): string[];
39
+ static get buttonElementTags(): string[];
25
40
  static get styles(): import("lit").CSSResult[];
26
41
  /**
27
42
  * This will register this element with the browser.
@@ -33,7 +48,27 @@ export class AuroForm extends LitElement {
33
48
  */
34
49
  static register(name?: string): void;
35
50
  /** @type {FormState} */
36
- _formState: FormState;
51
+ formState: FormState;
52
+ /** @type {"valid" | "invalid" | null} */
53
+ _validity: "valid" | "invalid" | null;
54
+ _isInitialState: boolean;
55
+ /** @type {(HTMLElement & {reset: () => void})[]} */
56
+ _elements: (HTMLElement & {
57
+ reset: () => void;
58
+ })[];
59
+ /** @type {HTMLButtonElement[]} */
60
+ _submitelements: HTMLButtonElement[];
61
+ /** @type {HTMLButtonElement[]} */
62
+ _resetElements: HTMLButtonElement[];
63
+ reset(): void;
64
+ /**
65
+ * Submit fires an event called `submit` - just as you would expect from a normal form.
66
+ *
67
+ * @example ```
68
+ * const form = document.querySelector('auro-
69
+ * ```
70
+ */
71
+ submit(): void;
37
72
  /**
38
73
  * Shared code for determining if an element is something we care about (submit, form element, etc.).
39
74
  * @param {string[]} collection - The array to use for tag name search.
@@ -49,11 +84,11 @@ export class AuroForm extends LitElement {
49
84
  */
50
85
  isFormElement(element: HTMLElement): boolean;
51
86
  /**
52
- * Check if the tag name is a submit element.
87
+ * Check if the tag name is a button element.
53
88
  * @param {HTMLElement} element - The element to check.
54
89
  * @returns {boolean}
55
90
  */
56
- isSubmitElement(element: HTMLElement): boolean;
91
+ isButtonElement(element: HTMLElement): boolean;
57
92
  /**
58
93
  * Reduce the form value into a key-value pair.
59
94
  *
@@ -64,15 +99,34 @@ export class AuroForm extends LitElement {
64
99
  * @returns {Record<string, string | number | boolean | string[] | null>} The form value.
65
100
  */
66
101
  get value(): Record<string, string | number | boolean | string[] | null>;
102
+ /**
103
+ * Infer validity status based on current formState.
104
+ * @private
105
+ */
106
+ private _calculateValidity;
107
+ /**
108
+ * Current validity state of the form, based on form element events.
109
+ * @returns {"valid" | "invalid"}
110
+ */
67
111
  get validity(): "valid" | "invalid";
112
+ _setInitialState(): void;
113
+ /**
114
+ * Mostly internal way to determine if a form is in the initial state.
115
+ * @returns {boolean}
116
+ */
68
117
  get isInitialState(): boolean;
69
- getSubmitFunction(): (event: any) => void;
118
+ setDisabledStateOnButtons(): void;
70
119
  /**
71
120
  * Construct the query strings from elements, append them together, execute, and return the NodeList.
72
121
  * @returns {NodeList}
73
122
  */
74
123
  queryAuroElements(): NodeList;
124
+ /**
125
+ * Initialize (or reinitialize) the form state.
126
+ */
127
+ initializeState(): void;
75
128
  firstUpdated(_changedProperties: any): void;
129
+ updated(_changedProperties: any): void;
76
130
  onSlotChange(): void;
77
131
  render(): import("lit-html").TemplateResult<1>;
78
132
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auro-form.d.ts","sourceRoot":"","sources":["../src/auro-form.js"],"names":[],"mappings":"AAcA;;;;;;GAMG;AAEH;;GAEG;AAIH;;;;;GAKG;AAGH;IACE;;;;MAIC;IAWD,uCAOC;IAsBD,yCAKC;IAWD,+CAEC;IAsED;;;;;;;OAOG;IACH,uBANW,MAAM,QAQhB;IArIC,wBAAwB;IACxB,YADW,SAAS,CACA;IActB;;;;;;OAMG;IACH,+BAEC;IAED;;;;OAIG;IACH,uBAHW,WAAW,GACT,OAAO,CAInB;IASD;;;;OAIG;IACH,yBAHW,WAAW,GACT,OAAO,CAInB;IAMD;;;;;;;;OAQG;IACH,aAFa,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,CAOvE;IAED,oCAYC;IAGD,8BAIC;IAED,0CAYC;IAED;;;OAGG;IACH,qBAFa,QAAQ,CAapB;IAcD,4CAqBC;IAED,qBAkBC;IAGD,+CASC;CACF;;;;;;;;WA3Na,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI;;;;cAC3C,aAAa;;;;cACb,OAAO;;;;aACP,WAAW;;;;;;;;2BAXQ,KAAK"}
1
+ {"version":3,"file":"auro-form.d.ts","sourceRoot":"","sources":["../src/auro-form.js"],"names":[],"mappings":"AAcA;;;;;;GAMG;AAEH;;GAEG;AAIH;;;;;GAKG;AAGH;IACE;;;;;;;;;;;;;;;;;;;MASC;IA4BD,uCAOC;IAsBD,yCAKC;IAWD,+CAEC;IAoMD;;;;;;;OAOG;IACH,uBANW,MAAM,QAQhB;IApRC,wBAAwB;IACxB,WADW,SAAS,CACD;IAEnB,yCAAyC;IACzC,WADW,OAAO,GAAG,SAAS,GAAG,IAAI,CAChB;IACrB,yBAA2B;IAE3B,oDAAoD;IACpD,WADW,CAAC,WAAW,GAAG;QAAC,KAAK,EAAE,MAAM,IAAI,CAAA;KAAC,CAAC,EAAE,CAC7B;IAEnB,kCAAkC;IAClC,iBADW,iBAAiB,EAAE,CACL;IAEzB,kCAAkC;IAClC,gBADW,iBAAiB,EAAE,CACN;IAgN1B,cAcC;IAED;;;;;;OAMG;IACH,eAmBC;IAxOD;;;;;;OAMG;IACH,+BAEC;IAED;;;;OAIG;IACH,uBAHW,WAAW,GACT,OAAO,CAInB;IASD;;;;OAIG;IACH,yBAHW,WAAW,GACT,OAAO,CAInB;IAMD;;;;;;;;OAQG;IACH,aAFa,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,CAOvE;IAED;;;OAGG;IACH,2BAcC;IAED;;;OAGG;IACH,gBAFa,OAAO,GAAG,SAAS,CAI/B;IAED,yBAUC;IAED;;;OAGG;IACH,sBAFa,OAAO,CAInB;IAED,kCAgBC;IAED;;;OAGG;IACH,qBAFa,QAAQ,CAsBpB;IAED;;OAEG;IACH,wBAqCC;IA0DD,4CAyBC;IAED,uCAaC;IAED,qBAEC;IAGD,+CAMC;CACF;;;;;;;;WA/Wa,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI;;;;cAC3C,aAAa;;;;cACb,OAAO;;;;aACP,WAAW;;;;;;;;2BAXQ,KAAK"}