@bizapps/ui 1.3.7 → 1.4.1

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/main.cjs CHANGED
@@ -10,8 +10,10 @@ var react = require('react');
10
10
  var radixUi = require('radix-ui');
11
11
  var dateFns = require('date-fns');
12
12
  var useEmblaCarousel = require('embla-carousel-react');
13
- var react$1 = require('motion/react');
13
+ var libphonenumberJs = require('libphonenumber-js');
14
14
  var cmdk = require('cmdk');
15
+ var _3x2 = require('country-flag-icons/react/3x2');
16
+ var react$1 = require('motion/react');
15
17
  var reactDropzone = require('react-dropzone');
16
18
  var Color = require('color');
17
19
  var reactDayPicker = require('react-day-picker');
@@ -1052,6 +1054,410 @@ function Link({
1052
1054
  }
1053
1055
  );
1054
1056
  }
1057
+ function Popover({ ...props }) {
1058
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Root, { "data-slot": "popover", ...props });
1059
+ }
1060
+ function PopoverTrigger({ ...props }) {
1061
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Trigger, { "data-slot": "popover-trigger", ...props });
1062
+ }
1063
+ function PopoverContent({
1064
+ className,
1065
+ align = "center",
1066
+ sideOffset = 4,
1067
+ container,
1068
+ ...props
1069
+ }) {
1070
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Portal, { container, children: /* @__PURE__ */ jsxRuntime.jsx(
1071
+ radixUi.Popover.Content,
1072
+ {
1073
+ "data-slot": "popover-content",
1074
+ align,
1075
+ sideOffset,
1076
+ className: cn(
1077
+ "bg-popover text-popover-foreground ring-foreground/5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-1 rounded-3xl p-4 text-sm shadow-lg ring-1 outline-hidden duration-100",
1078
+ className
1079
+ ),
1080
+ ...props
1081
+ }
1082
+ ) });
1083
+ }
1084
+ function PopoverAnchor({ ...props }) {
1085
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Anchor, { "data-slot": "popover-anchor", ...props });
1086
+ }
1087
+ function PopoverHeader({ className, ...props }) {
1088
+ return /* @__PURE__ */ jsxRuntime.jsx(
1089
+ "div",
1090
+ {
1091
+ "data-slot": "popover-header",
1092
+ className: cn("flex flex-col gap-1 text-sm", className),
1093
+ ...props
1094
+ }
1095
+ );
1096
+ }
1097
+ function PopoverTitle({ className, ...props }) {
1098
+ return /* @__PURE__ */ jsxRuntime.jsx(
1099
+ "div",
1100
+ {
1101
+ "data-slot": "popover-title",
1102
+ className: cn("text-base font-medium", className),
1103
+ ...props
1104
+ }
1105
+ );
1106
+ }
1107
+ function PopoverDescription({ className, ...props }) {
1108
+ return /* @__PURE__ */ jsxRuntime.jsx(
1109
+ "p",
1110
+ {
1111
+ "data-slot": "popover-description",
1112
+ className: cn("text-muted-foreground", className),
1113
+ ...props
1114
+ }
1115
+ );
1116
+ }
1117
+ function stripLeadingDialCode(raw, dialCode) {
1118
+ if (!raw.startsWith("+")) {
1119
+ return raw.replace(/\D/g, "");
1120
+ }
1121
+ const parsed = libphonenumberJs.parsePhoneNumberFromString(raw);
1122
+ if (parsed) {
1123
+ return parsed.nationalNumber;
1124
+ }
1125
+ const digits = raw.replace(/\D/g, "");
1126
+ const code = dialCode.replace(/\D/g, "");
1127
+ return code && digits.startsWith(code) ? digits.length > code.length ? digits.slice(code.length) : "" : digits;
1128
+ }
1129
+ var flagByCode = {
1130
+ AR: _3x2.AR,
1131
+ BO: _3x2.BO,
1132
+ BR: _3x2.BR,
1133
+ CA: _3x2.CA,
1134
+ CL: _3x2.CL,
1135
+ CO: _3x2.CO,
1136
+ CR: _3x2.CR,
1137
+ CU: _3x2.CU,
1138
+ DE: _3x2.DE,
1139
+ DO: _3x2.DO,
1140
+ EC: _3x2.EC,
1141
+ ES: _3x2.ES,
1142
+ FR: _3x2.FR,
1143
+ GB: _3x2.GB,
1144
+ GT: _3x2.GT,
1145
+ HN: _3x2.HN,
1146
+ IN: _3x2.IN,
1147
+ IT: _3x2.IT,
1148
+ MX: _3x2.MX,
1149
+ NI: _3x2.NI,
1150
+ PA: _3x2.PA,
1151
+ PE: _3x2.PE,
1152
+ PT: _3x2.PT,
1153
+ PY: _3x2.PY,
1154
+ SV: _3x2.SV,
1155
+ US: _3x2.US,
1156
+ UY: _3x2.UY,
1157
+ VE: _3x2.VE
1158
+ };
1159
+ function CountryFlag({
1160
+ code,
1161
+ flagUrl,
1162
+ className
1163
+ }) {
1164
+ if (flagUrl) {
1165
+ return /* @__PURE__ */ jsxRuntime.jsx(
1166
+ "img",
1167
+ {
1168
+ src: flagUrl,
1169
+ alt: "",
1170
+ "aria-hidden": "true",
1171
+ className: cn("size-4 shrink-0 rounded-[2px] object-cover", className)
1172
+ }
1173
+ );
1174
+ }
1175
+ const FlagComponent = flagByCode[(code || "").toUpperCase()];
1176
+ if (FlagComponent) {
1177
+ return /* @__PURE__ */ jsxRuntime.jsx(
1178
+ FlagComponent,
1179
+ {
1180
+ "aria-hidden": "true",
1181
+ className: cn("size-4 shrink-0 rounded-[2px]", className)
1182
+ }
1183
+ );
1184
+ }
1185
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: cn("bg-muted size-4 shrink-0 rounded-full", className) });
1186
+ }
1187
+ function PhoneField({
1188
+ countries,
1189
+ value,
1190
+ onValueChange,
1191
+ defaultCountry,
1192
+ placeholder = "Phone number",
1193
+ disabled = false,
1194
+ className,
1195
+ container,
1196
+ name,
1197
+ ...inputProps
1198
+ }) {
1199
+ const [open, setOpen] = react.useState(false);
1200
+ const [pickedCode, setPickedCode] = react.useState(
1201
+ (defaultCountry ?? countries[0]?.code)?.toUpperCase()
1202
+ );
1203
+ const [internalValue, setInternalValue] = react.useState("");
1204
+ const listRef = react.useRef(null);
1205
+ const inputRef = react.useRef(null);
1206
+ const caretRef = react.useRef(null);
1207
+ const listId = `${react.useId()}-countries-list`;
1208
+ const isControlled = value !== void 0;
1209
+ const currentValue = isControlled ? value : internalValue;
1210
+ const parsed = currentValue ? libphonenumberJs.parsePhoneNumberFromString(currentValue) : void 0;
1211
+ const parsedCountry = parsed?.country;
1212
+ const parsedCallingCode = parsed?.countryCallingCode;
1213
+ const countryInList = parsedCountry !== void 0 && countries.some((country) => country.code.toUpperCase() === parsedCountry);
1214
+ const callingCodeInList = parsedCallingCode !== void 0 && countries.some(
1215
+ (country) => country.dialCode.replace(/\D/g, "") === parsedCallingCode
1216
+ );
1217
+ const representedCode = countryInList ? parsedCountry : callingCodeInList ? countries.find(
1218
+ (country) => country.dialCode.replace(/\D/g, "") === parsedCallingCode
1219
+ )?.code : void 0;
1220
+ const selectedCode = representedCode ?? pickedCode ?? defaultCountry ?? countries[0]?.code;
1221
+ const selectedCountry = countries.find(
1222
+ (country) => country.code.toUpperCase() === selectedCode?.toUpperCase()
1223
+ ) ?? countries[0];
1224
+ const dialCode = selectedCountry ? selectedCountry.dialCode.replace(/\D/g, "") : "";
1225
+ const emitDialCode = parsedCallingCode ?? dialCode;
1226
+ const nationalDigits = parsed ? parsed.nationalNumber : currentValue ? stripLeadingDialCode(currentValue, dialCode) : "";
1227
+ const canFormat = selectedCountry !== void 0 && (!parsed || countryInList || callingCodeInList);
1228
+ const inputValue = selectedCountry && canFormat && nationalDigits ? new libphonenumberJs.AsYouType((selectedCountry.code || "").toUpperCase()).input(
1229
+ nationalDigits
1230
+ ) : nationalDigits;
1231
+ const isInvalid = inputProps["aria-invalid"] === true || inputProps["aria-invalid"] === "true";
1232
+ react.useLayoutEffect(() => {
1233
+ const input = inputRef.current;
1234
+ const caret = caretRef.current;
1235
+ if (!input || !caret || document.activeElement !== input) {
1236
+ return;
1237
+ }
1238
+ const digitsBefore = caret.raw.slice(0, caret.start).replace(/\D/g, "").length;
1239
+ let position = 0;
1240
+ if (digitsBefore > 0) {
1241
+ let digitsSeen = 0;
1242
+ for (let i = 0; i < inputValue.length; i++) {
1243
+ if (/\d/.test(inputValue[i])) {
1244
+ digitsSeen += 1;
1245
+ }
1246
+ position = i + 1;
1247
+ if (digitsSeen >= digitsBefore) {
1248
+ break;
1249
+ }
1250
+ }
1251
+ }
1252
+ input.setSelectionRange(position, position + (caret.end - caret.start));
1253
+ caretRef.current = null;
1254
+ }, [inputValue]);
1255
+ const handleSearchChange = () => {
1256
+ requestAnimationFrame(() => listRef.current?.scrollTo({ top: 0 }));
1257
+ };
1258
+ function handleCountrySelect(code) {
1259
+ setPickedCode(code);
1260
+ setOpen(false);
1261
+ const nextCountry = countries.find(
1262
+ (country) => country.code.toUpperCase() === code.toUpperCase()
1263
+ );
1264
+ if (nextCountry && nationalDigits) {
1265
+ const next = `+${nextCountry.dialCode.replace(/\D/g, "")}${nationalDigits}`;
1266
+ onValueChange?.(next);
1267
+ if (!isControlled) {
1268
+ setInternalValue(next);
1269
+ }
1270
+ }
1271
+ }
1272
+ function deriveFromE164(e164) {
1273
+ const parsed2 = libphonenumberJs.parsePhoneNumberFromString(e164);
1274
+ if (!parsed2?.nationalNumber) {
1275
+ return void 0;
1276
+ }
1277
+ const countryMatch = parsed2.country ? countries.find((country) => country.code.toUpperCase() === parsed2.country) : void 0;
1278
+ const nextPickedCode = countryMatch ? countryMatch.code : parsed2.countryCallingCode ? countries.find(
1279
+ (country) => country.dialCode.replace(/\D/g, "") === parsed2.countryCallingCode
1280
+ )?.code : void 0;
1281
+ return {
1282
+ nationalNumber: parsed2.nationalNumber,
1283
+ emitCode: parsed2.countryCallingCode,
1284
+ nextPickedCode
1285
+ };
1286
+ }
1287
+ function handleInputChange(raw, nativeEvent) {
1288
+ const input = inputRef.current;
1289
+ if (input) {
1290
+ caretRef.current = {
1291
+ raw,
1292
+ start: input.selectionStart ?? raw.length,
1293
+ end: input.selectionEnd ?? raw.length
1294
+ };
1295
+ }
1296
+ if (!selectedCountry) return;
1297
+ let national = stripLeadingDialCode(raw, dialCode);
1298
+ let emitCode = emitDialCode;
1299
+ let nextPickedCode;
1300
+ const plusIndex = raw.indexOf("+");
1301
+ if (plusIndex === 0) {
1302
+ const derived = deriveFromE164(raw);
1303
+ if (derived) {
1304
+ emitCode = derived.emitCode || emitDialCode;
1305
+ nextPickedCode = derived.nextPickedCode;
1306
+ } else if (nativeEvent?.inputType === "insertFromPaste") {
1307
+ national = "";
1308
+ }
1309
+ } else if (plusIndex > 0) {
1310
+ const pasted = nativeEvent?.inputType === "insertFromPaste" && nativeEvent.data?.startsWith("+") ? nativeEvent.data : void 0;
1311
+ if (pasted) {
1312
+ const derived = deriveFromE164(pasted);
1313
+ const prefixDigits = raw.slice(0, plusIndex).replace(/\D/g, "");
1314
+ const suffixDigits = raw.slice(plusIndex + pasted.length).replace(/\D/g, "");
1315
+ if (derived) {
1316
+ national = prefixDigits + derived.nationalNumber + suffixDigits;
1317
+ emitCode = derived.emitCode || emitDialCode;
1318
+ nextPickedCode = derived.nextPickedCode;
1319
+ } else {
1320
+ national = prefixDigits + suffixDigits;
1321
+ }
1322
+ }
1323
+ }
1324
+ if (nextPickedCode) {
1325
+ setPickedCode(nextPickedCode);
1326
+ }
1327
+ if (!national) {
1328
+ onValueChange?.("");
1329
+ if (!isControlled) {
1330
+ setInternalValue("");
1331
+ }
1332
+ return;
1333
+ }
1334
+ const next = `+${emitCode}${national}`;
1335
+ onValueChange?.(next);
1336
+ if (!isControlled) {
1337
+ setInternalValue(next);
1338
+ }
1339
+ }
1340
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1341
+ "div",
1342
+ {
1343
+ "data-slot": "phone-field",
1344
+ "data-invalid": isInvalid || void 0,
1345
+ className: cn(
1346
+ "border-input flex h-9 w-full min-w-0 items-center overflow-hidden rounded-md border bg-transparent shadow-xs transition-[color,box-shadow]",
1347
+ "focus-within:border-ring focus-within:ring-ring/30 focus-within:ring-3",
1348
+ "data-[invalid=true]:border-destructive data-[invalid=true]:ring-destructive/20 data-[invalid=true]:ring-3",
1349
+ "dark:data-[invalid=true]:border-destructive/50 dark:data-[invalid=true]:ring-destructive/40",
1350
+ className
1351
+ ),
1352
+ children: [
1353
+ /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
1354
+ /* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
1355
+ "button",
1356
+ {
1357
+ type: "button",
1358
+ "data-slot": "phone-field-country-select",
1359
+ disabled,
1360
+ "aria-expanded": open,
1361
+ "aria-haspopup": "listbox",
1362
+ "aria-controls": open ? listId : void 0,
1363
+ "aria-label": selectedCountry ? `${selectedCountry.name} ${selectedCountry.dialCode}` : void 0,
1364
+ className: cn(
1365
+ "flex h-full shrink-0 cursor-pointer items-center gap-1.5 border-r border-input px-2.5 text-sm font-medium outline-none select-none",
1366
+ "hover:bg-muted",
1367
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
1368
+ ),
1369
+ children: selectedCountry && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1370
+ /* @__PURE__ */ jsxRuntime.jsx(
1371
+ CountryFlag,
1372
+ {
1373
+ code: selectedCountry.code,
1374
+ flagUrl: selectedCountry.flagUrl
1375
+ }
1376
+ ),
1377
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tabular-nums", children: selectedCountry.dialCode }),
1378
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronsUpDownIcon, { size: 14, className: "text-muted-foreground shrink-0" })
1379
+ ] })
1380
+ }
1381
+ ) }),
1382
+ /* @__PURE__ */ jsxRuntime.jsx(
1383
+ PopoverContent,
1384
+ {
1385
+ className: "w-72 rounded-xl p-0",
1386
+ align: "start",
1387
+ container,
1388
+ children: /* @__PURE__ */ jsxRuntime.jsxs(cmdk.Command, { className: "rounded-xl", label: "Search countries", children: [
1389
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-border flex items-center gap-2 border-b px-3", children: [
1390
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchIcon, { size: 14, className: "text-muted-foreground shrink-0" }),
1391
+ /* @__PURE__ */ jsxRuntime.jsx(
1392
+ cmdk.Command.Input,
1393
+ {
1394
+ placeholder: "Search country...",
1395
+ onValueChange: handleSearchChange,
1396
+ className: "placeholder:text-muted-foreground flex h-9 w-full bg-transparent py-2 text-sm outline-none"
1397
+ }
1398
+ )
1399
+ ] }),
1400
+ /* @__PURE__ */ jsxRuntime.jsx("div", { id: listId, children: /* @__PURE__ */ jsxRuntime.jsxs(cmdk.Command.List, { ref: listRef, className: "max-h-56 overflow-y-auto p-1", children: [
1401
+ /* @__PURE__ */ jsxRuntime.jsx(cmdk.Command.Empty, { className: "text-muted-foreground py-4 text-center text-sm", children: "No country found." }),
1402
+ countries.map((country) => /* @__PURE__ */ jsxRuntime.jsxs(
1403
+ cmdk.Command.Item,
1404
+ {
1405
+ value: country.code,
1406
+ keywords: [country.name, country.dialCode],
1407
+ "data-slot": "phone-field-country-item",
1408
+ onSelect: () => handleCountrySelect(country.code),
1409
+ className: cn(
1410
+ "flex cursor-pointer items-center justify-between gap-2 rounded-md px-2 py-1.5 text-sm outline-none select-none",
1411
+ "data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground",
1412
+ "hover:bg-accent hover:text-accent-foreground"
1413
+ ),
1414
+ children: [
1415
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
1416
+ /* @__PURE__ */ jsxRuntime.jsx(CountryFlag, { code: country.code, flagUrl: country.flagUrl }),
1417
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: country.name })
1418
+ ] }),
1419
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
1420
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground tabular-nums", children: country.dialCode }),
1421
+ selectedCode?.toUpperCase() === country.code.toUpperCase() && /* @__PURE__ */ jsxRuntime.jsx(
1422
+ lucideReact.CheckIcon,
1423
+ {
1424
+ size: 14,
1425
+ className: "text-[var(--color-main-blue-primary)] shrink-0"
1426
+ }
1427
+ )
1428
+ ] })
1429
+ ]
1430
+ },
1431
+ country.code
1432
+ ))
1433
+ ] }) })
1434
+ ] })
1435
+ }
1436
+ )
1437
+ ] }),
1438
+ /* @__PURE__ */ jsxRuntime.jsx(
1439
+ Input,
1440
+ {
1441
+ ref: inputRef,
1442
+ ...inputProps,
1443
+ "data-slot": "phone-field-input",
1444
+ type: "tel",
1445
+ value: inputValue,
1446
+ onChange: (event) => handleInputChange(event.target.value, event.nativeEvent),
1447
+ placeholder,
1448
+ disabled,
1449
+ autoComplete: inputProps.autoComplete ?? "tel",
1450
+ className: cn(
1451
+ "h-full flex-1 rounded-none border-0 bg-transparent shadow-none",
1452
+ "px-3 focus-visible:border-transparent focus-visible:ring-0"
1453
+ )
1454
+ }
1455
+ ),
1456
+ name !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value: currentValue, "data-slot": "phone-field-hidden-input" })
1457
+ ]
1458
+ }
1459
+ );
1460
+ }
1055
1461
  function PinInput({
1056
1462
  length = 6,
1057
1463
  value = "",
@@ -2116,66 +2522,6 @@ function TooltipContent({
2116
2522
  }
2117
2523
  ) });
