@mediaradar/design-components 0.43.0 → 0.44.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.d.cts CHANGED
@@ -872,12 +872,17 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
872
872
  * @use for picking one value from a short list in a filter row or a form --
873
873
  * the caption-over-value chip is the one dropdown trigger.
874
874
  * @use the caption everywhere except tight spots where the field is obvious.
875
+ * @use `size="sm"` (32px) for a control in a card or panel header (a card's
876
+ * Measure or Compare by), with `inlineCaption` when the value alone doesn't
877
+ * say what it sets ("Sort by: Name"). There is no 36px step.
878
+ * @avoid a hand-built 36px "slim" chip; use `sm`.
875
879
  * @avoid a native <select> or a hand-built dropdown.
876
880
  * @avoid it for several values at once -- that's MultiSelectFilter.
877
881
  * @usage
878
882
  * ```tsx
879
883
  * <SelectFilter caption="Rank" value={rankFilter} onChange={setRankFilter} options={['All', 'VP / Director', 'Manager', 'Coordinator']} />
880
884
  * <SelectFilter caption="Group by" value={groupBy} onChange={setGroupBy} options={['Parent', 'Advertiser', 'Brand']} fullWidth testIdPrefix="dropdown-group-by" />
885
+ * <SelectFilter caption="Sort by" size="sm" inlineCaption value={sort} onChange={setSort} options={['Name', 'Spend']} align="right" />
881
886
  * <SelectFilter caption="Country" value={country} onChange={setCountry} options={['United States', 'Canada', 'United Kingdom']} renderIcon={(c) => <img src={FLAGS[c]} alt="" />} />
882
887
  * ```
883
888
  */
@@ -915,6 +920,12 @@ interface SelectFilterProps {
915
920
  * control in TablePagination. Defaults to 'md', the 44px caption chip.
916
921
  */
917
922
  size?: "md" | "sm";
923
+ /**
924
+ * With `size="sm"`: show the caption in the trigger, "Sort by: Name",
925
+ * instead of only the value. For a compact control whose value alone
926
+ * doesn't say what it sets.
927
+ */
928
+ inlineCaption?: boolean;
918
929
  /** Fades the trigger to 40% and blocks it, e.g. while a table loads. */
919
930
  disabled?: boolean;
920
931
  /**
@@ -926,7 +937,7 @@ interface SelectFilterProps {
926
937
  */
927
938
  renderIcon?: (option: string) => ReactNode;
928
939
  }
929
- declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
940
+ declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, inlineCaption, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
930
941
 
931
942
  /**
932
943
  * @pattern Card
@@ -2438,15 +2449,22 @@ interface MultiSelectGroup {
2438
2449
  * Escape closes it. Option rows carry their own checkbox semantics. Focus
2439
2450
  * is not moved into the menu on open, so keyboard users tab into it in DOM
2440
2451
  * order. The loading rows carry role="status" and the error line role="alert".
2452
+ * @behavior `valueLabel` replaces the trigger's value text, for when a picked
2453
+ * option's own label is ambiguous outside its group ("All" for a market
2454
+ * filter where nothing and everything mean the same). `hints` puts a short
2455
+ * definition under an option's label, keyed by option or group id, for a term
2456
+ * the user may not know. `note` is one line of explanation under the list.
2441
2457
  * @behavior `loading` swaps the list for grey placeholder rows and `error`
2442
2458
  * for a plain "Couldn't load options." line with a Try again link
2443
2459
  * (`onRetry`). The trigger never changes in either state.
2444
2460
  * @usage
2445
2461
  * ```tsx
2446
2462
  * <MultiSelectFilter caption="Media" options={mediaOptions} selected={selected} onChange={setSelected} />
2463
+ * <MultiSelectFilter caption="Market" options={markets} selected={selected} onChange={setSelected}
2464
+ * hints={{ national: "Ads that run nationwide" }} note="Nothing picked means every market." />
2447
2465
  * ```
2448
2466
  */
2449
- declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, }: {
2467
+ declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, valueLabel, hints, note, }: {
2450
2468
  caption: string;
2451
2469
  /**
2452
2470
  * Live option-id -> result count. Supplying it makes the menu faceted:
@@ -2496,6 +2514,14 @@ declare function MultiSelectFilter({ caption, options, groups, counts, variant,
2496
2514
  error?: boolean;
2497
2515
  /** Called by the Try again link in the error state. */
2498
2516
  onRetry?: () => void;
2517
+ /** Trigger text in place of the default ("All", the one label, "n selected"),
2518
+ * when a picked option's own label is ambiguous outside its group. */
2519
+ valueLabel?: string;
2520
+ /** A short definition under an option's label, by option or group id, for a
2521
+ * term the user may not know. */
2522
+ hints?: Record<string, string>;
2523
+ /** One line of explanation under the list, above the footer. */
2524
+ note?: React.ReactNode;
2499
2525
  }): react.JSX.Element;
