@mediaradar/design-components 0.39.0 → 0.40.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/approved-components.json +1 -1
- package/dist/index.cjs +55 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -12
- package/dist/index.d.ts +35 -12
- package/dist/index.js +69 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -245,6 +245,16 @@ function cx(...parts) {
|
|
|
245
245
|
return parts.filter(Boolean).join(" ");
|
|
246
246
|
}
|
|
247
247
|
var SELECT_ALL_THRESHOLD = 5;
|
|
248
|
+
function usePaging(total, pageSize, resetKey) {
|
|
249
|
+
const [pages, setPages] = (0, import_react2.useState)(1);
|
|
250
|
+
const [prevKey, setPrevKey] = (0, import_react2.useState)(resetKey);
|
|
251
|
+
if (prevKey !== resetKey) {
|
|
252
|
+
setPrevKey(resetKey);
|
|
253
|
+
setPages(1);
|
|
254
|
+
}
|
|
255
|
+
const shown = pageSize && pageSize > 0 ? Math.min(total, pages * pageSize) : total;
|
|
256
|
+
return { shown, remaining: total - shown, showMore: () => setPages((p) => p + 1) };
|
|
257
|
+
}
|
|
248
258
|
function slug(value) {
|
|
249
259
|
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
250
260
|
}
|
|
@@ -258,6 +268,8 @@ function AdvertiserQuickFilter({
|
|
|
258
268
|
showFooter = false,
|
|
259
269
|
clearValue = [],
|
|
260
270
|
parked = [],
|
|
271
|
+
prepopulate = false,
|
|
272
|
+
pageSize,
|
|
261
273
|
searchPlaceholder = "Search for an advertiser",
|
|
262
274
|
promptLabel = "an advertiser name",
|
|
263
275
|
noResultsHint = "Try checking your spelling or searching for a broader brand name.",
|
|
@@ -312,10 +324,28 @@ function AdvertiserQuickFilter({
|
|
|
312
324
|
() => draft.map((id) => options.find((o) => o.id === id)).filter(Boolean),
|
|
313
325
|
[draft, options]
|
|
314
326
|
);
|
|
315
|
-
const
|
|
316
|
-
() => ql ? options.filter((o) => !draft.includes(o.id) && o.label.toLowerCase().includes(ql)) : [],
|
|
317
|
-
[ql, options, draft]
|
|
327
|
+
const matches = (0, import_react2.useMemo)(
|
|
328
|
+
() => ql || prepopulate ? options.filter((o) => !draft.includes(o.id) && (!ql || o.label.toLowerCase().includes(ql))) : [],
|
|
329
|
+
[ql, prepopulate, options, draft]
|
|
318
330
|
);
|
|
331
|
+
const { shown: pageEnd, remaining, showMore } = usePaging(
|
|
332
|
+
matches.length,
|
|
333
|
+
prepopulate ? pageSize : void 0,
|
|
334
|
+
`${open}|${ql}`
|
|
335
|
+
);
|
|
336
|
+
const results = (0, import_react2.useMemo)(() => matches.slice(0, pageEnd), [matches, pageEnd]);
|
|
337
|
+
const resultsRef = (0, import_react2.useRef)(null);
|
|
338
|
+
const focusFrom = (0, import_react2.useRef)(null);
|
|
339
|
+
const loadMore = () => {
|
|
340
|
+
focusFrom.current = results.length;
|
|
341
|
+
showMore();
|
|
342
|
+
};
|
|
343
|
+
(0, import_react2.useEffect)(() => {
|
|
344
|
+
const from = focusFrom.current;
|
|
345
|
+
if (from === null) return;
|
|
346
|
+
focusFrom.current = null;
|
|
347
|
+
resultsRef.current?.querySelectorAll('[role="checkbox"]')[from]?.focus();
|
|
348
|
+
}, [pageEnd]);
|
|
319
349
|
const visibleIds = results.map((o) => o.id);
|
|
320
350
|
const allVisibleSelected = visibleIds.length > 0 && visibleIds.every((id) => draft.includes(id));
|
|
321
351
|
const toggleAllVisible = () => setDraft(
|
|
@@ -421,14 +451,18 @@ function AdvertiserQuickFilter({
|
|
|
421
451
|
o.id
|
|
422
452
|
)) })
|
|
423
453
|
] }),
|
|
424
|
-
|
|
454
|
+
prepopulate && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { role: "status", className: "sr-only", "data-testid": testIdPrefix && `${testIdPrefix}-result-count`, children: [
|
|
455
|
+
matches.length === 1 ? "1 result" : `${matches.length} results`,
|
|
456
|
+
remaining > 0 ? `, showing ${results.length}` : ""
|
|
457
|
+
] }),
|
|
458
|
+
!ql && !prepopulate ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AdvertiserSearchPrompt, { label: promptLabel }) : !ql && results.length === 0 ? null : results.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col items-center gap-1.5 px-4 py-8 text-center", children: [
|
|
425
459
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "text-[13px] font-medium text-text-primary", children: [
|
|
426
460
|
"No results found for \u201C",
|
|
427
461
|
q.trim(),
|
|
428
462
|
"\u201D"
|
|
429
463
|
] }),
|
|
430
464
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "text-[12px] leading-snug text-text-tertiary", children: noResultsHint })
|
|
431
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
465
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: resultsRef, children: [
|
|
432
466
|
results.length > SELECT_ALL_THRESHOLD && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
433
467
|
"button",
|
|
434
468
|
{
|
|
@@ -451,7 +485,22 @@ function AdvertiserQuickFilter({
|
|
|
451
485
|
testId: testIdPrefix && `${testIdPrefix}-option-${slug(o.id)}`
|
|
452
486
|
},
|
|
453
487
|
o.id
|
|
454
|
-
))
|
|
488
|
+
)),
|
|
489
|
+
remaining > 0 && !!pageSize && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
490
|
+
"button",
|
|
491
|
+
{
|
|
492
|
+
type: "button",
|
|
493
|
+
"data-testid": testIdPrefix && `${testIdPrefix}-show-more`,
|
|
494
|
+
onClick: loadMore,
|
|
495
|
+
className: "flex w-full items-center gap-1.5 rounded-control px-2 py-2 text-left text-xs font-semibold text-text-link transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus",
|
|
496
|
+
children: [
|
|
497
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react3.Plus, { size: 13, "aria-hidden": "true" }),
|
|
498
|
+
"Show ",
|
|
499
|
+
Math.min(remaining, pageSize),
|
|
500
|
+
" more"
|
|
501
|
+
]
|
|
502
|
+
}
|
|
503
|
+
)
|
|
455
504
|
] })
|
|
456
505
|
] }),
|
|
457
506
|
showFooter ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center justify-between border-t border-border-default px-3 py-2.5", children: [
|