@mediaradar/design-components 0.40.0 → 0.41.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.40.0",
2
+ "version": "0.41.0",
3
3
  "components": [
4
4
  "AISpark",
5
5
  "AdvertiserNoResults",
package/dist/index.cjs CHANGED
@@ -1173,6 +1173,23 @@ var MODE_LABEL = {
1173
1173
  contextual: "Contextual",
1174
1174
  adCode: "Ad Code"
1175
1175
  };
1176
+ function parseAdCodes(text) {
1177
+ return text.split(/[\s,;]+/).map((c) => c.trim()).filter(Boolean);
1178
+ }
1179
+ function mergeAdCodes(existing, incoming) {
1180
+ const seen = new Set(existing.map((c) => c.toUpperCase()));
1181
+ const out = [...existing];
1182
+ for (const code of incoming) {
1183
+ const key = code.toUpperCase();
1184
+ if (seen.has(key)) continue;
1185
+ seen.add(key);
1186
+ out.push(code);
1187
+ }
1188
+ return out;
1189
+ }
1190
+ function slug3(value) {
1191
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
1192
+ }
1176
1193
  function cx2(...classes) {
1177
1194
  return classes.filter(Boolean).join(" ");
1178
1195
  }
@@ -1184,12 +1201,53 @@ function SearchBar({
1184
1201
  size = "lg",
1185
1202
  matchValue,
1186
1203
  onMatchChange,
1204
+ adCodes = [],
1205
+ onAdCodesChange,
1206
+ isAdCodeMatched,
1207
+ onDownloadAdCodes,
1187
1208
  className,
1188
1209
  testIdPrefix
1189
1210
  }) {
1190
1211
  const [open, setOpen] = (0, import_react4.useState)(false);
1191
1212
  const ref = (0, import_react4.useRef)(null);
1192
1213
  const input = (0, import_react4.useRef)(null);
1214
+ const [codesOpen, setCodesOpen] = (0, import_react4.useState)(false);
1215
+ const codesRef = (0, import_react4.useRef)(null);
1216
+ const codesPopover = (0, import_react4.useRef)(null);
1217
+ const refocus = (0, import_react4.useRef)(null);
1218
+ const adCodeMode = variant === "filterable" && matchValue?.mode === "adCode" && !!onAdCodesChange;
1219
+ const matchedCount = adCodes.filter((c) => isAdCodeMatched?.(c)).length;
1220
+ const hasMisses = !!isAdCodeMatched && matchedCount < adCodes.length;
1221
+ (0, import_react4.useEffect)(() => {
1222
+ if (!codesOpen) return;
1223
+ const onKey = (e) => {
1224
+ if (e.key !== "Escape") return;
1225
+ setCodesOpen(false);
1226
+ input.current?.focus();
1227
+ };
1228
+ const onClick = (e) => {
1229
+ if (codesRef.current && !codesRef.current.contains(e.target)) setCodesOpen(false);
1230
+ };
1231
+ window.addEventListener("keydown", onKey);
1232
+ window.addEventListener("mousedown", onClick);
1233
+ return () => {
1234
+ window.removeEventListener("keydown", onKey);
1235
+ window.removeEventListener("mousedown", onClick);
1236
+ };
1237
+ }, [codesOpen]);
1238
+ (0, import_react4.useLayoutEffect)(() => {
1239
+ const i = refocus.current;
1240
+ if (i === null) return;
1241
+ refocus.current = null;
1242
+ const buttons = codesPopover.current?.querySelectorAll("[data-remove-code]");
1243
+ if (i >= 0 && buttons && buttons.length > 0) buttons[Math.min(i, buttons.length - 1)].focus();
1244
+ else input.current?.focus();
1245
+ }, [adCodes]);
1246
+ const updateCodes = (next, focusIndex) => {
1247
+ refocus.current = next.length ? focusIndex : -1;
1248
+ if (!next.length) setCodesOpen(false);
1249
+ onAdCodesChange?.(next);
1250
+ };
1193
1251
  (0, import_react4.useEffect)(() => {
1194
1252
  if (!open) return;
1195
1253
  const onKey = (e) => e.key === "Escape" && setOpen(false);
@@ -1208,27 +1266,158 @@ function SearchBar({
1208
1266
  "div",
1209
1267
  {
1210
1268
  className: cx2(
1211
- "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",
1269
+ "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",
1212
1270
  HEIGHT[size],
1213
1271
  className
1214
1272
  ),
1215
1273
  children: [
1216
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("label", { className: "flex min-w-0 flex-1 items-center gap-2 px-2.5", children: [
1217
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.Search, { size: 15, "aria-hidden": "true", className: "shrink-0 text-text-tertiary" }),
1218
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1219
- "input",
1220
- {
1221
- ref: input,
1222
- type: "text",
1223
- value,
1224
- onChange: (e) => onChange?.(e.target.value),
1225
- placeholder,
1226
- "aria-label": placeholder,
1227
- "data-testid": testIdPrefix && `${testIdPrefix}-search`,
1228
- className: "min-w-0 flex-1 bg-transparent text-dense text-text-primary outline-hidden placeholder:text-text-tertiary"
1229
- }
1230
- )
1231
- ] }),
1274
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1275
+ "div",
1276
+ {
1277
+ ref: codesRef,
1278
+ className: "flex min-w-0 flex-1 cursor-text items-center gap-2 px-2.5",
1279
+ onMouseDown: (e) => {
1280
+ if (e.target === e.currentTarget) {
1281
+ e.preventDefault();
1282
+ input.current?.focus();
1283
+ }
1284
+ },
1285
+ children: [
1286
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.Search, { size: 15, "aria-hidden": "true", className: "shrink-0 text-text-tertiary" }),
1287
+ adCodeMode && adCodes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1288
+ "span",
1289
+ {
1290
+ className: cx2(
1291
+ "inline-flex shrink-0 items-center gap-1 rounded-full py-0.5 pl-2 pr-1 text-xs font-medium",
1292
+ hasMisses ? "bg-status-danger/15 text-text-danger" : "bg-subtle text-text-primary"
1293
+ ),
1294
+ children: [
1295
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1296
+ "button",
1297
+ {
1298
+ type: "button",
1299
+ onClick: () => setCodesOpen((o) => !o),
1300
+ "aria-expanded": codesOpen,
1301
+ "aria-haspopup": "dialog",
1302
+ "data-testid": testIdPrefix && `${testIdPrefix}-ad-codes`,
1303
+ className: "inline-flex items-center gap-1 rounded-control focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1304
+ children: [
1305
+ hasMisses && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.AlertCircle, { size: 13, "aria-hidden": "true" }),
1306
+ hasMisses ? `${matchedCount} of ${adCodes.length} matched` : adCodes.length === 1 ? adCodes[0] : `${adCodes.length} Ad Codes`
1307
+ ]
1308
+ }
1309
+ ),
1310
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1311
+ "button",
1312
+ {
1313
+ type: "button",
1314
+ "aria-label": "Clear all ad codes",
1315
+ onClick: () => updateCodes([], -1),
1316
+ "data-testid": testIdPrefix && `${testIdPrefix}-ad-codes-clear`,
1317
+ className: "inline-flex rounded-full p-0.5 hover:bg-surface focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1318
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.X, { size: 12, "aria-hidden": "true" })
1319
+ }
1320
+ )
1321
+ ]
1322
+ }
1323
+ ),
1324
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1325
+ "input",
1326
+ {
1327
+ ref: input,
1328
+ type: "text",
1329
+ value,
1330
+ onChange: (e) => onChange?.(e.target.value),
1331
+ onKeyDown: (e) => {
1332
+ if (!adCodeMode || e.key !== "Enter") return;
1333
+ const typed = parseAdCodes(value ?? "");
1334
+ if (!typed.length) return;
1335
+ e.preventDefault();
1336
+ onAdCodesChange?.(mergeAdCodes(adCodes, typed));
1337
+ onChange?.("");
1338
+ },
1339
+ placeholder: adCodeMode && adCodes.length === 0 ? "Enter ad codes, then press Enter" : placeholder,
1340
+ "aria-label": placeholder,
1341
+ "data-testid": testIdPrefix && `${testIdPrefix}-search`,
1342
+ className: "min-w-0 flex-1 bg-transparent text-dense text-text-primary outline-hidden placeholder:text-text-tertiary"
1343
+ }
1344
+ ),
1345
+ adCodeMode && codesOpen && adCodes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1346
+ "div",
1347
+ {
1348
+ ref: codesPopover,
1349
+ role: "dialog",
1350
+ "aria-label": "Ad codes",
1351
+ "data-testid": testIdPrefix && `${testIdPrefix}-ad-codes-popover`,
1352
+ className: "absolute right-0 top-full z-50 mt-2 w-110 max-w-[90vw] cursor-auto rounded-card border border-border-default bg-surface p-3 shadow-overlay",
1353
+ children: [
1354
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "mb-2 text-xs font-medium text-text-secondary", children: isAdCodeMatched ? `${matchedCount} ${matchedCount === 1 ? "ad was" : "ads were"} found` : `${adCodes.length} ${adCodes.length === 1 ? "ad code" : "ad codes"}` }),
1355
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { className: "flex max-h-50 flex-wrap gap-2 overflow-y-auto p-0.5", children: adCodes.map((code, i) => {
1356
+ const missed = !!isAdCodeMatched && !isAdCodeMatched(code);
1357
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1358
+ "li",
1359
+ {
1360
+ className: cx2(
1361
+ "inline-flex items-center gap-1 rounded-full py-1 pl-2.5 pr-1.5 text-card-title",
1362
+ missed ? "bg-status-danger/15 text-text-danger" : "bg-subtle text-text-primary"
1363
+ ),
1364
+ children: [
1365
+ code,
1366
+ missed && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "sr-only", children: " (not found)" }),
1367
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1368
+ "button",
1369
+ {
1370
+ type: "button",
1371
+ "data-remove-code": "",
1372
+ "aria-label": `Remove ${code}`,
1373
+ onClick: () => updateCodes(adCodes.filter((c) => c !== code), i),
1374
+ "data-testid": testIdPrefix && `${testIdPrefix}-ad-code-remove-${slug3(code)}`,
1375
+ className: "inline-flex rounded-full p-0.5 hover:bg-surface focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1376
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.X, { size: 13, "aria-hidden": "true" })
1377
+ }
1378
+ )
1379
+ ]
1380
+ },
1381
+ code
1382
+ );
1383
+ }) }),
1384
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1385
+ "button",
1386
+ {
1387
+ type: "button",
1388
+ onClick: () => {
1389
+ setCodesOpen(false);
1390
+ input.current?.focus();
1391
+ },
1392
+ "data-testid": testIdPrefix && `${testIdPrefix}-ad-codes-done`,
1393
+ className: "rounded-control bg-brand-primaryAction px-4 py-2 text-dense font-semibold text-brand-onprimary transition hover:brightness-110 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-border-focus",
1394
+ children: "Search"
1395
+ }
1396
+ ) }),
1397
+ onDownloadAdCodes && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "mt-3 flex items-start gap-2 rounded-control border border-border-default px-3 py-2.5 text-card-title text-text-secondary", children: [
1398
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.AlertCircle, { size: 16, "aria-hidden": "true", className: "mt-0.5 shrink-0 text-text-tertiary" }),
1399
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { children: [
1400
+ hasMisses && "Some ad codes in your search could not be matched. ",
1401
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1402
+ "button",
1403
+ {
1404
+ type: "button",
1405
+ onClick: () => onDownloadAdCodes(adCodes),
1406
+ "data-testid": testIdPrefix && `${testIdPrefix}-ad-codes-download`,
1407
+ className: "font-medium text-text-link underline focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1408
+ children: "Download"
1409
+ }
1410
+ ),
1411
+ " ",
1412
+ hasMisses ? "the results to see the status of each ad code." : "the list of ad codes with their status."
1413
+ ] })
1414
+ ] })
1415
+ ]
1416
+ }
1417
+ )
1418
+ ]
1419
+ }
1420
+ ),
1232
1421
  value && onChange && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1233
