@mediaradar/design-components 0.66.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.66.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);
@@ -6263,8 +6264,10 @@ function DataTable({
6263
6264
  const [barH, setBarH] = (0, import_react33.useState)(0);
6264
6265
  const [scrollPad, setScrollPad] = (0, import_react33.useState)({ top: 0, bottom: 0 });
6265
6266
  const [footerStuck, setFooterStuck] = (0, import_react33.useState)(false);
6266
- const [scrolledDown, setScrolledDown] = (0, import_react33.useState)(false);
6267
- 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);
6268
6271
  (0, import_react33.useEffect)(() => {
6269
6272
  const thead = theadRef.current;
6270
6273
  if (!sticky || !thead || typeof ResizeObserver === "undefined") return void 0;
@@ -6287,9 +6290,9 @@ function DataTable({
6287
6290
  const update = () => {
6288
6291
  const thead = theadRef.current;
6289
6292
  const clone = cloneRef.current;
6290
- if (thead && clone) setStuck(clone.getBoundingClientRect().top > thead.getBoundingClientRect().top + 0.5);
6291
- setFooterStuck(wrap.getBoundingClientRect().bottom > viewportOf(root).bottom + 1);
6292
- 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);
6293
6296
  };
6294
6297
  const measure = () => {
6295
6298
  root = scrollParent(wrap);
@@ -6298,17 +6301,28 @@ function DataTable({
6298
6301
  const next = scrollPadding(root);
6299
6302
  return prev.top === next.top && prev.bottom === next.bottom ? prev : next;
6300
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
+ }
6301
6315
  update();
6302
6316
  };
6303
6317
  measure();
6304
- const raf = requestAnimationFrame(() => setAnimate(true));
6305
6318
  document.addEventListener("scroll", update, { capture: true, passive: true });
6306
6319
  window.addEventListener("resize", measure);
6307
6320
  const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
6308
6321
  if (bar2) ro?.observe(bar2);
6309
6322
  ro?.observe(wrap);
6323
+ const table = scroller.current?.firstElementChild;
6324
+ if (table) ro?.observe(table);
6310
6325
  return () => {
6311
- cancelAnimationFrame(raf);
6312
6326
  document.removeEventListener("scroll", update, { capture: true });
6313
6327
  window.removeEventListener("resize", measure);
6314
6328
  ro?.disconnect();
@@ -6444,8 +6458,15 @@ function DataTable({
6444
6458
  onScroll: (e) => {
6445
6459
  setScrolled(e.currentTarget.scrollLeft > 0);
6446
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;
6447
6462
  },
6448
- 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
+ ),
6449
6470
  children: /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)(
6450
6471
  "table",
6451
6472
  {
@@ -6583,12 +6604,17 @@ function DataTable({
6583
6604
  "div",
6584
6605
  {
6585
6606
  className: cn(
6586
- "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",
6587
6611
  // clip, not hidden, on a sticky table: hidden would make the frame the
6588
6612
  // box its header sticks in, instead of the page.
6589
6613
  sticky ? "overflow-clip" : "overflow-hidden",
6590
6614
  !sticky && bare && className
6591
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,
6592
6618
  "data-testid": testIdPrefix,
6593
6619
  children: [
6594
6620
  title && inside && /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)("div", { className: "flex items-start justify-between gap-2 p-card-padding", children: [
@@ -6627,22 +6653,36 @@ function DataTable({
6627
6653
  ]
6628
6654
  }
6629
6655
  );
6630
- const hideFooter = footerStuck && !scrolledDown;
6656
+ const bleed = stuck && (edges.left || edges.right);
6631
6657
  const body = sticky ? /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)("div", { ref: wrapRef, className: cn("flex w-full flex-col", bare && className), children: [
6632
6658
  frame,
6633
- footer && /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
6659
+ (footer || overflows) && /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)(
6634
6660
  "div",
6635
6661
  {
6636
6662
  "data-sticky-footer": "",
6637
- style: scrollPad.bottom ? { bottom: -scrollPad.bottom } : void 0,
6638
- className: cn(
6639
- "sticky bottom-0 z-3 border-t bg-canvas py-3",
6640
- footerStuck ? "border-border-default" : "border-transparent",
6641
- animate && "transition-[opacity,translate] duration-(--mr-motion-duration-interactive) ease-interactive motion-reduce:transition-none",
6642
- // Hidden, not gone: Tab still reaches it, and focus shows it.
6643
- hideFooter && "pointer-events-none translate-y-full opacity-0 focus-within:pointer-events-auto focus-within:translate-y-0 focus-within:opacity-100"
6644
- ),
6645
- 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
+ ]
6646
6686
  }
6647
6687
  )
6648
6688
  ] }) : frame;