@mediaradar/design-components 0.56.0 → 0.58.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.58.0",
3
3
  "components": [
4
4
  "AISpark",
5
5
  "AdvertiserNoResults",
package/dist/index.cjs CHANGED
@@ -61,6 +61,7 @@ __export(index_exports, {
61
61
  MultiSelectFilter: () => MultiSelectFilter,
62
62
  NO_RESULTS_BODY: () => NO_RESULTS_BODY,
63
63
  NO_RESULTS_TITLE: () => NO_RESULTS_TITLE,
64
+ NO_VALUE: () => NO_VALUE,
64
65
  NameListModal: () => NameListModal,
65
66
  NoResultsEmptyState: () => NoResultsEmptyState,
66
67
  PRIMARY_ACTION_CLASS: () => PRIMARY_ACTION_CLASS,
@@ -97,6 +98,23 @@ __export(index_exports, {
97
98
  buttonVariants: () => buttonVariants,
98
99
  chipTriggerClass: () => chipTriggerClass,
99
100
  cycleSort: () => cycleSort,
101
+ defaultDateOrder: () => defaultDateOrder,
102
+ formatCount: () => formatCount,
103
+ formatCountFull: () => formatCountFull,
104
+ formatDate: () => formatDate,
105
+ formatDateRange: () => formatDateRange,
106
+ formatDateTime: () => formatDateTime,
107
+ formatIsoDate: () => formatIsoDate,
108
+ formatMoney: () => formatMoney,
109
+ formatMoneyFull: () => formatMoneyFull,
110
+ formatMonth: () => formatMonth,
111
+ formatMonthAxis: () => formatMonthAxis,
112
+ formatOpenRange: () => formatOpenRange,
113
+ formatPercent: () => formatPercent,
114
+ formatQuarter: () => formatQuarter,
115
+ formatRelative: () => formatRelative,
116
+ formatTime: () => formatTime,
117
+ formatWeek: () => formatWeek,
100
118
  noResultsBody: () => noResultsBody,
101
119
  resolveRange: () => resolveRange,
102
120
  sortProp: () => sortProp
@@ -965,12 +983,12 @@ function DateRangeFilter({
965
983
  className,
966
984
  testIdPrefix,
967
985
  granularity = "day",
968
- formatDate,
986
+ formatDate: formatDate2,
969
987
  formatRange
970
988
  }) {
971
989
  const monthly = granularity === "month";
972
- const formatted = !!(formatDate || formatRange);
973
- const showDate = formatDate ?? fmt;
990
+ const formatted = !!(formatDate2 || formatRange);
991
+ const showDate = formatDate2 ?? fmt;
974
992
  const showRange = (s, e) => formatRange ? formatRange(s, e) : sameDay(s, e) ? showDate(s) : `${showDate(s)} \u2013 ${showDate(e)}`;
975
993
  const showValue = (v, s, e) => formatted && !monthly && (v === `${fmt(s)} \u2014 ${fmt(e)}` || v === `${fmt(s)} \u2013 ${fmt(e)}`) ? showRange(s, e) : v;
976
994
  const snap = (s, e) => monthly ? [firstOfMonth(s), lastOfMonth(e)] : [s, e];
@@ -4513,10 +4531,10 @@ function resolveRange(label, today = startOfToday()) {
4513
4531
  }
4514
4532
  return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
4515
4533
  }
4516
- function spanLabel2(label, today, formatDate, formatRange) {
4534
+ function spanLabel2(label, today, formatDate2, formatRange) {
4517
4535
  const [s, e] = resolveRange(label, today);
4518
4536
  if (formatRange) return formatRange(s, e);
4519
- const f = formatDate ?? fmtDate;
4537
+ const f = formatDate2 ?? fmtDate;
4520
4538
  return `${f(s)} \u2013 ${f(e)}`;
4521
4539
  }
4522
4540
  function MiniSelect({ value, onChange, options }) {
@@ -4543,7 +4561,7 @@ function DateRangePicker({
4543
4561
  showFooter = false,
4544
4562
  today,
4545
4563
  years,
4546
- formatDate,
4564
+ formatDate: formatDate2,
4547
4565
  formatRange,
4548
4566
  className,
4549
4567
  testIdPrefix
@@ -4605,7 +4623,7 @@ function DateRangePicker({
4605
4623
  className: chipTriggerClass(),
4606
4624
  children: [
4607
4625
  /* @__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) }),
4626
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-control-caption leading-none text-text-tertiary", children: spanLabel2(value, end, formatDate2, formatRange) }),
4609
4627
  /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-xs leading-none font-medium text-text-primary", children: value })
4610
4628
  ] }),
4611
4629
  /* @__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 +5391,7 @@ function DataTable({
5373
5391
  }) {
5374
5392
  const titleId = (0, import_react28.useId)();
5375
5393
  const head = HEAD_PAD[density];
5376
- const pad = CELL_PAD[density];
5394
+ const pad2 = CELL_PAD[density];
5377
5395
  const align = (c) => c.numeric ? "text-right" : "text-left";
5378
5396
  const width = (c) => WIDTH3[c.width ?? (c.numeric ? "md" : "fill")];
5379
5397
  const onSort = (key) => {
@@ -5421,7 +5439,7 @@ function DataTable({
5421
5439
  },
5422
5440
  c.key
5423
5441
  )) }) }),
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)(
5442
+ /* @__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
5443
  "span",
5426
5444
  {
5427
5445
  className: cn(
@@ -5432,7 +5450,7 @@ function DataTable({
5432
5450
  ) }, 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
5451
  "td",
5434
5452
  {
5435
- className: cn("border-b border-border-default", pad, align(c), c.numeric && "tabular-nums"),
5453
+ className: cn("border-b border-border-default", pad2, align(c), c.numeric && "tabular-nums"),
5436
5454
  children: c.cell(row)
5437
5455
  },
5438
5456
  c.key
@@ -5895,6 +5913,172 @@ function MenuLabel({ className, testIdPrefix, children }) {
5895
5913
  function MenuSeparator({ className, testIdPrefix }) {
5896
5914
  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
5915
  }
5916
+
5917
+ // src/dates.ts
5918
+ var MONTHS2 = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
5919
+ var MONTHS_LONG = [
5920
+ "January",
5921
+ "February",
5922
+ "March",
5923
+ "April",
5924
+ "May",
5925
+ "June",
5926
+ "July",
5927
+ "August",
5928
+ "September",
5929
+ "October",
5930
+ "November",
5931
+ "December"
5932
+ ];
5933
+ var WEEKDAYS2 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
5934
+ var EN_DASH = "\u2013";
5935
+ var pad = (n) => String(n).padStart(2, "0");
5936
+ function formatIsoDate(d) {
5937
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
5938
+ }
5939
+ function showYear(d, opts) {
5940
+ if (opts.year !== "auto") return true;
5941
+ return d.getFullYear() !== (opts.now ?? /* @__PURE__ */ new Date()).getFullYear();
5942
+ }
5943
+ function formatDate(d, opts = {}) {
5944
+ const order = opts.order ?? "mdy";
5945
+ const weekday = opts.weekday ? `${WEEKDAYS2[d.getDay()]}, ` : "";
5946
+ if (order === "ymd") return weekday + formatIsoDate(d);
5947
+ const mon = (opts.long ? MONTHS_LONG : MONTHS2)[d.getMonth()];
5948
+ const day = d.getDate();
5949
+ const year = showYear(d, opts);
5950
+ if (order === "dmy") return weekday + (year ? `${day} ${mon} ${d.getFullYear()}` : `${day} ${mon}`);
5951
+ return weekday + (year ? `${mon} ${day}, ${d.getFullYear()}` : `${mon} ${day}`);
5952
+ }
5953
+ var sameDay2 = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
5954
+ function formatDateRange(start, end, opts = {}) {
5955
+ const order = opts.order ?? "mdy";
5956
+ if (sameDay2(start, end)) return formatDate(start, opts);
5957
+ const join = (a, b, tight = false) => opts.sentence ? `${a} to ${b}` : tight ? `${a}${EN_DASH}${b}` : `${a} ${EN_DASH} ${b}`;
5958
+ if (order === "ymd") return join(formatIsoDate(start), formatIsoDate(end));
5959
+ const sameYear = start.getFullYear() === end.getFullYear();
5960
+ if (!sameYear) {
5961
+ const full = { ...opts, year: "always" };
5962
+ return join(formatDate(start, full), formatDate(end, full));
5963
+ }
5964
+ const year = showYear(end, opts) ? end.getFullYear() : void 0;
5965
+ const mons = opts.long ? MONTHS_LONG : MONTHS2;
5966
+ const ms = mons[start.getMonth()];
5967
+ const me = mons[end.getMonth()];
5968
+ const sameMonth = start.getMonth() === end.getMonth();
5969
+ const s = start.getDate();
5970
+ const e = end.getDate();
5971
+ if (order === "dmy") {
5972
+ const tail2 = year === void 0 ? "" : ` ${year}`;
5973
+ return sameMonth ? `${join(String(s), String(e), true)} ${me}${tail2}` : `${join(`${s} ${ms}`, `${e} ${me}`)}${tail2}`;
5974
+ }
5975
+ const tail = year === void 0 ? "" : `, ${year}`;
5976
+ return sameMonth ? `${join(`${ms} ${s}`, String(e))}${tail}` : `${join(`${ms} ${s}`, `${me} ${e}`)}${tail}`;
5977
+ }
5978
+ function formatOpenRange(start, end, opts = {}) {
5979
+ if (start && end) return formatDateRange(start, end, opts);
5980
+ if (start) return `Since ${formatDate(start, opts)}`;
5981
+ if (end) return `Until ${formatDate(end, opts)}`;
5982
+ return "";
5983
+ }
5984
+ function formatTime(d, opts = {}) {
5985
+ const h = d.getHours();
5986
+ const m = pad(d.getMinutes());
5987
+ if ((opts.order ?? "mdy") !== "mdy") return `${pad(h)}:${m}`;
5988
+ return `${h % 12 || 12}:${m} ${h < 12 ? "AM" : "PM"}`;
5989
+ }
5990
+ function formatDateTime(d, opts = {}) {
5991
+ return `${formatDate(d, opts)}, ${formatTime(d, opts)}`;
5992
+ }
5993
+ function formatMonth(d) {
5994
+ return `${MONTHS2[d.getMonth()]} ${d.getFullYear()}`;
5995
+ }
5996
+ function formatQuarter(d) {
5997
+ return `Q${Math.floor(d.getMonth() / 3) + 1} ${d.getFullYear()}`;
5998
+ }
5999
+ function formatWeek(firstDay, opts = {}) {
6000
+ return `Week of ${formatDate(firstDay, { ...opts, year: opts.year ?? "auto" })}`;
6001
+ }
6002
+ function formatMonthAxis(months) {
6003
+ return months.map((d, i) => {
6004
+ const changed = i === 0 || d.getFullYear() !== months[i - 1].getFullYear();
6005
+ return { month: MONTHS2[d.getMonth()], year: changed ? String(d.getFullYear()) : void 0 };
6006
+ });
6007
+ }
6008
+ var DAY_MS = 864e5;
6009
+ var startOfDay2 = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
6010
+ function formatRelative(d, opts = {}) {
6011
+ const now = opts.now ?? /* @__PURE__ */ new Date();
6012
+ const ms = now.getTime() - d.getTime();
6013
+ if (ms < 0) return formatDate(d, opts);
6014
+ if (ms < 6e4) return "Just now";
6015
+ if (ms < 36e5) return `${Math.floor(ms / 6e4)} min ago`;
6016
+ if (ms < DAY_MS) return `${Math.floor(ms / 36e5)} hr ago`;
6017
+ const days = Math.round((startOfDay2(now) - startOfDay2(d)) / DAY_MS);
6018
+ if (days <= 1) return "Yesterday";
6019
+ if (days <= 7) return `${days} days ago`;
6020
+ return formatDate(d, opts);
6021
+ }
6022
+ function defaultDateOrder(country) {
6023
+ const c = (country ?? "").toUpperCase();
6024
+ return c === "US" || c === "CA" || c === "" ? "mdy" : "dmy";
6025
+ }
6026
+
6027
+ // src/numbers.ts
6028
+ var US = { units: ["K", "M", "B", "T"] };
6029
+ var STYLES = {
6030
+ "en-US": US,
6031
+ "en-CA": US,
6032
+ "en-GB": { units: ["k", "m", "bn", "tn"] }
6033
+ };
6034
+ var styleFor = (language) => STYLES[language ?? "en-US"] ?? US;
6035
+ var NO_VALUE = "\u2014";
6036
+ var MINUS = "\u2212";
6037
+ var SHORTEN_FROM = 1e4;
6038
+ var isMissing = (v) => v === null || v === void 0 || Number.isNaN(v);
6039
+ var withCommas = (n) => Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
6040
+ function shortAbs(abs, style) {
6041
+ if (abs < SHORTEN_FROM) return withCommas(abs);
6042
+ let tier = Math.min(Math.floor(Math.log10(abs) / 3), 4);
6043
+ let scaled = Math.round(abs / 1e3 ** tier * 10) / 10;
6044
+ if (scaled >= 1e3 && tier < 4) {
6045
+ tier += 1;
6046
+ scaled = Math.round(abs / 1e3 ** tier * 10) / 10;
6047
+ }
6048
+ const text = Number.isInteger(scaled) ? withCommas(scaled) : scaled.toFixed(1);
6049
+ return `${text}${style.units[tier - 1]}`;
6050
+ }
6051
+ function symbol(opts) {
6052
+ const currency = opts.currency ?? "USD";
6053
+ if (currency === "GBP") return "\xA3";
6054
+ if (currency === "EUR") return "\u20AC";
6055
+ if (opts.mixedDollars) return currency === "CAD" ? "CA$" : "US$";
6056
+ return "$";
6057
+ }
6058
+ var sign = (v) => v < 0 ? MINUS : "";
6059
+ function formatCount(value, opts = {}) {
6060
+ if (isMissing(value)) return NO_VALUE;
6061
+ return sign(value) + shortAbs(Math.abs(value), styleFor(opts.language));
6062
+ }
6063
+ function formatCountFull(value) {
6064
+ if (isMissing(value)) return NO_VALUE;
6065
+ return sign(value) + withCommas(Math.abs(value));
6066
+ }
6067
+ function formatMoney(value, opts = {}) {
6068
+ if (isMissing(value)) return NO_VALUE;
6069
+ return sign(value) + symbol(opts) + shortAbs(Math.abs(value), styleFor(opts.language));
6070
+ }
6071
+ function formatMoneyFull(value, opts = {}) {
6072
+ if (isMissing(value)) return NO_VALUE;
6073
+ return sign(value) + symbol(opts) + withCommas(Math.abs(value));
6074
+ }
6075
+ function formatPercent(value, _opts = {}) {
6076
+ if (isMissing(value)) return NO_VALUE;
6077
+ const abs = Math.abs(value);
6078
+ if (abs > 0 && abs < 0.05) return `${value < 0 ? MINUS : ""}<0.1%`;
6079
+ const text = (Math.round(abs * 10) / 10).toFixed(1);
6080
+ return text === "0.0" ? "0.0%" : `${sign(value)}${text}%`;
6081
+ }
5898
6082
  // Annotate the CommonJS export names for ESM import in node:
5899
6083
  0 && (module.exports = {
5900
6084
  AISpark,
@@ -5937,6 +6121,7 @@ function MenuSeparator({ className, testIdPrefix }) {
5937
6121
  MultiSelectFilter,
5938
6122
  NO_RESULTS_BODY,
5939
6123
  NO_RESULTS_TITLE,
6124
+ NO_VALUE,
5940
6125
  NameListModal,
5941
6126
  NoResultsEmptyState,
5942
6127
  PRIMARY_ACTION_CLASS,
@@ -5973,6 +6158,23 @@ function MenuSeparator({ className, testIdPrefix }) {
5973
6158
  buttonVariants,
5974
6159
  chipTriggerClass,
5975
6160
  cycleSort,
6161
+ defaultDateOrder,
6162
+ formatCount,
6163
+ formatCountFull,
6164
+ formatDate,
6165
+ formatDateRange,
6166
+ formatDateTime,
6167
+ formatIsoDate,
6168
+ formatMoney,
6169
+ formatMoneyFull,
6170
+ formatMonth,
6171
+ formatMonthAxis,
6172
+ formatOpenRange,
6173
+ formatPercent,
6174
+ formatQuarter,
6175
+ formatRelative,
6176
+ formatTime,
6177
+ formatWeek,
5976
6178
  noResultsBody,
5977
6179
  resolveRange,
5978
6180
  sortProp