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