2500
2526
  type MultiSelectFilterProps = Parameters<typeof MultiSelectFilter>[0];
2501
2527
 
package/dist/index.d.ts CHANGED
@@ -872,12 +872,17 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
872
872
  * @use for picking one value from a short list in a filter row or a form --
873
873
  * the caption-over-value chip is the one dropdown trigger.
874
874
  * @use the caption everywhere except tight spots where the field is obvious.
875
+ * @use `size="sm"` (32px) for a control in a card or panel header (a card's
876
+ * Measure or Compare by), with `inlineCaption` when the value alone doesn't
877
+ * say what it sets ("Sort by: Name"). There is no 36px step.
878
+ * @avoid a hand-built 36px "slim" chip; use `sm`.
875
879
  * @avoid a native <select> or a hand-built dropdown.
876
880
  * @avoid it for several values at once -- that's MultiSelectFilter.
877
881
  * @usage
878
882
  * ```tsx
879
883
  * <SelectFilter caption="Rank" value={rankFilter} onChange={setRankFilter} options={['All', 'VP / Director', 'Manager', 'Coordinator']} />
880
884
  * <SelectFilter caption="Group by" value={groupBy} onChange={setGroupBy} options={['Parent', 'Advertiser', 'Brand']} fullWidth testIdPrefix="dropdown-group-by" />
885
+ * <SelectFilter caption="Sort by" size="sm" inlineCaption value={sort} onChange={setSort} options={['Name', 'Spend']} align="right" />
881
886
  * <SelectFilter caption="Country" value={country} onChange={setCountry} options={['United States', 'Canada', 'United Kingdom']} renderIcon={(c) => <img src={FLAGS[c]} alt="" />} />
882
887
  * ```
883
888
  */
@@ -915,6 +920,12 @@ interface SelectFilterProps {
915
920
  * control in TablePagination. Defaults to 'md', the 44px caption chip.
916
921
  */
917
922
  size?: "md" | "sm";
923
+ /**
924
+ * With `size="sm"`: show the caption in the trigger, "Sort by: Name",
925
+ * instead of only the value. For a compact control whose value alone
926
+ * doesn't say what it sets.
927
+ */
928
+ inlineCaption?: boolean;
918
929
  /** Fades the trigger to 40% and blocks it, e.g. while a table loads. */
919
930
  disabled?: boolean;
920
931
  /**
@@ -926,7 +937,7 @@ interface SelectFilterProps {
926
937
  */
927
938
  renderIcon?: (option: string) => ReactNode;
928
939
  }
929
- declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
940
+ declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, inlineCaption, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
930
941
 
931
942
  /**
932
943
  * @pattern Card
@@ -2438,15 +2449,22 @@ interface MultiSelectGroup {
2438
2449
  * Escape closes it. Option rows carry their own checkbox semantics. Focus
2439
2450
  * is not moved into the menu on open, so keyboard users tab into it in DOM
2440
2451
  * order. The loading rows carry role="status" and the error line role="alert".
2452
+ * @behavior `valueLabel` replaces the trigger's value text, for when a picked
2453
+ * option's own label is ambiguous outside its group ("All" for a market
2454
+ * filter where nothing and everything mean the same). `hints` puts a short
2455
+ * definition under an option's label, keyed by option or group id, for a term
2456
+ * the user may not know. `note` is one line of explanation under the list.
2441
2457
  * @behavior `loading` swaps the list for grey placeholder rows and `error`
2442
2458
  * for a plain "Couldn't load options." line with a Try again link
2443
2459
  * (`onRetry`). The trigger never changes in either state.
2444
2460
  * @usage
2445
2461
  * ```tsx
2446
2462
  * <MultiSelectFilter caption="Media" options={mediaOptions} selected={selected} onChange={setSelected} />
2463
+ * <MultiSelectFilter caption="Market" options={markets} selected={selected} onChange={setSelected}
2464
+ * hints={{ national: "Ads that run nationwide" }} note="Nothing picked means every market." />
2447
2465
  * ```
2448
2466
  */
