@abgov/react-components 6.6.1 → 6.7.0-alpha.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.
package/index.mjs CHANGED
@@ -3661,32 +3661,6 @@ function GoabTab({ heading, children }) {
3661
3661
  children
3662
3662
  ] });
3663
3663
  }
3664
- const GoabTemporaryNotification = ({
3665
- message: message2 = "",
3666
- type = "basic",
3667
- duration,
3668
- progress,
3669
- testId,
3670
- actionText,
3671
- visible = true,
3672
- animationDirection = "down"
3673
- }) => {
3674
- const el = useRef(null);
3675
- return /* @__PURE__ */ jsx(
3676
- "goa-temp-notification",
3677
- {
3678
- ref: el,
3679
- message: message2,
3680
- type,
3681
- duration,
3682
- progress,
3683
- testid: testId,
3684
- "action-text": actionText,
3685
- visible,
3686
- "animation-direction": animationDirection
3687
- }
3688
- );
3689
- };
3690
3664
  const GoabTemporaryNotificationCtrl = ({
3691
3665
  verticalPosition = "bottom",
3692
3666
  horizontalPosition = "center",
@@ -3884,6 +3858,19 @@ const GoabFilterChip = ({
3884
3858
  }
3885
3859
  );
3886
3860
  };
3861
+ function dispatch(el, eventName, detail, opts) {
3862
+ if (!el) {
3863
+ console.error("dispatch element is null");
3864
+ return;
3865
+ }
3866
+ el.dispatchEvent(
3867
+ new CustomEvent(eventName, {
3868
+ composed: true,
3869
+ bubbles: opts == null ? void 0 : opts.bubbles,
3870
+ detail
3871
+ })
3872
+ );
3873
+ }
3887
3874
  function relay(el, eventName, data, opts) {
3888
3875
  if (!el) {
3889
3876
  console.error("dispatch element is null");
@@ -3906,6 +3893,7 @@ class PublicFormController {
3906
3893
  __publicField(this, "state");
3907
3894
  __publicField(this, "_formData");
3908
3895
  __publicField(this, "_formRef");
3896
+ __publicField(this, "_isCompleting", false);
3909
3897
  this.type = type;
3910
3898
  }
3911
3899
  // Obtain reference to the form element
@@ -4089,6 +4077,70 @@ class PublicFormController {
4089
4077
  operation: "remove"
4090
4078
  });
4091
4079
  }
4080
+ /**
4081
+ * Completes the form and triggers the onComplete callback.
4082
+ * This method should be used when you want to complete a form without navigating to a summary page.
4083
+ *
4084
+ * @important Developers must validate the form before calling this method.
4085
+ *
4086
+ * @example
4087
+ * // Validate first, then complete
4088
+ * const [isValid] = this.validate(e, "firstName", [
4089
+ * requiredValidator("First name is required.")
4090
+ * ]);
4091
+ * if (isValid) {
4092
+ * this.complete();
4093
+ * }
4094
+ * @returns void
4095
+ */
4096
+ complete() {
4097
+ if (!this._formRef) {
4098
+ console.error("complete: form ref is not set");
4099
+ return;
4100
+ }
4101
+ if (this._isCompleting) {
4102
+ console.warn("complete: completion already in progress");
4103
+ return;
4104
+ }
4105
+ this._isCompleting = true;
4106
+ relay(this._formRef, "fieldset::submit", null, { bubbles: true });
4107
+ this._isCompleting = false;
4108
+ }
4109
+ /**
4110
+ * Completes a subform and returns control to the parent form.
4111
+ * This method should be used when working with subforms that need to complete without a summary page.
4112
+ *
4113
+ * @important Developers must validate the subform before calling this method.
4114
+ *
4115
+ * @example
4116
+ * // Validate first, then complete the subform
4117
+ * const [isValid] = this._childFormController.validate(e, "fullName", [
4118
+ * requiredValidator("Please enter the dependent's full name.")
4119
+ * ]);
4120
+ * if (isValid) {
4121
+ * this._childFormController.completeSubform();
4122
+ * }
4123
+ * @returns void
4124
+ */
4125
+ completeSubform() {
4126
+ if (!this._formRef) {
4127
+ console.error("completeSubform: form ref is not set");
4128
+ return;
4129
+ }
4130
+ if (this._isCompleting) {
4131
+ console.warn("completeSubform: completion already in progress");
4132
+ return;
4133
+ }
4134
+ const formRef = this._formRef;
4135
+ this._isCompleting = true;
4136
+ const stateChangeHandler = (e) => {
4137
+ formRef.removeEventListener("_stateChange", stateChangeHandler);
4138
+ dispatch(formRef, "_complete", {}, { bubbles: true });
4139
+ this._isCompleting = false;
4140
+ };
4141
+ formRef.addEventListener("_stateChange", stateChangeHandler);
4142
+ dispatch(formRef, "_continue", null, { bubbles: true });
4143
+ }
4092
4144
  // removes any data collected that doesn't correspond with the final history path
4093
4145
  clean(data) {
4094
4146
  return data.history.reduce((acc, fieldsetId) => {
@@ -4192,6 +4244,12 @@ function usePublicFormController(type = "details") {
4192
4244
  const getStateList = useCallback(() => {
4193
4245
  return controllerRef.current.getStateList();
4194
4246
  }, []);
4247
+ const complete = useCallback(() => {
4248
+ controllerRef.current.complete();
4249
+ }, []);
4250
+ const completeSubform = useCallback(() => {
4251
+ controllerRef.current.completeSubform();
4252
+ }, []);
4195
4253
  return {
4196
4254
  state,
4197
4255
  init,
@@ -4201,6 +4259,8 @@ function usePublicFormController(type = "details") {
4201
4259
  validate,
4202
4260
  getStateValue,
4203
4261
  getStateList,
4262
+ complete,
4263
+ completeSubform,
4204
4264
  controller: controllerRef.current
4205
4265
  };
4206
4266
  }
@@ -4287,7 +4347,6 @@ export {
4287
4347
  GoabTable,
4288
4348
  GoabTableSortHeader,
4289
4349
  GoabTabs,
4290
- GoabTemporaryNotification,
4291
4350
  GoabTemporaryNotificationCtrl,
4292
4351
  GoabText,
4293
4352
  GoabTextArea,