2118
2524
  }
2119
- function Popover({ ...props }) {
2120
- return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Root, { "data-slot": "popover", ...props });
2121
- }
2122
- function PopoverTrigger({ ...props }) {
2123
- return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Trigger, { "data-slot": "popover-trigger", ...props });
2124
- }
2125
- function PopoverContent({
2126
- className,
2127
- align = "center",
2128
- sideOffset = 4,
2129
- container,
2130
- ...props
2131
- }) {
2132
- return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Portal, { container, children: /* @__PURE__ */ jsxRuntime.jsx(
2133
- radixUi.Popover.Content,
2134
- {
2135
- "data-slot": "popover-content",
2136
- align,
2137
- sideOffset,
2138
- className: cn(
2139
- "bg-popover text-popover-foreground ring-foreground/5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-1 rounded-3xl p-4 text-sm shadow-lg ring-1 outline-hidden duration-100",
2140
- className
2141
- ),
2142
- ...props
2143
- }
2144
- ) });
2145
- }
2146
- function PopoverAnchor({ ...props }) {
2147
- return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Popover.Anchor, { "data-slot": "popover-anchor", ...props });
2148
- }
2149
- function PopoverHeader({ className, ...props }) {
2150
- return /* @__PURE__ */ jsxRuntime.jsx(
2151
- "div",
2152
- {
2153
- "data-slot": "popover-header",
2154
- className: cn("flex flex-col gap-1 text-sm", className),
2155
- ...props
2156
- }
2157
- );
2158
- }
2159
- function PopoverTitle({ className, ...props }) {
2160
- return /* @__PURE__ */ jsxRuntime.jsx(
2161
- "div",
2162
- {
2163
- "data-slot": "popover-title",
2164
- className: cn("text-base font-medium", className),
2165
- ...props
2166
- }
2167
- );
2168
- }
2169
- function PopoverDescription({ className, ...props }) {
2170
- return /* @__PURE__ */ jsxRuntime.jsx(
2171
- "p",
2172
- {
2173
- "data-slot": "popover-description",
2174
- className: cn("text-muted-foreground", className),
2175
- ...props
2176
- }
2177
- );
2178
- }
2179
2525
  var TEXT_SIZES = [12, 14, 16, 18, 20, 24, 28, 32, 40, 48];
