@mediaradar/design-components 0.48.1 → 0.50.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,10 +1,11 @@
1
1
  {
2
- "version": "0.48.1",
2
+ "version": "0.50.0",
3
3
  "components": [
4
4
  "AISpark",
5
5
  "AdvertiserNoResults",
6
6
  "AdvertiserQuickFilter",
7
7
  "AdvertiserSearchPrompt",
8
+ "AllFiltersButton",
8
9
  "Badge",
9
10
  "BarChartPlaceholder",
10
11
  "Button",
@@ -20,6 +21,7 @@
20
21
  "Drawer",
21
22
  "EmptyState",
22
23
  "FilterChipBar",
24
+ "FilterDrawer",
23
25
  "FilterDropdownFooter",
24
26
  "Freshness",
25
27
  "InfoTip",
package/dist/index.cjs CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  AdvertiserNoResults: () => AdvertiserNoResults,
26
26
  AdvertiserQuickFilter: () => AdvertiserQuickFilter,
27
27
  AdvertiserSearchPrompt: () => AdvertiserSearchPrompt,
28
+ AllFiltersButton: () => AllFiltersButton,
28
29
  Badge: () => Badge,
29
30
  BarChartPlaceholder: () => BarChartPlaceholder,
30
31
  Button: () => Button,
@@ -42,6 +43,7 @@ __export(index_exports, {
42
43
  Drawer: () => Drawer,
43
44
  EmptyState: () => EmptyState,
44
45
  FilterChipBar: () => FilterChipBar,
46
+ FilterDrawer: () => FilterDrawer,
45
47
  FilterDropdownFooter: () => FilterDropdownFooter,
46
48
  Freshness: () => Freshness,
47
49
  InfoTip: () => InfoTip,
@@ -1257,6 +1259,8 @@ var SearchBar = (0, import_react5.forwardRef)(function SearchBar2({
1257
1259
  onAdCodesChange,
1258
1260
  isAdCodeMatched,
1259
1261
  onDownloadAdCodes,
1262
+ scope,
1263
+ onScopeOpenChange,
1260
1264
  className,
1261
1265
  testIdPrefix
1262
1266
  }, forwardedRef) {
@@ -1323,12 +1327,16 @@ var SearchBar = (0, import_react5.forwardRef)(function SearchBar2({
1323
1327
  "div",
1324
1328
  {
1325
1329
  className: cn(
1326
- "relative flex min-w-[200px] flex-1 items-stretch rounded-control border border-border-strong bg-input focus-within:outline-2 focus-within:outline-offset-1 focus-within:outline-border-focus",
1330
+ // flex-auto, not flex-1: flex-1's 0% basis took the height away in a
1331
+ // column (a filter panel's stack), squashing the sm box from 32px to
1332
+ // its text's 22px. auto keeps the h-8/10/11 and still fills a row.
1333
+ "relative flex min-w-[200px] flex-auto items-stretch rounded-control border border-border-strong bg-input focus-within:outline-2 focus-within:outline-offset-1 focus-within:outline-border-focus",
1327
1334
  HEIGHT[size],
1328
1335
  className
1329
1336
  ),
1330
1337
  "data-testid": testIdPrefix,
1331
1338
  children: [
1339
+ scope && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ScopeMenu, { scope, onOpenChange: onScopeOpenChange, testIdPrefix }),
1332
1340
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1333
1341
  "div",
1334
1342
  {
@@ -1733,6 +1741,122 @@ function RowInfoTip({ text }) {
1733
1741
  )
1734
1742
  ] });
1735
1743
  }
1744
+ function ScopeMenu({
1745
+ scope,
1746
+ onOpenChange,
1747
+ testIdPrefix
1748
+ }) {
1749
+ const [open, setOpenState] = (0, import_react5.useState)(false);
1750
+ const ref = (0, import_react5.useRef)(null);
1751
+ const trigger = (0, import_react5.useRef)(null);
1752
+ const list = (0, import_react5.useRef)(null);
1753
+ const listId = (0, import_react5.useId)();
1754
+ const setOpen = (next) => {
1755
+ setOpenState(next);
1756
+ onOpenChange?.(next);
1757
+ };
1758
+ const close = (refocus) => {
1759
+ setOpen(false);
1760
+ if (refocus) trigger.current?.focus();
1761
+ };
1762
+ (0, import_react5.useEffect)(() => {
1763
+ if (!open) return;
1764
+ list.current?.querySelector('[aria-selected="true"]')?.focus();
1765
+ const onClick = (e) => {
1766
+ if (ref.current && !ref.current.contains(e.target)) close(false);
1767
+ };
1768
+ window.addEventListener("mousedown", onClick);
1769
+ return () => window.removeEventListener("mousedown", onClick);
1770
+ }, [open]);
1771
+ const onListKey = (e) => {
1772
+ const items = Array.from(list.current?.querySelectorAll('[role="option"]') ?? []);
1773
+ const i = items.indexOf(document.activeElement);
1774
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
1775
+ e.preventDefault();
1776
+ const next = e.key === "ArrowDown" ? Math.min(i + 1, items.length - 1) : Math.max(i - 1, 0);
1777
+ items[next]?.focus();
1778
+ } else if (e.key === "Home" || e.key === "End") {
1779
+ e.preventDefault();
1780
+ items[e.key === "Home" ? 0 : items.length - 1]?.focus();
1781
+ } else if (e.key === "Escape") {
1782
+ e.stopPropagation();
1783
+ close(true);
1784
+ } else if (e.key === "Tab") {
1785
+ close(false);
1786
+ }
1787
+ };
1788
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "relative flex shrink-0 border-r border-border-default", ref, children: [
1789
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1790
+ "button",
1791
+ {
1792
+ ref: trigger,
1793
+ type: "button",
1794
+ onClick: () => setOpen(!open),
1795
+ "aria-haspopup": "listbox",
1796
+ "aria-expanded": open,
1797
+ "aria-controls": open ? listId : void 0,
1798
+ "aria-label": `${scope.label}: ${scope.value}`,
1799
+ "data-testid": testIdPrefix && `${testIdPrefix}-scope-trigger`,
1800
+ className: "flex h-full items-center gap-1.5 rounded-l-control px-2.5 text-dense font-semibold text-text-primary transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-border-focus",
1801
+ children: [
1802
+ scope.value,
1803
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1804
+ import_lucide_react7.ChevronDown,
1805
+ {
1806
+ size: 13,
1807
+ "aria-hidden": "true",
1808
+ className: cn("shrink-0 text-text-tertiary transition-transform", open && "rotate-180")
1809
+ }
1810
+ )
1811
+ ]
1812
+ }
1813
+ ),
1814
+ open && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1815
+ "div",
1816
+ {
1817
+ ref: list,
1818
+ id: listId,
1819
+ role: "listbox",
1820
+ "aria-label": scope.label,
1821
+ onKeyDown: onListKey,
1822
+ "data-testid": testIdPrefix && `${testIdPrefix}-scope-popover`,
1823
+ className: "absolute left-0 top-[calc(100%+6px)] z-50 min-w-50 max-w-72 rounded-card border border-border-default bg-surface py-1 shadow-overlay",
1824
+ children: [
1825
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "px-3 pb-1.5 pt-1", "aria-hidden": "true", children: [
1826
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "text-micro font-semibold uppercase tracking-wide text-text-tertiary", children: scope.label }),
1827
+ scope.info && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "mt-0.5 text-xs text-text-secondary", children: scope.info })
1828
+ ] }),
1829
+ scope.options.map((o) => {
1830
+ const sel = o === scope.value;
1831
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1832
+ "button",
1833
+ {
1834
+ type: "button",
1835
+ role: "option",
1836
+ "aria-selected": sel,
1837
+ tabIndex: sel ? 0 : -1,
1838
+ onClick: () => {
1839
+ scope.onChange(o);
1840
+ close(true);
1841
+ },
1842
+ "data-testid": testIdPrefix && `${testIdPrefix}-scope-${slug3(o)}`,
1843
+ className: cn(
1844
+ "flex w-full items-center gap-2 px-3 py-2 text-left text-dense transition-colors hover:bg-subtle focus-visible:bg-subtle focus-visible:outline-none",
1845
+ sel ? "font-semibold text-text-primary" : "text-text-secondary"
1846
+ ),
1847
+ children: [
1848
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.Check, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-brand-primaryAction", !sel && "invisible") }),
1849
+ o
1850
+ ]
1851
+ },
1852
+ o
1853
+ );
1854
+ })
1855
+ ]
1856
+ }
1857
+ )
1858
+ ] });
1859
+ }
1736
1860
 
