@bison-lab/ui 5.9.1 → 5.11.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
@@ -521,17 +521,28 @@ const Form = React.forwardRef(({ onSubmit, schema, formMode = "native", errors:
521
521
  const editedRef = React.useRef(/* @__PURE__ */ new Set());
522
522
  const shownRef = React.useRef(/* @__PURE__ */ new Set());
523
523
  const judgeBlur = validateOn === "blur" && Boolean(schema);
524
- /** Re-judge one field against the whole form's current values. */
524
+ /**
525
+ * Re-judge one field against the whole form's current values, and with it
526
+ * every other field already showing an error. A cross-field rule (a
527
+ * confirmation that must match) reports on one field but is fixed by
528
+ * editing another, so a fix elsewhere has to clear it. Fields not showing
529
+ * an error are left alone: a neighbour's edit never raises a new one.
530
+ */
525
531
  const judgeField = React.useCallback((form, name) => {
526
532
  if (!schema) return;
527
- const message = schemaErrors(schema, readForm(form))[name];
528
- if (message) {
529
- shownRef.current.add(name);
530
- setFieldError(name, message);
531
- } else if (shownRef.current.has(name)) {
532
- shownRef.current.delete(name);
533
- clearFieldError(name);
534
- }
533
+ const found = schemaErrors(schema, readForm(form));
534
+ const judge = (field) => {
535
+ const message = found[field];
536
+ if (message) {
537
+ shownRef.current.add(field);
538
+ setFieldError(field, message);
539
+ } else if (shownRef.current.has(field)) {
540
+ shownRef.current.delete(field);
541
+ clearFieldError(field);
542
+ }
543
+ };
544
+ judge(name);
545
+ for (const other of Array.from(shownRef.current)) if (other !== name) judge(other);
535
546
  }, [
536
547
  schema,
537
548
  setFieldError,
@@ -1326,6 +1337,15 @@ const inputSurfaceClasses = "flex w-full rounded-md border border-input bg-backg
1326
1337
  */
1327
1338
  const inputFocusClasses = "focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-primary/30 focus-visible:ring-offset-0";
1328
1339
  /**
1340
+ * The destructive border on a control in error. Keyed on the `aria-invalid`
1341
+ * a field wrapper already sets, so a stacked field (label above) turns red the
1342
+ * way the outlined layout's shell does. Inside an outlined shell the control's
1343
+ * own border is reset to zero width, so the two never stack.
1344
+ *
1345
+ * Used by: Input, PasswordInput, Checkbox.
1346
+ */
1347
+ const invalidBorderClasses = "aria-invalid:border-destructive";
1348
+ /**
1329
1349
  * Standard single-line input sizing per size: density height + horizontal
1330
1350
  * padding + vertical padding, scaled per size. Textarea uses `min-h-[80px]`
1331
1351
  * instead of any of these.
@@ -1444,7 +1464,7 @@ const Input = React.forwardRef(({ className, type, size = "md", ...props }, ref)
1444
1464
  const fieldProps = useFieldControl(props);
1445
1465
  return /* @__PURE__ */ jsx("input", {
1446
1466
  type,
1447
- className: cn(inputSurfaceClasses, inputSizingClasses(size), inputFocusClasses, "file:border-0 file:bg-transparent file:text-base file:font-medium sm:file:text-sm", className),
1467
+ className: cn(inputSurfaceClasses, inputSizingClasses(size), inputFocusClasses, invalidBorderClasses, "file:border-0 file:bg-transparent file:text-base file:font-medium sm:file:text-sm", className),
1448
1468
  ref,
1449
1469
  ...fieldProps
1450
1470
  });
@@ -1454,14 +1474,16 @@ Input.displayName = "Input";
1454
1474
  //#region src/components/password-input.tsx
1455
1475
  const PasswordInput = React.forwardRef(({ className, toggleLabel = "Show or hide password", size = "md", ...props }, ref) => {
1456
1476
  const fieldProps = useFieldControl(props);
1477
+ const toggleId = `${React.useId()}-toggle`;
1457
1478
  return /* @__PURE__ */ jsx(unstable_PasswordToggleField.Root, { children: /* @__PURE__ */ jsxs("div", {
1458
1479
  className: "relative",
1459
1480
  children: [/* @__PURE__ */ jsx(unstable_PasswordToggleField.Input, {
1460
- className: cn(inputSurfaceClasses, inputSizingClasses(size), inputFocusClasses, "pr-10 file:border-0 file:bg-transparent file:text-base file:font-medium sm:file:text-sm", className),
1481
+ className: cn(inputSurfaceClasses, inputSizingClasses(size), inputFocusClasses, invalidBorderClasses, "pr-10 file:border-0 file:bg-transparent file:text-base file:font-medium sm:file:text-sm", className),
1461
1482
  ref,
1462
1483
  ...fieldProps
1463
1484
  }), /* @__PURE__ */ jsx(unstable_PasswordToggleField.Toggle, {
1464
1485
  className: "absolute right-0 top-0 flex h-full w-10 items-center justify-center text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50",
1486
+ id: toggleId,
1465
1487
  disabled: props.disabled,
1466
1488
  "aria-label": toggleLabel,
1467
1489
  children: /* @__PURE__ */ jsx(unstable_PasswordToggleField.Icon, {
@@ -1998,7 +2020,10 @@ const DatePicker = React.forwardRef(({ value, onChange, placeholder = "Pick a da
1998
2020
  disabled,
1999
2021
  className: cn("w-full justify-start text-left font-normal", !value && "text-muted-foreground", className),
2000
2022
  ...fieldProps,
2001
- children: [/* @__PURE__ */ jsx(Calendar$1, { className: "mr-2 h-4 w-4" }), value ? format(value, dateFormat) : /* @__PURE__ */ jsx("span", { children: placeholder })]
2023
+ children: [/* @__PURE__ */ jsx("span", {
2024
+ className: "min-w-0 flex-1 truncate text-left",
2025
+ children: value ? format(value, dateFormat) : placeholder
2026
+ }), /* @__PURE__ */ jsx(Calendar$1, { className: "ml-2 h-4 w-4 shrink-0" })]
2002
2027
  })
2003
2028
  }), /* @__PURE__ */ jsx(PopoverContent, {
2004
2029
  className: "w-auto p-0",
@@ -2260,6 +2285,16 @@ const dateRangePresets = {
2260
2285
  }
2261
2286
  })
2262
2287
  };
2288
+ /**
2289
+ * Where the clear button sits: the trigger's right padding, the 16px icon and
2290
+ * the 8px gap before it, so it lands exactly on the reserved slot. Follows
2291
+ * Button's padding per size (px-3, px-4, px-8).
2292
+ */
2293
+ const clearOffset = {
2294
+ sm: "right-9",
2295
+ md: "right-10",
2296
+ lg: "right-14"
2297
+ };
2263
2298
  const DateRangePicker = React.forwardRef(({ value, onChange, placeholder = "Pick a date range", dateFormat = "LLL dd, y", disabled = false, className, presets, numberOfMonths = 2, fromDate, toDate, clearable = true, clearLabel = "Clear date range", calendarLabel = "Choose a date range", size = "md" }, ref) => {
2264
2299
  const fieldProps = useFieldControl({});
2265
2300
  const [open, setOpen] = React.useState(false);
@@ -2285,14 +2320,20 @@ const DateRangePicker = React.forwardRef(({ value, onChange, placeholder = "Pick
2285
2320
  variant: "outline",
2286
2321
  size,
2287
2322
  disabled,
2288
- className: cn("w-full justify-start text-left font-normal", !value && "text-muted-foreground", showClear && "pr-9", className),
2323
+ className: cn("w-full justify-start text-left font-normal", !value && "text-muted-foreground", className),
2289
2324
  ...fieldProps,
2290
- children: [/* @__PURE__ */ jsx(Calendar$1, { className: "mr-2 h-4 w-4" }), value?.from ? value.to ? /* @__PURE__ */ jsxs(Fragment, { children: [
2291
- format(value.from, dateFormat),
2292
- " –",
2293
- " ",
2294
- format(value.to, dateFormat)
2295
- ] }) : format(value.from, dateFormat) : /* @__PURE__ */ jsx("span", { children: placeholder })]
2325
+ children: [
2326
+ /* @__PURE__ */ jsx("span", {
2327
+ className: "min-w-0 flex-1 truncate text-left",
2328
+ children: value?.from ? value.to ? `${format(value.from, dateFormat)} – ${format(value.to, dateFormat)}` : format(value.from, dateFormat) : placeholder
2329
+ }),
2330
+ showClear && /* @__PURE__ */ jsx("span", {
2331
+ "aria-hidden": "true",
2332
+ "data-clear-slot": "",
2333
+ className: "ml-2 h-4 w-4 shrink-0"
2334
+ }),
2335
+ /* @__PURE__ */ jsx(Calendar$1, { className: "ml-2 h-4 w-4 shrink-0" })
2336
+ ]
2296
2337
  })
2297
2338
  }), showClear && /* @__PURE__ */ jsx("button", {
2298
2339
  type: "button",
@@ -2302,7 +2343,7 @@ const DateRangePicker = React.forwardRef(({ value, onChange, placeholder = "Pick
2302
2343
  onKeyDown: (e) => {
2303
2344
  if (e.key === "Enter" || e.key === " ") handleClear(e);
2304
2345
  },
2305
- className: "absolute right-2 top-1/2 -translate-y-1/2 rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
2346
+ className: cn("absolute top-1/2", clearOffset[size], "-translate-y-1/2 rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1"),
2306
2347
  children: /* @__PURE__ */ jsx(CircleX, { className: "h-4 w-4" })
2307
2348
  })]
2308
2349
  }), /* @__PURE__ */ jsx(PopoverContent, {
@@ -2737,7 +2778,7 @@ const Checkbox = React.forwardRef(({ className, checked, ...props }, ref) => {
2737
2778
  return /* @__PURE__ */ jsx(Checkbox$1.Root, {
2738
2779
  ref,
2739
2780
  checked,
2740
- className: cn("peer h-4 w-4 shrink-0 cursor-pointer rounded-[2px] border border-primary bg-background ring-offset-background transition-[color,background-color,border-color] duration-fast ease-default focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/35 focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground", coarseHitAreaClasses, className),
2781
+ className: cn("peer h-4 w-4 shrink-0 cursor-pointer rounded-[2px] border border-primary bg-background ring-offset-background transition-[color,background-color,border-color] duration-fast ease-default focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/35 focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground", coarseHitAreaClasses, invalidBorderClasses, className),
2741
2782
  ...fieldProps,
2742
2783
  children: /* @__PURE__ */ jsx(Checkbox$1.Indicator, {
2743
2784
  className: cn("flex h-full w-full items-center justify-center text-current"),
@@ -3063,7 +3104,7 @@ const defaultIcons = {
3063
3104
  danger: /* @__PURE__ */ jsx(CircleAlert, { className: "size-4" }),
3064
3105
  info: /* @__PURE__ */ jsx(Info, { className: "size-4" })
3065
3106
  };
3066
- const Alert = React.forwardRef(({ className, variant = "default", showIcon = false, icon, dismissable = false, onDismiss, children, ...props }, ref) => {
3107
+ const Alert = React.forwardRef(({ className, variant = "default", showIcon = false, icon, dismissable = false, onDismiss, action, children, ...props }, ref) => {
3067
3108
  const [dismissed, setDismissed] = React.useState(false);
3068
3109
  if (dismissed) return null;
3069
3110
  const resolvedIcon = icon ?? (showIcon ? defaultIcons[variant ?? "default"] : null);
@@ -3084,7 +3125,17 @@ const Alert = React.forwardRef(({ className, variant = "default", showIcon = fal
3084
3125
  ...props,
3085
3126
  children: [
3086
3127
  leading,
3087
- /* @__PURE__ */ jsx("div", {
3128
+ action != null && action !== false ? /* @__PURE__ */ jsxs("div", {
3129
+ className: "flex min-w-0 flex-1 flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",
3130
+ children: [/* @__PURE__ */ jsx("div", {
3131
+ className: "min-w-0 flex-1",
3132
+ children
3133
+ }), /* @__PURE__ */ jsx("div", {
3134
+ "data-alert-action": "",
3135
+ className: "shrink-0 whitespace-nowrap font-medium [&_a:not([class])]:underline [&_a:not([class])]:underline-offset-4",
3136
+ children: action
3137
+ })]
3138
+ }) : /* @__PURE__ */ jsx("div", {
3088
3139
  className: "min-w-0 flex-1",
3089
3140
  children
3090
3141
  }),
@@ -5855,6 +5906,83 @@ function SidebarMenuSubButton({ asChild = false, size = "md", isActive = false,
5855
5906
  });
5856
5907
  }
5857
5908
  //#endregion
5909
+ //#region src/form/validators.ts
5910
+ /**
5911
+ * A trimmed, non-empty string.
5912
+ *
5913
+ * Trimming happens before the emptiness check, so a field holding only spaces
5914
+ * fails rather than passing as "filled".
5915
+ */
5916
+ function requiredText({ requiredMessage = "This field is required." } = {}) {
5917
+ return z.string().trim().min(1, { message: requiredMessage });
5918
+ }
5919
+ /** An email address. Trimmed, and empty-tolerant when `optional`. */
5920
+ function emailField({ requiredMessage = "Email address is required.", message = "Enter a valid email address.", optional = false } = {}) {
5921
+ const base = z.string().trim();
5922
+ if (optional) return base.refine((value) => value === "" || z.string().email().safeParse(value).success, { message });
5923
+ return base.min(1, { message: requiredMessage }).email({ message });
5924
+ }
5925
+ /**
5926
+ * A US (NANP) phone number, counted in digits rather than matched by shape.
5927
+ *
5928
+ * Accepts anything `PhoneInput` can produce or a human can paste:
5929
+ * `(555) 123-4567`, `555-123-4567`, `5551234567`, `+1 555 123 4567`. What it
5930
+ * checks is that exactly ten digits are present, which is the only part that
5931
+ * carries meaning — `PhoneInput` already owns the presentation.
5932
+ */
5933
+ function usPhoneField({ requiredMessage = "Phone number is required.", message = "Enter a 10-digit US phone number.", required = false } = {}) {
5934
+ const base = z.string().trim();
5935
+ const hasTenDigits = (value) => parseUsPhoneDigits(value).length === 10;
5936
+ if (required) return base.min(1, { message: requiredMessage }).refine(hasTenDigits, { message });
5937
+ return base.refine((value) => value === "" || hasTenDigits(value), { message });
5938
+ }
5939
+ /** A value the browser did not post reads as empty, not as a type error. */
5940
+ const posted = (schema) => z.preprocess((value) => value ?? "", schema);
5941
+ /**
5942
+ * A password that only has to be present. Not trimmed: spaces are characters
5943
+ * in a password, and trimming would turn " " into "missing".
5944
+ */
5945
+ function presentPassword(requiredMessage) {
5946
+ return z.string().min(1, { message: requiredMessage });
5947
+ }
5948
+ /**
5949
+ * The default schema of `SignInBlock`: an email and a password that is
5950
+ * present. Whether the pair is right is the server's call, reported through
5951
+ * the block's `error`.
5952
+ */
5953
+ function signInSchema() {
5954
+ return z.object({
5955
+ email: posted(emailField()),
5956
+ password: posted(presentPassword("Password is required."))
5957
+ });
5958
+ }
5959
+ /**
5960
+ * The default schema of `SignUpBlock`: first and last name, an email, a
5961
+ * password of at least `minPasswordLength` characters, and a confirmation
5962
+ * that matches it. A site with stricter password rules (an identity
5963
+ * provider's policy, say) passes its own schema to the block.
5964
+ *
5965
+ * The match is reported on `confirmPassword` even while other fields are
5966
+ * still empty, because `validateOn="blur"` judges one field against the
5967
+ * whole form as the person leaves it.
5968
+ */
5969
+ function signUpSchema({ minPasswordLength = 8 } = {}) {
5970
+ return z.object({
5971
+ firstName: posted(requiredText({ requiredMessage: "First name is required." })),
5972
+ lastName: posted(requiredText({ requiredMessage: "Last name is required." })),
5973
+ email: posted(emailField()),
5974
+ password: posted(presentPassword("Password is required.").min(minPasswordLength, { message: `Use at least ${minPasswordLength} characters.` })),
5975
+ confirmPassword: posted(presentPassword("Confirm your password."))
5976
+ }).refine((data) => !data.confirmPassword || data.password === data.confirmPassword, {
5977
+ message: "Passwords do not match.",
5978
+ path: ["confirmPassword"],
5979
+ when: (payload) => {
5980
+ const value = payload.value;
5981
+ return typeof value?.password === "string" && typeof value?.confirmPassword === "string";
5982
+ }
5983
+ });
5984
+ }
5985
+ //#endregion
5858
5986
  //#region src/blocks/auth/social-providers.tsx
5859
5987
  const providerConfig = {
5860
5988
  google: {
@@ -5931,7 +6059,17 @@ function SocialProviders({ providers, onSocialLogin, loading, disabled, classNam
5931
6059
  });
5932
6060
  }
5933
6061
  //#endregion
6062
+ //#region src/blocks/auth/auth-link.ts
6063
+ /**
6064
+ * A link-styled control in the auth blocks. Underlined, not only colored:
6065
+ * `text-primary` can match the body text in some themes, and a link has to
6066
+ * read as a link without relying on color (WCAG 1.4.1).
6067
+ */
6068
+ const authLinkClasses = "text-primary underline underline-offset-4 hover:decoration-2";
6069
+ //#endregion
5934
6070
  //#region src/blocks/auth/sign-in-block.tsx
6071
+ const DEFAULT_SCHEMA$1 = signInSchema();
6072
+ const OTP_EMAIL_SCHEMA = z.object({ "otp-email": z.preprocess((value) => value ?? "", emailField()) });
5935
6073
  const AUTH_TABS = {
5936
6074
  PASSWORD: "password",
5937
6075
  OTP: "otp"
@@ -5972,9 +6110,8 @@ function OtpForm({ onOtpRequest, onOtpVerify, loading = false, disabled = false
5972
6110
  const [otpError, setOtpError] = React.useState();
5973
6111
  const isLoading = loading || otpLoading;
5974
6112
  const displayError = otpError;
5975
- const handleEmailSubmit = async (e) => {
5976
- e.preventDefault();
5977
- const emailValue = new FormData(e.currentTarget).get("otp-email");
6113
+ const handleEmailSubmit = async (data) => {
6114
+ const emailValue = String(data["otp-email"] ?? "");
5978
6115
  setOtpError(void 0);
5979
6116
  setOtpLoading(true);
5980
6117
  try {
@@ -6015,7 +6152,7 @@ function OtpForm({ onOtpRequest, onOtpVerify, loading = false, disabled = false
6015
6152
  }),
6016
6153
  /* @__PURE__ */ jsx("button", {
6017
6154
  type: "button",
6018
- className: "w-full text-center text-sm text-muted-foreground hover:text-foreground",
6155
+ className: cn("w-full text-center text-sm", authLinkClasses),
6019
6156
  onClick: () => {
6020
6157
  setStep("email");
6021
6158
  setOtpError(void 0);
@@ -6024,14 +6161,15 @@ function OtpForm({ onOtpRequest, onOtpVerify, loading = false, disabled = false
6024
6161
  })
6025
6162
  ]
6026
6163
  })] });
6027
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FormError, { message: displayError }), /* @__PURE__ */ jsxs("form", {
6164
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FormError, { message: displayError }), /* @__PURE__ */ jsxs(Form, {
6165
+ schema: OTP_EMAIL_SCHEMA,
6166
+ validateOn: "blur",
6028
6167
  onSubmit: handleEmailSubmit,
6029
6168
  className: "space-y-4",
6030
- children: [/* @__PURE__ */ jsx(InputGroup, {
6169
+ children: [/* @__PURE__ */ jsx(FormField, {
6170
+ name: "otp-email",
6031
6171
  label: "Email",
6032
- htmlFor: "otp-email",
6033
6172
  children: /* @__PURE__ */ jsx(Input, {
6034
- id: "otp-email",
6035
6173
  name: "otp-email",
6036
6174
  type: "email",
6037
6175
  placeholder: "name@example.com",
@@ -6049,7 +6187,22 @@ function OtpForm({ onOtpRequest, onOtpVerify, loading = false, disabled = false
6049
6187
  })]
6050
6188
  })] });
6051
6189
  }
6052
- function SignInBlock({ onSubmit, onForgotPassword, onSocialLogin, socialProviders = [], loading = false, error, disabled = false, title = "Sign in", description = "Enter your credentials to access your account", signUpHref, onSignUp, className, children, onOtpRequest, onOtpVerify, otpLabel = "Email me a code", onTabChange }) {
6190
+ /**
6191
+ * Email and password sign-in in a card, with optional social providers and a
6192
+ * one-time-code tab. The fields are a `Form` with `FormField`s, so they get
6193
+ * what every library form gets: the error under the field, a check as the
6194
+ * person leaves a field (`validateOn="blur"`), the shake and focus on the
6195
+ * first wrong field after a failed submit, and a screen-reader summary.
6196
+ *
6197
+ * **Requires `zod` ^4.** The default schema (`signInSchema()` from
6198
+ * `@bison-lab/ui/validators`) is built with it. `zod` is a peer dependency of
6199
+ * `@bison-lab/ui`; install it in the app (`pnpm add zod`) even if the app
6200
+ * writes no schema of its own.
6201
+ *
6202
+ * Server results go in two props: `error` for a message that belongs to no
6203
+ * field (shown in the box above the form), `errors` for one that does.
6204
+ */
6205
+ function SignInBlock({ onSubmit, onForgotPassword, onSocialLogin, socialProviders = [], loading = false, error, errors, schema = DEFAULT_SCHEMA$1, validateOn = "blur", disabled = false, title = "Sign in", description = "Enter your credentials to access your account", signUpHref, onSignUp, className, children, onOtpRequest, onOtpVerify, otpLabel = "Email me a code", onTabChange }) {
6053
6206
  const [activeTab, setActiveTab] = React.useState(AUTH_TABS.PASSWORD);
6054
6207
  const otpEnabled = Boolean(onOtpRequest && onOtpVerify);
6055
6208
  const handleTabChange = React.useCallback((tab) => {
@@ -6065,23 +6218,23 @@ function SignInBlock({ onSubmit, onForgotPassword, onSocialLogin, socialProvider
6065
6218
  }
6066
6219
  }, [error, activeTab]);
6067
6220
  const visibleError = errorTab === activeTab ? error : void 0;
6068
- const handleSubmit = async (e) => {
6069
- e.preventDefault();
6070
- const formData = new FormData(e.currentTarget);
6221
+ const handleSubmit = async (data) => {
6071
6222
  await onSubmit({
6072
- email: formData.get("email"),
6073
- password: formData.get("password")
6223
+ email: typeof data.email === "string" ? data.email : "",
6224
+ password: typeof data.password === "string" ? data.password : ""
6074
6225
  });
6075
6226
  };
6076
- const passwordForm = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FormError, { message: visibleError }), /* @__PURE__ */ jsxs("form", {
6227
+ const passwordForm = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FormError, { message: visibleError }), /* @__PURE__ */ jsxs(Form, {
6228
+ schema,
6229
+ validateOn,
6230
+ errors,
6077
6231
  onSubmit: handleSubmit,
6078
6232
  className: "space-y-4",
6079
6233
  children: [
6080
- /* @__PURE__ */ jsx(InputGroup, {
6234
+ /* @__PURE__ */ jsx(FormField, {
6235
+ name: "email",
6081
6236
  label: "Email",
6082
- htmlFor: "email",
6083
6237
  children: /* @__PURE__ */ jsx(Input, {
6084
- id: "email",
6085
6238
  name: "email",
6086
6239
  type: "email",
6087
6240
  placeholder: "name@example.com",
@@ -6090,26 +6243,25 @@ function SignInBlock({ onSubmit, onForgotPassword, onSocialLogin, socialProvider
6090
6243
  autoComplete: "email"
6091
6244
  })
6092
6245
  }),
6093
- /* @__PURE__ */ jsxs(InputGroup, {
6246
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(FormField, {
6247
+ name: "password",
6094
6248
  label: "Password",
6095
- htmlFor: "password",
6096
- children: [/* @__PURE__ */ jsx(PasswordInput, {
6097
- id: "password",
6249
+ children: /* @__PURE__ */ jsx(PasswordInput, {
6098
6250
  name: "password",
6099
6251
  required: true,
6100
6252
  disabled: loading || disabled,
6101
6253
  autoComplete: "current-password"
6102
- }), onForgotPassword && /* @__PURE__ */ jsx("div", {
6103
- className: "flex justify-end",
6104
- children: /* @__PURE__ */ jsx("button", {
6105
- type: "button",
6106
- onClick: onForgotPassword,
6107
- className: "text-sm text-primary hover:underline",
6108
- tabIndex: -1,
6109
- children: "Forgot password?"
6110
- })
6111
- })]
6112
- }),
6254
+ })
6255
+ }), onForgotPassword && /* @__PURE__ */ jsx("div", {
6256
+ className: "mt-2 flex justify-end",
6257
+ children: /* @__PURE__ */ jsx("button", {
6258
+ type: "button",
6259
+ onClick: onForgotPassword,
6260
+ className: cn("text-sm", "text-primary underline underline-offset-4 hover:decoration-2"),
6261
+ tabIndex: -1,
6262
+ children: "Forgot password?"
6263
+ })
6264
+ })] }),
6113
6265
  /* @__PURE__ */ jsx(Button, {
6114
6266
  type: "submit",
6115
6267
  variant: "default",
@@ -6146,11 +6298,11 @@ function SignInBlock({ onSubmit, onForgotPassword, onSocialLogin, socialProvider
6146
6298
  onSignUp ? /* @__PURE__ */ jsx("button", {
6147
6299
  type: "button",
6148
6300
  onClick: onSignUp,
6149
- className: "text-primary hover:underline font-medium",
6301
+ className: cn("font-medium", "text-primary underline underline-offset-4 hover:decoration-2"),
6150
6302
  children: "Sign up"
6151
6303
  }) : /* @__PURE__ */ jsx("a", {
6152
6304
  href: signUpHref,
6153
- className: "text-primary hover:underline font-medium",
6305
+ className: cn("font-medium", "text-primary underline underline-offset-4 hover:decoration-2"),
6154
6306
  children: "Sign up"
6155
6307
  })
6156
6308
  ]
@@ -6208,17 +6360,32 @@ function SignInBlock({ onSubmit, onForgotPassword, onSocialLogin, socialProvider
6208
6360
  }
6209
6361
  //#endregion
6210
6362
  //#region src/blocks/auth/sign-up-block.tsx
6211
- function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading = false, error, disabled = false, title = "Create an account", description = "Enter your details to get started", signInHref, onSignIn, termsHref = "#", privacyHref = "#", className }) {
6363
+ const DEFAULT_SCHEMA = signUpSchema();
6364
+ /**
6365
+ * Registration in a card: first and last name, email, password and its
6366
+ * confirmation, and a terms tick, with optional social providers. The fields
6367
+ * are a `Form` with `FormField`s, so errors sit under their field, a field is
6368
+ * checked as the person leaves it (`validateOn="blur"`), and a failed submit
6369
+ * shakes the wrong fields, focuses the first and announces the count.
6370
+ *
6371
+ * **Requires `zod` ^4.** The default schema (`signUpSchema()` from
6372
+ * `@bison-lab/ui/validators`) is built with it. `zod` is a peer dependency of
6373
+ * `@bison-lab/ui`; install it in the app (`pnpm add zod`) even if the app
6374
+ * writes no schema of its own.
6375
+ *
6376
+ * Server results go in two props: `error` for a message that belongs to no
6377
+ * field (shown in the box above the form), `errors` for one that does.
6378
+ */
6379
+ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading = false, error, errors, schema = DEFAULT_SCHEMA, validateOn = "blur", disabled = false, title = "Create an account", description = "Enter your details to get started", signInHref, onSignIn, termsHref = "#", privacyHref = "#", className }) {
6212
6380
  const [termsAccepted, setTermsAccepted] = React.useState(false);
6213
- const handleSubmit = async (e) => {
6214
- e.preventDefault();
6215
- const formData = new FormData(e.currentTarget);
6381
+ const handleSubmit = async (data) => {
6382
+ const text = (key) => typeof data[key] === "string" ? data[key] : "";
6216
6383
  await onSubmit({
6217
- firstName: formData.get("firstName") ?? "",
6218
- lastName: formData.get("lastName") ?? "",
6219
- email: formData.get("email"),
6220
- password: formData.get("password"),
6221
- confirmPassword: formData.get("confirmPassword"),
6384
+ firstName: text("firstName"),
6385
+ lastName: text("lastName"),
6386
+ email: text("email"),
6387
+ password: text("password"),
6388
+ confirmPassword: text("confirmPassword"),
6222
6389
  termsAccepted
6223
6390
  });
6224
6391
  };
@@ -6249,15 +6416,17 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6249
6416
  })]
6250
6417
  })] }),
6251
6418
  /* @__PURE__ */ jsx(FormError, { message: error }),
6252
- /* @__PURE__ */ jsxs("form", {
6419
+ /* @__PURE__ */ jsxs(Form, {
6420
+ schema,
6421
+ validateOn,
6422
+ errors,
6253
6423
  onSubmit: handleSubmit,
6254
6424
  className: "space-y-4",
6255
6425
  children: [
6256
- /* @__PURE__ */ jsx(InputGroup, {
6426
+ /* @__PURE__ */ jsx(FormField, {
6427
+ name: "firstName",
6257
6428
  label: "First name",
6258
- htmlFor: "firstName",
6259
6429
  children: /* @__PURE__ */ jsx(Input, {
6260
- id: "firstName",
6261
6430
  name: "firstName",
6262
6431
  placeholder: "Jane",
6263
6432
  required: true,
@@ -6265,11 +6434,10 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6265
6434
  autoComplete: "given-name"
6266
6435
  })
6267
6436
  }),
6268
- /* @__PURE__ */ jsx(InputGroup, {
6437
+ /* @__PURE__ */ jsx(FormField, {
6438
+ name: "lastName",
6269
6439
  label: "Last name",
6270
- htmlFor: "lastName",
6271
6440
  children: /* @__PURE__ */ jsx(Input, {
6272
- id: "lastName",
6273
6441
  name: "lastName",
6274
6442
  placeholder: "Doe",
6275
6443
  required: true,
@@ -6277,11 +6445,10 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6277
6445
  autoComplete: "family-name"
6278
6446
  })
6279
6447
  }),
6280
- /* @__PURE__ */ jsx(InputGroup, {
6448
+ /* @__PURE__ */ jsx(FormField, {
6449
+ name: "email",
6281
6450
  label: "Email",
6282
- htmlFor: "email",
6283
6451
  children: /* @__PURE__ */ jsx(Input, {
6284
- id: "email",
6285
6452
  name: "email",
6286
6453
  type: "email",
6287
6454
  placeholder: "name@example.com",
@@ -6290,22 +6457,20 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6290
6457
  autoComplete: "email"
6291
6458
  })
6292
6459
  }),
6293
- /* @__PURE__ */ jsx(InputGroup, {
6460
+ /* @__PURE__ */ jsx(FormField, {
6461
+ name: "password",
6294
6462
  label: "Password",
6295
- htmlFor: "password",
6296
6463
  children: /* @__PURE__ */ jsx(PasswordInput, {
6297
- id: "password",
6298
6464
  name: "password",
6299
6465
  required: true,
6300
6466
  disabled: loading || disabled,
6301
6467
  autoComplete: "new-password"
6302
6468
  })
6303
6469
  }),
6304
- /* @__PURE__ */ jsx(InputGroup, {
6470
+ /* @__PURE__ */ jsx(FormField, {
6471
+ name: "confirmPassword",
6305
6472
  label: "Confirm password",
6306
- htmlFor: "confirmPassword",
6307
6473
  children: /* @__PURE__ */ jsx(PasswordInput, {
6308
- id: "confirmPassword",
6309
6474
  name: "confirmPassword",
6310
6475
  required: true,
6311
6476
  disabled: loading || disabled,
@@ -6328,7 +6493,7 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6328
6493
  " ",
6329
6494
  /* @__PURE__ */ jsx("a", {
6330
6495
  href: termsHref,
6331
- className: "text-primary hover:underline",
6496
+ className: authLinkClasses,
6332
6497
  children: "terms of service"
6333
6498
  }),
6334
6499
  " ",
@@ -6336,7 +6501,7 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6336
6501
  " ",
6337
6502
  /* @__PURE__ */ jsx("a", {
6338
6503
  href: privacyHref,
6339
- className: "text-primary hover:underline",
6504
+ className: authLinkClasses,
6340
6505
  children: "privacy policy"
6341
6506
  })
6342
6507
  ]
@@ -6359,11 +6524,11 @@ function SignUpBlock({ onSubmit, onSocialLogin, socialProviders = [], loading =
6359
6524
  onSignIn ? /* @__PURE__ */ jsx("button", {
6360
6525
  type: "button",
6361
6526
  onClick: onSignIn,
6362
- className: "text-primary hover:underline font-medium",
6527
+ className: cn("font-medium", "text-primary underline underline-offset-4 hover:decoration-2"),
6363
6528
  children: "Sign in"
6364
6529
  }) : /* @__PURE__ */ jsx("a", {
6365
6530
  href: signInHref,
6366
- className: "text-primary hover:underline font-medium",
6531
+ className: cn("font-medium", "text-primary underline underline-offset-4 hover:decoration-2"),
6367
6532
  children: "Sign in"
6368
6533
  })
6369
6534
  ]
@@ -8294,37 +8459,6 @@ const VideoBlock = React.forwardRef(({ eyebrow, title, description, headingLevel
8294
8459
  });
8295
8460
  VideoBlock.displayName = "VideoBlock";
8296
8461
  //#endregion
8297
- //#region src/form/validators.ts
8298
- /**
8299
- * A trimmed, non-empty string.
8300
- *
8301
- * Trimming happens before the emptiness check, so a field holding only spaces
8302
- * fails rather than passing as "filled".
8303
- */
8304
- function requiredText({ requiredMessage = "This field is required." } = {}) {
8305
- return z.string().trim().min(1, { message: requiredMessage });
8306
- }
8307
- /** An email address. Trimmed, and empty-tolerant when `optional`. */
8308
- function emailField({ requiredMessage = "Email address is required.", message = "Enter a valid email address.", optional = false } = {}) {
8309
- const base = z.string().trim();
8310
- if (optional) return base.refine((value) => value === "" || z.string().email().safeParse(value).success, { message });
8311
- return base.min(1, { message: requiredMessage }).email({ message });
8312
- }
8313
- /**
8314
- * A US (NANP) phone number, counted in digits rather than matched by shape.
8315
- *
8316
- * Accepts anything `PhoneInput` can produce or a human can paste:
8317
- * `(555) 123-4567`, `555-123-4567`, `5551234567`, `+1 555 123 4567`. What it
8318
- * checks is that exactly ten digits are present, which is the only part that
8319
- * carries meaning — `PhoneInput` already owns the presentation.
8320
- */
8321
- function usPhoneField({ requiredMessage = "Phone number is required.", message = "Enter a 10-digit US phone number.", required = false } = {}) {
8322
- const base = z.string().trim();
8323
- const hasTenDigits = (value) => parseUsPhoneDigits(value).length === 10;
8324
- if (required) return base.min(1, { message: requiredMessage }).refine(hasTenDigits, { message });
8325
- return base.refine((value) => value === "" || hasTenDigits(value), { message });
8326
- }
8327
- //#endregion
8328
8462
  //#region src/blocks/marketing/inquiry-form-block.tsx
8329
8463
  const AUTOCOMPLETE = {
8330
8464
  name: "name",