@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.
package/dist/index.js CHANGED
@@ -1166,6 +1166,8 @@ var SearchBar = forwardRef2(function SearchBar2({
1166
1166
  onAdCodesChange,
1167
1167
  isAdCodeMatched,
1168
1168
  onDownloadAdCodes,
1169
+ scope,
1170
+ onScopeOpenChange,
1169
1171
  className,
1170
1172
  testIdPrefix
1171
1173
  }, forwardedRef) {
@@ -1232,12 +1234,16 @@ var SearchBar = forwardRef2(function SearchBar2({
1232
1234
  "div",
1233
1235
  {
1234
1236
  className: cn(
1235
- "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",
1237
+ // flex-auto, not flex-1: flex-1's 0% basis took the height away in a
1238
+ // column (a filter panel's stack), squashing the sm box from 32px to
1239
+ // its text's 22px. auto keeps the h-8/10/11 and still fills a row.
1240
+ "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",
1236
1241
  HEIGHT[size],
1237
1242
  className
1238
1243
  ),
1239
1244
  "data-testid": testIdPrefix,
1240
1245
  children: [
1246
+ scope && /* @__PURE__ */ jsx9(ScopeMenu, { scope, onOpenChange: onScopeOpenChange, testIdPrefix }),
1241
1247
  /* @__PURE__ */ jsxs8(
1242
1248
  "div",
1243
1249
  {
@@ -1642,6 +1648,122 @@ function RowInfoTip({ text }) {
1642
1648
  )
1643
1649
  ] });
1644
1650
  }
1651
+ function ScopeMenu({
1652
+ scope,
1653
+ onOpenChange,
1654
+ testIdPrefix
1655
+ }) {
1656
+ const [open, setOpenState] = useState4(false);
1657
+ const ref = useRef4(null);
1658
+ const trigger = useRef4(null);
1659
+ const list = useRef4(null);
1660
+ const listId = useId3();
1661
+ const setOpen = (next) => {
1662
+ setOpenState(next);
1663
+ onOpenChange?.(next);
1664
+ };
1665
+ const close = (refocus) => {
1666
+ setOpen(false);
1667
+ if (refocus) trigger.current?.focus();
1668
+ };
1669
+ useEffect4(() => {
1670
+ if (!open) return;
1671
+ list.current?.querySelector('[aria-selected="true"]')?.focus();
1672
+ const onClick = (e) => {
1673
+ if (ref.current && !ref.current.contains(e.target)) close(false);
1674
+ };
1675
+ window.addEventListener("mousedown", onClick);
1676
+ return () => window.removeEventListener("mousedown", onClick);
1677
+ }, [open]);
1678
+ const onListKey = (e) => {
1679
+ const items = Array.from(list.current?.querySelectorAll('[role="option"]') ?? []);
1680
+ const i = items.indexOf(document.activeElement);
1681
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
1682
+ e.preventDefault();
1683
+ const next = e.key === "ArrowDown" ? Math.min(i + 1, items.length - 1) : Math.max(i - 1, 0);
1684
+ items[next]?.focus();
1685
+ } else if (e.key === "Home" || e.key === "End") {
1686
+ e.preventDefault();
1687
+ items[e.key === "Home" ? 0 : items.length - 1]?.focus();
1688
+ } else if (e.key === "Escape") {
1689
+ e.stopPropagation();
1690
+ close(true);
1691
+ } else if (e.key === "Tab") {
1692
+ close(false);
1693
+ }
1694
+ };
1695
+ return /* @__PURE__ */ jsxs8("div", { className: "relative flex shrink-0 border-r border-border-default", ref, children: [
1696
+ /* @__PURE__ */ jsxs8(
1697
+ "button",
1698
+ {
1699
+ ref: trigger,
1700
+ type: "button",
1701
+ onClick: () => setOpen(!open),
1702
+ "aria-haspopup": "listbox",
1703
+ "aria-expanded": open,
1704
+ "aria-controls": open ? listId : void 0,
1705
+ "aria-label": `${scope.label}: ${scope.value}`,
1706
+ "data-testid": testIdPrefix && `${testIdPrefix}-scope-trigger`,
1707
+ 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",
1708
+ children: [
1709
+ scope.value,
1710
+ /* @__PURE__ */ jsx9(
1711
+ ChevronDown3,
1712
+ {
1713
+ size: 13,
1714
+ "aria-hidden": "true",
1715
+ className: cn("shrink-0 text-text-tertiary transition-transform", open && "rotate-180")
1716
+ }
1717
+ )
1718
+ ]
1719
+ }
1720
+ ),
1721
+ open && /* @__PURE__ */ jsxs8(
1722
+ "div",
1723
+ {
1724
+ ref: list,
1725
+ id: listId,
1726
+ role: "listbox",
1727
+ "aria-label": scope.label,
1728
+ onKeyDown: onListKey,
1729
+ "data-testid": testIdPrefix && `${testIdPrefix}-scope-popover`,
1730
+ 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",
1731
+ children: [
1732
+ /* @__PURE__ */ jsxs8("div", { className: "px-3 pb-1.5 pt-1", "aria-hidden": "true", children: [
1733
+ /* @__PURE__ */ jsx9("p", { className: "text-micro font-semibold uppercase tracking-wide text-text-tertiary", children: scope.label }),
1734
+ scope.info && /* @__PURE__ */ jsx9("p", { className: "mt-0.5 text-xs text-text-secondary", children: scope.info })
1735
+ ] }),
1736
+ scope.options.map((o) => {
1737
+ const sel = o === scope.value;
1738
+ return /* @__PURE__ */ jsxs8(
1739
+ "button",
1740
+ {
1741
+ type: "button",
1742
+ role: "option",
1743
+ "aria-selected": sel,
1744
+ tabIndex: sel ? 0 : -1,
1745
+ onClick: () => {
1746
+ scope.onChange(o);
1747
+ close(true);
1748
+ },
1749
+ "data-testid": testIdPrefix && `${testIdPrefix}-scope-${slug3(o)}`,
1750
+ className: cn(
1751
+ "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",
1752
+ sel ? "font-semibold text-text-primary" : "text-text-secondary"
1753
+ ),
1754
+ children: [
1755
+ /* @__PURE__ */ jsx9(Check3, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-brand-primaryAction", !sel && "invisible") }),
1756
+ o
1757
+ ]
1758
+ },
1759
+ o
1760
+ );
1761
+ })
1762
+ ]
1763
+ }
1764
+ )
1765
+ ] });
1766
+ }
1645
1767
 
1646
1768
  // src/SectionRail.tsx
1647
1769
  import { useRef as useRef5 } from "react";
@@ -5183,11 +5305,199 @@ function InlineMessage({ tone = "info", title, children, actions, onDismiss, cla
5183
5305
  }
5184
5306
  );
5185
5307
  }
5308
+
5309
+ // src/FilterDrawer.tsx
5310
+ import { useEffect as useEffect17, useLayoutEffect as useLayoutEffect6, useRef as useRef19, useState as useState17 } from "react";
5311
+ import { ChevronLeft as ChevronLeft5, ChevronRight as ChevronRight6 } from "lucide-react";
5312
+ import { jsx as jsx56, jsxs as jsxs48 } from "react/jsx-runtime";
5313
+ var SLIDE_MS = 200;
5314
+ function reducedMotion() {
5315
+ return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
5316
+ }
5317
+ function FilterDrawer({
5318
+ open,
5319
+ onClose,
5320
+ sections,
5321
+ renderSection,
5322
+ activeCount = 0,
5323
+ onClearSection,
5324
+ onClearAll,
5325
+ onApply,
5326
+ focus = null,
5327
+ size = "sm",
5328
+ testIdPrefix
5329
+ }) {
5330
+ const [view, setViewState] = useState17(focus);
5331
+ const [leaving, setLeaving] = useState17(null);
5332
+ const [phase, setPhase] = useState17("run");
5333
+ const [wasOpen, setWasOpen] = useState17(open);
5334
+ if (open !== wasOpen) {
5335
+ setWasOpen(open);
5336
+ if (open) {
5337
+ setViewState(focus);
5338
+ setLeaving(null);
5339
+ }
5340
+ }
5341
+ const setView = (next) => {
5342
+ if (!reducedMotion()) {
5343
+ setLeaving({ view, dir: next ? 1 : -1 });
5344
+ setPhase("start");
5345
+ }
5346
+ setViewState(next);
5347
+ };
5348
+ useLayoutEffect6(() => {
5349
+ if (phase !== "start") return;
5350
+ const raf = requestAnimationFrame(() => requestAnimationFrame(() => setPhase("run")));
5351
+ return () => cancelAnimationFrame(raf);
5352
+ }, [phase]);
5353
+ useEffect17(() => {
5354
+ if (!leaving || phase !== "run") return;
5355
+ const t = setTimeout(() => setLeaving(null), SLIDE_MS);
5356
+ return () => clearTimeout(t);
5357
+ }, [leaving, phase]);
5358
+ const backRef = useRef19(null);
5359
+ const rowRefs = useRef19(/* @__PURE__ */ new Map());
5360
+ const lastView = useRef19(null);
5361
+ useEffect17(() => {
5362
+ if (!open) return;
5363
+ if (view) backRef.current?.focus();
5364
+ else if (lastView.current) rowRefs.current.get(lastView.current)?.focus();
5365
+ lastView.current = view;
5366
+ }, [view, open]);
5367
+ const focused = view ? sections.find((s) => s.id === view) : void 0;
5368
+ const dir = leaving?.dir ?? 1;
5369
+ const moving = !!leaving;
5370
+ const incoming = moving && phase === "start" ? dir > 0 ? "translateX(100%)" : "translateX(-33%)" : void 0;
5371
+ const outgoing = phase === "start" ? void 0 : dir > 0 ? "translateX(-33%)" : "translateX(100%)";
5372
+ const panel = (v, rows = true) => {
5373
+ const s = v ? sections.find((x) => x.id === v) : void 0;
5374
+ if (s) return /* @__PURE__ */ jsx56("div", { className: "px-5 pt-1", children: renderSection(s.id) });
5375
+ return /* @__PURE__ */ jsx56("ul", { className: "border-t border-border-default", children: sections.map((x) => /* @__PURE__ */ jsx56("li", { className: "border-b border-border-default", children: /* @__PURE__ */ jsxs48(
5376
+ "button",
5377
+ {
5378
+ ref: rows ? (el) => {
5379
+ if (el) rowRefs.current.set(x.id, el);
5380
+ else rowRefs.current.delete(x.id);
5381
+ } : void 0,
5382
+ type: "button",
5383
+ onClick: () => setView(x.id),
5384
+ "data-testid": testIdPrefix && `${testIdPrefix}-row-${x.id}`,
5385
+ 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",
5386
+ children: [
5387
+ /* @__PURE__ */ jsx56(
5388
+ x.icon,
5389
+ {
5390
+ size: 17,
5391
+ "aria-hidden": "true",
5392
+ className: x.badge ? "text-brand-primaryAction" : "text-text-secondary"
5393
+ }
5394
+ ),
5395
+ /* @__PURE__ */ jsx56("span", { className: "flex-1 text-sm font-medium text-text-primary", children: x.label }),
5396
+ x.badge && /* @__PURE__ */ jsx56(Badge, { tone: "brand", children: x.badge }),
5397
+ /* @__PURE__ */ jsx56(ChevronRight6, { size: 16, "aria-hidden": "true", className: "shrink-0 text-text-secondary" })
5398
+ ]
5399
+ }
5400
+ ) }, x.id)) });
5401
+ };
5402
+ return /* @__PURE__ */ jsx56(
5403
+ Drawer,
5404
+ {
5405
+ open,
5406
+ onClose,
5407
+ size,
5408
+ testIdPrefix,
5409
+ title: focused ? /* @__PURE__ */ jsxs48("span", { className: "flex items-center gap-1.5", children: [
5410
+ /* @__PURE__ */ jsx56(
5411
+ "button",
5412
+ {
5413
+ ref: backRef,
5414
+ type: "button",
5415
+ onClick: () => setView(null),
5416
+ "aria-label": "Back to all filters",
5417
+ "data-testid": testIdPrefix && `${testIdPrefix}-back`,
5418
+ 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",
5419
+ children: /* @__PURE__ */ jsx56(ChevronLeft5, { size: 18, "aria-hidden": "true" })
5420
+ }
5421
+ ),
5422
+ focused.label,
5423
+ focused.info && /* @__PURE__ */ jsx56(InfoTip, { text: focused.info, label: `About ${focused.label}` })
5424
+ ] }) : /* @__PURE__ */ jsxs48("span", { className: "flex items-center gap-2.5", children: [
5425
+ "Filters",
5426
+ activeCount > 0 && /* @__PURE__ */ jsx56(Badge, { tone: "brandSolid", kind: "count", children: activeCount })
5427
+ ] }),
5428
+ footer: /* @__PURE__ */ jsxs48("div", { className: "flex w-full items-center justify-between gap-2", children: [
5429
+ focused ? /* @__PURE__ */ jsx56(Button, { variant: "link", size: "md", onClick: () => onClearSection(focused.id), className: "px-0", children: "Clear" }) : /* @__PURE__ */ jsx56(Button, { variant: "link", size: "md", onClick: onClearAll, className: "px-0", children: "Clear all" }),
5430
+ /* @__PURE__ */ jsxs48("div", { className: "flex items-center gap-2", children: [
5431
+ /* @__PURE__ */ jsx56(Button, { variant: "secondary", size: "md", onClick: onClose, children: "Cancel" }),
5432
+ /* @__PURE__ */ jsx56(
5433
+ Button,
5434
+ {
5435
+ variant: "primary",
5436
+ size: "md",
5437
+ onClick: () => {
5438
+ onApply();
5439
+ onClose();
5440
+ },
5441
+ children: "Apply"
5442
+ }
5443
+ )
5444
+ ] })
5445
+ ] }),
5446
+ children: /* @__PURE__ */ jsxs48("div", { className: "relative -mx-5 overflow-x-clip", children: [
5447
+ /* @__PURE__ */ jsx56(
5448
+ "div",
5449
+ {
5450
+ style: { transform: incoming },
5451
+ className: cn(moving && "transition-transform duration-(--mr-motion-duration-interactive) ease-interactive motion-reduce:transition-none"),
5452
+ children: panel(view)
5453
+ },
5454
+ view ?? "__list"
5455
+ ),
5456
+ leaving && /* @__PURE__ */ jsx56(
5457
+ "div",
5458
+ {
5459
+ "aria-hidden": "true",
5460
+ ref: (el) => el?.setAttribute("inert", ""),
5461
+ style: { transform: outgoing, opacity: phase === "start" ? 1 : dir > 0 ? 0.4 : 1 },
5462
+ className: "pointer-events-none absolute inset-x-0 top-0 transition duration-(--mr-motion-duration-interactive) ease-interactive motion-reduce:transition-none",
5463
+ children: panel(leaving.view, false)
5464
+ }
5465
+ )
5466
+ ] })
5467
+ }
5468
+ );
5469
+ }
5470
+
5471
+ // src/AllFiltersButton.tsx
5472
+ import { forwardRef as forwardRef11 } from "react";
5473
+ import { SlidersHorizontal } from "lucide-react";
5474
+ import { jsx as jsx57, jsxs as jsxs49 } from "react/jsx-runtime";
5475
+ var AllFiltersButton = forwardRef11(function AllFiltersButton2({ count = 0, open, className, testIdPrefix, ...rest }, ref) {
5476
+ return /* @__PURE__ */ jsxs49(
5477
+ "button",
5478
+ {
5479
+ ref,
5480
+ type: "button",
5481
+ "aria-haspopup": "dialog",
5482
+ "aria-expanded": open,
5483
+ "aria-label": count > 0 ? `All filters, ${count} in use` : void 0,
5484
+ "data-testid": testIdPrefix,
5485
+ className: cn(chipTriggerClass(), className),
5486
+ ...rest,
5487
+ children: [
5488
+ /* @__PURE__ */ jsx57(SlidersHorizontal, { size: 15, "aria-hidden": "true", className: "text-text-secondary" }),
5489
+ /* @__PURE__ */ jsx57("span", { className: "text-dense font-medium text-text-primary", children: "All filters" }),
5490
+ count > 0 && /* @__PURE__ */ jsx57(Badge, { tone: "brandSolid", kind: "count", children: count })
5491
+ ]
5492
+ }
5493
+ );
5494
+ });
5186
5495
  export {
5187
5496
  AISpark,
5188
5497
  AdvertiserNoResults,
5189
5498
  AdvertiserQuickFilter,
5190
5499
  AdvertiserSearchPrompt,
5500
+ AllFiltersButton,
5191
5501
  Badge,
5192
5502
  BarChartPlaceholder,
5193
5503
  Button,
@@ -5205,6 +5515,7 @@ export {
5205
5515
  Drawer,
5206
5516
  EmptyState,
5207
5517
  FilterChipBar,
5518
+ FilterDrawer,
5208
5519
  FilterDropdownFooter,
5209
5520
  Freshness,
5210
5521
  InfoTip,