2180
2526
  var TEXT_WEIGHTS = [100, 200, 300, 400, 500, 700, 800, 900];
2181
2527
  function Text({
@@ -4201,22 +4547,52 @@ function DatePicker({
4201
4547
  disabled = false,
4202
4548
  className,
4203
4549
  fromDate,
4204
- toDate
4550
+ toDate,
4551
+ numberOfMonths = 1
4205
4552
  }) {
4206
4553
  const [open, setOpen] = react.useState(false);
4554
+ const [awaitingRangeEnd, setAwaitingRangeEnd] = react.useState(false);
4207
4555
  const label = react.useMemo(() => {
4208
4556
  if (mode === "range") {
4209
4557
  const range = selected;
4210
- if (range?.from && range?.to)
4211
- return `${dateFns.format(range.from, "MMM d, yyyy")} \u2013 ${dateFns.format(range.to, "MMM d, yyyy")}`;
4212
- if (range?.from) return `${dateFns.format(range.from, "MMM d, yyyy")} \u2013 \u2026`;
4213
- return placeholder;
4558
+ if (!range?.from) return placeholder;
4559
+ if (!range.to) return `${dateFns.format(range.from, "MMM d, yyyy")} \u2013 \u2026`;
4560
+ return `${dateFns.format(range.from, "MMM d, yyyy")} \u2013 ${dateFns.format(range.to, "MMM d, yyyy")}`;
4214
4561
  }
4215
4562
  const date = selected;
4216
4563
  return date ? dateFns.format(date, "MMM d, yyyy") : placeholder;
4217
4564
  }, [mode, selected, placeholder]);
4565
+ const handleOpenChange = (nextOpen) => {
4566
+ setOpen(nextOpen);
4567
+ if (!nextOpen) setAwaitingRangeEnd(false);
4568
+ };
4569
+ const handleRangeSelect = (range, triggerDate) => {
4570
+ const emit = onSelect;
4571
+ if (!awaitingRangeEnd) {
4572
+ setAwaitingRangeEnd(true);
4573
+ emit?.({ from: triggerDate, to: void 0 });
4574
+ return;
4575
+ }
4576
+ emit?.(range);
4577
+ if (!range?.from || !range.to) {
4578
+ setAwaitingRangeEnd(!!range?.from);
4579
+ return;
4580
+ }
4581
+ setAwaitingRangeEnd(false);
4582
+ setOpen(false);
4583
+ };
4584
+ const dateConstraints = react.useMemo(() => {
4585
+ const disabledMatchers = [];
4586
+ if (fromDate) disabledMatchers.push({ before: fromDate });
4587
+ if (toDate) disabledMatchers.push({ after: toDate });
4588
+ return {
4589
+ ...disabledMatchers.length > 0 && { disabled: disabledMatchers },
4590
+ ...fromDate && { startMonth: fromDate },
4591
+ ...toDate && { endMonth: toDate }
4592
+ };
4593
+ }, [fromDate, toDate]);
4218
4594
  const hasValue = mode === "range" ? !!selected?.from : !!selected;
4219
- return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
4595
+ return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
4220
4596
  /* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
4221
4597
  Button,
4222
4598
  {
@@ -4240,14 +4616,10 @@ function DatePicker({
4240
4616
  ...{
4241
4617
  mode: "range",
4242
4618
  selected,
4243
- onSelect: (range) => {
4244
- onSelect?.(range);
4245
- if (range?.to) setOpen(false);
4246
- },
4247
- fromDate,
4248
- toDate,
4249
- numberOfMonths: 2,
4250
- initialFocus: true
4619
+ onSelect: handleRangeSelect,
4620
+ ...dateConstraints,
4621
+ numberOfMonths,
4622
+ autoFocus: true
4251
4623
  }
4252
4624
  }
4253
4625
  ) : /* @__PURE__ */ jsxRuntime.jsx(
@@ -4260,9 +4632,9 @@ function DatePicker({
4260
4632
  onSelect?.(date);
4261
4633
  setOpen(false);
4262
4634
  },
4263
- fromDate,
4264
- toDate,
4265
- initialFocus: true
4635
+ ...dateConstraints,
4636
+ numberOfMonths,
4637
+ autoFocus: true
4266
4638
  }
4267
4639
  }
4268
4640
  ) })
@@ -8949,6 +9321,7 @@ exports.PaginationItem = PaginationItem;
8949
9321
  exports.PaginationLink = PaginationLink;
8950
9322
  exports.PaginationNext = PaginationNext;
8951
9323
  exports.PaginationPrevious = PaginationPrevious;
9324
+ exports.PhoneField = PhoneField;
8952
9325
  exports.PinInput = PinInput;
8953
9326
  exports.Popover = Popover;
8954
9327
  exports.PopoverAnchor = PopoverAnchor;