@planetaexo/design-system 0.4.8 → 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.d.cts CHANGED
@@ -571,6 +571,15 @@ interface RegistrationFormProps {
571
571
  defaultValues?: RegistrationFormValues;
572
572
  onChange?: (values: RegistrationFormValues) => void;
573
573
  onSubmit?: (values: RegistrationFormValues) => void;
574
+ /**
575
+ * Synchronous format/business validator called inside handleSubmit.
576
+ * Return a record of fieldId → error message to block submit and show inline errors.
577
+ * Called after the required-empty check, so values are guaranteed non-empty for required fields.
578
+ * For validating optional fields or additional format checks, use this instead of onSubmit.
579
+ */
580
+ onValidate?: (values: RegistrationFormValues) => Record<string, string>;
581
+ /** @deprecated Use onValidate instead. Per-field errors injected by the parent. */
582
+ externalErrors?: Record<string, string>;
574
583
  terms?: RegistrationTerms;
575
584
  includeTerms?: boolean;
576
585
  loading?: boolean;
@@ -580,7 +589,7 @@ interface RegistrationFormProps {
580
589
  labels?: RegistrationFormLabels;
581
590
  className?: string;
582
591
  }
583
- declare function RegistrationForm({ logo, logoAlt, heroImage, heroImageAlt, title, subtitle, adventure, booking, traveller, fields, values, defaultValues, onChange, onSubmit, terms, includeTerms, loading, error, defaultPhoneCountry, dateFormatter, labels, className, }: RegistrationFormProps): react_jsx_runtime.JSX.Element;
592
+ declare function RegistrationForm({ logo, logoAlt, heroImage, heroImageAlt, title, subtitle, adventure, booking, traveller, fields, values, defaultValues, onChange, onSubmit, onValidate, externalErrors, terms, includeTerms, loading, error, defaultPhoneCountry, dateFormatter, labels, className, }: RegistrationFormProps): react_jsx_runtime.JSX.Element;
584
593
  interface RegistrationSuccessCardProps {
585
594
  title?: string;
586
595
  message?: string;
package/dist/index.d.ts CHANGED
@@ -571,6 +571,15 @@ interface RegistrationFormProps {
571
571
  defaultValues?: RegistrationFormValues;
572
572
  onChange?: (values: RegistrationFormValues) => void;
573
573
  onSubmit?: (values: RegistrationFormValues) => void;
574
+ /**
575
+ * Synchronous format/business validator called inside handleSubmit.
576
+ * Return a record of fieldId → error message to block submit and show inline errors.
577
+ * Called after the required-empty check, so values are guaranteed non-empty for required fields.
578
+ * For validating optional fields or additional format checks, use this instead of onSubmit.
579
+ */
580
+ onValidate?: (values: RegistrationFormValues) => Record<string, string>;
581
+ /** @deprecated Use onValidate instead. Per-field errors injected by the parent. */
582
+ externalErrors?: Record<string, string>;
574
583
  terms?: RegistrationTerms;
575
584
  includeTerms?: boolean;
576
585
  loading?: boolean;
@@ -580,7 +589,7 @@ interface RegistrationFormProps {
580
589
  labels?: RegistrationFormLabels;
581
590
  className?: string;
582
591
  }
583
- declare function RegistrationForm({ logo, logoAlt, heroImage, heroImageAlt, title, subtitle, adventure, booking, traveller, fields, values, defaultValues, onChange, onSubmit, terms, includeTerms, loading, error, defaultPhoneCountry, dateFormatter, labels, className, }: RegistrationFormProps): react_jsx_runtime.JSX.Element;
592
+ declare function RegistrationForm({ logo, logoAlt, heroImage, heroImageAlt, title, subtitle, adventure, booking, traveller, fields, values, defaultValues, onChange, onSubmit, onValidate, externalErrors, terms, includeTerms, loading, error, defaultPhoneCountry, dateFormatter, labels, className, }: RegistrationFormProps): react_jsx_runtime.JSX.Element;
584
593
  interface RegistrationSuccessCardProps {
585
594
  title?: string;
586
595
  message?: string;
package/dist/index.js CHANGED
@@ -4500,6 +4500,8 @@ function RegistrationForm({
4500
4500
  defaultValues,
4501
4501
  onChange,
4502
4502
  onSubmit,
4503
+ onValidate,
4504
+ externalErrors,
4503
4505
  terms,
4504
4506
  includeTerms = false,
4505
4507
  loading = false,
@@ -4531,6 +4533,7 @@ function RegistrationForm({
4531
4533
  )
4532
4534
  );
4533
4535
  const [submitAttempted, setSubmitAttempted] = React21.useState(false);
4536
+ const [validationErrors, setValidationErrors] = React21.useState({});
4534
4537
  React21.useEffect(() => {
4535
4538
  if (isControlled) return;
4536
4539
  setInternal((prev) => {
@@ -4556,12 +4559,15 @@ function RegistrationForm({
4556
4559
  const termsEnabled = includeTerms && !!terms;
4557
4560
  const acceptControl = (_a = terms == null ? void 0 : terms.acceptControl) != null ? _a : "checkbox";
4558
4561
  const handleSubmit = (e) => {
4562
+ var _a2;
4559
4563
  e.preventDefault();
4560
4564
  setSubmitAttempted(true);
4561
4565
  const hasRequiredEmpty = sortedFields.some(
4562
4566
  (f) => f.required && isFieldEmpty(f, current[f.id])
4563
4567
  );
4564
- if (hasRequiredEmpty || termsEnabled && !termsAccepted) return;
4568
+ const extraErrors = (_a2 = onValidate == null ? void 0 : onValidate(current)) != null ? _a2 : {};
4569
+ setValidationErrors(extraErrors);
4570
+ if (hasRequiredEmpty || Object.keys(extraErrors).length > 0 || termsEnabled && !termsAccepted) return;
4565
4571
  onSubmit == null ? void 0 : onSubmit(current);
4566
4572
  };
4567
4573
  const dateRange = formatDateRange(adventure, dateFormatter);
@@ -4573,7 +4579,24 @@ function RegistrationForm({
4573
4579
  fieldErrors[field.id] = L.requiredFieldError;
4574
4580
  }
4575
4581
  }
4582
+ for (const [id, msg] of Object.entries(validationErrors)) {
4583
+ if (!fieldErrors[id]) fieldErrors[id] = msg;
4584
+ }
4585
+ if (externalErrors) {
4586
+ for (const [id, msg] of Object.entries(externalErrors)) {
4587
+ if (!fieldErrors[id]) fieldErrors[id] = msg;
4588
+ }
4589
+ }
4576
4590
  }
4591
+ const firstErrorFieldId = Object.keys(fieldErrors)[0];
4592
+ React21.useEffect(() => {
4593
+ if (!submitAttempted || !firstErrorFieldId) return;
4594
+ const timer = setTimeout(() => {
4595
+ const elem = document.getElementById(`rf-${firstErrorFieldId}`);
4596
+ if (elem) elem.scrollIntoView({ behavior: "smooth", block: "center" });
4597
+ }, 50);
4598
+ return () => clearTimeout(timer);
4599
+ }, [submitAttempted, firstErrorFieldId, validationErrors]);
4577
4600
  return /* @__PURE__ */ jsxs(
4578
4601
  "form",
4579
4602
  {
@@ -4649,7 +4672,7 @@ function RegistrationForm({
4649
4672
  ] }) }),
4650
4673
  /* @__PURE__ */ jsx(FormSection2, { title: L.detailsSectionTitle, children: sortedFields.map((field) => {
4651
4674
  var _a2;
4652
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
4675
+ return /* @__PURE__ */ jsxs("div", { id: `rf-${field.id}`, className: "flex flex-col gap-1.5", children: [
4653
4676
  /* @__PURE__ */ jsx(
4654
4677
  FieldRenderer,
4655
4678
  {