@forms.expert/sdk 0.2.13 → 0.3.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.
@@ -571,6 +571,49 @@ function getFieldBorderRadius(radius) {
571
571
  return "0.375rem";
572
572
  }
573
573
  }
574
+ function getWidthPercent(width) {
575
+ switch (width) {
576
+ case "1/4":
577
+ return "25%";
578
+ case "1/3":
579
+ return "33.333%";
580
+ case "1/2":
581
+ return "50%";
582
+ case "2/3":
583
+ return "66.666%";
584
+ case "3/4":
585
+ return "75%";
586
+ case "full":
587
+ return "100%";
588
+ default:
589
+ return void 0;
590
+ }
591
+ }
592
+ function groupFieldsIntoRows(fields) {
593
+ const result = [];
594
+ let i = 0;
595
+ while (i < fields.length) {
596
+ const field = fields[i];
597
+ if (field.row != null) {
598
+ const rowFields = [field];
599
+ let j = i + 1;
600
+ while (j < fields.length && fields[j].row === field.row) {
601
+ rowFields.push(fields[j]);
602
+ j++;
603
+ }
604
+ if (rowFields.length > 1) {
605
+ result.push({ type: "row", fields: rowFields });
606
+ } else {
607
+ result.push({ type: "single", field });
608
+ }
609
+ i = j;
610
+ } else {
611
+ result.push({ type: "single", field });
612
+ i++;
613
+ }
614
+ }
615
+ return result;
616
+ }
574
617
  function getButtonRadius(radius) {
575
618
  switch (radius) {
576
619
  case "none":
@@ -1045,21 +1088,39 @@ function FormsExpertForm({
1045
1088
  marginBottom: "0.5rem",
1046
1089
  color: styling.textColor
1047
1090
  }, children: form.config.hostedConfig?.pageTitle || form.config.name }),
1048
- fields.map((field) => /* @__PURE__ */ jsx2(
1049
- FormFieldInput,
1050
- {
1051
- field,
1052
- value: form.values[field.name],
1053
- error: form.errors[field.name],
1054
- onChange: handleChange,
1055
- onValueChange: (name, val) => form.setValue(name, val),
1056
- styling,
1057
- fieldSpacing,
1058
- labelSpacing,
1059
- phFontSize
1060
- },
1061
- field.name
1062
- )),
1091
+ groupFieldsIntoRows(fields).map((group, idx) => {
1092
+ if (group.type === "single") {
1093
+ return /* @__PURE__ */ jsx2(
1094
+ FormFieldInput,
1095
+ {
1096
+ field: group.field,
1097
+ value: form.values[group.field.name],
1098
+ error: form.errors[group.field.name],
1099
+ onChange: handleChange,
1100
+ onValueChange: (name, val) => form.setValue(name, val),
1101
+ styling,
1102
+ fieldSpacing,
1103
+ labelSpacing,
1104
+ phFontSize
1105
+ },
1106
+ group.field.name
1107
+ );
1108
+ }
1109
+ return /* @__PURE__ */ jsx2("div", { style: { display: "flex", gap: "0.75rem", flexWrap: "wrap", marginBottom: fieldSpacing }, children: group.fields.map((f) => /* @__PURE__ */ jsx2("div", { style: { flex: getWidthPercent(f.width) ? `0 0 calc(${getWidthPercent(f.width)} - 0.75rem)` : "1 1 0", minWidth: "120px" }, children: /* @__PURE__ */ jsx2(
1110
+ FormFieldInput,
1111
+ {
1112
+ field: f,
1113
+ value: form.values[f.name],
1114
+ error: form.errors[f.name],
1115
+ onChange: handleChange,
1116
+ onValueChange: (name, val) => form.setValue(name, val),
1117
+ styling,
1118
+ fieldSpacing: "0",
1119
+ labelSpacing,
1120
+ phFontSize
1121
+ }
1122
+ ) }, f.name)) }, `row-${idx}`);
1123
+ }),
1063
1124
  form.honeypotEnabled && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", left: "-9999px", opacity: 0, height: 0, overflow: "hidden" }, "aria-hidden": "true", children: /* @__PURE__ */ jsx2("input", { type: "text", name: "_hp", tabIndex: -1, autoComplete: "off" }) }),
1064
1125
  form.requiresCaptcha && form.captchaProvider !== "recaptcha" && /* @__PURE__ */ jsx2("div", { ref: captchaContainerRef, style: { marginTop: "1rem" } }),
1065
1126
  (() => {