@mediaradar/design-components 0.26.1 → 0.30.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
@@ -681,11 +681,19 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
681
681
  * `onChange` ever fires, so nothing would ever get selected. Selecting an
682
682
  * option commits immediately and closes -- there's no separate draft/Apply
683
683
  * step; Escape and outside-click just close without side effects.
684
+ * `renderIcon`, when given, puts a small image before each option's label and
685
+ * before the value in the trigger -- a country flag, say. Each icon sits in a
686
+ * fixed 16x12 slot between the check column and the label, so labels stay
687
+ * aligned even when an option's icon is missing (`renderIcon` returning null).
688
+ * Without `renderIcon` nothing changes: no slot, no extra space.
684
689
  * @a11y Trigger is a <button>; the popover is role="listbox" with role="option"
685
690
  * rows carrying aria-selected. The trigger owns the accessible name via
686
691
  * the caption. The popover is not a focus trap and does not move focus on
687
692
  * open, so keyboard users tab into it; a consumer rendering it inside
688
693
  * another dismissible layer has to sequence the two dismissals itself.
694
+ * Icons from `renderIcon` are wrapped aria-hidden, so each option's accessible
695
+ * name stays its label text -- don't put meaning in the icon that the label
696
+ * doesn't also say.
689
697
  * @use for picking one value from a short list in a filter row or a form --
690
698
  * the caption-over-value chip is the one dropdown trigger.
691
699
  * @use the caption everywhere except tight spots where the field is obvious.
@@ -695,6 +703,7 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
695
703
  * ```tsx
696
704
  * <SelectFilter caption="Rank" value={rankFilter} onChange={setRankFilter} options={['All', 'VP / Director', 'Manager', 'Coordinator']} />
697
705
  * <SelectFilter caption="Group by" value={groupBy} onChange={setGroupBy} options={['Parent', 'Advertiser', 'Brand']} fullWidth testIdPrefix="dropdown-group-by" />
706
+ * <SelectFilter caption="Country" value={country} onChange={setCountry} options={['United States', 'Canada', 'United Kingdom']} renderIcon={(c) => <img src={FLAGS[c]} alt="" />} />
698
707
  * ```
699
708
  */
700
709
  interface SelectFilterProps {
@@ -719,8 +728,16 @@ interface SelectFilterProps {
719
728
  * to this shared component's ids rather than losing its locators outright.
720
729
  */
721
730
  testIdPrefix?: string;
731
+ /**
732
+ * Optional leading icon for each option, called with the option's string.
733
+ * Shown before the label in the list and before the value in the trigger,
734
+ * in a fixed 16x12 slot sized for a country flag (larger images are scaled
735
+ * down to fit). Decorative only -- it's rendered aria-hidden. Return null
736
+ * for an option with no icon; its label still lines up with the others.
737
+ */
738
+ renderIcon?: (option: string) => ReactNode;
722
739
  }
723
- declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, }: SelectFilterProps): react.JSX.Element;
740
+ declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, renderIcon, }: SelectFilterProps): react.JSX.Element;
724
741
 
725
742
  /**
726
743
  * @pattern Card
package/dist/index.d.ts CHANGED
@@ -681,11 +681,19 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
681
681
  * `onChange` ever fires, so nothing would ever get selected. Selecting an
682
682
  * option commits immediately and closes -- there's no separate draft/Apply
683
683
  * step; Escape and outside-click just close without side effects.
684
+ * `renderIcon`, when given, puts a small image before each option's label and
685
+ * before the value in the trigger -- a country flag, say. Each icon sits in a
686
+ * fixed 16x12 slot between the check column and the label, so labels stay
687
+ * aligned even when an option's icon is missing (`renderIcon` returning null).
688
+ * Without `renderIcon` nothing changes: no slot, no extra space.
684
689
  * @a11y Trigger is a <button>; the popover is role="listbox" with role="option"
685
690
  * rows carrying aria-selected. The trigger owns the accessible name via
686
691
  * the caption. The popover is not a focus trap and does not move focus on
687
692
  * open, so keyboard users tab into it; a consumer rendering it inside
688
693
  * another dismissible layer has to sequence the two dismissals itself.
694
+ * Icons from `renderIcon` are wrapped aria-hidden, so each option's accessible
695
+ * name stays its label text -- don't put meaning in the icon that the label
696
+ * doesn't also say.
689
697
  * @use for picking one value from a short list in a filter row or a form --
690
698
  * the caption-over-value chip is the one dropdown trigger.
691
699
  * @use the caption everywhere except tight spots where the field is obvious.
@@ -695,6 +703,7 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
695
703
  * ```tsx
696
704
  * <SelectFilter caption="Rank" value={rankFilter} onChange={setRankFilter} options={['All', 'VP / Director', 'Manager', 'Coordinator']} />
697
705
  * <SelectFilter caption="Group by" value={groupBy} onChange={setGroupBy} options={['Parent', 'Advertiser', 'Brand']} fullWidth testIdPrefix="dropdown-group-by" />
706
+ * <SelectFilter caption="Country" value={country} onChange={setCountry} options={['United States', 'Canada', 'United Kingdom']} renderIcon={(c) => <img src={FLAGS[c]} alt="" />} />
698
707
  * ```
699
708
  */
