@mediaradar/design-components 0.48.0 → 0.48.1

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
@@ -523,9 +523,15 @@ declare const CheckBoxBox: react.ForwardRefExoticComponent<CheckBoxBoxProps & re
523
523
  * e.g. to follow a person's date-format setting. What `onChange` and `onApply`
524
524
  * report keeps the canonical "Nov 14, 2026" form, since apps parse it.
525
525
  * Month-level labels ("Nov 2025") have no day to order and stay as they are.
526
- * @a11y Trigger is a <button> with aria-expanded and an aria-label from the
527
- * caption; the panel is role="dialog" and Escape closes it. Focus is not
528
- * moved into the panel, so it is reached by tabbing.
526
+ * @a11y Trigger is a <button> with aria-expanded, named by its caption and
527
+ * value; the panel is role="dialog". Escape, Cancel and Apply close it and
528
+ * put focus back on the trigger (an outside click leaves focus where it
529
+ * lands). Focus is not moved into the panel, so it is reached by tabbing.
530
+ * Each calendar day is a button named with its full date and place in the
531
+ * range ("Monday, November 3, 2026, start of range"), with aria-pressed on
532
+ * the chosen days; each month's days are a group labelled by its title, and
533
+ * the titles are polite live regions, so paging months is announced. Arrow
534
+ * keys don't move between days yet; Tab does.
529
535
  * @use for every date range in the product; `granularity="month"` for monthly data.
530
536
  * @avoid DateRangePicker, which is being retired.
531
537
  * @usage
package/dist/index.d.ts CHANGED
@@ -523,9 +523,15 @@ declare const CheckBoxBox: react.ForwardRefExoticComponent<CheckBoxBoxProps & re
523
523
  * e.g. to follow a person's date-format setting. What `onChange` and `onApply`
524
524
  * report keeps the canonical "Nov 14, 2026" form, since apps parse it.
525
525
  * Month-level labels ("Nov 2025") have no day to order and stay as they are.
526
- * @a11y Trigger is a <button> with aria-expanded and an aria-label from the
527
- * caption; the panel is role="dialog" and Escape closes it. Focus is not
528
- * moved into the panel, so it is reached by tabbing.
526
+ * @a11y Trigger is a <button> with aria-expanded, named by its caption and
527
+ * value; the panel is role="dialog". Escape, Cancel and Apply close it and
528
+ * put focus back on the trigger (an outside click leaves focus where it
529
+ * lands). Focus is not moved into the panel, so it is reached by tabbing.
530
+ * Each calendar day is a button named with its full date and place in the
531
+ * range ("Monday, November 3, 2026, start of range"), with aria-pressed on
532
+ * the chosen days; each month's days are a group labelled by its title, and
533
+ * the titles are polite live regions, so paging months is announced. Arrow
534
+ * keys don't move between days yet; Tab does.
529
535
  * @use for every date range in the product; `granularity="month"` for monthly data.
530
536
  * @avoid DateRangePicker, which is being retired.
531
537
  * @usage
package/dist/index.js CHANGED
@@ -704,6 +704,7 @@ var CREATIVE_INTEL_SHORTCUTS = [
704
704
  ];
705
705
  var HIDDEN_SHORTCUTS = ["Last 30 days"];
706
706
  var WEEKDAYS = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
