@planetaexo/design-system 0.4.7 → 0.4.9

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.cjs CHANGED
@@ -4521,6 +4521,8 @@ function RegistrationForm({
4521
4521
  defaultValues,
4522
4522
  onChange,
4523
4523
  onSubmit,
4524
+ onValidate,
4525
+ externalErrors,
4524
4526
  terms,
4525
4527
  includeTerms = false,
4526
4528
  loading = false,
@@ -4552,6 +4554,7 @@ function RegistrationForm({
4552
4554
  )
4553
4555
  );
4554
4556
  const [submitAttempted, setSubmitAttempted] = React21__namespace.useState(false);
4557
+ const [validationErrors, setValidationErrors] = React21__namespace.useState({});
4555
4558
  React21__namespace.useEffect(() => {
4556
4559
  if (isControlled) return;
4557
4560
  setInternal((prev) => {
@@ -4577,12 +4580,15 @@ function RegistrationForm({
4577
4580
  const termsEnabled = includeTerms && !!terms;
4578
4581
  const acceptControl = (_a = terms == null ? void 0 : terms.acceptControl) != null ? _a : "checkbox";
4579
4582
  const handleSubmit = (e) => {
4583
+ var _a2;
4580
4584
  e.preventDefault();
4581
4585
  setSubmitAttempted(true);
4582
4586
  const hasRequiredEmpty = sortedFields.some(
4583
4587
  (f) => f.required && isFieldEmpty(f, current[f.id])
4584
4588
  );
4585
- if (hasRequiredEmpty || termsEnabled && !termsAccepted) return;
4589
+ const extraErrors = (_a2 = onValidate == null ? void 0 : onValidate(current)) != null ? _a2 : {};
4590
+ setValidationErrors(extraErrors);
4591
+ if (hasRequiredEmpty || Object.keys(extraErrors).length > 0 || termsEnabled && !termsAccepted) return;
4586
4592
  onSubmit == null ? void 0 : onSubmit(current);
4587
4593
  };
4588
4594
  const dateRange = formatDateRange(adventure, dateFormatter);
@@ -4594,7 +4600,24 @@ function RegistrationForm({
4594
4600
  fieldErrors[field.id] = L.requiredFieldError;
4595
4601
  }
4596
4602
  }
4603
+ for (const [id, msg] of Object.entries(validationErrors)) {
4604
+ if (!fieldErrors[id]) fieldErrors[id] = msg;
4605
+ }
4606
+ if (externalErrors) {
4607
+ for (const [id, msg] of Object.entries(externalErrors)) {
4608
+ if (!fieldErrors[id]) fieldErrors[id] = msg;
4609
+ }
4610
+ }
4597
4611
  }
4612
+ const firstErrorFieldId = Object.keys(fieldErrors)[0];
4613
+ React21__namespace.useEffect(() => {
4614
+ if (!submitAttempted || !firstErrorFieldId) return;
4615
+ const timer = setTimeout(() => {
4616
+ const elem = document.getElementById(`rf-${firstErrorFieldId}`);
4617
+ if (elem) elem.scrollIntoView({ behavior: "smooth", block: "center" });
4618
+ }, 50);
4619
+ return () => clearTimeout(timer);
4620
+ }, [submitAttempted, firstErrorFieldId, validationErrors]);
4598
4621
  return /* @__PURE__ */ jsxRuntime.jsxs(
4599
4622
  "form",
4600
4623
  {
@@ -4646,31 +4669,31 @@ function RegistrationForm({
4646
4669
  /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-black uppercase tracking-wide text-foreground font-heading leading-tight", children: title }),
4647
4670
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1.5 text-sm text-muted-foreground font-ui", children: subtitle != null ? subtitle : L.formSubtitle })
4648
4671
  ] }),
4649
- hasTripInfo && /* @__PURE__ */ jsxRuntime.jsx(FormSection2, { title: L.tripInfoSectionTitle, children: /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "grid grid-cols-1 gap-x-6 gap-y-3 text-sm font-ui sm:grid-cols-[max-content_1fr]", children: [
4650
- adventure && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4672
+ hasTripInfo && /* @__PURE__ */ jsxRuntime.jsx(FormSection2, { title: L.tripInfoSectionTitle, children: /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "flex flex-col gap-y-3 text-sm font-ui", children: [
4673
+ adventure && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-x-4", children: [
4651
4674
  /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-muted-foreground", children: L.adventureLabel }),
4652
- /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground font-medium", children: adventure.name })
4675
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground font-medium text-right min-w-0 break-words", children: adventure.name })
4653
4676
  ] }),
4654
- dateRange && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4677
+ dateRange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-x-4", children: [
4655
4678
  /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-muted-foreground", children: (adventure == null ? void 0 : adventure.startDate) && (adventure == null ? void 0 : adventure.endDate) ? "Dates" : "Date" }),
4656
- /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground", children: dateRange })
4679
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground text-right min-w-0", children: dateRange })
4657
4680
  ] }),
4658
- (adventure == null ? void 0 : adventure.partnerName) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4681
+ (adventure == null ? void 0 : adventure.partnerName) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-x-4", children: [
4659
4682
  /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-muted-foreground", children: L.partnerLabel }),
4660
- /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground", children: adventure.partnerName })
4683
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground text-right min-w-0", children: adventure.partnerName })
4661
4684
  ] }),
4662
- booking && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4685
+ booking && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-x-4", children: [
4663
4686
  /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-muted-foreground", children: L.bookingLabel }),
4664
- /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground font-mono tabular-nums", children: booking.id })
4687
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground font-mono tabular-nums text-right min-w-0", children: booking.id })
4665
4688
  ] }),
4666
- traveller && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4689
+ traveller && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-x-4", children: [
4667
4690
  /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-muted-foreground", children: L.travellerLabel }),
4668
- /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground font-medium", children: traveller.fullName })
4691
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground font-medium text-right min-w-0 break-words", children: traveller.fullName })
4669
4692
  ] })