1422
  "button",
1234
1423
  {
@@ -1374,34 +1563,40 @@ function ModeRow({
1374
1563
  onSelect,
1375
1564
  testId
1376
1565
  }) {
1566
+ const descId = (0, import_react4.useId)();
1377
1567
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1378
1568
  "div",
1379
1569
  {
1380
- role: "radio",
1381
- tabIndex: 0,
1382
- "aria-checked": selected,
1383
- "data-testid": testId,
1384
1570
  onClick: onSelect,
1385
- onKeyDown: (e) => {
1386
- if (e.key === "Enter" || e.key === " ") {
1387
- e.preventDefault();
1388
- onSelect();
1389
- }
1390
- },
1391
- className: "flex cursor-pointer flex-col items-stretch gap-1 rounded-control p-1.5 text-left transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1571
+ className: "flex cursor-pointer flex-col items-stretch gap-1 rounded-control p-1.5 text-left transition-colors hover:bg-subtle",
1392
1572
  children: [
1393
1573
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex items-center justify-between gap-2", children: [
1394
1574
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex flex-wrap items-center gap-3", children: [
1395
1575
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "flex items-center gap-1", children: [
1396
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-[14px] font-semibold text-text-primary", children: title }),
1576
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1577
+ "button",
1578
+ {
1579
+ type: "button",
1580
+ role: "radio",
1581
+ "aria-checked": selected,
1582
+ "aria-describedby": descId,
1583
+ "data-testid": testId,
1584
+ onClick: (e) => {
1585
+ e.stopPropagation();
1586
+ onSelect();
1587
+ },
1588
+ className: "rounded-control text-left text-[14px] font-semibold text-text-primary focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1589
+ children: title
1590
+ }
1591
+ ),
1397
1592
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(RowInfoTip, { text: infoText })
1398
1593
  ] }),
1399
- badge && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "rounded-full bg-subtle px-2 py-0.5 text-badge font-semibold uppercase tracking-wide text-text-secondary", children: badge }),
1594
+ badge && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Badge, { kind: "category", children: badge }),
1400
1595
  extra