2449
- declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, }: {
2467
+ declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, valueLabel, hints, note, }: {
2450
2468
  caption: string;
2451
2469
  /**
2452
2470
  * Live option-id -> result count. Supplying it makes the menu faceted:
@@ -2496,6 +2514,14 @@ declare function MultiSelectFilter({ caption, options, groups, counts, variant,
2496
2514
  error?: boolean;
2497
2515
  /** Called by the Try again link in the error state. */
2498
2516
  onRetry?: () => void;
2517
+ /** Trigger text in place of the default ("All", the one label, "n selected"),
2518
+ * when a picked option's own label is ambiguous outside its group. */
2519
+ valueLabel?: string;
2520
+ /** A short definition under an option's label, by option or group id, for a
2521
+ * term the user may not know. */
2522
+ hints?: Record<string, string>;
2523
+ /** One line of explanation under the list, above the footer. */
2524
+ note?: React.ReactNode;
2499
2525
  }): react.JSX.Element;
2500
2526
  type MultiSelectFilterProps = Parameters<typeof MultiSelectFilter>[0];
2501
2527
 
package/dist/index.js CHANGED
@@ -1817,6 +1817,7 @@ function SelectFilter({
1817
1817
  error = false,
1818
1818
  onRetry,
1819
1819
  size = "md",
1820
+ inlineCaption = false,
1820
1821
  disabled = false,
1821
1822
  renderIcon
1822
1823
  }) {
@@ -1831,7 +1832,11 @@ function SelectFilter({
1831
1832
  const r = ref.current.getBoundingClientRect();
1832
1833
  const h = Math.min(options.length * 36 + 8, 288);
1833
1834
  const above = r.bottom + 8 + h > window.innerHeight && r.top - 8 - h > 0;
1834
- setPos({ top: above ? r.top - 8 - h : r.bottom + 8, left: align === "right" ? r.right - r.width : r.left, width: r.width });
1835
+ setPos({
1836
+ top: above ? r.top - 8 - h : r.bottom + 8,
1837
+ ...align === "right" ? { right: document.documentElement.clientWidth - r.right } : { left: r.left },
1838
+ width: r.width
1839
+ });
1835
1840
  }, [align, options.length]);
1836
1841
  useLayoutEffect3(() => {
1837
1842
  if (!open) return;
@@ -1856,10 +1861,18 @@ function SelectFilter({
1856
1861
  window.removeEventListener("scroll", reposition, true);
1857
1862
  };
1858
1863
  }, [open, close, reposition]);
1859
- const triggerValue = renderIcon ? /* @__PURE__ */ jsxs12("span", { className: "flex items-center gap-1.5", children: [
1864
+ const valueContent = renderIcon ? /* @__PURE__ */ jsxs12("span", { className: "flex items-center gap-1.5", children: [
1860
1865
  /* @__PURE__ */ jsx13(OptionIcon, { children: renderIcon(value) }),
1861
1866
  value
1862
1867
  ] }) : value;
1868
+ const triggerValue = sm && inlineCaption ? /* @__PURE__ */ jsxs12("span", { children: [
1869
+ /* @__PURE__ */ jsxs12("span", { className: "font-normal text-text-secondary", children: [
1870
+ caption,
1871
+ ":"
1872
+ ] }),
1873
+ " ",
1874
+ valueContent
1875
+ ] }) : valueContent;
1863
1876
  return /* @__PURE__ */ jsxs12("div", { className: cx4("relative", fullWidth && "w-full"), ref, children: [
1864
1877
  /* @__PURE__ */ jsxs12(
1865
1878
  "button",
@@ -1869,7 +1882,7 @@ function SelectFilter({
1869
1882
  onClick: () => setOpen((o) => !o),
1870
1883
  "aria-expanded": open,
1871
1884
  "aria-haspopup": "listbox",
1872
- "aria-label": sm ? caption : void 0,
1885
+ "aria-label": sm && !inlineCaption ? caption : void 0,
1873
1886
  disabled,
1874
1887
  className: cx4(
1875
1888
  sm ? "flex h-8 items-center gap-1.5 rounded-control border border-border-strong bg-input pl-2.5 pr-2 text-dense font-medium text-text-primary transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-border-focus" : chipTriggerClass(),
@@ -1896,10 +1909,10 @@ function SelectFilter({
1896
1909
  {
1897
1910
  ref: popoverRef,
1898
1911
  "data-testid": testIdPrefix && `${testIdPrefix}-popover`,
1899
- style: { position: "fixed", top: pos.top, left: pos.left, width: fullWidth ? pos.width : void 0 },
1912
+ style: { position: "fixed", top: pos.top, left: pos.left, right: pos.right, width: fullWidth ? pos.width : void 0 },
1900
1913
  className: cx4(
1901
1914
  "z-[65] flex flex-col overflow-hidden rounded-card border border-border-default bg-surface shadow-overlay",
1902
- !fullWidth && (sm ? "w-28" : "w-56")
1915
+ !fullWidth && (sm ? "w-max min-w-28 max-w-72" : "w-56")
1903
1916
  ),
1904
1917
  role: loading || error ? "group" : "listbox",
1905
1918
  "aria-label": caption,
@@ -4169,7 +4182,10 @@ function MultiSelectFilter({
4169
4182
  fullWidth = false,
4170
4183
  loading = false,
4171
4184
  error = false,
4172
- onRetry
4185
+ onRetry,
4186
+ valueLabel,
4187
+ hints,
4188
+ note
4173
4189
  }) {
4174
4190
  const groupLeaves = (g) => g.children.length ? g.children : [{ id: g.id, label: g.label }];
4175
4191
  const leafOptions = groups ? groups.flatMap(groupLeaves) : options;
@@ -4230,7 +4246,11 @@ function MultiSelectFilter({
4230
4246
  };
4231
4247
  const shown = open && !showFooter ? draft : selected;
4232
4248
  const isAll = shown.length === 0 || fullIsAll && shown.length === leafOptions.length;
4233
- const value = isAll ? allLabel : shown.length === 1 ? leafOptions.find((o) => o.id === shown[0])?.label ?? `${shown.length} selected` : `${shown.length} selected`;
4249
+ const value = valueLabel ?? (isAll ? allLabel : shown.length === 1 ? leafOptions.find((o) => o.id === shown[0])?.label ?? `${shown.length} selected` : `${shown.length} selected`);
4250
+ const labelled = (id, label) => hints?.[id] ? /* @__PURE__ */ jsxs36("span", { className: "flex flex-col", children: [
4251
+ /* @__PURE__ */ jsx40("span", { children: label }),
4252
+ /* @__PURE__ */ jsx40("span", { className: "text-xs font-normal text-text-tertiary", children: hints[id] })
4253
+ ] }) : label;
4234
4254
  const ql = q.trim().toLowerCase();
4235
4255
  const items = options.filter((o) => isAvailable(o.id) && (!ql || o.label.toLowerCase().includes(ql)));
4236
4256
  const visibleGroups = groups ? groups.map((g) => {
@@ -4298,7 +4318,7 @@ function MultiSelectFilter({
4298
4318
  className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
4299
4319
  children: [
4300
4320
  /* @__PURE__ */ jsx40(CheckBoxBox, { checked: state === "all", indeterminate: state === "some" }),
4301
- /* @__PURE__ */ jsx40("span", { className: cn("flex-1 text-[14px] text-text-primary", !plainParent && "font-semibold"), children: g.label }),
4321
+ /* @__PURE__ */ jsx40("span", { className: cn("flex-1 text-[14px] text-text-primary", !plainParent && "font-semibold"), children: labelled(g.id, g.label) }),
4302
4322
  counts && /* @__PURE__ */ jsx40(OptionCount, { n: countFor(g.id) })
4303
4323
  ]
4304
4324
  }
@@ -4313,7 +4333,7 @@ function MultiSelectFilter({
4313
4333
  className: "flex w-full items-center gap-2.5 rounded-control py-2 pl-9 pr-2 text-left transition-colors hover:bg-subtle",
4314
4334
  children: [
4315
4335
  /* @__PURE__ */ jsx40(CheckBoxBox, { checked }),
4316
- /* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: c.label }),
4336
+ /* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: labelled(c.id, c.label) }),
4317
4337
  counts && /* @__PURE__ */ jsx40(OptionCount, { n: countFor(c.id) })
4318
4338
  ]
4319
4339
  },
@@ -4331,7 +4351,7 @@ function MultiSelectFilter({
4331
4351
  className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
4332
4352
  children: [
4333
4353
  /* @__PURE__ */ jsx40(CheckBoxBox, { checked }),
4334
- /* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: o.label }),
4354
+ /* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: labelled(o.id, o.label) }),
4335
4355
  counts && /* @__PURE__ */ jsx40(OptionCount, { n: countFor(o.id) })
4336
4356
  ]
4337
4357
  },
@@ -4340,6 +4360,7 @@ function MultiSelectFilter({
4340
4360
  }),
4341
4361
  (groups && !visibleGroups.length || !groups && !items.length) && /* @__PURE__ */ jsx40("div", { className: "py-6 text-center text-[13px] text-text-tertiary", children: "No matches." })
4342
4362
  ] }),
4363
+ note && /* @__PURE__ */ jsx40("p", { className: "border-t border-border-default px-3 py-2 text-xs text-text-tertiary", children: note }),
4343
4364
  showFooter ? /* @__PURE__ */ jsx40(FilterDropdownFooter, { onClear: () => setDraft(clearValue), onApply: apply }) : min === 0 && draft.length > 0 && /* @__PURE__ */ jsx40("div", { className: "border-t border-border-default p-2", children: /* @__PURE__ */ jsxs36(
4344
4365
  "button",
4345
4366
  {