@eqtylab/equality 5.4.0 → 5.4.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  Notable changes to Equality are recorded here, following [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
4
4
 
5
+ ## 5.4.2 - 2026-11-10
6
+
7
+ ### Changed
8
+
9
+ - `Pagination` fills its container's width, as it measures its own width to choose a layout. In a
10
+ parent that sizes to its content, such as `w-fit`, `inline-flex` or a right-aligned flex row, give
11
+ it a width; side margins on it now overflow its parent.
12
+ - `Pagination`'s info reads "51–75 of 146 agents", then the items-per-page dropdown labelled "per
13
+ page". It read "Showing 51 to [25] of 146 agents", with the page size where the range's end
14
+ belongs, so past page 1 it read as "51 to 25". Screen readers hear "51 to 75 of 146 agents".
15
+
16
+ ### Fixed
17
+
18
+ - `Pagination` fits a phone, where its row ran off the screen. Below 42rem it keeps one line: the
19
+ count without its noun, the items-per-page dropdown, labelled "per page" where it fits, and
20
+ previous, current page and next. When even that doesn't fit, the page buttons wrap below the
21
+ count and stay on the right.
22
+ - `Pagination` shows a `currentPage` outside 1 to the last page, such as after a filter shrinks
23
+ the list, as the nearest page. It had shown no current page and a count such as "95–95 of 95".
24
+ Clamp your own page state too, or the list shows an empty page.
25
+
26
+ ## 5.4.1 - 2026-11-09
27
+
28
+ ### Added
29
+
30
+ - `DateRangePicker` takes `timeZone`, an IANA name. Its today, selected days, label and the
31
+ `from` and `to` it hands back follow that zone, so a range picked under a user's zone
32
+ preference starts and ends at that zone's midnights. Without it, days follow the browser's zone
33
+ as before.
34
+ - `DateRangePicker` marks today with `aria-current="date"`.
35
+
36
+ ### Fixed
37
+
38
+ - `DateRangePicker` treats an invalid `from` or `to` as unset. It had labelled the range
39
+ "Invalid Date".
40
+
5
41
  ## 5.4.0 - 2026-11-09
6
42
 
7
43
  ### Added
package/dist/index.cjs CHANGED
@@ -1481,21 +1481,68 @@ var PopoverContent = React16__namespace.forwardRef(({ className, align = "center
1481
1481
  }
1482
1482
  ) }));
1483
1483
  PopoverContent.displayName = PopoverPrimitive__namespace.Content.displayName;
1484
+
1485
+ // src/lib/zoned-day.ts
1486
+ var formatters = /* @__PURE__ */ new Map();
1487
+ var formatterFor = (timeZone) => {
1488
+ const key = timeZone ?? "";
1489
+ let formatter = formatters.get(key);
1490
+ if (!formatter) {
1491
+ formatter = new Intl.DateTimeFormat("en-US", {
1492
+ timeZone,
1493
+ year: "numeric",
1494
+ month: "numeric",
1495
+ day: "numeric"
1496
+ });
1497
+ formatters.set(key, formatter);
1498
+ }
1499
+ return formatter;
1500
+ };
1501
+ var dayOf = (instant, timeZone) => {
1502
+ const parts = formatterFor(timeZone).formatToParts(instant);
1503
+ const part = (type) => Number(parts.find((p) => p.type === type)?.value);
1504
+ return { year: part("year"), month: part("month") - 1, day: part("day") };
1505
+ };
1506
+ var dayKey = ({ year, month, day }) => year * 1e4 + month * 100 + day;
1507
+ var addDays = ({ year, month, day }, count2) => {
1508
+ const date = new Date(Date.UTC(year, month, day + count2));
1509
+ return { year: date.getUTCFullYear(), month: date.getUTCMonth(), day: date.getUTCDate() };
1510
+ };
1511
+ var SEARCH_WINDOW = 15 * 60 * 60 * 1e3;
1512
+ var startOfDay = (target, timeZone) => {
1513
+ const key = dayKey(target);
1514
+ const utcMidnight = Date.UTC(target.year, target.month, target.day);
1515
+ let low = utcMidnight - SEARCH_WINDOW;
1516
+ let high = utcMidnight + SEARCH_WINDOW;
1517
+ while (low < high) {
1518
+ const middle = Math.floor((low + high) / 2);
1519
+ if (dayKey(dayOf(new Date(middle), timeZone)) < key) low = middle + 1;
1520
+ else high = middle;
1521
+ }
1522
+ return new Date(low);
1523
+ };
1524
+ var endOfDay = (target, timeZone) => new Date(startOfDay(addDays(target, 1), timeZone).getTime() - 1);
1484
1525
  var CalendarDaysIcon = LucideIcons.CalendarDays;
1485
1526
  var ChevronLeftIcon = LucideIcons.ChevronLeft;
