@bookinglab/booking-ui-react 1.7.1 → 1.9.0

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/dist/index.mjs CHANGED
@@ -786,7 +786,8 @@ var ContactDetailsForm = forwardRef(
786
786
  submitLabel = "Submit",
787
787
  className = "",
788
788
  classNames = {},
789
- fieldSettings = {}
789
+ fieldSettings = {},
790
+ hideSubmitButton = false
790
791
  }, ref) => {
791
792
  const formId = useId();
792
793
  const [firstName, setFirstName] = useState(initialValues?.firstName || "");
@@ -827,6 +828,7 @@ var ContactDetailsForm = forwardRef(
827
828
  }, [fieldSettings]);
828
829
  const validateQuestionField = useCallback((question, value) => {
829
830
  if (question.detail_type === "heading") return null;
831
+ if (question.disabled) return null;
830
832
  if (question.required) {
831
833
  if (value === void 0 || value === "" || value === null) {
832
834
  return `${question.name} is required`;
@@ -1037,6 +1039,7 @@ var ContactDetailsForm = forwardRef(
1037
1039
  const value = questionValues[question.id];
1038
1040
  const error = questionTouched[question.id] ? questionErrors[question.id] : void 0;
1039
1041
  const hasError = !!error;
1042
+ const isDisabled = !!question.disabled;
1040
1043
  const ariaProps = {
1041
1044
  "aria-invalid": hasError ? true : void 0,
1042
1045
  "aria-describedby": hasError ? errorId : void 0,
@@ -1057,10 +1060,11 @@ var ContactDetailsForm = forwardRef(
1057
1060
  id: fieldId,
1058
1061
  type: "text",
1059
1062
  value: value || "",
1063
+ disabled: isDisabled,
1060
1064
  onChange: (e) => handleQuestionChange(question.id, e.target.value),
1061
1065
  onBlur: () => handleQuestionBlur(question.id),
1062
1066
  placeholder: question.settings?.placeholder,
1063
- className: inputClasses(hasError),
1067
+ className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
1064
1068
  ...ariaProps
1065
1069
  }
1066
1070
  ),
@@ -1078,11 +1082,12 @@ var ContactDetailsForm = forwardRef(
1078
1082
  {
1079
1083
  id: fieldId,
1080
1084
  value: value || "",
1085
+ disabled: isDisabled,
1081
1086
  onChange: (e) => handleQuestionChange(question.id, e.target.value),
1082
1087
  onBlur: () => handleQuestionBlur(question.id),
1083
1088
  placeholder: question.settings?.placeholder,
1084
1089
  rows: 4,
1085
- className: inputClasses(hasError),
1090
+ className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
1086
1091
  ...ariaProps
1087
1092
  }
1088
1093
  ),
@@ -1100,9 +1105,10 @@ var ContactDetailsForm = forwardRef(
1100
1105
  {
1101
1106
  id: fieldId,
1102
1107
  value: value ?? "",
1108
+ disabled: isDisabled,
1103
1109
  onChange: (e) => handleQuestionChange(question.id, e.target.value),
1104
1110
  onBlur: () => handleQuestionBlur(question.id),
1105
- className: inputClasses(hasError),
1111
+ className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
1106
1112
  ...ariaProps,
1107
1113
  children: [
1108
1114
  /* @__PURE__ */ jsx("option", { value: "", children: "Select an option" }),
@@ -1125,12 +1131,13 @@ var ContactDetailsForm = forwardRef(
1125
1131
  id: fieldId,
1126
1132
  type: "number",
1127
1133
  value: value ?? "",
1134
+ disabled: isDisabled,
1128
1135
  onChange: (e) => handleQuestionChange(question.id, e.target.value ? Number(e.target.value) : ""),
1129
1136
  onBlur: () => handleQuestionBlur(question.id),
1130
1137
  min: question.settings?.min,
1131
1138
  max: question.settings?.max,
1132
1139
  placeholder: question.settings?.placeholder,
1133
- className: inputClasses(hasError),
1140
+ className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
1134
1141
  ...ariaProps
1135
1142
  }
1136
1143
  ),
@@ -1149,9 +1156,10 @@ var ContactDetailsForm = forwardRef(
1149
1156
  id: fieldId,
1150
1157
  type: "date",
1151
1158
  value: value || "",
1159
+ disabled: isDisabled,
1152
1160
  onChange: (e) => handleQuestionChange(question.id, e.target.value),
1153
1161
  onBlur: () => handleQuestionBlur(question.id),
1154
- className: inputClasses(hasError),
1162
+ className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
1155
1163
  ...ariaProps
1156
1164
  }
1157
1165
  ),
@@ -1167,9 +1175,10 @@ var ContactDetailsForm = forwardRef(
1167
1175
  id: fieldId,
1168
1176
  type: "checkbox",
1169
1177
  checked: !!value,
1178
+ disabled: isDisabled,
1170
1179
  onChange: (e) => handleQuestionChange(question.id, e.target.checked),
1171
1180
  onBlur: () => handleQuestionBlur(question.id),
1172
- className: styles.checkbox,
1181
+ className: cx2(styles.checkbox, isDisabled ? "opacity-50 cursor-not-allowed" : ""),
1173
1182
  ...ariaProps
1174
1183
  }
1175
1184
  ),
@@ -1185,12 +1194,24 @@ var ContactDetailsForm = forwardRef(
1185
1194
  return null;
1186
1195
  }
1187
1196
  };
1197
+ useEffect(() => {
1198
+ if (hideSubmitButton && _onChange) {
1199
+ const contactValid = !contactFields.some((f) => {
1200
+ if (getFieldDisabled(f.name)) return false;
1201
+ return !!validateContactField(f.name, f.value);
1202
+ });
1203
+ const questionsValid = !questions.some(
1204
+ (q) => !!validateQuestionField(q, questionValues[q.id])
1205
+ );
1206
+ _onChange(buildOutput(), contactValid && questionsValid);
1207
+ }
1208
+ }, [hideSubmitButton, firstName, lastName, emailValue, questionValues]);
1188
1209
  return /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className, noValidate: true, children: [
1189
1210
  renderContactField("firstName", "First name", firstName),
1190
1211
  renderContactField("lastName", "Last name", lastName),
1191
1212
  renderContactField("email", "Email", emailValue, "email"),
1192
1213
  questions.map(renderQuestionField),
1193
- /* @__PURE__ */ jsx("button", { type: "submit", className: styles.button, children: submitLabel })
1214
+ !hideSubmitButton && /* @__PURE__ */ jsx("button", { type: "submit", className: styles.button, children: submitLabel })
1194
1215
  ] });
1195
1216
  }
1196
1217
  );