@eqtylab/equality 3.8.0 → 3.9.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.d.cts CHANGED
@@ -838,19 +838,25 @@ declare const Tabs: ({ id, items, className, tabsListBackground, defaultValue, o
838
838
 
839
839
  declare const Textarea: React$1.ForwardRefExoticComponent<Omit<React$1.DetailedHTMLProps<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React$1.RefAttributes<HTMLTextAreaElement>>;
840
840
 
841
- type FormatDateDisplayMode = 'relative' | 'absolute';
841
+ type FormatDateDisplayMode = 'relative' | 'absolute' | 'until' | 'since';
842
842
  interface FormatDateProps extends Omit<React$1.TimeHTMLAttributes<HTMLTimeElement>, 'dateTime' | 'children'> {
843
843
  /** The date to display. Accepts an ISO 8601 string, epoch milliseconds, or a Date. A missing value (null, undefined, or empty string) renders a placeholder. */
844
844
  date: string | number | Date | null | undefined;
845
- /** Render relative ("2 weeks ago") or absolute ("Jun 09 2026, 18:42:03 UTC") time. */
845
+ /**
846
+ * How to render the date:
847
+ * - `absolute` — the full date and time ("Jun 09 2026, 18:42:03 UTC")
848
+ * - `relative` — idiomatic distance from now, in either direction ("2 weeks ago", "next week")
849
+ * - `until` — exact countdown to a future date ("10 days"), a placeholder once it has passed
850
+ * - `since` — exact time elapsed since a past date ("10 days ago"), a placeholder until it arrives
851
+ */
846
852
  displayAs?: FormatDateDisplayMode;
847
853
  /** Time zone used for absolute formatting. Defaults to "UTC". */
848
854
  timeZone?: string;
849
855
  /** BCP 47 locale used for formatting. Defaults to "en-US". */
850
856
  locale?: string;
851
- /** When relative, show a tooltip with the absolute time on hover/focus. Defaults to true. */
857
+ /** Unless absolute, show a tooltip with the absolute time on hover/focus. Defaults to true. */
852
858
  tooltip?: boolean;
853
- /** When relative, re-render on an interval so the value stays current. Defaults to true. */
859
+ /** Unless absolute, re-render on an interval so the value stays current. Defaults to true. */
854
860
  live?: boolean;
855
861
  /** Override the Intl options used for absolute formatting. */
856
862
  absoluteOptions?: Intl.DateTimeFormatOptions;
@@ -933,7 +939,7 @@ declare const TruncatedDescription: ({ className, description, maxLength, }: Tru
933
939
 
934
940
  declare const iconVariants: (props?: ({
935
941
  size?: "xs" | "sm" | "md" | "lg" | null | undefined;
936
- background?: "square" | "circle" | "transparent" | null | undefined;
942
+ background?: "circle" | "square" | "transparent" | null | undefined;
937
943
  } & class_variance_authority_types.ClassProp) | undefined) => string;
938
944
  declare const iconElevationVariants: (props?: ({
939
945
  elevation?: string | number | null | undefined;
package/dist/index.d.ts CHANGED
@@ -838,19 +838,25 @@ declare const Tabs: ({ id, items, className, tabsListBackground, defaultValue, o
838
838
 
839
839
  declare const Textarea: React$1.ForwardRefExoticComponent<Omit<React$1.DetailedHTMLProps<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React$1.RefAttributes<HTMLTextAreaElement>>;
840
840
 
841
- type FormatDateDisplayMode = 'relative' | 'absolute';
841
+ type FormatDateDisplayMode = 'relative' | 'absolute' | 'until' | 'since';
842
842
  interface FormatDateProps extends Omit<React$1.TimeHTMLAttributes<HTMLTimeElement>, 'dateTime' | 'children'> {
843
843
  /** The date to display. Accepts an ISO 8601 string, epoch milliseconds, or a Date. A missing value (null, undefined, or empty string) renders a placeholder. */
844
844
  date: string | number | Date | null | undefined;
845
- /** Render relative ("2 weeks ago") or absolute ("Jun 09 2026, 18:42:03 UTC") time. */
845
+ /**
846
+ * How to render the date:
847
+ * - `absolute` — the full date and time ("Jun 09 2026, 18:42:03 UTC")
848
+ * - `relative` — idiomatic distance from now, in either direction ("2 weeks ago", "next week")
849
+ * - `until` — exact countdown to a future date ("10 days"), a placeholder once it has passed
850
+ * - `since` — exact time elapsed since a past date ("10 days ago"), a placeholder until it arrives
851
+ */
846
852
  displayAs?: FormatDateDisplayMode;
847
853
  /** Time zone used for absolute formatting. Defaults to "UTC". */
848
854
  timeZone?: string;
849
855
  /** BCP 47 locale used for formatting. Defaults to "en-US". */
850
856
  locale?: string;
851
- /** When relative, show a tooltip with the absolute time on hover/focus. Defaults to true. */
857
+ /** Unless absolute, show a tooltip with the absolute time on hover/focus. Defaults to true. */
852
858
  tooltip?: boolean;
853
- /** When relative, re-render on an interval so the value stays current. Defaults to true. */
859
+ /** Unless absolute, re-render on an interval so the value stays current. Defaults to true. */
854
860
  live?: boolean;
855
861
  /** Override the Intl options used for absolute formatting. */
856
862
  absoluteOptions?: Intl.DateTimeFormatOptions;
@@ -933,7 +939,7 @@ declare const TruncatedDescription: ({ className, description, maxLength, }: Tru
933
939
 
934
940
  declare const iconVariants: (props?: ({
935
941
  size?: "xs" | "sm" | "md" | "lg" | null | undefined;
936
- background?: "square" | "circle" | "transparent" | null | undefined;
942
+ background?: "circle" | "square" | "transparent" | null | undefined;
937
943
  } & class_variance_authority_types.ClassProp) | undefined) => string;
938
944
  declare const iconElevationVariants: (props?: ({
939
945
  elevation?: string | number | null | undefined;
package/dist/index.js CHANGED
@@ -3673,6 +3673,22 @@ var RELATIVE_DIVISIONS = [
3673
3673
  { amount: Number.POSITIVE_INFINITY, unit: "year" }
3674
3674
  ];
3675
3675
  var LIVE_INTERVAL_MS = 3e4;
3676
+ var MINUTE_MS = 6e4;
3677
+ var HOUR_MS = 60 * MINUTE_MS;
3678
+ var DAY_MS = 24 * HOUR_MS;
3679
+ var YEAR_MS = 365.25 * DAY_MS;
3680
+ var MONTH_MS = YEAR_MS / 12;
3681
+ var JUST_NOW_MS = 45e3;
3682
+ var COARSE_AFTER_MS = 90 * DAY_MS;
3683
+ var FINE_UNITS = [
3684
+ { ms: DAY_MS, unit: "day" },
3685
+ { ms: HOUR_MS, unit: "hour" },
3686
+ { ms: MINUTE_MS, unit: "minute" }
3687
+ ];
3688
+ var COARSE_UNITS = [
3689
+ { ms: YEAR_MS, unit: "year" },
3690
+ { ms: MONTH_MS, unit: "month" }
3691
+ ];
3676
3692
  var NO_DATE_PLACEHOLDER = "---";
3677
3693
  function isMissing(value) {
3678
3694
  return value == null || typeof value === "string" && value.trim() === "";
@@ -3685,8 +3701,8 @@ function formatAbsolute(date, timeZone, options, locale) {
3685
3701
  return new Intl.DateTimeFormat(locale, { ...options, timeZone }).format(date);
3686
3702
  }
3687
3703
  function formatRelative(date, now, locale) {
3704
+ if (Math.abs(date.getTime() - now.getTime()) < JUST_NOW_MS) return "Just now";
3688
3705
  let duration = (date.getTime() - now.getTime()) / 1e3;
3689
- if (Math.abs(duration) < 45) return "Just now";
3690
3706
  const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
3691
3707
  for (const division of RELATIVE_DIVISIONS) {
3692
3708
  if (Math.abs(duration) < division.amount) {
@@ -3696,6 +3712,30 @@ function formatRelative(date, now, locale) {
3696
3712
  }
3697
3713
  return "Just now";
3698
3714
  }
3715
+ function measureSpan(spanMs) {
3716
+ const units = spanMs < COARSE_AFTER_MS ? FINE_UNITS : COARSE_UNITS;
3717
+ const index = units.findIndex(({ ms: ms2 }) => spanMs >= ms2);
3718
+ if (index === -1) return { value: 1, unit: units[units.length - 1].unit };
3719
+ const { ms, unit } = units[index];
3720
+ const value = Math.round(spanMs / ms);
3721
+ const next = units[index - 1];
3722
+ if (next && value * ms >= next.ms) {
3723
+ return { value: Math.round(spanMs / next.ms), unit: next.unit };
3724
+ }
3725
+ return { value, unit };
3726
+ }
3727
+ function formatDirected(date, now, mode, locale) {
3728
+ const spanMs = mode === "until" ? date.getTime() - now.getTime() : now.getTime() - date.getTime();
3729
+ if (spanMs <= 0) return null;
3730
+ if (mode === "since" && spanMs < JUST_NOW_MS) return "Just now";
3731
+ const { value, unit } = measureSpan(spanMs);
3732
+ if (mode === "until") {
3733
+ return new Intl.NumberFormat(locale, { style: "unit", unit, unitDisplay: "long" }).format(
3734
+ value
3735
+ );
3736
+ }
3737
+ return new Intl.RelativeTimeFormat(locale, { numeric: "always" }).format(-value, unit);
3738
+ }
3699
3739
  function FormatDate({
3700
3740
  date,
3701
3741
  displayAs = "absolute",
@@ -3711,13 +3751,13 @@ function FormatDate({
3711
3751
  const parsed = React15.useMemo(() => isMissing(date) ? null : toDate(date), [date]);
3712
3752
  const [now, setNow] = React15.useState(() => /* @__PURE__ */ new Date());
3713
3753
  const [mounted, setMounted] = React15.useState(false);
3714
- const isRelative = displayAs === "relative";
3754
+ const isAbsolute = displayAs === "absolute";
3715
3755
  React15.useEffect(() => setMounted(true), []);
3716
3756
  React15.useEffect(() => {
3717
- if (!isRelative || !live) return;
3757
+ if (isAbsolute || !live) return;
3718
3758
  const id = setInterval(() => setNow(/* @__PURE__ */ new Date()), LIVE_INTERVAL_MS);
3719
3759
  return () => clearInterval(id);
3720
- }, [isRelative, live]);
3760
+ }, [isAbsolute, live]);
3721
3761
  if (missing) {
3722
3762
  return /* @__PURE__ */ jsx("span", { className: cn(styles57["format-date"], className), "aria-label": "No date", ...props, children: NO_DATE_PLACEHOLDER });
3723
3763
  }
@@ -3731,12 +3771,23 @@ function FormatDate({
3731
3771
  absoluteOptions ?? DEFAULT_ABSOLUTE_OPTIONS,
3732
3772
  locale
3733
3773
  );
3734
- if (!isRelative) {
3774
+ if (isAbsolute) {
3735
3775
  return /* @__PURE__ */ jsx("time", { dateTime: machineValue, className: cn(styles57["format-date"], className), ...props, children: absolute });
3736
3776
  }
3737
- const relative = mounted ? formatRelative(parsed, now, locale) : absolute;
3777
+ const measured = !mounted ? absolute : displayAs === "relative" ? formatRelative(parsed, now, locale) : formatDirected(parsed, now, displayAs, locale);
3778
+ if (measured === null) {
3779
+ return /* @__PURE__ */ jsx(
3780
+ "span",
3781
+ {
3782
+ className: cn(styles57["format-date"], className),
3783
+ "aria-label": displayAs === "until" ? "Date has passed" : "Date not yet reached",
3784
+ ...props,
3785
+ children: NO_DATE_PLACEHOLDER
3786
+ }
3787
+ );
3788
+ }
3738
3789
  if (!tooltip) {
3739
- return /* @__PURE__ */ jsx("time", { dateTime: machineValue, className: cn(styles57["format-date"], className), ...props, children: relative });
3790
+ return /* @__PURE__ */ jsx("time", { dateTime: machineValue, className: cn(styles57["format-date"], className), ...props, children: measured });
3740
3791
  }
3741
3792
  return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip, { children: [
3742
3793
  /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
@@ -3746,7 +3797,7 @@ function FormatDate({
3746
3797
  tabIndex: 0,
3747
3798
  className: cn(styles57["format-date"], styles57["format-date--interactive"], className),
3748
3799
  ...props,
3749
- children: relative
3800
+ children: measured
3750
3801
  }
3751
3802
  ) }),
3752
3803
  /* @__PURE__ */ jsx(TooltipContent, { children: absolute })