@fairmint/ui 0.2.12 → 0.2.13

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.
@@ -26868,7 +26868,7 @@ const Tabs = Object.assign(TabsBase, {
26868
26868
  const TextInput = forwardRef((props, ref) => /* @__PURE__ */ jsx(TextInput$1, { size: "md", ...props, ref }));
26869
26869
  TextInput.displayName = "TextInput";
26870
26870
  function Tooltip(props) {
26871
- return /* @__PURE__ */ jsx(Tooltip$1, { ...props });
26871
+ return /* @__PURE__ */ jsx(Tooltip$1, { fz: "xs", ...props });
26872
26872
  }
26873
26873
  function ErrorFallback({
26874
26874
  title = "Something went wrong",
@@ -28227,17 +28227,77 @@ function PasswordField({ error: error2, ...rest }) {
28227
28227
  }
28228
28228
  );
28229
28229
  }
28230
- const phoneSchema = stringType().regex(/^\+?[\d\s\-().]{7,20}$/, "Please enter a valid phone number");
28231
- function PhoneField({ error: error2, ...rest }) {
28230
+ const phoneSchema = stringType().refine((value) => {
28231
+ if (!/^\+?[\d\s\-().]*$/.test(value)) return false;
28232
+ const digits = value.replace(/\D/g, "");
28233
+ if (value.startsWith("+")) {
28234
+ if (digits.startsWith("1")) return digits.length === 11;
28235
+ return digits.length >= 8 && digits.length <= 15;
28236
+ }
28237
+ return digits.length === 10 || digits.length === 11 && digits.startsWith("1");
28238
+ }, "Please enter a valid phone number");
28239
+ function formatPhone(raw) {
28240
+ const hasPlus = raw.startsWith("+");
28241
+ const digits = raw.replace(/\D/g, "");
28242
+ if (!digits) return hasPlus ? "+" : "";
28243
+ if (!hasPlus && digits.length === 11 && digits.startsWith("1")) {
28244
+ return formatPhone(`+${digits}`);
28245
+ }
28246
+ if (hasPlus && digits.startsWith("1")) {
28247
+ const local = digits.slice(1);
28248
+ if (!local.length) return "+1";
28249
+ if (local.length <= 3) return `+1 (${local}`;
28250
+ if (local.length <= 6) return `+1 (${local.slice(0, 3)}) ${local.slice(3)}`;
28251
+ return `+1 (${local.slice(0, 3)}) ${local.slice(3, 6)}-${local.slice(6, 10)}`;
28252
+ }
28253
+ if (hasPlus) return `+${digits}`;
28254
+ if (digits.length <= 3) return digits;
28255
+ if (digits.length <= 6) return `(${digits.slice(0, 3)}) ${digits.slice(3)}`;
28256
+ return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6, 10)}`;
28257
+ }
28258
+ function normalizePhone(formatted) {
28259
+ const hasPlus = formatted.startsWith("+");
28260
+ const digits = formatted.replace(/\D/g, "");
28261
+ if (!digits) return "";
28262
+ if (hasPlus) return `+${digits}`;
28263
+ if (digits.length === 10) return `+1${digits}`;
28264
+ return `+${digits}`;
28265
+ }
28266
+ const formatPhoneDisplay = formatPhone;
28267
+ function PhoneField({ error: error2, onChange, value, ...rest }) {
28268
+ const inputRef = React__default.useRef(null);
28269
+ const handleChange = (e) => {
28270
+ const raw = e.target.value;
28271
+ const hasPlus = raw.startsWith("+");
28272
+ let digits = raw.replace(/\D/g, "");
28273
+ const shouldFormatAsUsCountryCode = digits.startsWith("1") && (hasPlus || !hasPlus && digits.length > 10);
28274
+ if (shouldFormatAsUsCountryCode) {
28275
+ digits = digits.slice(0, 11);
28276
+ } else {
28277
+ digits = digits.slice(0, hasPlus ? 15 : 10);
28278
+ }
28279
+ const formatted = formatPhone(hasPlus || shouldFormatAsUsCountryCode ? `+${digits}` : digits);
28280
+ e.target.value = formatted;
28281
+ onChange?.(e);
28282
+ };
28283
+ const displayValue = typeof value === "string" ? formatPhone(value) : value;
28284
+ React__default.useEffect(() => {
28285
+ if (inputRef.current && displayValue != null && inputRef.current.value !== String(displayValue)) {
28286
+ inputRef.current.value = String(displayValue);
28287
+ }
28288
+ }, [displayValue]);
28232
28289
  return /* @__PURE__ */ jsx(
28233
28290
  TextInput,
28234
28291
  {
28292
+ ref: inputRef,
28235
28293
  type: "tel",
28236
28294
  label: rest.label ?? "Phone",
28237
- placeholder: rest.placeholder ?? "+1 (555) 000-0000",
28295
+ placeholder: rest.placeholder ?? "(555) 000-0000",
28238
28296
  autoComplete: "tel",
28297
+ ...rest,
28239
28298
  error: error2,
28240
- ...rest
28299
+ value: displayValue,
28300
+ onChange: handleChange
28241
28301
  }
28242
28302
  );
28243
28303
  }
@@ -30355,6 +30415,8 @@ function InvestorProfileCard({
30355
30415
  subtitle,
30356
30416
  children,
30357
30417
  onEditName,
30418
+ editNameDisabled,
30419
+ editNameTooltip,
30358
30420
  onUploadPhoto,
30359
30421
  photoUploading,
30360
30422
  editNameIcon,
@@ -30443,7 +30505,21 @@ function InvestorProfileCard({
30443
30505
  /* @__PURE__ */ jsxs(Group, { gap: "xs", wrap: "nowrap", align: "center", children: [
30444
30506
  /* @__PURE__ */ jsx(Text, { fw: 600, size: "md", children: displayName }),
30445
30507
  verificationStatus && /* @__PURE__ */ jsx(StatusBadge, { status: verificationStatus, size: "xs" }),
30446
- onEditName && /* @__PURE__ */ jsx(ActionIcon, { variant: "subtle", size: "sm", onClick: onEditName, "aria-label": "Edit name", children: editNameIcon ?? /* @__PURE__ */ jsx(DefaultPencilIcon, {}) })
30508
+ onEditName && (editNameDisabled ? /* @__PURE__ */ jsx(Tooltip, { label: editNameTooltip ?? "Coming soon", children: /* @__PURE__ */ jsx(
30509
+ ActionIcon,
30510
+ {
30511
+ variant: "subtle",
30512
+ size: "sm",
30513
+ "aria-label": "Edit name",
30514
+ "aria-disabled": "true",
30515
+ onClick: (event) => {
30516
+ event.preventDefault();
30517
+ event.stopPropagation();
30518
+ },
30519
+ style: { opacity: 0.5, cursor: "not-allowed" },
30520
+ children: editNameIcon ?? /* @__PURE__ */ jsx(DefaultPencilIcon, {})
30521
+ }
30522
+ ) }) : /* @__PURE__ */ jsx(ActionIcon, { variant: "subtle", size: "sm", onClick: onEditName, "aria-label": "Edit name", children: editNameIcon ?? /* @__PURE__ */ jsx(DefaultPencilIcon, {}) }))
30447
30523
  ] }),
30448
30524
  email && /* @__PURE__ */ jsx(Text, { size: "sm", c: `${colors.neutral}.5`, children: email }),
30449
30525
  memberSinceText && /* @__PURE__ */ jsx(Text, { size: "xs", c: `${colors.neutral}.4`, children: memberSinceText }),
@@ -30770,10 +30846,13 @@ export {
30770
30846
  formatDate,
30771
30847
  formatNumber,
30772
30848
  formatPercent,
30849
+ formatPhone,
30850
+ formatPhoneDisplay,
30773
30851
  formatPreciseWithCurrency,
30774
30852
  getAvatarColor,
30775
30853
  isEthereumAddress,
30776
30854
  neutralColors,
30855
+ normalizePhone,
30777
30856
  notify,
30778
30857
  passwordSchema,
30779
30858
  phoneSchema,