1486
1527
  var ChevronRightIcon = LucideIcons.ChevronRight;
1487
- var DateRangePicker = ({ dateRange, onSelect, className }) => {
1528
+ var validDate = (date) => date && !Number.isNaN(date.getTime()) ? date : void 0;
1529
+ var DateRangePicker = ({ dateRange, onSelect, className, timeZone }) => {
1530
+ const today = dayOf(/* @__PURE__ */ new Date(), timeZone);
1488
1531
  const [selecting, setSelecting] = React16.useState(null);
1489
- const [displayedMonth, setDisplayedMonth] = React16.useState((/* @__PURE__ */ new Date()).getMonth());
1490
- const [displayedYear, setDisplayedYear] = React16.useState((/* @__PURE__ */ new Date()).getFullYear());
1491
- const daysInMonth = new Date(displayedYear, displayedMonth + 1, 0).getDate();
1492
- const firstDayOfMonth = new Date(displayedYear, displayedMonth, 1).getDay();
1532
+ const [displayedMonth, setDisplayedMonth] = React16.useState(today.month);
1533
+ const [displayedYear, setDisplayedYear] = React16.useState(today.year);
1534
+ const from = validDate(dateRange.from);
1535
+ const to = validDate(dateRange.to);
1536
+ const daysInMonth = new Date(Date.UTC(displayedYear, displayedMonth + 1, 0)).getUTCDate();
1537
+ const firstDayOfMonth = new Date(Date.UTC(displayedYear, displayedMonth, 1)).getUTCDay();
1493
1538
  const days = Array.from(
1494
1539
  { length: daysInMonth },
1495
- (_, i) => new Date(displayedYear, displayedMonth, i + 1)
1540
+ (_, i) => ({ year: displayedYear, month: displayedMonth, day: i + 1 })
1496
1541
  );
1542
+ const fromKey = from && dayKey(dayOf(from, timeZone));
1543
+ const toKey = to && dayKey(dayOf(to, timeZone));
1497
1544
  const paddingDays = Array.from({ length: firstDayOfMonth }, (_, _i) => null);
1498
- const hasSelection = dateRange.from || dateRange.to;
1545
+ const hasSelection = from || to;
1499
1546
  const MONTHS = [
1500
1547
  "January",
1501
1548
  "February",
@@ -1512,11 +1559,8 @@ var DateRangePicker = ({ dateRange, onSelect, className }) => {
1512
1559
  ];
1513
1560
  const DAY_HEADERS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
1514
1561
  const formatDate = (date) => {
1515
- return date.toLocaleDateString("en-US", {
1516
- year: "numeric",
1517
- month: "2-digit",
1518
- day: "2-digit"
1519
- });
1562
+ const { year, month, day } = dayOf(date, timeZone);
1563
+ return `${String(month + 1).padStart(2, "0")}/${String(day).padStart(2, "0")}/${year}`;
1520
1564
  };
1521
1565
  const formatRange = (range) => {
1522
1566
  if (!range.from && !range.to) return "Select Date Range";
@@ -1524,15 +1568,9 @@ var DateRangePicker = ({ dateRange, onSelect, className }) => {
1524
1568
  if (!range.from) return `Until ${formatDate(range.to)}`;
1525
1569
  return `${formatDate(range.from)} - ${formatDate(range.to)}`;
1526
1570
  };
1527
- const isDateSelected = (day, dateRange2) => {
1528
- const matchesFrom = dateRange2.from && day.getDate() === dateRange2.from.getDate() && day.getMonth() === dateRange2.from.getMonth() && day.getFullYear() === dateRange2.from.getFullYear();
1529
- const matchesTo = dateRange2.to && day.getDate() === dateRange2.to.getDate() && day.getMonth() === dateRange2.to.getMonth() && day.getFullYear() === dateRange2.to.getFullYear();
1530
- return !!matchesFrom || !!matchesTo;
1531
- };
1532
- const checkIsToday = (day) => {
1533
- const today = /* @__PURE__ */ new Date();
1534
- return day.getDate() === today.getDate() && day.getMonth() === today.getMonth() && day.getFullYear() === today.getFullYear();
1535
- };
1571
+ const isDateSelected = (day) => dayKey(day) === fromKey || dayKey(day) === toKey;
1572
+ const todayKey = dayKey(today);
1573
+ const checkIsToday = (day) => dayKey(day) === todayKey;
1536
1574
  const goToPreviousMonth = () => {
1537
1575
  if (displayedMonth === 0) {
1538
1576
  setDisplayedMonth(11);
@@ -1549,34 +1587,23 @@ var DateRangePicker = ({ dateRange, onSelect, className }) => {
1549
1587
  setDisplayedMonth(displayedMonth + 1);
1550
1588
  }
1551
1589
  };
1552
- const isInRange = (date) => {
1553
- if (!dateRange.from || !dateRange.to) return false;
1554
- return date >= dateRange.from && date <= dateRange.to;
1590
+ const isInRange = (day) => {
1591
+ if (fromKey === void 0 || toKey === void 0) return false;
1592
+ return dayKey(day) >= fromKey && dayKey(day) <= toKey;
1555
1593
  };
1556
- const handleDateSelect = (selectedDate) => {
1557
- const startOfDay = (date) => {
1558
- const d = new Date(date);
1559
- d.setHours(0, 0, 0, 0);
1560
- return d;
1561
- };
1562
- const endOfDay = (date) => {
1563
- const d = new Date(date);
1564
- d.setHours(23, 59, 59, 999);
1565
- return d;
1566
- };
1567
- if (!selecting || !dateRange) {
1568
- onSelect({ from: startOfDay(selectedDate), to: void 0 });
1594
+ const handleDateSelect = (selectedDay) => {
1595
+ if (!selecting || !from) {
1596
+ onSelect({ from: startOfDay(selectedDay, timeZone), to: void 0 });
1569
1597
  setSelecting("to");
1570
1598
  return;
1571
1599
  }
1572
- if (selecting === "to") {
1573
- if (dateRange.from && selectedDate < dateRange.from) {
1574
- onSelect({ from: startOfDay(selectedDate), to: endOfDay(dateRange.from) });
1575
- } else {
1576
- onSelect({ from: startOfDay(dateRange.from), to: endOfDay(selectedDate) });
1577
- }
1578
- setSelecting(null);
1600
+ const fromDay = dayOf(from, timeZone);
1601
+ if (dayKey(selectedDay) < dayKey(fromDay)) {
1602
+ onSelect({ from: startOfDay(selectedDay, timeZone), to: endOfDay(fromDay, timeZone) });
1603
+ } else {
1604
+ onSelect({ from: startOfDay(fromDay, timeZone), to: endOfDay(selectedDay, timeZone) });
1579
1605
  }
1606
+ setSelecting(null);
1580
1607
  };
1581
1608
  const clearSelection = () => {
1582
1609
  onSelect({ from: void 0, to: void 0 });
@@ -1602,7 +1629,7 @@ var DateRangePicker = ({ dateRange, onSelect, className }) => {
1602
1629
  }
1603
1630
  ),
1604
1631
  className,
1605
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles20__default.default["date-range"], children: formatRange(dateRange) })
1632
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles20__default.default["date-range"], children: formatRange({ from, to }) })
1606
1633
  }
1607
1634
  ) }) }),