700
709
  interface SelectFilterProps {
@@ -719,8 +728,16 @@ interface SelectFilterProps {
719
728
  * to this shared component's ids rather than losing its locators outright.
720
729
  */
721
730
  testIdPrefix?: string;
731
+ /**
732
+ * Optional leading icon for each option, called with the option's string.
733
+ * Shown before the label in the list and before the value in the trigger,
734
+ * in a fixed 16x12 slot sized for a country flag (larger images are scaled
735
+ * down to fit). Decorative only -- it's rendered aria-hidden. Return null
736
+ * for an option with no icon; its label still lines up with the others.
737
+ */
738
+ renderIcon?: (option: string) => ReactNode;
722
739
  }
723
- declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, }: SelectFilterProps): react.JSX.Element;
740
+ declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, renderIcon, }: SelectFilterProps): react.JSX.Element;
724
741
 
725
742
  /**
726
743
  * @pattern Card
package/dist/index.js CHANGED
@@ -1413,6 +1413,16 @@ function cx4(...classes) {
1413
1413
  function slug3(value) {
1414
1414
  return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
1415
1415
  }
1416
+ function OptionIcon({ children }) {
1417
+ return /* @__PURE__ */ jsx11(
1418
+ "span",
1419
+ {
1420
+ "aria-hidden": "true",
1421
+ className: "flex h-3 w-4 shrink-0 items-center justify-center overflow-hidden text-text-secondary *:max-h-full *:max-w-full",
1422
+ children
1423
+ }
1424
+ );
1425
+ }
1416
1426
  function SelectFilter({
1417
1427
  caption,
1418
1428
  value,
@@ -1421,7 +1431,8 @@ function SelectFilter({
1421
1431
  align = "left",
1422
1432
  fullWidth = false,
1423
1433
  className,
1424
- testIdPrefix
1434
+ testIdPrefix,
1435
+ renderIcon
1425
1436
  }) {
1426
1437
  const [open, setOpen] = useState6(false);
1427
1438
  const [pos, setPos] = useState6(null);
@@ -1456,6 +1467,7 @@ function SelectFilter({
1456
1467
  window.removeEventListener("scroll", reposition, true);
1457
1468
  };
1458
1469
  }, [open, close, reposition]);
1470
+ const valueText = /* @__PURE__ */ jsx11("span", { className: "text-[12px] font-medium text-text-primary", children: value });
1459
1471
  return /* @__PURE__ */ jsxs10("div", { className: cx4("relative", fullWidth && "w-full"), ref, children: [
1460
1472
  /* @__PURE__ */ jsxs10(
1461
1473
  "button",
@@ -1473,7 +1485,10 @@ function SelectFilter({
1473
1485
  children: [
1474
1486
  /* @__PURE__ */ jsxs10("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
1475
1487
  /* @__PURE__ */ jsx11("span", { className: "text-control-caption uppercase tracking-wide text-text-tertiary", children: caption }),
1476
- /* @__PURE__ */ jsx11("span", { className: "text-[12px] font-medium text-text-primary", children: value })
1488
+ renderIcon ? /* @__PURE__ */ jsxs10("span", { className: "flex items-center gap-1.5", children: [
1489
+ /* @__PURE__ */ jsx11(OptionIcon, { children: renderIcon(value) }),
1490
+ valueText
1491
+ ] }) : valueText
1477
1492
  ] }),
1478
1493
  /* @__PURE__ */ jsx11(
1479
1494
  ChevronDown5,
@@ -1515,6 +1530,7 @@ function SelectFilter({
1515
1530
  className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
1516
1531
  children: [
1517
1532
  /* @__PURE__ */ jsx11("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center text-brand-primaryAction", children: selected && /* @__PURE__ */ jsx11(Check5, { size: 15, strokeWidth: 3 }) }),
1533
+ renderIcon && /* @__PURE__ */ jsx11(OptionIcon, { children: renderIcon(o) }),
1518
1534
  /* @__PURE__ */ jsx11(
1519
1535
  "span",
1520
1536
  {