@mediaradar/design-components 0.42.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.
package/dist/index.d.cts CHANGED
@@ -481,6 +481,11 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
481
481
  * `granularity="month"` rounds every range out to whole months (presets,
482
482
  * clicked days and Apply alike), shows months on the trigger, and adds a
483
483
  * "Data is monthly" note beside Cancel/Apply.
484
+ * `formatDate` / `formatRange` write every day-level date the component shows
485
+ * (dates line, a custom span on the chip, Start/End fields, compare-to dates),
486
+ * e.g. to follow a person's date-format setting. What `onChange` and `onApply`
487
+ * report keeps the canonical "Nov 14, 2026" form, since apps parse it.
488
+ * Month-level labels ("Nov 2025") have no day to order and stay as they are.
484
489
  * @a11y Trigger is a <button> with aria-expanded and an aria-label from the
485
490
  * caption; the panel is role="dialog" and Escape closes it. Focus is not
486
491
  * moved into the panel, so it is reached by tabbing.
@@ -492,6 +497,7 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
492
497
  * <DateRangeFilter caption="Dates" showDates shortDates placement="right" />
493
498
  * <DateRangeFilter presetSet="creativeIntel" defaultValue="Last 7 days" onChange={setRange} />
494
499
  * <DateRangeFilter presetSet="creativeIntel" value={preset} range={[start, end]} onChange={setPreset} onRangeChange={(s, e) => setRange({ start: s, end: e })} />
500
+ * <DateRangeFilter caption="Dates" showDates formatDate={formatDate} formatRange={formatDateRange} />
495
501
  * <DateRangeFilter presetSet="creativeIntel" excludePresets={["Rolling 3 months", "Rolling 6 months"]} emptyLabel="Any time" onRangeChange={setRange} />
496
502
  * <DateRangeFilter
497
503
  * presetSet="creativeIntel"
@@ -586,8 +592,25 @@ interface DateRangeFilterProps {
586
592
  * "Data is monthly". Defaults to 'day'.
587
593
  */
588
594
  granularity?: "day" | "month";
595
+ /**
596
+ * Writes each date the component shows: the dates line, a custom span on
597
+ * the chip, the Start/End fields and the compare-to dates. For following a
598
+ * person's date-format setting ("14 Nov 2026", "2026-11-14"). Defaults to
599
+ * "Nov 14, 2026" (with `shortDates` off, the dates line keeps its long
600
+ * "November 14, 2026" form only while no formatter is given). Display only:
601
+ * `onChange` and `onApply` still report "Nov 14, 2026 – ...", since apps
602
+ * parse those labels. Month-level labels ("Nov 2025") are left as they are.
603
+ */
604
+ formatDate?: (d: Date) => string;
605
+ /**
606
+ * Writes a span (dates line, custom span on the chip, compare-to dates) when
607
+ * it reads more briefly than two full dates ("4–17 Oct 2026"). Takes
608
+ * precedence over `formatDate` for spans. Defaults to
609
+ * `${formatDate(start)} – ${formatDate(end)}`, or one date when they match.
610
+ */
611
+ formatRange?: (start: Date, end: Date) => string;
589
612
  }
590
- declare function DateRangeFilter({ caption, defaultValue, value: controlledValue, range: controlledRange, align, placement, onChange, onRangeChange, showDates, shortDates, icon, presetSet, excludePresets, emptyLabel, today: todayProp, initialRange, compare, onApply, testIdPrefix, granularity, }: DateRangeFilterProps): react.JSX.Element;
613
+ declare function DateRangeFilter({ caption, defaultValue, value: controlledValue, range: controlledRange, align, placement, onChange, onRangeChange, showDates, shortDates, icon, presetSet, excludePresets, emptyLabel, today: todayProp, initialRange, compare, onApply, testIdPrefix, granularity, formatDate, formatRange, }: DateRangeFilterProps): react.JSX.Element;
591
614
 
592
615
  /**
593
616
  * @pattern SearchBar
@@ -2341,7 +2364,7 @@ type DateGranularity = 'month' | 'quarter' | 'year';
2341
2364
  /** Resolve a label to its actual [start, end] span, ending at `today`. */
2342
2365
  declare function resolveRange(label: string, today?: Date): [Date, Date];
2343
2366
  /** @deprecated Use DateRangeFilter, with `granularity="month"` for monthly data. */
