@mediaradar/design-components 0.33.0 → 0.34.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.cjs +96 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -5
- package/dist/index.d.ts +51 -5
- package/dist/index.js +116 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -433,13 +433,20 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
|
|
|
433
433
|
* @tokens text-control-caption, rounded-control, rounded-card, border-border-default, border-border-strong,
|
|
434
434
|
* bg-surface, bg-input, bg-subtle, bg-ai-tint, bg-brand-primaryAction, text-brand-onprimary,
|
|
435
435
|
* shadow-overlay, text-text-primary, text-text-secondary, text-text-tertiary,
|
|
436
|
-
* hover:bg-subtle, hover:text-text-primary, focus-visible:outline-border-focus
|
|
436
|
+
* hover:bg-subtle, hover:text-text-primary, focus-visible:outline-border-focus, text-dense
|
|
437
437
|
* @dependencies lucide-react
|
|
438
438
|
* @behavior Escape and outside-click both close the popup. Opening always
|
|
439
439
|
* resets the draft (shortcut/start/end/visible month) to the last committed
|
|
440
440
|
* values, so a previous unsaved edit never lingers into the next open. Only
|
|
441
441
|
* the Apply button commits -- Cancel, Escape, and outside-click all discard
|
|
442
|
-
* the draft silently.
|
|
442
|
+
* the draft silently. "Last 30 days" is a hidden preset: a `defaultValue` or
|
|
443
|
+
* `value` naming it resolves to its dates, but the rail never offers it.
|
|
444
|
+
* `excludePresets` drops presets from the rail. `emptyLabel` starts the chip
|
|
445
|
+
* with no range chosen (Apply stays disabled until a day is picked).
|
|
446
|
+
* `compare` adds a "Compare to" radio group under the calendar, staged with
|
|
447
|
+
* the dates until Apply; the chip then reads "Last 7 days · vs prior period".
|
|
448
|
+
* `today` sets the day presets end on, for data that stops before the real
|
|
449
|
+
* today.
|
|
443
450
|
* `granularity="month"` rounds every range out to whole months (presets,
|
|
444
451
|
* clicked days and Apply alike), shows months on the trigger, and adds a
|
|
445
452
|
* "Data is monthly" note beside Cancel/Apply.
|
|
@@ -454,6 +461,17 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
|
|
|
454
461
|
* <DateRangeFilter caption="Dates" showDates shortDates placement="right" />
|
|
455
462
|
* <DateRangeFilter presetSet="creativeIntel" defaultValue="Last 7 days" onChange={setRange} />
|
|
456
463
|
* <DateRangeFilter presetSet="creativeIntel" value={preset} range={[start, end]} onChange={setPreset} onRangeChange={(s, e) => setRange({ start: s, end: e })} />
|
|
464
|
+
* <DateRangeFilter presetSet="creativeIntel" excludePresets={["Rolling 3 months", "Rolling 6 months"]} emptyLabel="Any time" onRangeChange={setRange} />
|
|
465
|
+
* <DateRangeFilter
|
|
466
|
+
* presetSet="creativeIntel"
|
|
467
|
+
* defaultValue={filters.range}
|
|
468
|
+
* initialRange={customDates}
|
|
469
|
+
* today={dataDay}
|
|
470
|
+
* showDates
|
|
471
|
+
* shortDates
|
|
472
|
+
* compare={{ value: filters.compare, options: [{ id: "prior", label: "Prior period" }, { id: "year", label: "Same period last year" }] }}
|
|
473
|
+
* onApply={(label, start, end, compare) => update({ range: label, compare })}
|
|
474
|
+
* />
|
|
457
475
|
* ```
|
|
458
476
|
*/
|
|
459
477
|
interface DateRangeFilterProps {
|
|
@@ -496,11 +514,39 @@ interface DateRangeFilterProps {
|
|
|
496
514
|
icon?: React.ReactNode;
|
|
497
515
|
/** 'creativeIntel' swaps in the day-level shortcut list (Today/Yesterday/Last N days/All available history) used by that dashboard. */
|
|
498
516
|
presetSet?: "default" | "creativeIntel";
|
|
517
|
+
/** Preset labels to leave out of the rail, e.g. the rolling-month ones. */
|
|
518
|
+
excludePresets?: readonly string[];
|
|
519
|
+
/**
|
|
520
|
+
* Start with no range chosen and show this label ("Any time") until a range
|
|
521
|
+
* is applied. Uncontrolled only. Remount (change `key`) to reset.
|
|
522
|
+
*/
|
|
523
|
+
emptyLabel?: string;
|
|
524
|
+
/** The day presets end on: the data's last day. Defaults to the real today. */
|
|
525
|
+
today?: Date;
|
|
526
|
+
/** The dates behind a `defaultValue` that isn't a preset (a custom span). Uncontrolled only. */
|
|
527
|
+
initialRange?: [Date, Date];
|
|
528
|
+
/**
|
|
529
|
+
* What changes are measured against, picked under the calendar and staged
|
|
530
|
+
* with the dates until Apply. The chip reads "· vs <label>" for the applied
|
|
531
|
+
* pick; a new `compare.value` from the parent replaces it.
|
|
532
|
+
*/
|
|
533
|
+
compare?: {
|
|
534
|
+
value?: string;
|
|
535
|
+
options: {
|
|
536
|
+
id: string;
|
|
537
|
+
label: string;
|
|
538
|
+
}[];
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Fired on Apply only: the preset's name (or a custom span as "Oct 1, 2025 – Oct 17, 2026"),
|
|
542
|
+
* its dates, and the compare-to pick.
|
|
543
|
+
*/
|
|
544
|
+
onApply?: (label: string, start: Date, end: Date, compare?: string) => void;
|
|
499
545
|
/**
|
|
500
546
|
* Prefix for `data-testid` attributes on the trigger (`${testIdPrefix}-trigger`),
|
|
501
547
|
* the popover (`-popover`), each preset (`-option-<slugified-label>`, e.g.
|
|
502
|
-
* `-option-last-7-days`),
|
|
503
|
-
* no test-id wiring.
|
|
548
|
+
* `-option-last-7-days`), each `compare` option (`-compare-<slugified-id>`),
|
|
549
|
+
* and Cancel (`-cancel`) / Apply (`-apply`). Omit for no test-id wiring.
|
|
504
550
|
*/
|
|
505
551
|
testIdPrefix?: string;
|
|
506
552
|
/**
|
|
@@ -510,7 +556,7 @@ interface DateRangeFilterProps {
|
|
|
510
556
|
*/
|
|
511
557
|
granularity?: "day" | "month";
|
|
512
558
|
}
|
|
513
|
-
declare function DateRangeFilter({ caption, defaultValue, value: controlledValue, range: controlledRange, align, placement, onChange, onRangeChange, showDates, shortDates, icon, presetSet, testIdPrefix, granularity, }: DateRangeFilterProps): react.JSX.Element;
|
|
559
|
+
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;
|
|
514
560
|
|
|
515
561
|
/**
|
|
516
562
|
* @pattern SearchBar
|
package/dist/index.d.ts
CHANGED
|
@@ -433,13 +433,20 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
|
|
|
433
433
|
* @tokens text-control-caption, rounded-control, rounded-card, border-border-default, border-border-strong,
|
|
434
434
|
* bg-surface, bg-input, bg-subtle, bg-ai-tint, bg-brand-primaryAction, text-brand-onprimary,
|
|
435
435
|
* shadow-overlay, text-text-primary, text-text-secondary, text-text-tertiary,
|
|
436
|
-
* hover:bg-subtle, hover:text-text-primary, focus-visible:outline-border-focus
|
|
436
|
+
* hover:bg-subtle, hover:text-text-primary, focus-visible:outline-border-focus, text-dense
|
|
437
437
|
* @dependencies lucide-react
|
|
438
438
|
* @behavior Escape and outside-click both close the popup. Opening always
|
|
439
439
|
* resets the draft (shortcut/start/end/visible month) to the last committed
|
|
440
440
|
* values, so a previous unsaved edit never lingers into the next open. Only
|
|
441
441
|
* the Apply button commits -- Cancel, Escape, and outside-click all discard
|
|
442
|
-
* the draft silently.
|
|
442
|
+
* the draft silently. "Last 30 days" is a hidden preset: a `defaultValue` or
|
|
443
|
+
* `value` naming it resolves to its dates, but the rail never offers it.
|
|
444
|
+
* `excludePresets` drops presets from the rail. `emptyLabel` starts the chip
|
|
445
|
+
* with no range chosen (Apply stays disabled until a day is picked).
|
|
446
|
+
* `compare` adds a "Compare to" radio group under the calendar, staged with
|
|
447
|
+
* the dates until Apply; the chip then reads "Last 7 days · vs prior period".
|
|
448
|
+
* `today` sets the day presets end on, for data that stops before the real
|
|
449
|
+
* today.
|
|
443
450
|
* `granularity="month"` rounds every range out to whole months (presets,
|
|
444
451
|
* clicked days and Apply alike), shows months on the trigger, and adds a
|
|
445
452
|
* "Data is monthly" note beside Cancel/Apply.
|
|
@@ -454,6 +461,17 @@ declare function CheckBoxBox({ checked, indeterminate, disabled, className }: Ch
|
|
|
454
461
|
* <DateRangeFilter caption="Dates" showDates shortDates placement="right" />
|
|
455
462
|
* <DateRangeFilter presetSet="creativeIntel" defaultValue="Last 7 days" onChange={setRange} />
|
|
456
463
|
* <DateRangeFilter presetSet="creativeIntel" value={preset} range={[start, end]} onChange={setPreset} onRangeChange={(s, e) => setRange({ start: s, end: e })} />
|
|
464
|
+
* <DateRangeFilter presetSet="creativeIntel" excludePresets={["Rolling 3 months", "Rolling 6 months"]} emptyLabel="Any time" onRangeChange={setRange} />
|
|
465
|
+
* <DateRangeFilter
|
|
466
|
+
* presetSet="creativeIntel"
|
|
467
|
+
* defaultValue={filters.range}
|
|
468
|
+
* initialRange={customDates}
|
|
469
|
+
* today={dataDay}
|
|
470
|
+
* showDates
|
|
471
|
+
* shortDates
|
|
472
|
+
* compare={{ value: filters.compare, options: [{ id: "prior", label: "Prior period" }, { id: "year", label: "Same period last year" }] }}
|
|
473
|
+
* onApply={(label, start, end, compare) => update({ range: label, compare })}
|
|
474
|
+
* />
|
|
457
475
|
* ```
|
|
458
476
|
*/
|
|
459
477
|
interface DateRangeFilterProps {
|
|
@@ -496,11 +514,39 @@ interface DateRangeFilterProps {
|
|
|
496
514
|
icon?: React.ReactNode;
|
|
497
515
|
/** 'creativeIntel' swaps in the day-level shortcut list (Today/Yesterday/Last N days/All available history) used by that dashboard. */
|
|
498
516
|
presetSet?: "default" | "creativeIntel";
|
|
517
|
+
/** Preset labels to leave out of the rail, e.g. the rolling-month ones. */
|
|
518
|
+
excludePresets?: readonly string[];
|
|
519
|
+
/**
|
|
520
|
+
* Start with no range chosen and show this label ("Any time") until a range
|
|
521
|
+
* is applied. Uncontrolled only. Remount (change `key`) to reset.
|
|
522
|
+
*/
|
|
523
|
+
emptyLabel?: string;
|
|
524
|
+
/** The day presets end on: the data's last day. Defaults to the real today. */
|
|
525
|
+
today?: Date;
|
|
526
|
+
/** The dates behind a `defaultValue` that isn't a preset (a custom span). Uncontrolled only. */
|
|
527
|
+
initialRange?: [Date, Date];
|
|
528
|
+
/**
|
|
529
|
+
* What changes are measured against, picked under the calendar and staged
|
|
530
|
+
* with the dates until Apply. The chip reads "· vs <label>" for the applied
|
|
531
|
+
* pick; a new `compare.value` from the parent replaces it.
|
|
532
|
+
*/
|
|
533
|
+
compare?: {
|
|
534
|
+
value?: string;
|
|
535
|
+
options: {
|
|
536
|
+
id: string;
|
|
537
|
+
label: string;
|
|
538
|
+
}[];
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Fired on Apply only: the preset's name (or a custom span as "Oct 1, 2025 – Oct 17, 2026"),
|
|
542
|
+
* its dates, and the compare-to pick.
|
|
543
|
+
*/
|
|
544
|
+
onApply?: (label: string, start: Date, end: Date, compare?: string) => void;
|
|
499
545
|
/**
|
|
500
546
|
* Prefix for `data-testid` attributes on the trigger (`${testIdPrefix}-trigger`),
|
|
501
547
|
* the popover (`-popover`), each preset (`-option-<slugified-label>`, e.g.
|
|
502
|
-
* `-option-last-7-days`),
|
|
503
|
-
* no test-id wiring.
|
|
548
|
+
* `-option-last-7-days`), each `compare` option (`-compare-<slugified-id>`),
|
|
549
|
+
* and Cancel (`-cancel`) / Apply (`-apply`). Omit for no test-id wiring.
|
|
504
550
|
*/
|
|
505
551
|
testIdPrefix?: string;
|
|
506
552
|
/**
|
|
@@ -510,7 +556,7 @@ interface DateRangeFilterProps {
|
|
|
510
556
|
*/
|
|
511
557
|
granularity?: "day" | "month";
|
|
512
558
|
}
|
|
513
|
-
declare function DateRangeFilter({ caption, defaultValue, value: controlledValue, range: controlledRange, align, placement, onChange, onRangeChange, showDates, shortDates, icon, presetSet, testIdPrefix, granularity, }: DateRangeFilterProps): react.JSX.Element;
|
|
559
|
+
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;
|
|
514
560
|
|
|
515
561
|
/**
|
|
516
562
|
* @pattern SearchBar
|
package/dist/index.js
CHANGED
|
@@ -608,7 +608,7 @@ function CheckBoxBox({ checked, indeterminate, disabled, className }) {
|
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
// src/DateRangeFilter.tsx
|
|
611
|
-
import { useEffect as useEffect3, useLayoutEffect, useMemo as useMemo2, useRef as useRef3, useState as useState3 } from "react";
|
|
611
|
+
import { useEffect as useEffect3, useId as useId2, useLayoutEffect, useMemo as useMemo2, useRef as useRef3, useState as useState3 } from "react";
|
|
612
612
|
import { ChevronDown as ChevronDown2, ChevronLeft, ChevronRight } from "lucide-react";
|
|
613
613
|
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
614
614
|
var DEFAULT_SHORTCUTS = [
|
|
@@ -636,6 +636,7 @@ var CREATIVE_INTEL_SHORTCUTS = [
|
|
|
636
636
|
"All available history",
|
|
637
637
|
"Custom"
|
|
638
638
|
];
|
|
639
|
+
var HIDDEN_SHORTCUTS = ["Last 30 days"];
|
|
639
640
|
var WEEKDAYS = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
|
640
641
|
var MONTHS = [
|
|
641
642
|
"January",
|
|
@@ -666,6 +667,20 @@ var fmt = (d) => `${MONTHS[d.getMonth()].slice(0, 3)} ${d.getDate()}, ${d.getFul
|
|
|
666
667
|
var fmtFull = (d) => `${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
|
|
667
668
|
var fullRangeLabel = (s, e) => `${fmtFull(s)} - ${fmtFull(e)}`;
|
|
668
669
|
var presetLabel = (sc) => sc === "Custom" ? "Custom range" : sc;
|
|
670
|
+
var MON = (d) => MONTHS[d.getMonth()].slice(0, 3);
|
|
671
|
+
function spanLabel(s, e) {
|
|
672
|
+
if (s.getFullYear() !== e.getFullYear()) return `${fmt(s)} \u2013 ${fmt(e)}`;
|
|
673
|
+
if (s.getMonth() !== e.getMonth()) return `${MON(s)} ${s.getDate()} \u2013 ${MON(e)} ${e.getDate()}, ${e.getFullYear()}`;
|
|
674
|
+
return s.getDate() === e.getDate() ? fmt(s) : `${MON(s)} ${s.getDate()} \u2013 ${e.getDate()}, ${e.getFullYear()}`;
|
|
675
|
+
}
|
|
676
|
+
function compareSpan(s, e, mode) {
|
|
677
|
+
if (mode === "year") {
|
|
678
|
+
const back = (d) => new Date(d.getFullYear() - 1, d.getMonth(), d.getDate());
|
|
679
|
+
return [back(s), back(e)];
|
|
680
|
+
}
|
|
681
|
+
const days = Math.round((startOfDay(e).getTime() - startOfDay(s).getTime()) / 864e5) + 1;
|
|
682
|
+
return [addDays(s, -days), addDays(s, -1)];
|
|
683
|
+
}
|
|
669
684
|
function presetRange(key, today) {
|
|
670
685
|
const t = startOfDay(today);
|
|
671
686
|
const qMonth = Math.floor(t.getMonth() / 3) * 3;
|
|
@@ -702,6 +717,8 @@ function presetRange(key, today) {
|
|
|
702
717
|
return [addDays(t, -6), t];
|
|
703
718
|
case "Last 14 days":
|
|
704
719
|
return [addDays(t, -13), t];
|
|
720
|
+
case "Last 30 days":
|
|
721
|
+
return [addDays(t, -29), t];
|
|
705
722
|
case "Last month": {
|
|
706
723
|
const s = new Date(t.getFullYear(), t.getMonth() - 1, 1);
|
|
707
724
|
const e = new Date(t.getFullYear(), t.getMonth(), 0);
|
|
@@ -723,7 +740,7 @@ function monthGrid(year, month) {
|
|
|
723
740
|
}
|
|
724
741
|
function matchShortcut(shortcuts, label) {
|
|
725
742
|
if (!label) return "Rolling 12 months";
|
|
726
|
-
const hit = shortcuts.find((s) => s.toLowerCase() === label.toLowerCase());
|
|
743
|
+
const hit = [...shortcuts, ...HIDDEN_SHORTCUTS].find((s) => s.toLowerCase() === label.toLowerCase());
|
|
727
744
|
return hit || "Custom";
|
|
728
745
|
}
|
|
729
746
|
function slug2(value) {
|
|
@@ -742,23 +759,43 @@ function DateRangeFilter({
|
|
|
742
759
|
shortDates = false,
|
|
743
760
|
icon,
|
|
744
761
|
presetSet = "default",
|
|
762
|
+
excludePresets = [],
|
|
763
|
+
emptyLabel,
|
|
764
|
+
today: todayProp,
|
|
765
|
+
initialRange,
|
|
766
|
+
compare,
|
|
767
|
+
onApply,
|
|
745
768
|
testIdPrefix,
|
|
746
769
|
granularity = "day"
|
|
747
770
|
}) {
|
|
748
771
|
const monthly = granularity === "month";
|
|
749
772
|
const snap = (s, e) => monthly ? [firstOfMonth(s), lastOfMonth(e)] : [s, e];
|
|
750
773
|
const controlled = controlledValue !== void 0 && controlledRange !== void 0;
|
|
751
|
-
const
|
|
752
|
-
const
|
|
774
|
+
const startsEmpty = !controlled && !!emptyLabel;
|
|
775
|
+
const SHORTCUTS = (presetSet === "creativeIntel" ? CREATIVE_INTEL_SHORTCUTS : DEFAULT_SHORTCUTS).filter(
|
|
776
|
+
(s) => !excludePresets.includes(s)
|
|
777
|
+
);
|
|
778
|
+
const today = useMemo2(() => todayProp ?? /* @__PURE__ */ new Date(), []);
|
|
753
779
|
const initShortcut = matchShortcut(SHORTCUTS, controlled ? controlledValue : defaultValue);
|
|
754
|
-
const initRange = controlled ? controlledRange : snap(...presetRange(initShortcut === "Custom" ? "Rolling 12 months" : initShortcut, today));
|
|
780
|
+
const initRange = controlled ? controlledRange : initShortcut === "Custom" && initialRange ? snap(...initialRange) : snap(...presetRange(initShortcut === "Custom" ? "Rolling 12 months" : initShortcut, today));
|
|
781
|
+
const compareLabel = (id) => compare?.options.find((o) => o.id === id)?.label;
|
|
755
782
|
const dateLine = (s, e) => monthly ? `${fmtMonth(s)} \u2013 ${fmtMonth(e)}` : shortDates ? `${fmt(s)} \u2013 ${fmt(e)}` : fullRangeLabel(s, e);
|
|
756
783
|
const [open, setOpen] = useState3(false);
|
|
757
784
|
const [uncontrolledValue, setUncontrolledValue] = useState3(
|
|
758
|
-
showDates ? presetLabel(initShortcut) : defaultValue || "Last 7 days"
|
|
785
|
+
startsEmpty ? emptyLabel : showDates ? presetLabel(initShortcut) : defaultValue || "Last 7 days"
|
|
786
|
+
);
|
|
787
|
+
const [uncontrolledDatesLine, setUncontrolledDatesLine] = useState3(
|
|
788
|
+
startsEmpty ? null : dateLine(initRange[0], initRange[1])
|
|
759
789
|
);
|
|
760
|
-
const
|
|
761
|
-
const
|
|
790
|
+
const committed = useRef3({ shortcut: initShortcut, start: initRange[0], end: initRange[1], set: !startsEmpty });
|
|
791
|
+
const [cmp, setCmp] = useState3(compare?.value);
|
|
792
|
+
const committedCmp = useRef3(compare?.value);
|
|
793
|
+
const [appliedCmp, setAppliedCmp] = useState3(compare?.value);
|
|
794
|
+
useEffect3(() => {
|
|
795
|
+
committedCmp.current = compare?.value;
|
|
796
|
+
setAppliedCmp(compare?.value);
|
|
797
|
+
}, [compare?.value]);
|
|
798
|
+
const compareName = `${useId2()}-compare`;
|
|
762
799
|
const displayValue = controlled ? showDates ? presetLabel(initShortcut) : controlledValue : uncontrolledValue;
|
|
763
800
|
const displayDatesLine = controlled ? dateLine(initRange[0], initRange[1]) : uncontrolledDatesLine;
|
|
764
801
|
const [shortcut, setShortcut] = useState3(initShortcut);
|
|
@@ -767,7 +804,7 @@ function DateRangeFilter({
|
|
|
767
804
|
const [leftMonth, setLeftMonth] = useState3(new Date(initRange[0].getFullYear(), initRange[0].getMonth(), 1));
|
|
768
805
|
const ref = useRef3(null);
|
|
769
806
|
useEffect3(() => {
|
|
770
|
-
if (controlled) return;
|
|
807
|
+
if (controlled || startsEmpty) return;
|
|
771
808
|
onRangeChange?.(committed.current.start, committed.current.end);
|
|
772
809
|
}, []);
|
|
773
810
|
useEffect3(() => {
|
|
@@ -775,10 +812,12 @@ function DateRangeFilter({
|
|
|
775
812
|
const committedShortcut = controlled ? initShortcut : committed.current.shortcut;
|
|
776
813
|
const committedStart = controlled ? initRange[0] : committed.current.start;
|
|
777
814
|
const committedEnd = controlled ? initRange[1] : committed.current.end;
|
|
815
|
+
const hasRange = controlled || committed.current.set;
|
|
778
816
|
setShortcut(committedShortcut);
|
|
779
|
-
setStart(committedStart);
|
|
780
|
-
setEnd(committedEnd);
|
|
781
|
-
setLeftMonth(new Date(committedStart.getFullYear(), committedStart.getMonth(), 1));
|
|
817
|
+
setStart(hasRange ? committedStart : null);
|
|
818
|
+
setEnd(hasRange ? committedEnd : null);
|
|
819
|
+
setLeftMonth(hasRange ? new Date(committedStart.getFullYear(), committedStart.getMonth(), 1) : addMonths(today, -1));
|
|
820
|
+
setCmp(committedCmp.current);
|
|
782
821
|
const onKey = (e) => e.key === "Escape" && setOpen(false);
|
|
783
822
|
const onClick = (e) => {
|
|
784
823
|
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
@@ -812,17 +851,22 @@ function DateRangeFilter({
|
|
|
812
851
|
setEnd(e);
|
|
813
852
|
} else setEnd(monthly ? lastOfMonth(d) : d);
|
|
814
853
|
};
|
|
854
|
+
const canApply = !!start || controlled || committed.current.set;
|
|
815
855
|
const apply = () => {
|
|
856
|
+
if (!canApply) return;
|
|
816
857
|
const [s, e] = snap(start || initRange[0], end || start || initRange[0]);
|
|
817
858
|
const custom = monthly ? `${fmtMonth(s)} \u2014 ${fmtMonth(e)}` : `${fmt(s)} \u2014 ${fmt(e)}`;
|
|
818
859
|
const v = showDates ? presetLabel(shortcut) : shortcut === "Custom" ? custom : shortcut;
|
|
819
860
|
if (!controlled) {
|
|
820
|
-
committed.current = { shortcut, start: s, end: e };
|
|
861
|
+
committed.current = { shortcut, start: s, end: e, set: true };
|
|
821
862
|
setUncontrolledValue(v);
|
|
822
863
|
setUncontrolledDatesLine(dateLine(s, e));
|
|
823
864
|
}
|
|
865
|
+
committedCmp.current = cmp;
|
|
866
|
+
setAppliedCmp(cmp);
|
|
824
867
|
onChange?.(v);
|
|
825
868
|
onRangeChange?.(s, e);
|
|
869
|
+
onApply?.(shortcut === "Custom" ? `${fmt(s)} \u2013 ${fmt(e)}` : shortcut, s, e, cmp);
|
|
826
870
|
setOpen(false);
|
|
827
871
|
};
|
|
828
872
|
const popRef = useRef3(null);
|
|
@@ -844,8 +888,14 @@ function DateRangeFilter({
|
|
|
844
888
|
children: [
|
|
845
889
|
icon && /* @__PURE__ */ jsx8("span", { className: "shrink-0 text-text-tertiary", children: icon }),
|
|
846
890
|
/* @__PURE__ */ jsxs7("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
|
|
847
|
-
/* @__PURE__ */ jsx8("span", { className: showDates ? "text-[11px] text-text-tertiary" : "text-control-caption uppercase tracking-wide text-text-tertiary", children: showDates ? displayDatesLine : caption }),
|
|
848
|
-
/* @__PURE__ */
|
|
891
|
+
/* @__PURE__ */ jsx8("span", { className: showDates && displayDatesLine ? "text-[11px] text-text-tertiary" : "text-control-caption uppercase tracking-wide text-text-tertiary", children: showDates && displayDatesLine ? displayDatesLine : caption }),
|
|
892
|
+
/* @__PURE__ */ jsxs7("span", { className: "text-[12px] font-medium text-text-primary", children: [
|
|
893
|
+
displayValue,
|
|
894
|
+
compareLabel(appliedCmp) && /* @__PURE__ */ jsxs7("span", { className: "font-normal text-text-secondary", children: [
|
|
895
|
+
" \xB7 vs ",
|
|
896
|
+
compareLabel(appliedCmp).toLowerCase()
|
|
897
|
+
] })
|
|
898
|
+
] })
|
|
849
899
|
] }),
|
|
850
900
|
/* @__PURE__ */ jsx8(ChevronDown2, { size: 14, "aria-hidden": "true", className: `shrink-0 text-text-secondary transition-transform ${open ? "rotate-180" : ""}` })
|
|
851
901
|
]
|
|
@@ -921,10 +971,39 @@ function DateRangeFilter({
|
|
|
921
971
|
] })
|
|
922
972
|
] }, offset);
|
|
923
973
|
}) }),
|
|
974
|
+
compare && /* @__PURE__ */ jsxs7("fieldset", { className: "mt-4 border-t border-border-default pt-4", children: [
|
|
975
|
+
/* @__PURE__ */ jsx8("legend", { className: "float-left mb-2 w-full text-xs font-medium text-text-secondary", children: "Compare to" }),
|
|
976
|
+
/* @__PURE__ */ jsx8("div", { className: "clear-left flex flex-col gap-1", children: compare.options.map((o) => {
|
|
977
|
+
const on = (cmp ?? compare.value) === o.id;
|
|
978
|
+
return /* @__PURE__ */ jsxs7(
|
|
979
|
+
"label",
|
|
980
|
+
{
|
|
981
|
+
className: `flex cursor-pointer items-center gap-2.5 rounded-control px-2 py-1.5 text-dense transition-colors ${on ? "bg-subtle" : "hover:bg-subtle"}`,
|
|
982
|
+
children: [
|
|
983
|
+
/* @__PURE__ */ jsx8(
|
|
984
|
+
"input",
|
|
985
|
+
{
|
|
986
|
+
type: "radio",
|
|
987
|
+
name: compareName,
|
|
988
|
+
value: o.id,
|
|
989
|
+
checked: on,
|
|
990
|
+
onChange: () => setCmp(o.id),
|
|
991
|
+
"data-testid": testIdPrefix && `${testIdPrefix}-compare-${slug2(o.id)}`,
|
|
992
|
+
className: "h-4 w-4 accent-brand-primaryAction"
|
|
993
|
+
}
|
|
994
|
+
),
|
|
995
|
+
/* @__PURE__ */ jsx8("span", { className: `w-44 shrink-0 ${on ? "font-semibold text-text-primary" : "text-text-secondary"}`, children: o.label }),
|
|
996
|
+
start && /* @__PURE__ */ jsx8("span", { className: "tabular-nums text-text-tertiary", children: spanLabel(...compareSpan(start, end ?? start, o.id)) })
|
|
997
|
+
]
|
|
998
|
+
},
|
|
999
|
+
o.id
|
|
1000
|
+
);
|
|
1001
|
+
}) })
|
|
1002
|
+
] }),
|
|
924
1003
|
/* @__PURE__ */ jsxs7("div", { className: "mt-4 flex items-center justify-end gap-2", children: [
|
|
925
1004
|
monthly && /* @__PURE__ */ jsx8("span", { className: "mr-auto text-xs text-text-tertiary", children: "Data is monthly, so ranges cover whole months." }),
|
|
926
1005
|
/* @__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-[13px] font-semibold text-text-primary transition-colors hover:bg-subtle", children: "Cancel" }),
|
|
927
|
-
/* @__PURE__ */ jsx8("button", { type: "button", "data-testid": testIdPrefix && `${testIdPrefix}-apply`, onClick: apply, className: "rounded-control bg-brand-primaryAction px-5 py-2 text-[13px] font-semibold text-brand-onprimary transition-[filter] hover:brightness-110", children: "Apply" })
|
|
1006
|
+
/* @__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-[13px] font-semibold text-brand-onprimary transition-[filter] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50", children: "Apply" })
|
|
928
1007
|
] })
|
|
929
1008
|
] })
|
|
930
1009
|
]
|
|
@@ -943,7 +1022,7 @@ function NavBtn({ children, onClick, ...rest }) {
|
|
|
943
1022
|
}
|
|
944
1023
|
|
|
945
1024
|
// src/SearchBar.tsx
|
|
946
|
-
import { useEffect as useEffect4, useId as
|
|
1025
|
+
import { useEffect as useEffect4, useId as useId3, useRef as useRef4, useState as useState4 } from "react";
|
|
947
1026
|
import { AlertCircle, Check as Check3, ChevronDown as ChevronDown3, Search as Search3, X as X2 } from "lucide-react";
|
|
948
1027
|
import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
949
1028
|
var HEIGHT = { sm: "h-8", md: "h-10", lg: "h-11" };
|
|
@@ -1223,7 +1302,7 @@ function RadioOption({
|
|
|
1223
1302
|
}
|
|
1224
1303
|
function RowInfoTip({ text }) {
|
|
1225
1304
|
const [open, setOpen] = useState4(false);
|
|
1226
|
-
const id =
|
|
1305
|
+
const id = useId3();
|
|
1227
1306
|
const ref = useRef4(null);
|
|
1228
1307
|
useEffect4(() => {
|
|
1229
1308
|
if (!open) return;
|
|
@@ -1982,7 +2061,7 @@ function StackedColumnPlaceholder({
|
|
|
1982
2061
|
}
|
|
1983
2062
|
|
|
1984
2063
|
// src/Tooltip.tsx
|
|
1985
|
-
import { useEffect as useEffect8, useId as
|
|
2064
|
+
import { useEffect as useEffect8, useId as useId4, useLayoutEffect as useLayoutEffect3, useRef as useRef9, useState as useState8 } from "react";
|
|
1986
2065
|
import { createPortal as createPortal3 } from "react-dom";
|
|
1987
2066
|
import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
1988
2067
|
function cx6(...parts) {
|
|
@@ -2033,7 +2112,7 @@ function Tooltip({
|
|
|
2033
2112
|
const [shown, setShown] = useState8(false);
|
|
2034
2113
|
const openRef = useRef9(false);
|
|
2035
2114
|
const mountedRef = useRef9(false);
|
|
2036
|
-
const id =
|
|
2115
|
+
const id = useId4();
|
|
2037
2116
|
const describedRef = useRef9(null);
|
|
2038
2117
|
const clearHideTimer = () => {
|
|
2039
2118
|
if (hideTimer.current) {
|
|
@@ -3012,7 +3091,7 @@ function FilterDropdownFooter({
|
|
|
3012
3091
|
}
|
|
3013
3092
|
|
|
3014
3093
|
// src/NameListModal.tsx
|
|
3015
|
-
import { useEffect as useEffect10, useId as
|
|
3094
|
+
import { useEffect as useEffect10, useId as useId5, useRef as useRef11, useState as useState11 } from "react";
|
|
3016
3095
|
import { createPortal as createPortal5 } from "react-dom";
|
|
3017
3096
|
import { jsx as jsx30, jsxs as jsxs28 } from "react/jsx-runtime";
|
|
3018
3097
|
function NameListModal({
|
|
@@ -3031,8 +3110,8 @@ function NameListModal({
|
|
|
3031
3110
|
);
|
|
3032
3111
|
const toggle = (key) => setChecked((c) => ({ ...c, [key]: !c[key] }));
|
|
3033
3112
|
const dialogRef = useRef11(null);
|
|
3034
|
-
const titleId =
|
|
3035
|
-
const fieldId =
|
|
3113
|
+
const titleId = useId5();
|
|
3114
|
+
const fieldId = useId5();
|
|
3036
3115
|
useEffect10(() => {
|
|
3037
3116
|
const onKey = (e) => e.key === "Escape" && onCancel();
|
|
3038
3117
|
window.addEventListener("keydown", onKey);
|
|
@@ -3585,7 +3664,7 @@ function resolveRange(label, today = startOfToday()) {
|
|
|
3585
3664
|
}
|
|
3586
3665
|
return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
|
|
3587
3666
|
}
|
|
3588
|
-
function
|
|
3667
|
+
function spanLabel2(label, today) {
|
|
3589
3668
|
const [s, e] = resolveRange(label, today);
|
|
3590
3669
|
return `${fmtDate(s)} \u2013 ${fmtDate(e)}`;
|
|
3591
3670
|
}
|
|
@@ -3671,7 +3750,7 @@ function DateRangePicker({
|
|
|
3671
3750
|
className: chipTriggerClass(),
|
|
3672
3751
|
children: [
|
|
3673
3752
|
/* @__PURE__ */ jsxs34("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
|
|
3674
|
-
/* @__PURE__ */ jsx38("span", { className: "text-control-caption text-text-tertiary", children:
|
|
3753
|
+
/* @__PURE__ */ jsx38("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end) }),
|
|
3675
3754
|
/* @__PURE__ */ jsx38("span", { className: "text-[12px] font-medium text-text-primary", children: value })
|
|
3676
3755
|
] }),
|
|
3677
3756
|
/* @__PURE__ */ jsx38(ChevronDown9, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-text-secondary transition-transform", open && "rotate-180") })
|
|
@@ -4014,11 +4093,11 @@ function Toggle({ checked, onChange, label, size = "md", disabled, className, te
|
|
|
4014
4093
|
}
|
|
4015
4094
|
|
|
4016
4095
|
// src/AISpark.tsx
|
|
4017
|
-
import { useId as
|
|
4096
|
+
import { useId as useId6 } from "react";
|
|
4018
4097
|
import { Sparkles } from "lucide-react";
|
|
4019
4098
|
import { Fragment as Fragment6, jsx as jsx41, jsxs as jsxs36 } from "react/jsx-runtime";
|
|
4020
4099
|
function AISpark({ size = 16, className }) {
|
|
4021
|
-
const id =
|
|
4100
|
+
const id = useId6();
|
|
4022
4101
|
return /* @__PURE__ */ jsxs36(Fragment6, { children: [
|
|
4023
4102
|
/* @__PURE__ */ jsx41("svg", { width: "0", height: "0", "aria-hidden": "true", style: { position: "absolute" }, children: /* @__PURE__ */ jsx41("defs", { children: /* @__PURE__ */ jsxs36("linearGradient", { id, x1: "0", y1: "0", x2: "1", y2: "1", children: [
|
|
4024
4103
|
/* @__PURE__ */ jsx41("stop", { offset: "0%", stopColor: "var(--mr-color-brand-primary)" }),
|
|
@@ -4089,7 +4168,7 @@ function PageHeader({ title, description, actions, back, className }) {
|
|
|
4089
4168
|
}
|
|
4090
4169
|
|
|
4091
4170
|
// src/Modal.tsx
|
|
4092
|
-
import { useEffect as useEffect14, useId as
|
|
4171
|
+
import { useEffect as useEffect14, useId as useId7, useRef as useRef15 } from "react";
|
|
4093
4172
|
import { createPortal as createPortal7 } from "react-dom";
|
|
4094
4173
|
import { X as X6 } from "lucide-react";
|
|
4095
4174
|
import { jsx as jsx45, jsxs as jsxs39 } from "react/jsx-runtime";
|
|
@@ -4103,8 +4182,8 @@ var WIDTH = {
|
|
|
4103
4182
|
};
|
|
4104
4183
|
var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
4105
4184
|
function Modal({ open, onClose, title, description, size = "md", footer, children, className }) {
|
|
4106
|
-
const titleId =
|
|
4107
|
-
const descId =
|
|
4185
|
+
const titleId = useId7();
|
|
4186
|
+
const descId = useId7();
|
|
4108
4187
|
const panel = useRef15(null);
|
|
4109
4188
|
const close = useRef15(onClose);
|
|
4110
4189
|
close.current = onClose;
|
|
@@ -4314,12 +4393,12 @@ function SegmentedControl({
|
|
|
4314
4393
|
}
|
|
4315
4394
|
|
|
4316
4395
|
// src/TextField.tsx
|
|
4317
|
-
import { forwardRef as forwardRef3, useId as
|
|
4396
|
+
import { forwardRef as forwardRef3, useId as useId8 } from "react";
|
|
4318
4397
|
import { jsx as jsx48, jsxs as jsxs42 } from "react/jsx-runtime";
|
|
4319
4398
|
var HEIGHT2 = { sm: "h-8", md: "h-10", lg: "h-11" };
|
|
4320
4399
|
var TextField = forwardRef3(
|
|
4321
4400
|
({ label, hint, error, size = "md", icon, className, id, disabled, ...props }, ref) => {
|
|
4322
|
-
const auto =
|
|
4401
|
+
const auto = useId8();
|
|
4323
4402
|
const fieldId = id ?? auto;
|
|
4324
4403
|
const noteId = `${fieldId}-note`;
|
|
4325
4404
|
const note = error ?? hint;
|
|
@@ -4358,7 +4437,7 @@ var TextField = forwardRef3(
|
|
|
4358
4437
|
TextField.displayName = "TextField";
|
|
4359
4438
|
|
|
4360
4439
|
// src/Drawer.tsx
|
|
4361
|
-
import { useEffect as useEffect15, useId as
|
|
4440
|
+
import { useEffect as useEffect15, useId as useId9, useRef as useRef17, useState as useState15 } from "react";
|
|
4362
4441
|
import { createPortal as createPortal8 } from "react-dom";
|
|
4363
4442
|
import { X as X7 } from "lucide-react";
|
|
4364
4443
|
import { jsx as jsx49, jsxs as jsxs43 } from "react/jsx-runtime";
|
|
@@ -4370,8 +4449,8 @@ var WIDTH2 = {
|
|
|
4370
4449
|
var EXIT_MS = 200;
|
|
4371
4450
|
var FOCUSABLE2 = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
4372
4451
|
function Drawer({ open, onClose, title, description, size = "sm", footer, children, className }) {
|
|
4373
|
-
const titleId =
|
|
4374
|
-
const descId =
|
|
4452
|
+
const titleId = useId9();
|
|
4453
|
+
const descId = useId9();
|
|
4375
4454
|
const panel = useRef17(null);
|
|
4376
4455
|
const close = useRef17(onClose);
|
|
4377
4456
|
close.current = onClose;
|
|
@@ -4480,7 +4559,7 @@ function Drawer({ open, onClose, title, description, size = "sm", footer, childr
|
|
|
4480
4559
|
}
|
|
4481
4560
|
|
|
4482
4561
|
// src/DataTable.tsx
|
|
4483
|
-
import { useId as
|
|
4562
|
+
import { useId as useId10 } from "react";
|
|
4484
4563
|
import { jsx as jsx50, jsxs as jsxs44 } from "react/jsx-runtime";
|
|
4485
4564
|
var WIDTH3 = { fill: "", sm: "w-24", md: "w-36", lg: "w-48" };
|
|
4486
4565
|
var MAX_H = { sm: "max-h-80", md: "max-h-120", lg: "max-h-160" };
|
|
@@ -4504,7 +4583,7 @@ function DataTable({
|
|
|
4504
4583
|
className,
|
|
4505
4584
|
...rest
|
|
4506
4585
|
}) {
|
|
4507
|
-
const titleId =
|
|
4586
|
+
const titleId = useId10();
|
|
4508
4587
|
const head = HEAD_PAD[density];
|
|
4509
4588
|
const pad = CELL_PAD[density];
|
|
4510
4589
|
const align = (c) => c.numeric ? "text-right" : "text-left";
|