1737
1861
  // src/SectionRail.tsx
1738
1862
  var import_react6 = require("react");
@@ -5274,12 +5398,200 @@ function InlineMessage({ tone = "info", title, children, actions, onDismiss, cla
5274
5398
  }
5275
5399
  );
5276
5400
  }
5401
+
5402
+ // src/FilterDrawer.tsx
5403
+ var import_react30 = require("react");
5404
+ var import_lucide_react31 = require("lucide-react");
5405
+ var import_jsx_runtime56 = require("react/jsx-runtime");
5406
+ var SLIDE_MS = 200;
5407
+ function reducedMotion() {
5408
+ return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
5409
+ }
5410
+ function FilterDrawer({
5411
+ open,
5412
+ onClose,
5413
+ sections,
5414
+ renderSection,
5415
+ activeCount = 0,
5416
+ onClearSection,
5417
+ onClearAll,
5418
+ onApply,
5419
+ focus = null,
5420
+ size = "sm",
5421
+ testIdPrefix
5422
+ }) {
5423
+ const [view, setViewState] = (0, import_react30.useState)(focus);
5424
+ const [leaving, setLeaving] = (0, import_react30.useState)(null);
5425
+ const [phase, setPhase] = (0, import_react30.useState)("run");
5426
+ const [wasOpen, setWasOpen] = (0, import_react30.useState)(open);
5427
+ if (open !== wasOpen) {
5428
+ setWasOpen(open);
5429
+ if (open) {
5430
+ setViewState(focus);
5431
+ setLeaving(null);
5432
+ }
5433
+ }
5434
+ const setView = (next) => {
5435
+ if (!reducedMotion()) {
5436
+ setLeaving({ view, dir: next ? 1 : -1 });
5437
+ setPhase("start");
5438
+ }
5439
+ setViewState(next);
5440
+ };
5441
+ (0, import_react30.useLayoutEffect)(() => {
5442
+ if (phase !== "start") return;
5443
+ const raf = requestAnimationFrame(() => requestAnimationFrame(() => setPhase("run")));
5444
+ return () => cancelAnimationFrame(raf);
5445
+ }, [phase]);
5446
+ (0, import_react30.useEffect)(() => {
5447
+ if (!leaving || phase !== "run") return;
5448
+ const t = setTimeout(() => setLeaving(null), SLIDE_MS);
5449
+ return () => clearTimeout(t);
5450
+ }, [leaving, phase]);
5451
+ const backRef = (0, import_react30.useRef)(null);
5452
+ const rowRefs = (0, import_react30.useRef)(/* @__PURE__ */ new Map());
5453
+ const lastView = (0, import_react30.useRef)(null);
5454
+ (0, import_react30.useEffect)(() => {
5455
+ if (!open) return;
5456
+ if (view) backRef.current?.focus();
5457
+ else if (lastView.current) rowRefs.current.get(lastView.current)?.focus();
5458
+ lastView.current = view;
5459
+ }, [view, open]);
5460
+ const focused = view ? sections.find((s) => s.id === view) : void 0;
5461
+ const dir = leaving?.dir ?? 1;
5462
+ const moving = !!leaving;
5463
+ const incoming = moving && phase === "start" ? dir > 0 ? "translateX(100%)" : "translateX(-33%)" : void 0;
5464
+ const outgoing = phase === "start" ? void 0 : dir > 0 ? "translateX(-33%)" : "translateX(100%)";
5465
+ const panel = (v, rows = true) => {
5466
+ const s = v ? sections.find((x) => x.id === v) : void 0;
5467
+ if (s) return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("div", { className: "px-5 pt-1", children: renderSection(s.id) });
5468
+ return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("ul", { className: "border-t border-border-default", children: sections.map((x) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("li", { className: "border-b border-border-default", children: /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(
5469
+ "button",
5470
+ {
5471
+ ref: rows ? (el) => {
5472
+ if (el) rowRefs.current.set(x.id, el);
5473
+ else rowRefs.current.delete(x.id);
5474
+ } : void 0,
5475
+ type: "button",
5476
+ onClick: () => setView(x.id),
5477
+ "data-testid": testIdPrefix && `${testIdPrefix}-row-${x.id}`,
5478
+ className: "flex w-full items-center gap-3 px-5 py-3.5 text-left transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-border-focus",
5479
+ children: [
5480
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
5481
+ x.icon,
5482
+ {
5483
+ size: 17,
5484
+ "aria-hidden": "true",
5485
+ className: x.badge ? "text-brand-primaryAction" : "text-text-secondary"
5486
+ }
5487
+ ),
5488
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("span", { className: "flex-1 text-sm font-medium text-text-primary", children: x.label }),
5489
+ x.badge && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Badge, { tone: "brand", children: x.badge }),
5490
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_lucide_react31.ChevronRight, { size: 16, "aria-hidden": "true", className: "shrink-0 text-text-secondary" })
5491
+ ]
5492
+ }
5493
+ ) }, x.id)) });
5494
+ };
5495
+ return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
5496
+ Drawer,
5497
+ {
5498
+ open,
5499
+ onClose,
5500
+ size,
5501
+ testIdPrefix,
5502
+ title: focused ? /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)("span", { className: "flex items-center gap-1.5", children: [
5503
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
5504
+ "button",
5505
+ {
5506
+ ref: backRef,
5507
+ type: "button",
5508
+ onClick: () => setView(null),
5509
+ "aria-label": "Back to all filters",
5510
+ "data-testid": testIdPrefix && `${testIdPrefix}-back`,
5511
+ className: "-ml-1.5 rounded-control p-1 text-text-secondary hover:bg-subtle hover:text-text-primary focus-visible:outline-2 focus-visible:outline-border-focus",
5512
+ children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_lucide_react31.ChevronLeft, { size: 18, "aria-hidden": "true" })
5513
+ }
5514
+ ),
5515
+ focused.label,
5516
+ focused.info && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(InfoTip, { text: focused.info, label: `About ${focused.label}` })
5517
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)("span", { className: "flex items-center gap-2.5", children: [
5518
+ "Filters",
5519
+ activeCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Badge, { tone: "brandSolid", kind: "count", children: activeCount })
5520
+ ] }),
5521
+ footer: /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)("div", { className: "flex w-full items-center justify-between gap-2", children: [
5522
+ focused ? /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Button, { variant: "link", size: "md", onClick: () => onClearSection(focused.id), className: "px-0", children: "Clear" }) : /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Button, { variant: "link", size: "md", onClick: onClearAll, className: "px-0", children: "Clear all" }),
5523
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)("div", { className: "flex items-center gap-2", children: [
5524
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Button, { variant: "secondary", size: "md", onClick: onClose, children: "Cancel" }),
5525
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
5526
+ Button,
5527
+ {
5528
+ variant: "primary",
5529
+ size: "md",
5530
+ onClick: () => {
5531
+ onApply();
5532
+ onClose();
5533
+ },
5534
+ children: "Apply"
5535
+ }
5536
+ )
5537
+ ] })
5538
+ ] }),
5539
+ children: /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)("div", { className: "relative -mx-5 overflow-x-clip", children: [
5540
+ /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
5541
+ "div",
5542
+ {
5543
+ style: { transform: incoming },
5544
+ className: cn(moving && "transition-transform duration-(--mr-motion-duration-interactive) ease-interactive motion-reduce:transition-none"),
5545
+ children: panel(view)
5546
+ },
5547
+ view ?? "__list"
5548
+ ),
5549
+ leaving && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
5550
+ "div",
5551
+ {
5552
+ "aria-hidden": "true",
5553
+ ref: (el) => el?.setAttribute("inert", ""),
5554
+ style: { transform: outgoing, opacity: phase === "start" ? 1 : dir > 0 ? 0.4 : 1 },
5555
+ className: "pointer-events-none absolute inset-x-0 top-0 transition duration-(--mr-motion-duration-interactive) ease-interactive motion-reduce:transition-none",
5556
+ children: panel(leaving.view, false)
5557
+ }
5558
+ )
5559
+ ] })
5560
+ }
5561
+ );
5562
+ }
5563
+
5564
+ // src/AllFiltersButton.tsx
5565
+ var import_react31 = require("react");
5566
+ var import_lucide_react32 = require("lucide-react");
5567
+ var import_jsx_runtime57 = require("react/jsx-runtime");
5568
+ var AllFiltersButton = (0, import_react31.forwardRef)(function AllFiltersButton2({ count = 0, open, className, testIdPrefix, ...rest }, ref) {
5569
+ return /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)(
5570
+ "button",
5571
+ {
5572
+ ref,
5573
+ type: "button",
5574
+ "aria-haspopup": "dialog",
5575
+ "aria-expanded": open,
5576
+ "aria-label": count > 0 ? `All filters, ${count} in use` : void 0,
5577
+ "data-testid": testIdPrefix,
5578
+ className: cn(chipTriggerClass(), className),
5579
+ ...rest,
5580
+ children: [
5581
+ /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(import_lucide_react32.SlidersHorizontal, { size: 15, "aria-hidden": "true", className: "text-text-secondary" }),
5582
+ /* @__PURE__ */ (0, import_jsx_runtime57.jsx)("span", { className: "text-dense font-medium text-text-primary", children: "All filters" }),
5583
+ count > 0 && /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(Badge, { tone: "brandSolid", kind: "count", children: count })
5584
+ ]
5585
+ }
5586
+ );
5587
+ });
5277
5588
  // Annotate the CommonJS export names for ESM import in node:
5278
5589
  0 && (module.exports = {
5279
5590
  AISpark,
5280
5591
  AdvertiserNoResults,
5281
5592
  AdvertiserQuickFilter,
5282
5593
  AdvertiserSearchPrompt,
5594
+ AllFiltersButton,
5283
5595
  Badge,
5284
5596
  BarChartPlaceholder,
5285
5597
  Button,
@@ -5297,6 +5609,7 @@ function InlineMessage({ tone = "info", title, children, actions, onDismiss, cla
5297
5609
  Drawer,
5298
5610
  EmptyState,
5299
5611
  FilterChipBar,
5612
+ FilterDrawer,
5300
5613
  FilterDropdownFooter,
5301
5614
  Freshness,
5302
5615
  InfoTip,