@idkwebsites/components 0.1.14 → 0.1.15

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.js CHANGED
@@ -906,6 +906,35 @@ function BookingWidget({
906
906
  if (!maxAdvanceMonths || maxAdvanceMonths <= 0) return null;
907
907
  return new Date(todayDate.getFullYear(), todayDate.getMonth() + maxAdvanceMonths - 1, 1);
908
908
  }, [maxAdvanceMonths, todayDate]);
909
+ const monthOptionCount = useMemo4(() => {
910
+ if (!maxAdvanceMonths || maxAdvanceMonths <= 0) return 12;
911
+ return maxAdvanceMonths;
912
+ }, [maxAdvanceMonths]);
913
+ const monthOptions = useMemo4(() => {
914
+ return Array.from({ length: monthOptionCount }, (_, index) => {
915
+ const date = new Date(todayDate.getFullYear(), todayDate.getMonth() + index, 1);
916
+ return {
917
+ value: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`,
918
+ label: new Intl.DateTimeFormat("en-US", { month: "long", year: "numeric" }).format(date),
919
+ date
920
+ };
921
+ });
922
+ }, [monthOptionCount, todayDate]);
923
+ const calendarDays = useMemo4(() => getMonthDays(calendarMonth), [getMonthDays, calendarMonth]);
924
+ const availabilityByDate = useMemo4(() => {
925
+ const map = /* @__PURE__ */ new Map();
926
+ (availability.data?.dates || []).forEach((entry) => {
927
+ map.set(entry.date, entry);
928
+ });
929
+ return map;
930
+ }, [availability.data]);
931
+ const hasBlockedInCalendarView = useMemo4(() => {
932
+ return calendarDays.some((day) => {
933
+ const entry = availabilityByDate.get(day.date);
934
+ if (!entry) return false;
935
+ return !entry.slots.some((slot) => slot.available);
936
+ });
937
+ }, [calendarDays, availabilityByDate]);
909
938
  const handlePrevDates = () => {
910
939
  if (availabilityStartDate <= todayString) return;
911
940
  setAvailabilityStartDate((prev) => addDays(prev, -availabilityDays));
@@ -945,6 +974,15 @@ function BookingWidget({
945
974
  setSelectedEndTime(null);
946
975
  setBookingError(null);
947
976
  };
977
+ const handleMonthSelect = (value) => {
978
+ const [year, month] = value.split("-").map(Number);
979
+ if (!year || !month) return;
980
+ setCalendarMonth(new Date(year, month - 1, 1));
981
+ setSelectedDate(null);
982
+ setSelectedTime(null);
983
+ setSelectedEndTime(null);
984
+ setBookingError(null);
985
+ };
948
986
  useEffect(() => {
949
987
  if (step !== "time") return;
950
988
  if (!availability.data?.dates?.length) return;
@@ -1277,7 +1315,39 @@ function BookingWidget({
1277
1315
  calendarVariant === "compact" ? "idk-calendar--compact" : ""
1278
1316
  ].filter(Boolean).join(" "),
1279
1317
  children: [
1280
- /* @__PURE__ */ jsxs4("div", { className: "idk-calendar__header", children: [
1318
+ /* @__PURE__ */ jsx8("div", { className: "idk-calendar__header", children: calendarVariant === "compact" ? /* @__PURE__ */ jsxs4("div", { className: "idk-calendar__header idk-calendar__header--compact", children: [
1319
+ /* @__PURE__ */ jsx8(
1320
+ "button",
1321
+ {
1322
+ type: "button",
1323
+ className: "idk-calendar__nav-btn",
1324
+ onClick: handlePrevMonth,
1325
+ disabled: calendarMonth <= getMonthStart(todayDate),
1326
+ "aria-label": "Previous month",
1327
+ children: "<"
1328
+ }
1329
+ ),
1330
+ /* @__PURE__ */ jsx8(
1331
+ "select",
1332
+ {
1333
+ className: "idk-calendar__month-select",
1334
+ value: `${calendarMonth.getFullYear()}-${String(calendarMonth.getMonth() + 1).padStart(2, "0")}`,
1335
+ onChange: (event) => handleMonthSelect(event.target.value),
1336
+ children: monthOptions.map((option) => /* @__PURE__ */ jsx8("option", { value: option.value, children: option.label }, option.value))
1337
+ }
1338
+ ),
1339
+ /* @__PURE__ */ jsx8(
1340
+ "button",
1341
+ {
1342
+ type: "button",
1343
+ className: "idk-calendar__nav-btn",
1344
+ onClick: handleNextMonth,
1345
+ disabled: Boolean(maxAdvanceMonthStart && calendarMonth >= maxAdvanceMonthStart),
1346
+ "aria-label": "Next month",
1347
+ children: ">"
1348
+ }
1349
+ )
1350
+ ] }) : /* @__PURE__ */ jsxs4(Fragment, { children: [
1281
1351
  /* @__PURE__ */ jsx8(
1282
1352
  "button",
1283
1353
  {
@@ -1285,7 +1355,7 @@ function BookingWidget({
1285
1355
  className: "idk-button idk-button--ghost",
1286
1356
  onClick: handlePrevMonth,
1287
1357
  disabled: calendarMonth <= getMonthStart(todayDate),
1288
- children: "Previous"
1358
+ children: "Prev"
1289
1359
  }
1290
1360
  ),
1291
1361
  /* @__PURE__ */ jsx8("div", { className: "idk-calendar__title", children: new Intl.DateTimeFormat("en-US", {
@@ -1302,12 +1372,10 @@ function BookingWidget({
1302
1372
  children: "Next"
1303
1373
  }
1304
1374
  )
1305
- ] }),
1375
+ ] }) }),
1306
1376
  /* @__PURE__ */ jsx8("div", { className: "idk-calendar__weekdays", children: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].map((label) => /* @__PURE__ */ jsx8("span", { children: label }, label)) }),
1307
- /* @__PURE__ */ jsx8("div", { className: "idk-calendar__grid", children: getMonthDays(calendarMonth).map((day) => {
1308
- const entry = availability.data?.dates?.find(
1309
- (item) => item.date === day.date
1310
- );
1377
+ /* @__PURE__ */ jsx8("div", { className: "idk-calendar__grid", children: calendarDays.map((day) => {
1378
+ const entry = availabilityByDate.get(day.date);
1311
1379
  const hasAvailable = entry?.slots?.some((slot) => slot.available) ?? false;
1312
1380
  const dateValue = parseDateOnly(day.date);
1313
1381
  const isPast = dateValue ? dateValue < todayDate : false;
@@ -1338,12 +1406,16 @@ function BookingWidget({
1338
1406
  },
1339
1407
  children: [
1340
1408
  /* @__PURE__ */ jsx8("span", { children: day.date.split("-")[2] }),
1341
- showFullyBookedLabel && isBlocked && day.isCurrentMonth ? /* @__PURE__ */ jsx8("span", { className: "idk-calendar__label", children: calendarVariant === "compact" ? "Full" : "Fully booked" }) : null
1409
+ showFullyBookedLabel && isBlocked && day.isCurrentMonth ? /* @__PURE__ */ jsx8("span", { className: "idk-calendar__label", children: calendarVariant === "compact" ? "\u2022" : "Fully booked" }) : null
1342
1410
  ]
1343
1411
  },
1344
1412
  day.date
1345
1413
  );
1346
- }) })
1414
+ }) }),
1415
+ showFullyBookedLabel && calendarVariant === "compact" && hasBlockedInCalendarView ? /* @__PURE__ */ jsxs4("div", { className: "idk-calendar__legend", children: [
1416
+ /* @__PURE__ */ jsx8("span", { className: "idk-calendar__legend-dot", children: "\u2022" }),
1417
+ " Fully booked"
1418
+ ] }) : null
1347
1419
  ]
1348
1420
  }
1349
1421
  ) : /* @__PURE__ */ jsxs4(Fragment, { children: [