2344
- declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, }: {
2367
+ declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, formatDate, formatRange, }: {
2345
2368
  defaultValue?: string;
2346
2369
  align?: 'left' | 'right';
2347
2370
  /**
@@ -2364,6 +2387,19 @@ declare function DateRangePicker({ defaultValue, granularity, align, presets, on
2364
2387
  /** Years offered in the Custom Range selects. Defaults to the last four,
2365
2388
  * ending with `today`'s year. */
2366
2389
  years?: number[];
2390
+ /**
2391
+ * Writes each date in the dates line above the label, e.g. to follow a
2392
+ * person's date-format setting ("14 Nov 2026", "2026-11-14"). Defaults to
2393
+ * "Nov 14, 2026". Only what's shown changes: the label and `onChange` keep
2394
+ * the canonical form.
2395
+ */
2396
+ formatDate?: (d: Date) => string;
2397
+ /**
2398
+ * Writes the whole dates line, for a span that reads more briefly than two
2399
+ * full dates. Takes precedence over `formatDate`. Defaults to
2400
+ * `${formatDate(start)} – ${formatDate(end)}`.
2401
+ */
2402
+ formatRange?: (start: Date, end: Date) => string;
2367
2403
  }): react.JSX.Element;
2368
2404
  type DateRangePickerProps = Parameters<typeof DateRangePicker>[0];
2369
2405
 
package/dist/index.d.ts CHANGED
@@ -481,6 +481,11 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
481
481
  * `granularity="month"` rounds every range out to whole months (presets,
482
482
  * clicked days and Apply alike), shows months on the trigger, and adds a
483
483
  * "Data is monthly" note beside Cancel/Apply.
484
+ * `formatDate` / `formatRange` write every day-level date the component shows
485
+ * (dates line, a custom span on the chip, Start/End fields, compare-to dates),
486
+ * e.g. to follow a person's date-format setting. What `onChange` and `onApply`
487
+ * report keeps the canonical "Nov 14, 2026" form, since apps parse it.
488
+ * Month-level labels ("Nov 2025") have no day to order and stay as they are.
484
489
  * @a11y Trigger is a <button> with aria-expanded and an aria-label from the
485
490
  * caption; the panel is role="dialog" and Escape closes it. Focus is not
486
491
  * moved into the panel, so it is reached by tabbing.
@@ -492,6 +497,7 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
492
497
  * <DateRangeFilter caption="Dates" showDates shortDates placement="right" />
493
498
  * <DateRangeFilter presetSet="creativeIntel" defaultValue="Last 7 days" onChange={setRange} />
494
499
  * <DateRangeFilter presetSet="creativeIntel" value={preset} range={[start, end]} onChange={setPreset} onRangeChange={(s, e) => setRange({ start: s, end: e })} />
500
+ * <DateRangeFilter caption="Dates" showDates formatDate={formatDate} formatRange={formatDateRange} />
495
501
  * <DateRangeFilter presetSet="creativeIntel" excludePresets={["Rolling 3 months", "Rolling 6 months"]} emptyLabel="Any time" onRangeChange={setRange} />
496
502
  * <DateRangeFilter
497
503
  * presetSet="creativeIntel"
@@ -586,8 +592,25 @@ interface DateRangeFilterProps {
586
592
  * "Data is monthly". Defaults to 'day'.
587
593
  */
588
594
  granularity?: "day" | "month";
595
+ /**
596
+ * Writes each date the component shows: the dates line, a custom span on
597
+ * the chip, the Start/End fields and the compare-to dates. For following a
598
+ * person's date-format setting ("14 Nov 2026", "2026-11-14"). Defaults to
599
+ * "Nov 14, 2026" (with `shortDates` off, the dates line keeps its long
600
+ * "November 14, 2026" form only while no formatter is given). Display only:
601
+ * `onChange` and `onApply` still report "Nov 14, 2026 – ...", since apps
602
+ * parse those labels. Month-level labels ("Nov 2025") are left as they are.
603
+ */
604
+ formatDate?: (d: Date) => string;
605
+ /**
606
+ * Writes a span (dates line, custom span on the chip, compare-to dates) when
607
+ * it reads more briefly than two full dates ("4–17 Oct 2026"). Takes
608
+ * precedence over `formatDate` for spans. Defaults to
609
+ * `${formatDate(start)} – ${formatDate(end)}`, or one date when they match.
610
+ */
611
+ formatRange?: (start: Date, end: Date) => string;
589
612
  }
590
- declare function DateRangeFilter({ caption, defaultValue, value: controlledValue, range: controlledRange, align, placement, onChange, onRangeChange, showDates, shortDates, icon, presetSet, excludePresets, emptyLabel, today: todayProp, initialRange, compare, onApply, testIdPrefix, granularity, }: DateRangeFilterProps): react.JSX.Element;
613
+ declare function DateRangeFilter({ caption, defaultValue, value: controlledValue, range: controlledRange, align, placement, onChange, onRangeChange, showDates, shortDates, icon, presetSet, excludePresets, emptyLabel, today: todayProp, initialRange, compare, onApply, testIdPrefix, granularity, formatDate, formatRange, }: DateRangeFilterProps): react.JSX.Element;
591
614
 