4670
4693
  ] }) }),
4671
4694
  /* @__PURE__ */ jsxRuntime.jsx(FormSection2, { title: L.detailsSectionTitle, children: sortedFields.map((field) => {
4672
4695
  var _a2;
4673
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1.5", children: [
4696
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: `rf-${field.id}`, className: "flex flex-col gap-1.5", children: [
4674
4697
  /* @__PURE__ */ jsxRuntime.jsx(
4675
4698
  FieldRenderer,
4676
4699
  {
@@ -4858,9 +4881,9 @@ function RegistrationSuccessCard({
4858
4881
  /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-black uppercase tracking-wide text-foreground font-heading leading-tight", children: title }),
4859
4882
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground font-ui", children: message })
4860
4883
  ] }),
4861
- sorted.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(FormSection2, { title: answersTitle, children: /* @__PURE__ */ jsxRuntime.jsx("dl", { className: "grid grid-cols-1 gap-x-6 gap-y-3 text-sm font-ui sm:grid-cols-[max-content_1fr]", children: sorted.map((f) => /* @__PURE__ */ jsxRuntime.jsxs(React21__namespace.Fragment, { children: [
4884
+ sorted.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(FormSection2, { title: answersTitle, children: /* @__PURE__ */ jsxRuntime.jsx("dl", { className: "flex flex-col gap-y-3 text-sm font-ui", children: sorted.map((f) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-x-4", children: [
4862
4885
  /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-muted-foreground", children: f.label }),
4863
- /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground", children: (formatAnswer != null ? formatAnswer : ((field, v) => defaultFormatAnswer(field, v, dateFormatter)))(
4886
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-foreground text-right min-w-0 break-words", children: (formatAnswer != null ? formatAnswer : ((field, v) => defaultFormatAnswer(field, v, dateFormatter)))(
4864
4887
  f,
4865
4888
  answers[f.id]
4866
4889
  ) })