1401
1596
  ] }),
1402
1597
  selected && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.Check, { size: 16, strokeWidth: 2.5, "aria-hidden": "true", className: "shrink-0 text-brand-primaryAction" })
1403
1598
  ] }),
1404
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "block text-[12.5px] leading-snug text-text-secondary", children: description })
1599
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { id: descId, className: "block text-[12.5px] leading-snug text-text-secondary", children: description })
1405
1600
  ]
1406
1601
  }
1407
1602
  );
@@ -1464,7 +1659,7 @@ function RowInfoTip({ text }) {
1464
1659
  "aria-label": "More information",
1465
1660
  "aria-expanded": open,
1466
1661
  "aria-describedby": id,
1467
- className: "inline-flex text-text-tertiary transition-colors hover:text-text-primary focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1662
+ className: "-m-1.5 inline-flex size-6 items-center justify-center rounded-control text-text-tertiary transition-colors hover:text-text-primary focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
1468
1663
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react7.AlertCircle, { size: 13, "aria-hidden": "true" })
1469
1664
  }
1470
1665
  ),
@@ -1681,7 +1876,7 @@ var import_jsx_runtime13 = require("react/jsx-runtime");
1681
1876
  function cx4(...classes) {
1682
1877
  return classes.filter(Boolean).join(" ");
1683
1878
  }
