@mediaradar/design-components 0.41.0 → 0.43.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.41.0",
2
+ "version": "0.43.0",
3
3
  "components": [
4
4
  "AISpark",
5
5
  "AdvertiserNoResults",
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 ? fmt(start) : "\u2014" }),
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 ? fmt(end) : start ? fmt(start) : "\u2014" })
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
@@ -4084,9 +4090,11 @@ function resolveRange(label, today = startOfToday()) {
4084
4090
  }
4085
4091
  return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
4086
4092
  }
4087
- function spanLabel2(label, today) {
4093
+ function spanLabel2(label, today, formatDate, formatRange) {
4088
4094
  const [s, e] = resolveRange(label, today);
4089
- return `${fmtDate(s)} \u2013 ${fmtDate(e)}`;
4095
+ if (formatRange) return formatRange(s, e);
4096
+ const f = formatDate ?? fmtDate;
4097
+ return `${f(s)} \u2013 ${f(e)}`;
4090
4098
  }
4091
4099
  function MiniSelect({ value, onChange, options }) {
4092
4100
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
@@ -4111,7 +4119,9 @@ function DateRangePicker({
4111
4119
  onRangeChange,
4112
4120
  showFooter = false,
4113
4121
  today,
4114
- years
4122
+ years,
4123
+ formatDate,
4124
+ formatRange
4115
4125
  }) {
4116
4126
  const end = (0, import_react17.useMemo)(() => today ?? startOfToday(), [today]);
4117
4127
  const yearOptions = years ?? [3, 2, 1, 0].map((n) => end.getFullYear() - n);
@@ -4170,7 +4180,7 @@ function DateRangePicker({
4170
4180
  className: chipTriggerClass(),
4171
4181
  children: [
4172
4182
  /* @__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) }),
4183
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end, formatDate, formatRange) }),
4174
4184
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "text-[12px] font-medium text-text-primary", children: value })
4175
4185
  ] }),
4176
4186
  /* @__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") })
@@ -4540,7 +4550,7 @@ function SectionHeading({ title, description, actions, as: Tag2 = "h2", id, clas
4540
4550
  // src/PageHeader.tsx
4541
4551
  var import_lucide_react25 = require("lucide-react");
4542
4552
  var import_jsx_runtime45 = require("react/jsx-runtime");
4543
- function PageHeader({ title, description, actions, back, className }) {
4553
+ function PageHeader({ title, description, actions, meta, back, className }) {
4544
4554
  return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("header", { className: cn("flex flex-wrap items-center justify-between gap-x-6 gap-y-3", className), children: [
4545
4555
  /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "min-w-0", children: [
4546
4556
  back && /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
@@ -4555,7 +4565,10 @@ function PageHeader({ title, description, actions, back, className }) {
4555
4565
  ]
4556
4566
  }
4557
4567
  ),
4558
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("h1", { className: "text-xl font-semibold tracking-tight text-text-primary", children: title }),
4568
+ meta ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex flex-wrap items-center gap-x-2.5 gap-y-1", children: [
4569
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("h1", { className: "text-xl font-semibold tracking-tight text-text-primary", children: title }),
4570
+ meta
4571
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("h1", { className: "text-xl font-semibold tracking-tight text-text-primary", children: title }),
4559
4572
  description && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("p", { className: "mt-0.5 max-w-2xl text-sm text-text-secondary", children: description })
4560
4573
  ] }),
4561
4574
  actions && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "flex shrink-0 items-center gap-2", children: actions })