707
+ var WEEKDAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
707
708
  var MONTHS = [
708
709
  "January",
709
710
  "February",
@@ -732,6 +733,14 @@ var fmtMonth = (d) => `${MONTHS[d.getMonth()].slice(0, 3)} ${d.getFullYear()}`;
732
733
  var fmt = (d) => `${MONTHS[d.getMonth()].slice(0, 3)} ${d.getDate()}, ${d.getFullYear()}`;
733
734
  var fmtFull = (d) => `${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
734
735
  var fullRangeLabel = (s, e) => `${fmtFull(s)} - ${fmtFull(e)}`;
736
+ function dayLabel(d, place) {
737
+ const base = `${WEEKDAY_NAMES[d.getDay()]}, ${fmtFull(d)}`;
738
+ if (place === "single") return `${base}, start and end of range`;
739
+ if (place === "start") return `${base}, start of range`;
740
+ if (place === "end") return `${base}, end of range`;
741
+ if (place === "in") return `${base}, in range`;
742
+ return base;
743
+ }
735
744
  var presetLabel = (sc) => sc === "Custom" ? "Custom range" : sc;
736
745
  var MON = (d) => MONTHS[d.getMonth()].slice(0, 3);
737
746
  function spanLabel(s, e) {
@@ -876,6 +885,7 @@ function DateRangeFilter({
876
885
  const [end, setEnd] = useState3(initRange[1]);
877
886
  const [leftMonth, setLeftMonth] = useState3(new Date(initRange[0].getFullYear(), initRange[0].getMonth(), 1));
878
887
  const ref = useRef3(null);
888
+ const triggerRef = useRef3(null);
879
889
  useEffect3(() => {
880
890
  if (controlled || startsEmpty) return;
881
891
  onRangeChange?.(committed.current.start, committed.current.end);
@@ -891,7 +901,11 @@ function DateRangeFilter({
891
901
  setEnd(hasRange ? committedEnd : null);
892
902
  setLeftMonth(hasRange ? new Date(committedStart.getFullYear(), committedStart.getMonth(), 1) : addMonths(today, -1));
893
903
  setCmp(committedCmp.current);
894
- const onKey = (e) => e.key === "Escape" && setOpen(false);
904
+ const onKey = (e) => {
905
+ if (e.key !== "Escape") return;
906
+ setOpen(false);
907
+ triggerRef.current?.focus();
908
+ };
895
909
  const onClick = (e) => {
896
910
  if (ref.current && !ref.current.contains(e.target)) setOpen(false);
897
911
  };
@@ -941,8 +955,10 @@ function DateRangeFilter({
941
955
  onRangeChange?.(s, e);
942
956
  onApply?.(shortcut === "Custom" ? `${fmt(s)} \u2013 ${fmt(e)}` : shortcut, s, e, cmp);
943
957
  setOpen(false);
958
+ triggerRef.current?.focus();
944
959
  };
945
960
  const popRef = useRef3(null);
961
+ const monthIdBase = useId2();
946
962
  const [flipBelow, setFlipBelow] = useState3(false);
947
963
  useLayoutEffect(() => {
948
964
  if (!open || placement !== "above" || !ref.current || !popRef.current) return;
@@ -953,6 +969,7 @@ function DateRangeFilter({
953
969
  /* @__PURE__ */ jsxs7(
954
970
  "button",
955
971
  {
972
+ ref: triggerRef,
956
973
  type: "button",
957
974
  "data-testid": testIdPrefix && `${testIdPrefix}-trigger`,
958
975
  onClick: () => setOpen((v) => !v),
@@ -1007,15 +1024,15 @@ function DateRangeFilter({
1007
1024
  return /* @__PURE__ */ jsxs7("div", { className: "w-[252px]", children: [
1008
1025
  /* @__PURE__ */ jsxs7("div", { className: "mb-2 flex items-center justify-between", children: [
1009
1026
  offset === 0 ? /* @__PURE__ */ jsx8(NavBtn, { onClick: () => setLeftMonth(addMonths(leftMonth, -1)), "aria-label": "Previous month", children: /* @__PURE__ */ jsx8(ChevronLeft, { size: 16 }) }) : /* @__PURE__ */ jsx8("span", { className: "h-7 w-7" }),
1010
- /* @__PURE__ */ jsxs7("span", { className: "text-panel-title font-semibold text-text-primary", children: [
1027
+ /* @__PURE__ */ jsxs7("span", { id: `${monthIdBase}-m${offset}`, "aria-live": "polite", className: "text-panel-title font-semibold text-text-primary", children: [
1011
1028
  MONTHS[m.getMonth()],
1012
1029
  " ",
1013
1030
  m.getFullYear()
1014
1031
  ] }),
1015
1032
  offset === 1 ? /* @__PURE__ */ jsx8(NavBtn, { onClick: () => setLeftMonth(addMonths(leftMonth, 1)), "aria-label": "Next month", children: /* @__PURE__ */ jsx8(ChevronRight, { size: 16 }) }) : /* @__PURE__ */ jsx8("span", { className: "h-7 w-7" })
1016
1033
  ] }),
1017
- /* @__PURE__ */ jsxs7("div", { className: "grid grid-cols-7", children: [
1018
- WEEKDAYS.map((w) => /* @__PURE__ */ jsx8("div", { className: "flex h-8 items-center justify-center text-xs font-semibold text-text-secondary", children: w }, w)),
1034
+ /* @__PURE__ */ jsxs7("div", { className: "grid grid-cols-7", role: "group", "aria-labelledby": `${monthIdBase}-m${offset}`, children: [
1035
+ WEEKDAYS.map((w) => /* @__PURE__ */ jsx8("div", { "aria-hidden": "true", className: "flex h-8 items-center justify-center text-xs font-semibold text-text-secondary", children: w }, w)),
1019
1036
  grid.map((d, i) => {
1020
1037
  const inMonth = d.getMonth() === m.getMonth();
1021
1038
  const hasRange = !!(start && end);
@@ -1030,16 +1047,27 @@ function DateRangeFilter({
1030
1047
  else if (end && isEnd) band = "left-0 right-1/2";
1031
1048
  else band = "left-0 right-0";
1032
1049
  }
1033
- return /* @__PURE__ */ jsxs7("button", { type: "button", onClick: () => pickDay(d), className: "relative flex h-9 items-center justify-center focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-border-focus", children: [
1034
- band && /* @__PURE__ */ jsx8("span", { className: `absolute inset-y-[3px] bg-ai-tint ${band}`, "aria-hidden": "true" }),
1035
- /* @__PURE__ */ jsx8(
1036
- "span",
1037
- {
1038
- className: `relative z-10 flex h-8 w-8 items-center justify-center rounded-full text-dense tabular-nums ${endpoint ? "bg-brand-primaryAction font-semibold text-brand-onprimary" : inMonth ? "text-text-primary hover:bg-subtle" : "text-text-tertiary"}`,
1039
- children: d.getDate()
1040
- }
1041
- )
1042
- ] }, i);
1050
+ return /* @__PURE__ */ jsxs7(
1051
+ "button",
1052
+ {
1053
+ type: "button",
1054
+ onClick: () => pickDay(d),
1055
+ "aria-label": dayLabel(d, single ? "single" : isStart ? "start" : end && isEnd ? "end" : inRange ? "in" : null),
1056
+ "aria-pressed": endpoint || inRange,
1057
+ className: "relative flex h-9 items-center justify-center focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-border-focus",
1058
+ children: [
1059
+ band && /* @__PURE__ */ jsx8("span", { className: `absolute inset-y-[3px] bg-ai-tint ${band}`, "aria-hidden": "true" }),
1060
+ /* @__PURE__ */ jsx8(
1061
+ "span",
1062
+ {
1063
+ className: `relative z-10 flex h-8 w-8 items-center justify-center rounded-full text-dense tabular-nums ${endpoint ? "bg-brand-primaryAction font-semibold text-brand-onprimary" : inMonth ? "text-text-primary hover:bg-subtle" : "text-text-tertiary"}`,
1064
+ children: d.getDate()
1065
+ }
1066
+ )
1067
+ ]
1068
+ },
1069
+ i
1070
+ );
1043
1071
  })
1044
1072
  ] })
1045
1073
  ] }, offset);
@@ -1075,7 +1103,10 @@ function DateRangeFilter({
1075
1103
  ] }),
1076
1104
  /* @__PURE__ */ jsxs7("div", { className: "mt-4 flex items-center justify-end gap-2", children: [
1077
1105
  monthly && /* @__PURE__ */ jsx8("span", { className: "mr-auto text-xs text-text-tertiary", children: "Data is monthly, so ranges cover whole months." }),
1078
- /* @__PURE__ */ jsx8("button", { type: "button", "data-testid": testIdPrefix && `${testIdPrefix}-cancel`, onClick: () => setOpen(false), className: "rounded-control border border-border-default bg-surface px-5 py-2 text-dense font-semibold text-text-primary transition-colors hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-border-focus", children: "Cancel" }),
1106
+ /* @__PURE__ */ jsx8("button", { type: "button", "data-testid": testIdPrefix && `${testIdPrefix}-cancel`, onClick: () => {
1107
+ setOpen(false);
1108
+ triggerRef.current?.focus();
1109
+ }, className: "rounded-control border border-border-default bg-surface px-5 py-2 text-dense font-semibold text-text-primary transition-colors hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-border-focus", children: "Cancel" }),
1079
1110
  /* @__PURE__ */ jsx8("button", { type: "button", "data-testid": testIdPrefix && `${testIdPrefix}-apply`, onClick: apply, disabled: !canApply, className: "rounded-control bg-brand-primaryAction px-5 py-2 text-dense font-semibold text-brand-onprimary transition-[filter] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-border-focus", children: "Apply" })
1080
1111
  ] })
1081
1112
  ] })