@mediaradar/design-components 0.65.0 → 0.67.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.65.0",
2
+ "version": "0.67.0",
3
3
  "components": [
4
4
  "AISpark",
5
5
  "AdvertiserNoResults",
package/dist/index.cjs CHANGED
@@ -1169,18 +1169,19 @@ function compareSpan(s, e, mode) {
1169
1169
  const days = Math.round((startOfDay(e).getTime() - startOfDay(s).getTime()) / 864e5) + 1;
1170
1170
  return [addDays(s, -days), addDays(s, -1)];
1171
1171
  }
1172
- function presetRange(key, today) {
1172
+ function presetRange(key, today, monthly = false) {
1173
1173
  const t = startOfDay(today);
1174
1174
  const qMonth = Math.floor(t.getMonth() / 3) * 3;
1175
+ const rolling = (n) => monthly ? [new Date(t.getFullYear(), t.getMonth() - n, 1), new Date(t.getFullYear(), t.getMonth(), 0)] : [addMonths(t, -n), t];
1175
1176
  switch (key) {
1176
1177
  case "Year to date":
1177
1178
  return [new Date(t.getFullYear(), 0, 1), t];
1178
1179
  case "Rolling 3 months":
1179
- return [addMonths(t, -3), t];
1180
+ return rolling(3);
1180
1181
  case "Rolling 6 months":
1181
- return [addMonths(t, -6), t];
1182
+ return rolling(6);
1182
1183
  case "Rolling 12 months":
1183
- return [addMonths(t, -12), t];
1184
+ return rolling(12);
1184
1185
  case "Previous quarter": {
1185
1186
  const s = new Date(t.getFullYear(), qMonth - 3, 1);
1186
1187
  const e = new Date(t.getFullYear(), qMonth, 0);
@@ -1272,7 +1273,7 @@ function DateRangeFilter({
1272
1273
  );
1273
1274
  const today = (0, import_react6.useMemo)(() => todayProp ?? /* @__PURE__ */ new Date(), []);
1274
1275
  const initShortcut = matchShortcut(SHORTCUTS, controlled ? controlledValue : defaultValue);
1275
- const initRange = controlled ? controlledRange : initShortcut === "Custom" && initialRange ? snap(...initialRange) : snap(...presetRange(initShortcut === "Custom" ? "Rolling 12 months" : initShortcut, today));
1276
+ const initRange = controlled ? controlledRange : initShortcut === "Custom" && initialRange ? snap(...initialRange) : snap(...presetRange(initShortcut === "Custom" ? "Rolling 12 months" : initShortcut, today, monthly));
1276
1277
  const compareLabel = (id) => compare?.options.find((o) => o.id === id)?.label;
1277
1278
  const dateLine = (s, e) => monthly ? `${fmtMonth(s)} \u2013 ${fmtMonth(e)}` : formatted ? showRange(s, e) : shortDates ? `${fmt(s)} \u2013 ${fmt(e)}` : fullRangeLabel(s, e);
1278
1279
  const [open, setOpen] = (0, import_react6.useState)(false);
@@ -1332,7 +1333,7 @@ function DateRangeFilter({
1332
1333
  const choosePreset = (key) => {
1333
1334
  setShortcut(key);
1334
1335
  if (key === "Custom") return;
1335
- const r = presetRange(key, today);
1336
+ const r = presetRange(key, today, monthly);
1336
1337
  if (r) {
1337
1338
  const [s, e] = snap(r[0], r[1]);
1338
1339
  setStart(s);
@@ -5844,6 +5845,7 @@ function RadioSection({
5844
5845
  value,
5845
5846
  onPick,
5846
5847
  first,
5848
+ className,
5847
5849
  testId
5848
5850
  }) {
5849
5851
  const id = (0, import_react32.useId)();
@@ -5859,7 +5861,7 @@ function RadioSection({
5859
5861
  const el = e.currentTarget.querySelectorAll('[role="radio"]:not([aria-disabled="true"])')[next];
5860
5862
  el?.focus();
5861
5863
  };
5862
- return /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)(import_jsx_runtime57.Fragment, { children: [
5864
+ return /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)("div", { className: cn("flex min-w-0 flex-col p-1", className), children: [
5863
5865
  /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(MenuLabel, { id, children: label }),
5864
5866
  /* @__PURE__ */ (0, import_jsx_runtime57.jsx)("div", { role: "radiogroup", "aria-labelledby": id, onKeyDown: onKey, "data-testid": testId, "data-first-group": first ? "" : void 0, className: "flex flex-col", children: rows.map((r) => {
5865
5867
  const checked = r.id === value;
@@ -5891,8 +5893,6 @@ function RadioSection({
5891
5893
  function HeaderMenuTrigger({
5892
5894
  menu,
5893
5895
  columnLabel,
5894
- sortDir,
5895
- onSort,
5896
5896
  testId
5897
5897
  }) {
5898
5898
  const [open, setOpen] = (0, import_react32.useState)(false);
@@ -5904,11 +5904,9 @@ function HeaderMenuTrigger({
5904
5904
  const breakLabel = breakOutBy?.value != null ? breakOutBy.options.find((o) => o.id === breakOutBy.value)?.label : void 0;
5905
5905
  const [draftGroup, setDraftGroup] = (0, import_react32.useState)(groupBy.value);
5906
5906
  const [draftBreak, setDraftBreak] = (0, import_react32.useState)(breakOutBy?.value ?? null);
5907
- const [draftSort, setDraftSort] = (0, import_react32.useState)(sortDir);
5908
5907
  const openPanel = () => {
5909
5908
  setDraftGroup(groupBy.value);
5910
5909
  setDraftBreak(breakOutBy?.value ?? null);
5911
- setDraftSort(sortDir);
5912
5910
  setOpen(true);
5913
5911
  };
5914
5912
  const close = (0, import_react32.useCallback)((refocus) => {
@@ -5918,7 +5916,6 @@ function HeaderMenuTrigger({
5918
5916
  const apply = () => {
5919
5917
  if (draftGroup !== groupBy.value) groupBy.onChange(draftGroup);
5920
5918
  if (breakOutBy && draftBreak !== breakOutBy.value) breakOutBy.onChange(draftBreak);
5921
- if (onSort && draftSort && draftSort !== sortDir) onSort(draftSort);
5922
5919
  close(true);
5923
5920
  };
5924
5921
  const place = (0, import_react32.useCallback)(() => {
@@ -6022,9 +6019,13 @@ function HeaderMenuTrigger({
6022
6019
  "data-testid": testId && `${testId}-menu`,
6023
6020
  onKeyDown: onPanelKey,
6024
6021
  style: { position: "fixed", top: pos?.top ?? 0, left: pos?.left ?? 0, visibility: pos ? void 0 : "hidden" },
6025
- className: "z-dropdown flex max-h-120 w-60 flex-col overflow-hidden rounded-card border border-border-default bg-surface text-left normal-case tracking-normal shadow-overlay",
6022
+ className: cn(
6023
+ "z-dropdown flex max-h-120 flex-col overflow-hidden rounded-card border border-border-default bg-surface text-left normal-case tracking-normal shadow-overlay",
6024
+ // Two columns side by side, as Advertising Trends' Group by.
6025
+ breakOutBy ? "w-105" : "w-60"
6026
+ ),
6026
6027
  children: [
6027
- /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)("div", { className: "flex min-h-0 flex-col overflow-y-auto p-1", children: [
6028
+ /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)("div", { className: cn("grid min-h-0 overflow-y-auto", breakOutBy && "grid-cols-2"), children: [
6028
6029
  /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
6029
6030
  RadioSection,
6030
6031
  {
@@ -6032,38 +6033,21 @@ function HeaderMenuTrigger({
6032
6033
  label: groupBy.label ?? "Group rows by",
6033
6034
  rows: groupBy.options,
6034
6035
  value: draftGroup,
6035
- onPick: pickGroup
6036
+ onPick: pickGroup,
6037
+ className: breakOutBy ? "border-r border-border-default" : void 0
6036
6038
  }
6037
6039
  ),
6038
- breakOutBy && /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)(import_jsx_runtime57.Fragment, { children: [
6039
- /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(MenuSeparator, {}),
6040
- /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
6041
- RadioSection,
6042
- {
6043
- label: breakOutBy.label ?? "Then break out by",
6044
- rows: [{ id: null, label: "None" }, ...breakOutBy.options.map((o) => ({ ...o, disabled: o.id === draftGroup }))],
6045
- value: draftBreak,
6046
- onPick: setDraftBreak
6047
- }
6048
- )
6049
- ] }),
6050
- onSort && /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)(import_jsx_runtime57.Fragment, { children: [
6051
- /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(MenuSeparator, {}),
6052
- /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
6053
- RadioSection,
6054
- {
6055
- label: "Sort",
6056
- rows: [
6057
- { id: "asc", label: "A to Z" },
6058
- { id: "desc", label: "Z to A" }
6059
- ],
6060
- value: draftSort ?? void 0,
6061
- onPick: setDraftSort
6062
- }
6063
- )
6064
- ] })
6040
+ breakOutBy && /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
6041
+ RadioSection,
6042
+ {
6043
+ label: breakOutBy.label ?? "Then break out by",
6044
+ rows: [{ id: null, label: "None" }, ...breakOutBy.options.map((o) => ({ ...o, disabled: o.id === draftGroup }))],
6045
+ value: draftBreak,
6046
+ onPick: setDraftBreak
6047
+ }
6048
+ )
6065
6049
  ] }),
6066
- /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(FilterDropdownFooter, { onCancel: () => close(true), onApply: apply })
6050
+ /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(FilterDropdownFooter, { onApply: apply })
6067
6051
  ]
6068
6052
  }
6069
6053
  ),
@@ -6280,8 +6264,10 @@ function DataTable({
6280
6264
  const [barH, setBarH] = (0, import_react33.useState)(0);
6281
6265
  const [scrollPad, setScrollPad] = (0, import_react33.useState)({ top: 0, bottom: 0 });
6282
6266
  const [footerStuck, setFooterStuck] = (0, import_react33.useState)(false);
6283
- const [scrolledDown, setScrolledDown] = (0, import_react33.useState)(false);
6284
- const [animate, setAnimate] = (0, import_react33.useState)(false);
6267
+ const [edges, setEdges] = (0, import_react33.useState)({ left: 0, right: 0 });
6268
+ const railRef = (0, import_react33.useRef)(null);
6269
+ const [scrollW, setScrollW] = (0, import_react33.useState)(0);
6270
+ const [overflows, setOverflows] = (0, import_react33.useState)(false);
6285
6271
  (0, import_react33.useEffect)(() => {
6286
6272
  const thead = theadRef.current;
6287
6273
  if (!sticky || !thead || typeof ResizeObserver === "undefined") return void 0;
@@ -6304,9 +6290,9 @@ function DataTable({
6304
6290
  const update = () => {
6305
6291
  const thead = theadRef.current;
6306
6292
  const clone = cloneRef.current;
6307
- if (thead && clone) setStuck(clone.getBoundingClientRect().top > thead.getBoundingClientRect().top + 0.5);
6308
- setFooterStuck(wrap.getBoundingClientRect().bottom > viewportOf(root).bottom + 1);
6309
- setScrolledDown((root ? root.scrollTop : window.scrollY) > 0);
6293
+ const isStuck = !!thead && !!clone && clone.getBoundingClientRect().top > thead.getBoundingClientRect().top + 0.5;
6294
+ setStuck(isStuck);
6295
+ setFooterStuck(isStuck && wrap.getBoundingClientRect().bottom > viewportOf(root).bottom + 1);
6310
6296
  };
6311
6297
  const measure = () => {
6312
6298
  root = scrollParent(wrap);
@@ -6315,17 +6301,28 @@ function DataTable({
6315
6301
  const next = scrollPadding(root);
6316
6302
  return prev.top === next.top && prev.bottom === next.bottom ? prev : next;
6317
6303
  });
6304
+ const pr = wrap.getBoundingClientRect();
6305
+ const rr = root?.getBoundingClientRect();
6306
+ const boxLeft = root && rr ? rr.left + root.clientLeft : 0;
6307
+ const boxRight = root && rr ? rr.left + root.clientLeft + root.clientWidth : document.documentElement.clientWidth;
6308
+ const nextEdges = { left: Math.max(0, Math.round(pr.left - boxLeft)), right: Math.max(0, Math.round(boxRight - pr.right)) };
6309
+ setEdges((prev) => prev.left === nextEdges.left && prev.right === nextEdges.right ? prev : nextEdges);
6310
+ const sc = scroller.current;
6311
+ if (sc) {
6312
+ setScrollW(sc.scrollWidth);
6313
+ setOverflows(sc.scrollWidth > sc.clientWidth + 1);
6314
+ }
6318
6315
  update();
6319
6316
  };
6320
6317
  measure();
6321
- const raf = requestAnimationFrame(() => setAnimate(true));
6322
6318
  document.addEventListener("scroll", update, { capture: true, passive: true });
6323
6319
  window.addEventListener("resize", measure);
6324
6320
  const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
6325
6321
  if (bar2) ro?.observe(bar2);
6326
6322
  ro?.observe(wrap);
6323
+ const table = scroller.current?.firstElementChild;
6324
+ if (table) ro?.observe(table);
6327
6325
  return () => {
6328
- cancelAnimationFrame(raf);
6329
6326
  document.removeEventListener("scroll", update, { capture: true });
6330
6327
  window.removeEventListener("resize", measure);
6331
6328
  ro?.disconnect();
@@ -6404,7 +6401,7 @@ function DataTable({
6404
6401
  {
6405
6402
  ref: !clone && ci <= nameIdx ? headRef(ci) : void 0,
6406
6403
  scope: "col",
6407
- "aria-sort": c.sortable || c.headerMenu && onSortChange ? ariaSortFor(shown, c.key) : void 0,
6404
+ "aria-sort": c.sortable && !c.headerMenu ? ariaSortFor(shown, c.key) : void 0,
6408
6405
  className: cn(
6409
6406
  "group/head whitespace-nowrap border-b border-border-default font-semibold",
6410
6407
  head,
@@ -6420,8 +6417,6 @@ function DataTable({
6420
6417
  {
6421
6418
  menu: c.headerMenu,
6422
6419
  columnLabel: c.label,
6423
- sortDir: shown?.key === c.key ? shown.dir : null,
6424
- onSort: onSortChange ? (dir) => onSortChange({ key: c.key, dir }) : void 0,
6425
6420
  testId: clone || !testIdPrefix ? void 0 : `${testIdPrefix}-header-menu-${c.key}`
6426
6421
  }
6427
6422
  ) : c.sortable && onSortChange ? /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
@@ -6463,8 +6458,15 @@ function DataTable({
6463
6458
  onScroll: (e) => {
6464
6459
  setScrolled(e.currentTarget.scrollLeft > 0);
6465
6460
  if (cloneRef.current) cloneRef.current.scrollLeft = e.currentTarget.scrollLeft;
6461
+ if (railRef.current && railRef.current.scrollLeft !== e.currentTarget.scrollLeft) railRef.current.scrollLeft = e.currentTarget.scrollLeft;
6466
6462
  },
6467
- className: cn("overflow-x-auto", SCROLLBAR, maxHeight && cn("overflow-y-auto", MAX_H[maxHeight])),
6463
+ className: cn(
6464
+ "overflow-x-auto",
6465
+ // Sticky: its own bar is hidden; the one under the table stands in
6466
+ // for it, so it can pin to the bottom of the screen.
6467
+ sticky ? "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden" : SCROLLBAR,
6468
+ maxHeight && cn("overflow-y-auto", MAX_H[maxHeight])
6469
+ ),
6468
6470
  children: /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)(
6469
6471
  "table",
6470
6472
  {
@@ -6602,12 +6604,17 @@ function DataTable({
6602
6604
  "div",
6603
6605
  {
6604
6606
  className: cn(
6605
- "relative flex w-full flex-col rounded-card border border-border-default bg-surface",
6607
+ "relative flex w-full flex-col border border-border-default bg-surface",
6608
+ // Full screen mode (sticky, header stuck): edge to edge, square
6609
+ // corners, no side borders, like StickyBar's band.
6610
+ sticky && stuck ? "rounded-none border-x-transparent" : "rounded-card",
6606
6611
  // clip, not hidden, on a sticky table: hidden would make the frame the
6607
6612
  // box its header sticks in, instead of the page.
6608
6613
  sticky ? "overflow-clip" : "overflow-hidden",
6609
6614
  !sticky && bare && className
6610
6615
  ),
6616
+ style: sticky && stuck && (edges.left || edges.right) ? { marginLeft: -edges.left, marginRight: -edges.right, width: "auto" } : void 0,
6617
+ "data-full-screen": sticky && stuck ? "" : void 0,
6611
6618
  "data-testid": testIdPrefix,
6612
6619
  children: [
6613
6620
  title && inside && /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)("div", { className: "flex items-start justify-between gap-2 p-card-padding", children: [
@@ -6646,22 +6653,36 @@ function DataTable({
6646
6653
  ]
6647
6654
  }
6648
6655
  );
6649
- const hideFooter = footerStuck && !scrolledDown;
6656
+ const bleed = stuck && (edges.left || edges.right);
6650
6657
  const body = sticky ? /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)("div", { ref: wrapRef, className: cn("flex w-full flex-col", bare && className), children: [
6651
6658
  frame,
6652
- footer && /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
6659
+ (footer || overflows) && /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)(
6653
6660
  "div",
6654
6661
  {
6655
6662
  "data-sticky-footer": "",
6656
- style: scrollPad.bottom ? { bottom: -scrollPad.bottom } : void 0,
6657
- className: cn(
6658
- "sticky bottom-0 z-3 border-t bg-canvas py-3",
6659
- footerStuck ? "border-border-default" : "border-transparent",
6660
- animate && "transition-[opacity,translate] duration-(--mr-motion-duration-interactive) ease-interactive motion-reduce:transition-none",
6661
- // Hidden, not gone: Tab still reaches it, and focus shows it.
6662
- hideFooter && "pointer-events-none translate-y-full opacity-0 focus-within:pointer-events-auto focus-within:translate-y-0 focus-within:opacity-100"
6663
- ),
6664
- children: footer
6663
+ style: {
6664
+ ...stuck && scrollPad.bottom ? { bottom: -scrollPad.bottom } : null,
6665
+ ...bleed ? { marginLeft: -edges.left, marginRight: -edges.right, paddingLeft: edges.left, paddingRight: edges.right } : null
6666
+ },
6667
+ className: cn("z-3 border-t bg-canvas", stuck && "sticky bottom-0", footerStuck ? "border-border-default" : "border-transparent"),
6668
+ children: [
6669
+ overflows && /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
6670
+ "div",
6671
+ {
6672
+ ref: railRef,
6673
+ "aria-hidden": "true",
6674
+ "data-sticky-scrollbar": "",
6675
+ onScroll: (e) => {
6676
+ const x = e.currentTarget.scrollLeft;
6677
+ if (scroller.current && scroller.current.scrollLeft !== x) scroller.current.scrollLeft = x;
6678
+ },
6679
+ className: cn("overflow-x-auto", SCROLLBAR),
6680
+ style: bleed ? { marginLeft: -edges.left, marginRight: -edges.right } : void 0,
6681
+ children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)("div", { className: "h-px", style: { width: scrollW } })
6682
+ }
6683
+ ),
6684
+ footer && /* @__PURE__ */ (0, import_jsx_runtime58.jsx)("div", { className: "py-3", children: footer })
6685
+ ]
6665
6686
  }
6666
6687
  )
6667
6688
  ] }) : frame;