1608
1635
  /* @__PURE__ */ jsxRuntime.jsxs(PopoverContent, { className: styles20__default.default["popover-content"], align: "end", children: [
@@ -1636,7 +1663,7 @@ var DateRangePicker = ({ dateRange, onSelect, className }) => {
1636
1663
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles20__default.default["calendar-grid"], children: [
1637
1664
  paddingDays.map((_, index) => /* @__PURE__ */ jsxRuntime.jsx("div", {}, `padding-${index}`)),
1638
1665
  days.map((day, index) => {
1639
- const isSelected = isDateSelected(day, dateRange);
1666
+ const isSelected = isDateSelected(day);
1640
1667
  const isToday = checkIsToday(day);
1641
1668
  const inRange = isInRange(day);
1642
1669
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -1649,8 +1676,9 @@ var DateRangePicker = ({ dateRange, onSelect, className }) => {
1649
1676
  isToday && !isSelected && styles20__default.default["calendar-day-btn--today"],
1650
1677
  inRange && !isSelected && styles20__default.default["calendar-day-btn--in-range"]
1651
1678
  ),
1679
+ "aria-current": isToday ? "date" : void 0,
1652
1680
  onClick: () => handleDateSelect(day),
1653
- children: day.getDate()
1681
+ children: day.day
1654
1682
  },
1655
1683
  index
1656
1684
  );
@@ -3901,7 +3929,7 @@ var ChevronRightIcon3 = LucideIcons.ChevronRight;
3901
3929
  var ChevronsLeftIcon = LucideIcons.ChevronsLeft;
3902
3930
  var ChevronsRightIcon = LucideIcons.ChevronsRight;
3903
3931
  var Pagination = ({
3904
- currentPage,
3932
+ currentPage: requestedPage,
3905
3933
  totalItems,
3906
3934
  filteredItems,
3907
3935
  itemsPerPage,
@@ -3916,6 +3944,7 @@ var Pagination = ({
3916
3944
  scrollTargetRef
3917
3945
  }) => {
3918
3946
  const totalPages = Math.ceil(filteredItems / itemsPerPage);
3947
+ const currentPage = Math.min(Math.max(requestedPage, 1), Math.max(totalPages, 1));
3919
3948
  const startItem = Math.min(filteredItems, 1 + (currentPage - 1) * itemsPerPage);
3920
3949
  const endItem = Math.min(currentPage * itemsPerPage, filteredItems);
3921
3950
  const hasFilteredItems = filteredItems > 0;
@@ -3982,6 +4011,7 @@ var Pagination = ({
3982
4011
  onClick: () => handlePageChange(i),
3983
4012
  "aria-label": `Page ${i} of ${totalPages}`,
3984
4013
  "aria-current": currentPage === i ? "page" : void 0,
4014
+ className: cn(currentPage !== i && styles43__default.default["wide-only"]),
3985
4015
  children: i
3986
4016
  },
3987
4017
  i
@@ -3991,30 +4021,55 @@ var Pagination = ({
3991
4021
  return pageButtons;
3992
4022
  };
3993
4023
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(styles43__default.default["pagination"], className), children: [
3994
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles43__default.default["info-container"], children: showInfo && hasFilteredItems && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3995
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3996
- "Showing ",
3997
- startItem,
3998
- " to"
4024
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles43__default.default["info-container"], children: [
4025
+ showInfo && hasFilteredItems && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
4026
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { "aria-hidden": "true", children: [
4027
+ startItem,
4028
+ "\u2013",
4029
+ endItem,
4030
+ " of ",
4031
+ filteredItems,
4032
+ type && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: styles43__default.default["wide-only"], children: [
4033
+ " ",
4034
+ type
4035
+ ] })
4036
+ ] }),
4037
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: styles43__default.default["spoken-count"], children: [
4038
+ startItem,
4039
+ " to ",
4040
+ endItem,
4041
+ " of ",
4042
+ filteredItems,
4043
+ " ",
4044
+ type
4045
+ ] })
3999
4046
  ] }),
4000
- onItemsPerPageChange ? /* @__PURE__ */ jsxRuntime.jsxs(Select, { value: itemsPerPage.toString(), onValueChange: handleItemsPerPageChange, children: [
4047
+ showInfo && hasFilteredItems && onItemsPerPageChange && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4048
+ /* @__PURE__ */ jsxRuntime.jsxs(Select, { value: itemsPerPage.toString(), onValueChange: handleItemsPerPageChange, children: [
4049
+ /* @__PURE__ */ jsxRuntime.jsx(
4050
+ SelectTrigger,
4051
+ {
4052
+ className: styles43__default.default["items-per-page-trigger"],
4053
+ "aria-label": "Items per page",
4054
+ children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {})
4055
+ }
4056
+ ),
4057
+ /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: itemsPerPageOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: option.toString(), children: option }, option)) })
4058
+ ] }),
4001
4059
  /* @__PURE__ */ jsxRuntime.jsx(
4002
- SelectTrigger,
4060
+ "span",
4003
4061
  {
4004
- className: styles43__default.default["items-per-page-trigger"],
4005
- "aria-label": "Items per page",
4006
- children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {})
4062
+ className: cn(
4063
+ styles43__default.default["page-size-label"],
4064
+ filteredItems < 100 && styles43__default.default["page-size-label--short"],
4065
+ filteredItems >= 100 && filteredItems < 1e3 && styles43__default.default["page-size-label--medium"]
4066
+ ),
4067
+ "aria-hidden": "true",
4068
+ children: "per page"
4007
4069
  }
4008
- ),
4009
- /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: itemsPerPageOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: option.toString(), children: option }, option)) })
4010
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: endItem }),
4011
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
4012
- "of ",
4013
- filteredItems,
4014
- " ",
4015
- type
4070
+ )
4016
4071
  ] })
4017
- ] }) }),
4072
+ ] }),
4018
4073
  /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: styles43__default.default["page-navigation-container"], "aria-label": "Pagination", children: [
4019
4074
  showFirstLastButtons && /* @__PURE__ */ jsxRuntime.jsx(
4020
4075
  Button,
@@ -4024,6 +4079,7 @@ var Pagination = ({
4024
4079
  onClick: handleFirstPage,
4025
4080
  disabled: isFirstPage,
4026
4081
  "aria-label": "First page",
4082
+ className: styles43__default.default["wide-only"],
4027
4083
  children: /* @__PURE__ */ jsxRuntime.jsx(ChevronsLeftIcon, {})
4028
4084
  }
4029
4085
  ),
@@ -4058,6 +4114,7 @@ var Pagination = ({
4058
4114
  onClick: handleLastPage,
4059
4115
  disabled: isLastPage,
4060
4116
  "aria-label": `Last page (${totalPages})`,
4117
+ className: styles43__default.default["wide-only"],
4061
4118
  children: /* @__PURE__ */ jsxRuntime.jsx(ChevronsRightIcon, {})
4062
4119
  }
4063
4120
  )