@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/approved-components.json +1 -1
- package/dist/index.cjs +46 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +46 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -795,6 +795,7 @@ var CREATIVE_INTEL_SHORTCUTS = [
|
|
|
795
795
|
];
|
|
796
796
|
var HIDDEN_SHORTCUTS = ["Last 30 days"];
|
|
797
797
|
var WEEKDAYS = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
|
798
|
+
var WEEKDAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
798
799
|
var MONTHS = [
|
|
799
800
|
"January",
|
|
800
801
|
"February",
|
|
@@ -823,6 +824,14 @@ var fmtMonth = (d) => `${MONTHS[d.getMonth()].slice(0, 3)} ${d.getFullYear()}`;
|
|
|
823
824
|
var fmt = (d) => `${MONTHS[d.getMonth()].slice(0, 3)} ${d.getDate()}, ${d.getFullYear()}`;
|
|
824
825
|
var fmtFull = (d) => `${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
|
|
825
826
|
var fullRangeLabel = (s, e) => `${fmtFull(s)} - ${fmtFull(e)}`;
|
|
827
|
+
function dayLabel(d, place) {
|
|
828
|
+
const base = `${WEEKDAY_NAMES[d.getDay()]}, ${fmtFull(d)}`;
|
|
829
|
+
if (place === "single") return `${base}, start and end of range`;
|
|
830
|
+
if (place === "start") return `${base}, start of range`;
|
|
831
|
+
if (place === "end") return `${base}, end of range`;
|
|
832
|
+
if (place === "in") return `${base}, in range`;
|
|
833
|
+
return base;
|
|
834
|
+
}
|
|
826
835
|
var presetLabel = (sc) => sc === "Custom" ? "Custom range" : sc;
|
|
827
836
|
var MON = (d) => MONTHS[d.getMonth()].slice(0, 3);
|
|
828
837
|
function spanLabel(s, e) {
|
|
@@ -967,6 +976,7 @@ function DateRangeFilter({
|
|
|
967
976
|
const [end, setEnd] = (0, import_react4.useState)(initRange[1]);
|
|
968
977
|
const [leftMonth, setLeftMonth] = (0, import_react4.useState)(new Date(initRange[0].getFullYear(), initRange[0].getMonth(), 1));
|
|
969
978
|
const ref = (0, import_react4.useRef)(null);
|
|
979
|
+
const triggerRef = (0, import_react4.useRef)(null);
|
|
970
980
|
(0, import_react4.useEffect)(() => {
|
|
971
981
|
if (controlled || startsEmpty) return;
|
|
972
982
|
onRangeChange?.(committed.current.start, committed.current.end);
|
|
@@ -982,7 +992,11 @@ function DateRangeFilter({
|
|
|
982
992
|
setEnd(hasRange ? committedEnd : null);
|
|
983
993
|
setLeftMonth(hasRange ? new Date(committedStart.getFullYear(), committedStart.getMonth(), 1) : addMonths(today, -1));
|
|
984
994
|
setCmp(committedCmp.current);
|
|
985
|
-
const onKey = (e) =>
|
|
995
|
+
const onKey = (e) => {
|
|
996
|
+
if (e.key !== "Escape") return;
|
|
997
|
+
setOpen(false);
|
|
998
|
+
triggerRef.current?.focus();
|
|
999
|
+
};
|
|
986
1000
|
const onClick = (e) => {
|
|
987
1001
|
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
988
1002
|
};
|
|
@@ -1032,8 +1046,10 @@ function DateRangeFilter({
|
|
|
1032
1046
|
onRangeChange?.(s, e);
|
|
1033
1047
|
onApply?.(shortcut === "Custom" ? `${fmt(s)} \u2013 ${fmt(e)}` : shortcut, s, e, cmp);
|
|
1034
1048
|
setOpen(false);
|
|
1049
|
+
triggerRef.current?.focus();
|
|
1035
1050
|
};
|
|
1036
1051
|
const popRef = (0, import_react4.useRef)(null);
|
|
1052
|
+
const monthIdBase = (0, import_react4.useId)();
|
|
1037
1053
|
const [flipBelow, setFlipBelow] = (0, import_react4.useState)(false);
|
|
1038
1054
|
(0, import_react4.useLayoutEffect)(() => {
|
|
1039
1055
|
if (!open || placement !== "above" || !ref.current || !popRef.current) return;
|
|
@@ -1044,6 +1060,7 @@ function DateRangeFilter({
|
|
|
1044
1060
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1045
1061
|
"button",
|
|
1046
1062
|
{
|
|
1063
|
+
ref: triggerRef,
|
|
1047
1064
|
type: "button",
|
|
1048
1065
|
"data-testid": testIdPrefix && `${testIdPrefix}-trigger`,
|
|
1049
1066
|
onClick: () => setOpen((v) => !v),
|
|
@@ -1098,15 +1115,15 @@ function DateRangeFilter({
|
|
|
1098
1115
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "w-[252px]", children: [
|
|
1099
1116
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "mb-2 flex items-center justify-between", children: [
|
|
1100
1117
|
offset === 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NavBtn, { onClick: () => setLeftMonth(addMonths(leftMonth, -1)), "aria-label": "Previous month", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.ChevronLeft, { size: 16 }) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "h-7 w-7" }),
|
|
1101
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "text-panel-title font-semibold text-text-primary", children: [
|
|
1118
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { id: `${monthIdBase}-m${offset}`, "aria-live": "polite", className: "text-panel-title font-semibold text-text-primary", children: [
|
|
1102
1119
|
MONTHS[m.getMonth()],
|
|
1103
1120
|
" ",
|
|
1104
1121
|
m.getFullYear()
|
|
1105
1122
|
] }),
|
|
1106
1123
|
offset === 1 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NavBtn, { onClick: () => setLeftMonth(addMonths(leftMonth, 1)), "aria-label": "Next month", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.ChevronRight, { size: 16 }) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "h-7 w-7" })
|
|
1107
1124
|
] }),
|
|
1108
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "grid grid-cols-7", children: [
|
|
1109
|
-
WEEKDAYS.map((w) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex h-8 items-center justify-center text-xs font-semibold text-text-secondary", children: w }, w)),
|
|
1125
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "grid grid-cols-7", role: "group", "aria-labelledby": `${monthIdBase}-m${offset}`, children: [
|
|
1126
|
+
WEEKDAYS.map((w) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "aria-hidden": "true", className: "flex h-8 items-center justify-center text-xs font-semibold text-text-secondary", children: w }, w)),
|
|
1110
1127
|
grid.map((d, i) => {
|
|
1111
1128
|
const inMonth = d.getMonth() === m.getMonth();
|
|
1112
1129
|
const hasRange = !!(start && end);
|
|
@@ -1121,16 +1138,27 @@ function DateRangeFilter({
|
|
|
1121
1138
|
else if (end && isEnd) band = "left-0 right-1/2";
|
|
1122
1139
|
else band = "left-0 right-0";
|
|
1123
1140
|
}
|
|
1124
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
"
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1142
|
+
"button",
|
|
1143
|
+
{
|
|
1144
|
+
type: "button",
|
|
1145
|
+
onClick: () => pickDay(d),
|
|
1146
|
+
"aria-label": dayLabel(d, single ? "single" : isStart ? "start" : end && isEnd ? "end" : inRange ? "in" : null),
|
|
1147
|
+
"aria-pressed": endpoint || inRange,
|
|
1148
|
+
className: "relative flex h-9 items-center justify-center focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-border-focus",
|
|
1149
|
+
children: [
|
|
1150
|
+
band && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: `absolute inset-y-[3px] bg-ai-tint ${band}`, "aria-hidden": "true" }),
|
|
1151
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1152
|
+
"span",
|
|
1153
|
+
{
|
|
1154
|
+
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"}`,
|
|
1155
|
+
children: d.getDate()
|
|
1156
|
+
}
|
|
1157
|
+
)
|
|
1158
|
+
]
|
|
1159
|
+
},
|
|
1160
|
+
i
|
|
1161
|
+
);
|
|
1134
1162
|
})
|
|
1135
1163
|
] })
|
|
1136
1164
|
] }, offset);
|
|
@@ -1166,7 +1194,10 @@ function DateRangeFilter({
|
|
|
1166
1194
|
] }),
|
|
1167
1195
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "mt-4 flex items-center justify-end gap-2", children: [
|
|
1168
1196
|
monthly && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "mr-auto text-xs text-text-tertiary", children: "Data is monthly, so ranges cover whole months." }),
|
|
1169
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", "data-testid": testIdPrefix && `${testIdPrefix}-cancel`, onClick: () =>
|
|
1197
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", "data-testid": testIdPrefix && `${testIdPrefix}-cancel`, onClick: () => {
|
|
1198
|
+
setOpen(false);
|
|
1199
|
+
triggerRef.current?.focus();
|
|
1200
|
+
}, 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" }),
|
|
1170
1201
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("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" })
|
|
1171
1202
|
] })
|
|
1172
1203
|
] })
|