1684
- function slug3(value) {
1879
+ function slug4(value) {
1685
1880
  return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
1686
1881
  }
1687
1882
  function OptionIcon({ children }) {
@@ -1801,7 +1996,7 @@ function SelectFilter({
1801
1996
  type: "button",
1802
1997
  role: "option",
1803
1998
  "aria-selected": selected,
1804
- "data-testid": testIdPrefix && `${testIdPrefix}-option-${slug3(o)}`,
1999
+ "data-testid": testIdPrefix && `${testIdPrefix}-option-${slug4(o)}`,
1805
2000
  onClick: () => {
1806
2001
  onChange(o);
1807
2002
  close();
@@ -2609,7 +2804,7 @@ var import_jsx_runtime27 = require("react/jsx-runtime");
2609
2804
  function cx8(...parts) {
2610
2805
  return parts.filter(Boolean).join(" ");
2611
2806
  }
2612
- function slug4(value) {
2807
+ function slug5(value) {
2613
2808
  return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
2614
2809
  }
2615
2810
  function SelectionPicker({
@@ -2806,7 +3001,7 @@ function SelectionPicker({
2806
3001
  checked: isSel,
2807
3002
  onChange: () => toggleRow(row),
2808
3003
  ariaLabel: row.name,
2809
- testId: testIdPrefix && `${testIdPrefix}-row-${slug4(row.id)}`
3004
+ testId: testIdPrefix && `${testIdPrefix}-row-${slug5(row.id)}`
2810
3005
  }
2811
3006
  ),
2812
3007
  /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: cx8("grid gap-2 text-dense text-text-primary", gridForColumns(columns)), children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: cx8("truncate", c.className), children: c.render(row) }, c.key)) }),
@@ -3024,7 +3219,7 @@ function FilterDropdown({
3024
3219
  }, [open]);
3025
3220
  const count = active.size;
3026
3221
  const label = count === 0 ? filter.label : count === 1 ? [...active][0] : "Multiple";
3027
- const filterSlug = slug4(filter.label);
3222
+ const filterSlug = slug5(filter.label);
3028
3223
  return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "relative", children: [
3029
3224
  /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
3030
3225
  "button",
@@ -3077,7 +3272,7 @@ function FilterDropdown({
3077
3272
  checked: on,
3078
3273
  onChange: () => onToggle(opt),
3079
3274
  ariaLabel: opt,
3080
- testId: testIdPrefix && `${testIdPrefix}-filter-${filterSlug}-${slug4(opt)}`
3275
+ testId: testIdPrefix && `${testIdPrefix}-filter-${filterSlug}-${slug5(opt)}`
3081
3276
  }
3082
3277
  ),
3083
3278
  opt