@mediaradar/design-components 0.42.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/approved-components.json +1 -1
- package/dist/index.cjs +51 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -4
- package/dist/index.d.ts +66 -4
- package/dist/index.js +51 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -906,9 +906,15 @@ function DateRangeFilter({
|
|
|
906
906
|
compare,
|
|
907
907
|
onApply,
|
|
908
908
|
testIdPrefix,
|
|
909
|
-
granularity = "day"
|
|
909
|
+
granularity = "day",
|
|
910
|
+
formatDate,
|
|
911
|
+
formatRange
|
|
910
912
|
}) {
|
|
911
913
|
const monthly = granularity === "month";
|
|
914
|
+
const formatted = !!(formatDate || formatRange);
|
|
915
|
+
const showDate = formatDate ?? fmt;
|
|
916
|
+
const showRange = (s, e) => formatRange ? formatRange(s, e) : sameDay(s, e) ? showDate(s) : `${showDate(s)} \u2013 ${showDate(e)}`;
|
|
917
|
+
const showValue = (v, s, e) => formatted && !monthly && (v === `${fmt(s)} \u2014 ${fmt(e)}` || v === `${fmt(s)} \u2013 ${fmt(e)}`) ? showRange(s, e) : v;
|
|
912
918
|
const snap = (s, e) => monthly ? [firstOfMonth(s), lastOfMonth(e)] : [s, e];
|
|
913
919
|
const controlled = controlledValue !== void 0 && controlledRange !== void 0;
|
|
914
920
|
const startsEmpty = !controlled && !!emptyLabel;
|
|
@@ -919,7 +925,7 @@ function DateRangeFilter({
|
|
|
919
925
|
const initShortcut = matchShortcut(SHORTCUTS, controlled ? controlledValue : defaultValue);
|
|
920
926
|
const initRange = controlled ? controlledRange : initShortcut === "Custom" && initialRange ? snap(...initialRange) : snap(...presetRange(initShortcut === "Custom" ? "Rolling 12 months" : initShortcut, today));
|
|
921
927
|
const compareLabel = (id) => compare?.options.find((o) => o.id === id)?.label;
|
|
922
|
-
const dateLine = (s, e) => monthly ? `${fmtMonth(s)} \u2013 ${fmtMonth(e)}` : shortDates ? `${fmt(s)} \u2013 ${fmt(e)}` : fullRangeLabel(s, e);
|
|
928
|
+
const dateLine = (s, e) => monthly ? `${fmtMonth(s)} \u2013 ${fmtMonth(e)}` : formatted ? showRange(s, e) : shortDates ? `${fmt(s)} \u2013 ${fmt(e)}` : fullRangeLabel(s, e);
|
|
923
929
|
const [open, setOpen] = (0, import_react3.useState)(false);
|
|
924
930
|
const [uncontrolledValue, setUncontrolledValue] = (0, import_react3.useState)(
|
|
925
931
|
startsEmpty ? emptyLabel : showDates ? presetLabel(initShortcut) : defaultValue || "Last 7 days"
|
|
@@ -936,7 +942,7 @@ function DateRangeFilter({
|
|
|
936
942
|
setAppliedCmp(compare?.value);
|
|
937
943
|
}, [compare?.value]);
|
|
938
944
|
const compareName = `${(0, import_react3.useId)()}-compare`;
|
|
939
|
-
const displayValue = controlled ? showDates ? presetLabel(initShortcut) : controlledValue : uncontrolledValue;
|
|
945
|
+
const displayValue = controlled ? showDates ? presetLabel(initShortcut) : showValue(controlledValue, initRange[0], initRange[1]) : showValue(uncontrolledValue, committed.current.start, committed.current.end);
|
|
940
946
|
const displayDatesLine = controlled ? dateLine(initRange[0], initRange[1]) : uncontrolledDatesLine;
|
|
941
947
|
const [shortcut, setShortcut] = (0, import_react3.useState)(initShortcut);
|
|
942
948
|
const [start, setStart] = (0, import_react3.useState)(initRange[0]);
|
|
@@ -1063,9 +1069,9 @@ function DateRangeFilter({
|
|
|
1063
1069
|
)) }),
|
|
1064
1070
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex flex-col p-4", children: [
|
|
1065
1071
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-end gap-3", children: [
|
|
1066
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Field, { label: "Start date", value: start ?
|
|
1072
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Field, { label: "Start date", value: start ? showDate(start) : "\u2014" }),
|
|
1067
1073
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "pb-2.5 text-text-tertiary", children: "\u2014" }),
|
|
1068
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Field, { label: "End date", value: end ?
|
|
1074
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Field, { label: "End date", value: end ? showDate(end) : start ? showDate(start) : "\u2014" })
|
|
1069
1075
|
] }),
|
|
1070
1076
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "my-4 border-t border-border-default" }),
|
|
1071
1077
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex gap-8", children: [0, 1].map((offset) => {
|
|
@@ -1133,7 +1139,7 @@ function DateRangeFilter({
|
|
|
1133
1139
|
}
|
|
1134
1140
|
),
|
|
1135
1141
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: `w-44 shrink-0 ${on ? "font-semibold text-text-primary" : "text-text-secondary"}`, children: o.label }),
|
|
1136
|
-
start && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "tabular-nums text-text-tertiary", children: spanLabel(...compareSpan(start, end ?? start, o.id)) })
|
|
1142
|
+
start && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "tabular-nums text-text-tertiary", children: (formatted ? showRange : spanLabel)(...compareSpan(start, end ?? start, o.id)) })
|
|
1137
1143
|
]
|
|
1138
1144
|
},
|
|
1139
1145
|
o.id
|
|
@@ -1902,6 +1908,7 @@ function SelectFilter({
|
|
|
1902
1908
|
error = false,
|
|
1903
1909
|
onRetry,
|
|
1904
1910
|
size = "md",
|
|
1911
|
+
inlineCaption = false,
|
|
1905
1912
|
disabled = false,
|
|
1906
1913
|
renderIcon
|
|
1907
1914
|
}) {
|
|
@@ -1916,7 +1923,11 @@ function SelectFilter({
|
|
|
1916
1923
|
const r = ref.current.getBoundingClientRect();
|
|
1917
1924
|
const h = Math.min(options.length * 36 + 8, 288);
|
|
1918
1925
|
const above = r.bottom + 8 + h > window.innerHeight && r.top - 8 - h > 0;
|
|
1919
|
-
setPos({
|
|
1926
|
+
setPos({
|
|
1927
|
+
top: above ? r.top - 8 - h : r.bottom + 8,
|
|
1928
|
+
...align === "right" ? { right: document.documentElement.clientWidth - r.right } : { left: r.left },
|
|
1929
|
+
width: r.width
|
|
1930
|
+
});
|
|
1920
1931
|
}, [align, options.length]);
|
|
1921
1932
|
(0, import_react7.useLayoutEffect)(() => {
|
|
1922
1933
|
if (!open) return;
|
|
@@ -1941,10 +1952,18 @@ function SelectFilter({
|
|
|
1941
1952
|
window.removeEventListener("scroll", reposition, true);
|
|
1942
1953
|
};
|
|
1943
1954
|
}, [open, close, reposition]);
|
|
1944
|
-
const
|
|
1955
|
+
const valueContent = renderIcon ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "flex items-center gap-1.5", children: [
|
|
1945
1956
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(OptionIcon, { children: renderIcon(value) }),
|
|
1946
1957
|
value
|
|
1947
1958
|
] }) : value;
|
|
1959
|
+
const triggerValue = sm && inlineCaption ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
|
|
1960
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "font-normal text-text-secondary", children: [
|
|
1961
|
+
caption,
|
|
1962
|
+
":"
|
|
1963
|
+
] }),
|
|
1964
|
+
" ",
|
|
1965
|
+
valueContent
|
|
1966
|
+
] }) : valueContent;
|
|
1948
1967
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: cx4("relative", fullWidth && "w-full"), ref, children: [
|
|
1949
1968
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1950
1969
|
"button",
|
|
@@ -1954,7 +1973,7 @@ function SelectFilter({
|
|
|
1954
1973
|
onClick: () => setOpen((o) => !o),
|
|
1955
1974
|
"aria-expanded": open,
|
|
1956
1975
|
"aria-haspopup": "listbox",
|
|
1957
|
-
"aria-label": sm ? caption : void 0,
|
|
1976
|
+
"aria-label": sm && !inlineCaption ? caption : void 0,
|
|
1958
1977
|
disabled,
|
|
1959
1978
|
className: cx4(
|
|
1960
1979
|
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(),
|
|
@@ -1981,10 +2000,10 @@ function SelectFilter({
|
|
|
1981
2000
|
{
|
|
1982
2001
|
ref: popoverRef,
|
|
1983
2002
|
"data-testid": testIdPrefix && `${testIdPrefix}-popover`,
|
|
1984
|
-
style: { position: "fixed", top: pos.top, left: pos.left, width: fullWidth ? pos.width : void 0 },
|
|
2003
|
+
style: { position: "fixed", top: pos.top, left: pos.left, right: pos.right, width: fullWidth ? pos.width : void 0 },
|
|
1985
2004
|
className: cx4(
|
|
1986
2005
|
"z-[65] flex flex-col overflow-hidden rounded-card border border-border-default bg-surface shadow-overlay",
|
|
1987
|
-
!fullWidth && (sm ? "w-28" : "w-56")
|
|
2006
|
+
!fullWidth && (sm ? "w-max min-w-28 max-w-72" : "w-56")
|
|
1988
2007
|
),
|
|
1989
2008
|
role: loading || error ? "group" : "listbox",
|
|
1990
2009
|
"aria-label": caption,
|
|
@@ -4084,9 +4103,11 @@ function resolveRange(label, today = startOfToday()) {
|
|
|
4084
4103
|
}
|
|
4085
4104
|
return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
|
|
4086
4105
|
}
|
|
4087
|
-
function spanLabel2(label, today) {
|
|
4106
|
+
function spanLabel2(label, today, formatDate, formatRange) {
|
|
4088
4107
|
const [s, e] = resolveRange(label, today);
|
|
4089
|
-
|
|
4108
|
+
if (formatRange) return formatRange(s, e);
|
|
4109
|
+
const f = formatDate ?? fmtDate;
|
|
4110
|
+
return `${f(s)} \u2013 ${f(e)}`;
|
|
4090
4111
|
}
|
|
4091
4112
|
function MiniSelect({ value, onChange, options }) {
|
|
4092
4113
|
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
@@ -4111,7 +4132,9 @@ function DateRangePicker({
|
|
|
4111
4132
|
onRangeChange,
|
|
4112
4133
|
showFooter = false,
|
|
4113
4134
|
today,
|
|
4114
|
-
years
|
|
4135
|
+
years,
|
|
4136
|
+
formatDate,
|
|
4137
|
+
formatRange
|
|
4115
4138
|
}) {
|
|
4116
4139
|
const end = (0, import_react17.useMemo)(() => today ?? startOfToday(), [today]);
|
|
4117
4140
|
const yearOptions = years ?? [3, 2, 1, 0].map((n) => end.getFullYear() - n);
|
|
@@ -4170,7 +4193,7 @@ function DateRangePicker({
|
|
|
4170
4193
|
className: chipTriggerClass(),
|
|
4171
4194
|
children: [
|
|
4172
4195
|
/* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
|
|
4173
|
-
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end) }),
|
|
4196
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end, formatDate, formatRange) }),
|
|
4174
4197
|
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "text-[12px] font-medium text-text-primary", children: value })
|
|
4175
4198
|
] }),
|
|
4176
4199
|
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_lucide_react22.ChevronDown, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-text-secondary transition-transform", open && "rotate-180") })
|
|
@@ -4250,7 +4273,10 @@ function MultiSelectFilter({
|
|
|
4250
4273
|
fullWidth = false,
|
|
4251
4274
|
loading = false,
|
|
4252
4275
|
error = false,
|
|
4253
|
-
onRetry
|
|
4276
|
+
onRetry,
|
|
4277
|
+
valueLabel,
|
|
4278
|
+
hints,
|
|
4279
|
+
note
|
|
4254
4280
|
}) {
|
|
4255
4281
|
const groupLeaves = (g) => g.children.length ? g.children : [{ id: g.id, label: g.label }];
|
|
4256
4282
|
const leafOptions = groups ? groups.flatMap(groupLeaves) : options;
|
|
@@ -4311,7 +4337,11 @@ function MultiSelectFilter({
|
|
|
4311
4337
|
};
|
|
4312
4338
|
const shown = open && !showFooter ? draft : selected;
|
|
4313
4339
|
const isAll = shown.length === 0 || fullIsAll && shown.length === leafOptions.length;
|
|
4314
|
-
const value = isAll ? allLabel : shown.length === 1 ? leafOptions.find((o) => o.id === shown[0])?.label ?? `${shown.length} selected` : `${shown.length} selected
|
|
4340
|
+
const value = valueLabel ?? (isAll ? allLabel : shown.length === 1 ? leafOptions.find((o) => o.id === shown[0])?.label ?? `${shown.length} selected` : `${shown.length} selected`);
|
|
4341
|
+
const labelled = (id, label) => hints?.[id] ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("span", { className: "flex flex-col", children: [
|
|
4342
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { children: label }),
|
|
4343
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "text-xs font-normal text-text-tertiary", children: hints[id] })
|
|
4344
|
+
] }) : label;
|
|
4315
4345
|
const ql = q.trim().toLowerCase();
|
|
4316
4346
|
const items = options.filter((o) => isAvailable(o.id) && (!ql || o.label.toLowerCase().includes(ql)));
|
|
4317
4347
|
const visibleGroups = groups ? groups.map((g) => {
|
|
@@ -4379,7 +4409,7 @@ function MultiSelectFilter({
|
|
|
4379
4409
|
className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
|
|
4380
4410
|
children: [
|
|
4381
4411
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(CheckBoxBox, { checked: state === "all", indeterminate: state === "some" }),
|
|
4382
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: cn("flex-1 text-[14px] text-text-primary", !plainParent && "font-semibold"), children: g.label }),
|
|
4412
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: cn("flex-1 text-[14px] text-text-primary", !plainParent && "font-semibold"), children: labelled(g.id, g.label) }),
|
|
4383
4413
|
counts && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(OptionCount, { n: countFor(g.id) })
|
|
4384
4414
|
]
|
|
4385
4415
|
}
|
|
@@ -4394,7 +4424,7 @@ function MultiSelectFilter({
|
|
|
4394
4424
|
className: "flex w-full items-center gap-2.5 rounded-control py-2 pl-9 pr-2 text-left transition-colors hover:bg-subtle",
|
|
4395
4425
|
children: [
|
|
4396
4426
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(CheckBoxBox, { checked }),
|
|
4397
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1 text-[14px] text-text-primary", children: c.label }),
|
|
4427
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1 text-[14px] text-text-primary", children: labelled(c.id, c.label) }),
|
|
4398
4428
|
counts && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(OptionCount, { n: countFor(c.id) })
|
|
4399
4429
|
]
|
|
4400
4430
|
},
|
|
@@ -4412,7 +4442,7 @@ function MultiSelectFilter({
|
|
|
4412
4442
|
className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
|
|
4413
4443
|
children: [
|
|
4414
4444
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(CheckBoxBox, { checked }),
|
|
4415
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1 text-[14px] text-text-primary", children: o.label }),
|
|
4445
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1 text-[14px] text-text-primary", children: labelled(o.id, o.label) }),
|
|
4416
4446
|
counts && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(OptionCount, { n: countFor(o.id) })
|
|
4417
4447
|
]
|
|
4418
4448
|
},
|
|
@@ -4421,6 +4451,7 @@ function MultiSelectFilter({
|
|
|
4421
4451
|
}),
|
|
4422
4452
|
(groups && !visibleGroups.length || !groups && !items.length) && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "py-6 text-center text-[13px] text-text-tertiary", children: "No matches." })
|
|
4423
4453
|
] }),
|
|
4454
|
+
note && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "border-t border-border-default px-3 py-2 text-xs text-text-tertiary", children: note }),
|
|
4424
4455
|
showFooter ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(FilterDropdownFooter, { onClear: () => setDraft(clearValue), onApply: apply }) : min === 0 && draft.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "border-t border-border-default p-2", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
|
|
4425
4456
|
"button",
|
|
4426
4457
|
{
|