592
615
  /**
593
616
  * @pattern SearchBar
@@ -2341,7 +2364,7 @@ type DateGranularity = 'month' | 'quarter' | 'year';
2341
2364
  /** Resolve a label to its actual [start, end] span, ending at `today`. */
2342
2365
  declare function resolveRange(label: string, today?: Date): [Date, Date];
2343
2366
  /** @deprecated Use DateRangeFilter, with `granularity="month"` for monthly data. */
2344
- declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, }: {
2367
+ declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, formatDate, formatRange, }: {
2345
2368
  defaultValue?: string;
2346
2369
  align?: 'left' | 'right';
2347
2370
  /**
@@ -2364,6 +2387,19 @@ declare function DateRangePicker({ defaultValue, granularity, align, presets, on
2364
2387
  /** Years offered in the Custom Range selects. Defaults to the last four,
2365
2388
  * ending with `today`'s year. */
2366
2389
  years?: number[];
2390
+ /**
2391
+ * Writes each date in the dates line above the label, e.g. to follow a
2392
+ * person's date-format setting ("14 Nov 2026", "2026-11-14"). Defaults to
2393
+ * "Nov 14, 2026". Only what's shown changes: the label and `onChange` keep
2394
+ * the canonical form.
2395
+ */
2396
+ formatDate?: (d: Date) => string;
2397
+ /**
2398
+ * Writes the whole dates line, for a span that reads more briefly than two
2399
+ * full dates. Takes precedence over `formatDate`. Defaults to
2400
+ * `${formatDate(start)} – ${formatDate(end)}`.
2401
+ */
2402
+ formatRange?: (start: Date, end: Date) => string;
2367
2403
  }): react.JSX.Element;
2368
2404
  type DateRangePickerProps = Parameters<typeof DateRangePicker>[0];
2369
2405
 
