@mediaradar/design-components 0.56.0 → 0.57.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.56.0",
2
+ "version": "0.57.0",
3
3
  "components": [
4
4
  "AISpark",
5
5
  "AdvertiserNoResults",
package/dist/index.cjs CHANGED
@@ -97,6 +97,18 @@ __export(index_exports, {
97
97
  buttonVariants: () => buttonVariants,
98
98
  chipTriggerClass: () => chipTriggerClass,
99
99
  cycleSort: () => cycleSort,
100
+ defaultDateOrder: () => defaultDateOrder,
101
+ formatDate: () => formatDate,
102
+ formatDateRange: () => formatDateRange,
103
+ formatDateTime: () => formatDateTime,
104
+ formatIsoDate: () => formatIsoDate,
105
+ formatMonth: () => formatMonth,
106
+ formatMonthAxis: () => formatMonthAxis,
107
+ formatOpenRange: () => formatOpenRange,
108
+ formatQuarter: () => formatQuarter,
109
+ formatRelative: () => formatRelative,
110
+ formatTime: () => formatTime,
111
+ formatWeek: () => formatWeek,
100
112
  noResultsBody: () => noResultsBody,
101
113
  resolveRange: () => resolveRange,
102
114
  sortProp: () => sortProp
@@ -965,12 +977,12 @@ function DateRangeFilter({
965
977
  className,
966
978
  testIdPrefix,
967
979
  granularity = "day",
968
- formatDate,
980
+ formatDate: formatDate2,
969
981
  formatRange
970
982
  }) {
971
983
  const monthly = granularity === "month";
972
- const formatted = !!(formatDate || formatRange);
973
- const showDate = formatDate ?? fmt;
984
+ const formatted = !!(formatDate2 || formatRange);
985
+ const showDate = formatDate2 ?? fmt;
974
986
  const showRange = (s, e) => formatRange ? formatRange(s, e) : sameDay(s, e) ? showDate(s) : `${showDate(s)} \u2013 ${showDate(e)}`;
975
987
  const showValue = (v, s, e) => formatted && !monthly && (v === `${fmt(s)} \u2014 ${fmt(e)}` || v === `${fmt(s)} \u2013 ${fmt(e)}`) ? showRange(s, e) : v;
976
988
  const snap = (s, e) => monthly ? [firstOfMonth(s), lastOfMonth(e)] : [s, e];
@@ -4513,10 +4525,10 @@ function resolveRange(label, today = startOfToday()) {
4513
4525
  }
4514
4526
  return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
4515
4527
  }
4516
- function spanLabel2(label, today, formatDate, formatRange) {
4528
+ function spanLabel2(label, today, formatDate2, formatRange) {
4517
4529
  const [s, e] = resolveRange(label, today);
4518
4530
  if (formatRange) return formatRange(s, e);
4519
- const f = formatDate ?? fmtDate;
4531
+ const f = formatDate2 ?? fmtDate;
4520
4532
  return `${f(s)} \u2013 ${f(e)}`;
4521
4533
  }
4522
4534
  function MiniSelect({ value, onChange, options }) {
@@ -4543,7 +4555,7 @@ function DateRangePicker({
4543
4555
  showFooter = false,
4544
4556
  today,
4545
4557
  years,
4546
- formatDate,
4558
+ formatDate: formatDate2,
4547
4559
  formatRange,
4548
4560
  className,
4549
4561
  testIdPrefix
@@ -4605,7 +4617,7 @@ function DateRangePicker({
4605
4617
  className: chipTriggerClass(),
4606
4618
  children: [
4607
4619
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
4608
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-control-caption leading-none text-text-tertiary", children: spanLabel2(value, end, formatDate, formatRange) }),
4620
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-control-caption leading-none text-text-tertiary", children: spanLabel2(value, end, formatDate2, formatRange) }),
4609
4621
  /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-xs leading-none font-medium text-text-primary", children: value })
4610
4622
  ] }),
4611
4623
  /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_lucide_react23.ChevronDown, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-text-secondary transition-transform", open && "rotate-180") })
@@ -5373,7 +5385,7 @@ function DataTable({
5373
5385
  }) {
5374
5386
  const titleId = (0, import_react28.useId)();
5375
5387
  const head = HEAD_PAD[density];
5376
- const pad = CELL_PAD[density];
5388
+ const pad2 = CELL_PAD[density];
5377
5389
  const align = (c) => c.numeric ? "text-right" : "text-left";
5378
5390
  const width = (c) => WIDTH3[c.width ?? (c.numeric ? "md" : "fill")];
5379
5391
  const onSort = (key) => {
@@ -5421,7 +5433,7 @@ function DataTable({
5421
5433
  },
5422
5434
  c.key
5423
5435
  )) }) }),
5424
- /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tbody", { className: "text-dense text-text-primary", children: loading ? Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { "aria-hidden": "true", className: "[&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("td", { className: cn("border-b border-border-default", pad, align(c)), children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
5436
+ /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tbody", { className: "text-dense text-text-primary", children: loading ? Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { "aria-hidden": "true", className: "[&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("td", { className: cn("border-b border-border-default", pad2, align(c)), children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
5425
5437
  "span",
5426
5438
  {
5427
5439
  className: cn(
@@ -5432,7 +5444,7 @@ function DataTable({
5432
5444
  ) }, c.key)) }, i)) : rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("td", { colSpan: columns.length, className: "px-6 py-12", children: empty ?? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(NoResultsEmptyState, {}) }) }) : rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { className: "hover:bg-subtle [&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
5433
5445
  "td",
5434
5446
  {
5435
- className: cn("border-b border-border-default", pad, align(c), c.numeric && "tabular-nums"),
5447
+ className: cn("border-b border-border-default", pad2, align(c), c.numeric && "tabular-nums"),
5436
5448
  children: c.cell(row)
5437
5449
  },
5438
5450
  c.key
@@ -5895,6 +5907,116 @@ function MenuLabel({ className, testIdPrefix, children }) {
5895
5907
  function MenuSeparator({ className, testIdPrefix }) {
5896
5908
  return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { role: "separator", "data-testid": testIdPrefix, className: cn("-mx-1 my-1 border-t border-border-default", className) });
5897
5909
  }
5910
+
5911
+ // src/dates.ts
5912
+ var MONTHS2 = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
5913
+ var MONTHS_LONG = [
5914
+ "January",
5915
+ "February",
5916
+ "March",
5917
+ "April",
5918
+ "May",
5919
+ "June",
5920
+ "July",
5921
+ "August",
5922
+ "September",
5923
+ "October",
5924
+ "November",
5925
+ "December"
5926
+ ];
5927
+ var WEEKDAYS2 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
5928
+ var EN_DASH = "\u2013";
5929
+ var pad = (n) => String(n).padStart(2, "0");
5930
+ function formatIsoDate(d) {
5931
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
5932
+ }
5933
+ function showYear(d, opts) {
5934
+ if (opts.year !== "auto") return true;
5935
+ return d.getFullYear() !== (opts.now ?? /* @__PURE__ */ new Date()).getFullYear();
5936
+ }
5937
+ function formatDate(d, opts = {}) {
5938
+ const order = opts.order ?? "mdy";
5939
+ const weekday = opts.weekday ? `${WEEKDAYS2[d.getDay()]}, ` : "";
5940
+ if (order === "ymd") return weekday + formatIsoDate(d);
5941
+ const mon = (opts.long ? MONTHS_LONG : MONTHS2)[d.getMonth()];
5942
+ const day = d.getDate();
5943
+ const year = showYear(d, opts);
5944
+ if (order === "dmy") return weekday + (year ? `${day} ${mon} ${d.getFullYear()}` : `${day} ${mon}`);
5945
+ return weekday + (year ? `${mon} ${day}, ${d.getFullYear()}` : `${mon} ${day}`);
5946
+ }
5947
+ var sameDay2 = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
5948
+ function formatDateRange(start, end, opts = {}) {
5949
+ const order = opts.order ?? "mdy";
5950
+ if (sameDay2(start, end)) return formatDate(start, opts);
5951
+ const join = (a, b, tight = false) => opts.sentence ? `${a} to ${b}` : tight ? `${a}${EN_DASH}${b}` : `${a} ${EN_DASH} ${b}`;
5952
+ if (order === "ymd") return join(formatIsoDate(start), formatIsoDate(end));
5953
+ const sameYear = start.getFullYear() === end.getFullYear();
5954
+ if (!sameYear) {
5955
+ const full = { ...opts, year: "always" };
5956
+ return join(formatDate(start, full), formatDate(end, full));
5957
+ }
5958
+ const year = showYear(end, opts) ? end.getFullYear() : void 0;
5959
+ const mons = opts.long ? MONTHS_LONG : MONTHS2;
5960
+ const ms = mons[start.getMonth()];
5961
+ const me = mons[end.getMonth()];
5962
+ const sameMonth = start.getMonth() === end.getMonth();
5963
+ const s = start.getDate();
5964
+ const e = end.getDate();
5965
+ if (order === "dmy") {
5966
+ const tail2 = year === void 0 ? "" : ` ${year}`;
5967
+ return sameMonth ? `${join(String(s), String(e), true)} ${me}${tail2}` : `${join(`${s} ${ms}`, `${e} ${me}`)}${tail2}`;
5968
+ }
5969
+ const tail = year === void 0 ? "" : `, ${year}`;
5970
+ return sameMonth ? `${join(`${ms} ${s}`, String(e))}${tail}` : `${join(`${ms} ${s}`, `${me} ${e}`)}${tail}`;
5971
+ }
5972
+ function formatOpenRange(start, end, opts = {}) {
5973
+ if (start && end) return formatDateRange(start, end, opts);
5974
+ if (start) return `Since ${formatDate(start, opts)}`;
5975
+ if (end) return `Until ${formatDate(end, opts)}`;
5976
+ return "";
5977
+ }
5978
+ function formatTime(d, opts = {}) {
5979
+ const h = d.getHours();
5980
+ const m = pad(d.getMinutes());
5981
+ if ((opts.order ?? "mdy") !== "mdy") return `${pad(h)}:${m}`;
5982
+ return `${h % 12 || 12}:${m} ${h < 12 ? "AM" : "PM"}`;
5983
+ }
5984
+ function formatDateTime(d, opts = {}) {
5985
+ return `${formatDate(d, opts)}, ${formatTime(d, opts)}`;
5986
+ }
5987
+ function formatMonth(d) {
5988
+ return `${MONTHS2[d.getMonth()]} ${d.getFullYear()}`;
5989
+ }
5990
+ function formatQuarter(d) {
5991
+ return `Q${Math.floor(d.getMonth() / 3) + 1} ${d.getFullYear()}`;
5992
+ }
5993
+ function formatWeek(firstDay, opts = {}) {
5994
+ return `Week of ${formatDate(firstDay, { ...opts, year: opts.year ?? "auto" })}`;
5995
+ }
5996
+ function formatMonthAxis(months) {
5997
+ return months.map((d, i) => {
5998
+ const changed = i === 0 || d.getFullYear() !== months[i - 1].getFullYear();
5999
+ return { month: MONTHS2[d.getMonth()], year: changed ? String(d.getFullYear()) : void 0 };
6000
+ });
6001
+ }
6002
+ var DAY_MS = 864e5;
6003
+ var startOfDay2 = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
6004
+ function formatRelative(d, opts = {}) {
6005
+ const now = opts.now ?? /* @__PURE__ */ new Date();
6006
+ const ms = now.getTime() - d.getTime();
6007
+ if (ms < 0) return formatDate(d, opts);
6008
+ if (ms < 6e4) return "Just now";
6009
+ if (ms < 36e5) return `${Math.floor(ms / 6e4)} min ago`;
6010
+ if (ms < DAY_MS) return `${Math.floor(ms / 36e5)} hr ago`;
6011
+ const days = Math.round((startOfDay2(now) - startOfDay2(d)) / DAY_MS);
6012
+ if (days <= 1) return "Yesterday";
6013
+ if (days <= 7) return `${days} days ago`;
6014
+ return formatDate(d, opts);
6015
+ }
6016
+ function defaultDateOrder(country) {
6017
+ const c = (country ?? "").toUpperCase();
6018
+ return c === "US" || c === "CA" || c === "" ? "mdy" : "dmy";
6019
+ }
5898
6020
  // Annotate the CommonJS export names for ESM import in node:
5899
6021
  0 && (module.exports = {
5900
6022
  AISpark,
@@ -5973,6 +6095,18 @@ function MenuSeparator({ className, testIdPrefix }) {
5973
6095
  buttonVariants,
5974
6096
  chipTriggerClass,
5975
6097
  cycleSort,
6098
+ defaultDateOrder,
6099
+ formatDate,
6100
+ formatDateRange,
6101
+ formatDateTime,
6102
+ formatIsoDate,
6103
+ formatMonth,
6104
+ formatMonthAxis,
6105
+ formatOpenRange,
6106
+ formatQuarter,
6107
+ formatRelative,
6108
+ formatTime,
6109
+ formatWeek,
5976
6110
  noResultsBody,
5977
6111
  resolveRange,
5978
6112
  sortProp