@planetaexo/design-system 0.4.8 → 0.4.10
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 +25 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
{
|
|
@@ -4670,7 +4693,7 @@ function RegistrationForm({
|
|
|
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
|
{
|