package/dist/index.js CHANGED
@@ -815,9 +815,15 @@ function DateRangeFilter({
815
815
  compare,
816
816
  onApply,
817
817
  testIdPrefix,
818
- granularity = "day"
818
+ granularity = "day",
819
+ formatDate,
820
+ formatRange
819
821
  }) {
820
822
  const monthly = granularity === "month";
823
+ const formatted = !!(formatDate || formatRange);
824
+ const showDate = formatDate ?? fmt;
825
+ const showRange = (s, e) => formatRange ? formatRange(s, e) : sameDay(s, e) ? showDate(s) : `${showDate(s)} \u2013 ${showDate(e)}`;
826
+ const showValue = (v, s, e) => formatted && !monthly && (v === `${fmt(s)} \u2014 ${fmt(e)}` || v === `${fmt(s)} \u2013 ${fmt(e)}`) ? showRange(s, e) : v;
821
827
  const snap = (s, e) => monthly ? [firstOfMonth(s), lastOfMonth(e)] : [s, e];
822
828
  const controlled = controlledValue !== void 0 && controlledRange !== void 0;
823
829
  const startsEmpty = !controlled && !!emptyLabel;
@@ -828,7 +834,7 @@ function DateRangeFilter({
828
834
  const initShortcut = matchShortcut(SHORTCUTS, controlled ? controlledValue : defaultValue);
829
835
  const initRange = controlled ? controlledRange : initShortcut === "Custom" && initialRange ? snap(...initialRange) : snap(...presetRange(initShortcut === "Custom" ? "Rolling 12 months" : initShortcut, today));
830
836
  const compareLabel = (id) => compare?.options.find((o) => o.id === id)?.label;
831
- const dateLine = (s, e) => monthly ? `${fmtMonth(s)} \u2013 ${fmtMonth(e)}` : shortDates ? `${fmt(s)} \u2013 ${fmt(e)}` : fullRangeLabel(s, e);
837
+ const dateLine = (s, e) => monthly ? `${fmtMonth(s)} \u2013 ${fmtMonth(e)}` : formatted ? showRange(s, e) : shortDates ? `${fmt(s)} \u2013 ${fmt(e)}` : fullRangeLabel(s, e);
832
838
  const [open, setOpen] = useState3(false);
833
839
  const [uncontrolledValue, setUncontrolledValue] = useState3(
834
840
  startsEmpty ? emptyLabel : showDates ? presetLabel(initShortcut) : defaultValue || "Last 7 days"
@@ -845,7 +851,7 @@ function DateRangeFilter({
845
851
  setAppliedCmp(compare?.value);
846
852
  }, [compare?.value]);
847
853
  const compareName = `${useId2()}-compare`;
848
- const displayValue = controlled ? showDates ? presetLabel(initShortcut) : controlledValue : uncontrolledValue;
854
+ const displayValue = controlled ? showDates ? presetLabel(initShortcut) : showValue(controlledValue, initRange[0], initRange[1]) : showValue(uncontrolledValue, committed.current.start, committed.current.end);
849
855
  const displayDatesLine = controlled ? dateLine(initRange[0], initRange[1]) : uncontrolledDatesLine;
850
856
  const [shortcut, setShortcut] = useState3(initShortcut);
851
857
  const [start, setStart] = useState3(initRange[0]);
@@ -972,9 +978,9 @@ function DateRangeFilter({
972
978
  )) }),
973
979
  /* @__PURE__ */ jsxs7("div", { className: "flex flex-col p-4", children: [
974
980
  /* @__PURE__ */ jsxs7("div", { className: "flex items-end gap-3", children: [
975
- /* @__PURE__ */ jsx8(Field, { label: "Start date", value: start ? fmt(start) : "\u2014" }),
981
+ /* @__PURE__ */ jsx8(Field, { label: "Start date", value: start ? showDate(start) : "\u2014" }),
976
982
  /* @__PURE__ */ jsx8("span", { className: "pb-2.5 text-text-tertiary", children: "\u2014" }),
977
- /* @__PURE__ */ jsx8(Field, { label: "End date", value: end ? fmt(end) : start ? fmt(start) : "\u2014" })
983
+ /* @__PURE__ */ jsx8(Field, { label: "End date", value: end ? showDate(end) : start ? showDate(start) : "\u2014" })
978
984
  ] }),
979
985
  /* @__PURE__ */ jsx8("div", { className: "my-4 border-t border-border-default" }),
980
986
  /* @__PURE__ */ jsx8("div", { className: "flex gap-8", children: [0, 1].map((offset) => {
@@ -1042,7 +1048,7 @@ function DateRangeFilter({
1042
1048
  }
1043
1049
  ),
1044
1050
  /* @__PURE__ */ jsx8("span", { className: `w-44 shrink-0 ${on ? "font-semibold text-text-primary" : "text-text-secondary"}`, children: o.label }),
1045
- start && /* @__PURE__ */ jsx8("span", { className: "tabular-nums text-text-tertiary", children: spanLabel(...compareSpan(start, end ?? start, o.id)) })
1051
+ start && /* @__PURE__ */ jsx8("span", { className: "tabular-nums text-text-tertiary", children: (formatted ? showRange : spanLabel)(...compareSpan(start, end ?? start, o.id)) })
1046
1052
  ]
1047
1053
  },
1048
1054
  o.id
@@ -3993,9 +3999,11 @@ function resolveRange(label, today = startOfToday()) {
3993
3999
  }
3994
4000
  return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
3995
4001
  }
3996
- function spanLabel2(label, today) {
4002
+ function spanLabel2(label, today, formatDate, formatRange) {
3997
4003
  const [s, e] = resolveRange(label, today);
3998
- return `${fmtDate(s)} \u2013 ${fmtDate(e)}`;
4004
+ if (formatRange) return formatRange(s, e);
4005
+ const f = formatDate ?? fmtDate;
4006
+ return `${f(s)} \u2013 ${f(e)}`;
3999
4007
  }
4000
4008
  function MiniSelect({ value, onChange, options }) {
4001
4009
  return /* @__PURE__ */ jsx39(
@@ -4020,7 +4028,9 @@ function DateRangePicker({
4020
4028
  onRangeChange,
4021
4029
  showFooter = false,
4022
4030
  today,
4023
- years
4031
+ years,
4032
+ formatDate,
4033
+ formatRange
4024
4034
  }) {
4025
4035
  const end = useMemo4(() => today ?? startOfToday(), [today]);
4026
4036
  const yearOptions = years ?? [3, 2, 1, 0].map((n) => end.getFullYear() - n);
@@ -4079,7 +4089,7 @@ function DateRangePicker({
4079
4089
  className: chipTriggerClass(),
4080
4090
  children: [
4081
4091
  /* @__PURE__ */ jsxs35("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
4082
- /* @__PURE__ */ jsx39("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end) }),
4092
+ /* @__PURE__ */ jsx39("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end, formatDate, formatRange) }),
4083
4093
  /* @__PURE__ */ jsx39("span", { className: "text-[12px] font-medium text-text-primary", children: value })
4084
4094
  ] }),
4085
4095
  /* @__PURE__ */ jsx39(ChevronDown9, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-text-secondary transition-transform", open && "rotate-180") })