@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.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
|
|
@@ -849,12 +872,17 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
|
|
|
849
872
|
* @use for picking one value from a short list in a filter row or a form --
|
|
850
873
|
* the caption-over-value chip is the one dropdown trigger.
|
|
851
874
|
* @use the caption everywhere except tight spots where the field is obvious.
|
|
875
|
+
* @use `size="sm"` (32px) for a control in a card or panel header (a card's
|
|
876
|
+
* Measure or Compare by), with `inlineCaption` when the value alone doesn't
|
|
877
|
+
* say what it sets ("Sort by: Name"). There is no 36px step.
|
|
878
|
+
* @avoid a hand-built 36px "slim" chip; use `sm`.
|
|
852
879
|
* @avoid a native <select> or a hand-built dropdown.
|
|
853
880
|
* @avoid it for several values at once -- that's MultiSelectFilter.
|
|
854
881
|
* @usage
|
|
855
882
|
* ```tsx
|
|
856
883
|
* <SelectFilter caption="Rank" value={rankFilter} onChange={setRankFilter} options={['All', 'VP / Director', 'Manager', 'Coordinator']} />
|
|
857
884
|
* <SelectFilter caption="Group by" value={groupBy} onChange={setGroupBy} options={['Parent', 'Advertiser', 'Brand']} fullWidth testIdPrefix="dropdown-group-by" />
|
|
885
|
+
* <SelectFilter caption="Sort by" size="sm" inlineCaption value={sort} onChange={setSort} options={['Name', 'Spend']} align="right" />
|
|
858
886
|
* <SelectFilter caption="Country" value={country} onChange={setCountry} options={['United States', 'Canada', 'United Kingdom']} renderIcon={(c) => <img src={FLAGS[c]} alt="" />} />
|
|
859
887
|
* ```
|
|
860
888
|
*/
|
|
@@ -892,6 +920,12 @@ interface SelectFilterProps {
|
|
|
892
920
|
* control in TablePagination. Defaults to 'md', the 44px caption chip.
|
|
893
921
|
*/
|
|
894
922
|
size?: "md" | "sm";
|
|
923
|
+
/**
|
|
924
|
+
* With `size="sm"`: show the caption in the trigger, "Sort by: Name",
|
|
925
|
+
* instead of only the value. For a compact control whose value alone
|
|
926
|
+
* doesn't say what it sets.
|
|
927
|
+
*/
|
|
928
|
+
inlineCaption?: boolean;
|
|
895
929
|
/** Fades the trigger to 40% and blocks it, e.g. while a table loads. */
|
|
896
930
|
disabled?: boolean;
|
|
897
931
|
/**
|
|
@@ -903,7 +937,7 @@ interface SelectFilterProps {
|
|
|
903
937
|
*/
|
|
904
938
|
renderIcon?: (option: string) => ReactNode;
|
|
905
939
|
}
|
|
906
|
-
declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
|
|
940
|
+
declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, inlineCaption, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
|
|
907
941
|
|
|
908
942
|
/**
|
|
909
943
|
* @pattern Card
|
|
@@ -2341,7 +2375,7 @@ type DateGranularity = 'month' | 'quarter' | 'year';
|
|
|
2341
2375
|
/** Resolve a label to its actual [start, end] span, ending at `today`. */
|
|
2342
2376
|
declare function resolveRange(label: string, today?: Date): [Date, Date];
|
|
2343
2377
|
/** @deprecated Use DateRangeFilter, with `granularity="month"` for monthly data. */
|
|
2344
|
-
declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, }: {
|
|
2378
|
+
declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, formatDate, formatRange, }: {
|
|
2345
2379
|
defaultValue?: string;
|
|
2346
2380
|
align?: 'left' | 'right';
|
|
2347
2381
|
/**
|
|
@@ -2364,6 +2398,19 @@ declare function DateRangePicker({ defaultValue, granularity, align, presets, on
|
|
|
2364
2398
|
/** Years offered in the Custom Range selects. Defaults to the last four,
|
|
2365
2399
|
* ending with `today`'s year. */
|
|
2366
2400
|
years?: number[];
|
|
2401
|
+
/**
|
|
2402
|
+
* Writes each date in the dates line above the label, e.g. to follow a
|
|
2403
|
+
* person's date-format setting ("14 Nov 2026", "2026-11-14"). Defaults to
|
|
2404
|
+
* "Nov 14, 2026". Only what's shown changes: the label and `onChange` keep
|
|
2405
|
+
* the canonical form.
|
|
2406
|
+
*/
|
|
2407
|
+
formatDate?: (d: Date) => string;
|
|
2408
|
+
/**
|
|
2409
|
+
* Writes the whole dates line, for a span that reads more briefly than two
|
|
2410
|
+
* full dates. Takes precedence over `formatDate`. Defaults to
|
|
2411
|
+
* `${formatDate(start)} – ${formatDate(end)}`.
|
|
2412
|
+
*/
|
|
2413
|
+
formatRange?: (start: Date, end: Date) => string;
|
|
2367
2414
|
}): react.JSX.Element;
|
|
2368
2415
|
type DateRangePickerProps = Parameters<typeof DateRangePicker>[0];
|
|
2369
2416
|
|
|
@@ -2402,15 +2449,22 @@ interface MultiSelectGroup {
|
|
|
2402
2449
|
* Escape closes it. Option rows carry their own checkbox semantics. Focus
|
|
2403
2450
|
* is not moved into the menu on open, so keyboard users tab into it in DOM
|
|
2404
2451
|
* order. The loading rows carry role="status" and the error line role="alert".
|
|
2452
|
+
* @behavior `valueLabel` replaces the trigger's value text, for when a picked
|
|
2453
|
+
* option's own label is ambiguous outside its group ("All" for a market
|
|
2454
|
+
* filter where nothing and everything mean the same). `hints` puts a short
|
|
2455
|
+
* definition under an option's label, keyed by option or group id, for a term
|
|
2456
|
+
* the user may not know. `note` is one line of explanation under the list.
|
|
2405
2457
|
* @behavior `loading` swaps the list for grey placeholder rows and `error`
|
|
2406
2458
|
* for a plain "Couldn't load options." line with a Try again link
|
|
2407
2459
|
* (`onRetry`). The trigger never changes in either state.
|
|
2408
2460
|
* @usage
|
|
2409
2461
|
* ```tsx
|
|
2410
2462
|
* <MultiSelectFilter caption="Media" options={mediaOptions} selected={selected} onChange={setSelected} />
|
|
2463
|
+
* <MultiSelectFilter caption="Market" options={markets} selected={selected} onChange={setSelected}
|
|
2464
|
+
* hints={{ national: "Ads that run nationwide" }} note="Nothing picked means every market." />
|
|
2411
2465
|
* ```
|
|
2412
2466
|
*/
|
|
2413
|
-
declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, }: {
|
|
2467
|
+
declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, valueLabel, hints, note, }: {
|
|
2414
2468
|
caption: string;
|
|
2415
2469
|
/**
|
|
2416
2470
|
* Live option-id -> result count. Supplying it makes the menu faceted:
|
|
@@ -2460,6 +2514,14 @@ declare function MultiSelectFilter({ caption, options, groups, counts, variant,
|
|
|
2460
2514
|
error?: boolean;
|
|
2461
2515
|
/** Called by the Try again link in the error state. */
|
|
2462
2516
|
onRetry?: () => void;
|
|
2517
|
+
/** Trigger text in place of the default ("All", the one label, "n selected"),
|
|
2518
|
+
* when a picked option's own label is ambiguous outside its group. */
|
|
2519
|
+
valueLabel?: string;
|
|
2520
|
+
/** A short definition under an option's label, by option or group id, for a
|
|
2521
|
+
* term the user may not know. */
|
|
2522
|
+
hints?: Record<string, string>;
|
|
2523
|
+
/** One line of explanation under the list, above the footer. */
|
|
2524
|
+
note?: React.ReactNode;
|
|
2463
2525
|
}): react.JSX.Element;
|
|
2464
2526
|
type MultiSelectFilterProps = Parameters<typeof MultiSelectFilter>[0];
|
|
2465
2527
|
|
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
|
|
@@ -849,12 +872,17 @@ declare function DataScopeFilter({ value, onChange, align }: DataScopeFilterProp
|
|
|
849
872
|
* @use for picking one value from a short list in a filter row or a form --
|
|
850
873
|
* the caption-over-value chip is the one dropdown trigger.
|
|
851
874
|
* @use the caption everywhere except tight spots where the field is obvious.
|
|
875
|
+
* @use `size="sm"` (32px) for a control in a card or panel header (a card's
|
|
876
|
+
* Measure or Compare by), with `inlineCaption` when the value alone doesn't
|
|
877
|
+
* say what it sets ("Sort by: Name"). There is no 36px step.
|
|
878
|
+
* @avoid a hand-built 36px "slim" chip; use `sm`.
|
|
852
879
|
* @avoid a native <select> or a hand-built dropdown.
|
|
853
880
|
* @avoid it for several values at once -- that's MultiSelectFilter.
|
|
854
881
|
* @usage
|
|
855
882
|
* ```tsx
|
|
856
883
|
* <SelectFilter caption="Rank" value={rankFilter} onChange={setRankFilter} options={['All', 'VP / Director', 'Manager', 'Coordinator']} />
|
|
857
884
|
* <SelectFilter caption="Group by" value={groupBy} onChange={setGroupBy} options={['Parent', 'Advertiser', 'Brand']} fullWidth testIdPrefix="dropdown-group-by" />
|
|
885
|
+
* <SelectFilter caption="Sort by" size="sm" inlineCaption value={sort} onChange={setSort} options={['Name', 'Spend']} align="right" />
|
|
858
886
|
* <SelectFilter caption="Country" value={country} onChange={setCountry} options={['United States', 'Canada', 'United Kingdom']} renderIcon={(c) => <img src={FLAGS[c]} alt="" />} />
|
|
859
887
|
* ```
|
|
860
888
|
*/
|
|
@@ -892,6 +920,12 @@ interface SelectFilterProps {
|
|
|
892
920
|
* control in TablePagination. Defaults to 'md', the 44px caption chip.
|
|
893
921
|
*/
|
|
894
922
|
size?: "md" | "sm";
|
|
923
|
+
/**
|
|
924
|
+
* With `size="sm"`: show the caption in the trigger, "Sort by: Name",
|
|
925
|
+
* instead of only the value. For a compact control whose value alone
|
|
926
|
+
* doesn't say what it sets.
|
|
927
|
+
*/
|
|
928
|
+
inlineCaption?: boolean;
|
|
895
929
|
/** Fades the trigger to 40% and blocks it, e.g. while a table loads. */
|
|
896
930
|
disabled?: boolean;
|
|
897
931
|
/**
|
|
@@ -903,7 +937,7 @@ interface SelectFilterProps {
|
|
|
903
937
|
*/
|
|
904
938
|
renderIcon?: (option: string) => ReactNode;
|
|
905
939
|
}
|
|
906
|
-
declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
|
|
940
|
+
declare function SelectFilter({ caption, value, options, onChange, align, fullWidth, className, testIdPrefix, loading, error, onRetry, size, inlineCaption, disabled, renderIcon, }: SelectFilterProps): react.JSX.Element;
|
|
907
941
|
|
|
908
942
|
/**
|
|
909
943
|
* @pattern Card
|
|
@@ -2341,7 +2375,7 @@ type DateGranularity = 'month' | 'quarter' | 'year';
|
|
|
2341
2375
|
/** Resolve a label to its actual [start, end] span, ending at `today`. */
|
|
2342
2376
|
declare function resolveRange(label: string, today?: Date): [Date, Date];
|
|
2343
2377
|
/** @deprecated Use DateRangeFilter, with `granularity="month"` for monthly data. */
|
|
2344
|
-
declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, }: {
|
|
2378
|
+
declare function DateRangePicker({ defaultValue, granularity, align, presets, onChange, onRangeChange, showFooter, today, years, formatDate, formatRange, }: {
|
|
2345
2379
|
defaultValue?: string;
|
|
2346
2380
|
align?: 'left' | 'right';
|
|
2347
2381
|
/**
|
|
@@ -2364,6 +2398,19 @@ declare function DateRangePicker({ defaultValue, granularity, align, presets, on
|
|
|
2364
2398
|
/** Years offered in the Custom Range selects. Defaults to the last four,
|
|
2365
2399
|
* ending with `today`'s year. */
|
|
2366
2400
|
years?: number[];
|
|
2401
|
+
/**
|
|
2402
|
+
* Writes each date in the dates line above the label, e.g. to follow a
|
|
2403
|
+
* person's date-format setting ("14 Nov 2026", "2026-11-14"). Defaults to
|
|
2404
|
+
* "Nov 14, 2026". Only what's shown changes: the label and `onChange` keep
|
|
2405
|
+
* the canonical form.
|
|
2406
|
+
*/
|
|
2407
|
+
formatDate?: (d: Date) => string;
|
|
2408
|
+
/**
|
|
2409
|
+
* Writes the whole dates line, for a span that reads more briefly than two
|
|
2410
|
+
* full dates. Takes precedence over `formatDate`. Defaults to
|
|
2411
|
+
* `${formatDate(start)} – ${formatDate(end)}`.
|
|
2412
|
+
*/
|
|
2413
|
+
formatRange?: (start: Date, end: Date) => string;
|
|
2367
2414
|
}): react.JSX.Element;
|
|
2368
2415
|
type DateRangePickerProps = Parameters<typeof DateRangePicker>[0];
|
|
2369
2416
|
|
|
@@ -2402,15 +2449,22 @@ interface MultiSelectGroup {
|
|
|
2402
2449
|
* Escape closes it. Option rows carry their own checkbox semantics. Focus
|
|
2403
2450
|
* is not moved into the menu on open, so keyboard users tab into it in DOM
|
|
2404
2451
|
* order. The loading rows carry role="status" and the error line role="alert".
|
|
2452
|
+
* @behavior `valueLabel` replaces the trigger's value text, for when a picked
|
|
2453
|
+
* option's own label is ambiguous outside its group ("All" for a market
|
|
2454
|
+
* filter where nothing and everything mean the same). `hints` puts a short
|
|
2455
|
+
* definition under an option's label, keyed by option or group id, for a term
|
|
2456
|
+
* the user may not know. `note` is one line of explanation under the list.
|
|
2405
2457
|
* @behavior `loading` swaps the list for grey placeholder rows and `error`
|
|
2406
2458
|
* for a plain "Couldn't load options." line with a Try again link
|
|
2407
2459
|
* (`onRetry`). The trigger never changes in either state.
|
|
2408
2460
|
* @usage
|
|
2409
2461
|
* ```tsx
|
|
2410
2462
|
* <MultiSelectFilter caption="Media" options={mediaOptions} selected={selected} onChange={setSelected} />
|
|
2463
|
+
* <MultiSelectFilter caption="Market" options={markets} selected={selected} onChange={setSelected}
|
|
2464
|
+
* hints={{ national: "Ads that run nationwide" }} note="Nothing picked means every market." />
|
|
2411
2465
|
* ```
|
|
2412
2466
|
*/
|
|
2413
|
-
declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, }: {
|
|
2467
|
+
declare function MultiSelectFilter({ caption, options, groups, counts, variant, selected, onChange, allLabel, searchable, searchPlaceholder, align, fullIsAll, min, icon, showFooter, clearValue, menuWidthClass, plainParent, fullWidth, loading, error, onRetry, valueLabel, hints, note, }: {
|
|
2414
2468
|
caption: string;
|
|
2415
2469
|
/**
|
|
2416
2470
|
* Live option-id -> result count. Supplying it makes the menu faceted:
|
|
@@ -2460,6 +2514,14 @@ declare function MultiSelectFilter({ caption, options, groups, counts, variant,
|
|
|
2460
2514
|
error?: boolean;
|
|
2461
2515
|
/** Called by the Try again link in the error state. */
|
|
2462
2516
|
onRetry?: () => void;
|
|
2517
|
+
/** Trigger text in place of the default ("All", the one label, "n selected"),
|
|
2518
|
+
* when a picked option's own label is ambiguous outside its group. */
|
|
2519
|
+
valueLabel?: string;
|
|
2520
|
+
/** A short definition under an option's label, by option or group id, for a
|
|
2521
|
+
* term the user may not know. */
|
|
2522
|
+
hints?: Record<string, string>;
|
|
2523
|
+
/** One line of explanation under the list, above the footer. */
|
|
2524
|
+
note?: React.ReactNode;
|
|
2463
2525
|
}): react.JSX.Element;
|
|
2464
2526
|
type MultiSelectFilterProps = Parameters<typeof MultiSelectFilter>[0];
|
|
2465
2527
|
|
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 ?
|
|
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 ?
|
|
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
|
|
@@ -1811,6 +1817,7 @@ function SelectFilter({
|
|
|
1811
1817
|
error = false,
|
|
1812
1818
|
onRetry,
|
|
1813
1819
|
size = "md",
|
|
1820
|
+
inlineCaption = false,
|
|
1814
1821
|
disabled = false,
|
|
1815
1822
|
renderIcon
|
|
1816
1823
|
}) {
|
|
@@ -1825,7 +1832,11 @@ function SelectFilter({
|
|
|
1825
1832
|
const r = ref.current.getBoundingClientRect();
|
|
1826
1833
|
const h = Math.min(options.length * 36 + 8, 288);
|
|
1827
1834
|
const above = r.bottom + 8 + h > window.innerHeight && r.top - 8 - h > 0;
|
|
1828
|
-
setPos({
|
|
1835
|
+
setPos({
|
|
1836
|
+
top: above ? r.top - 8 - h : r.bottom + 8,
|
|
1837
|
+
...align === "right" ? { right: document.documentElement.clientWidth - r.right } : { left: r.left },
|
|
1838
|
+
width: r.width
|
|
1839
|
+
});
|
|
1829
1840
|
}, [align, options.length]);
|
|
1830
1841
|
useLayoutEffect3(() => {
|
|
1831
1842
|
if (!open) return;
|
|
@@ -1850,10 +1861,18 @@ function SelectFilter({
|
|
|
1850
1861
|
window.removeEventListener("scroll", reposition, true);
|
|
1851
1862
|
};
|
|
1852
1863
|
}, [open, close, reposition]);
|
|
1853
|
-
const
|
|
1864
|
+
const valueContent = renderIcon ? /* @__PURE__ */ jsxs12("span", { className: "flex items-center gap-1.5", children: [
|
|
1854
1865
|
/* @__PURE__ */ jsx13(OptionIcon, { children: renderIcon(value) }),
|
|
1855
1866
|
value
|
|
1856
1867
|
] }) : value;
|
|
1868
|
+
const triggerValue = sm && inlineCaption ? /* @__PURE__ */ jsxs12("span", { children: [
|
|
1869
|
+
/* @__PURE__ */ jsxs12("span", { className: "font-normal text-text-secondary", children: [
|
|
1870
|
+
caption,
|
|
1871
|
+
":"
|
|
1872
|
+
] }),
|
|
1873
|
+
" ",
|
|
1874
|
+
valueContent
|
|
1875
|
+
] }) : valueContent;
|
|
1857
1876
|
return /* @__PURE__ */ jsxs12("div", { className: cx4("relative", fullWidth && "w-full"), ref, children: [
|
|
1858
1877
|
/* @__PURE__ */ jsxs12(
|
|
1859
1878
|
"button",
|
|
@@ -1863,7 +1882,7 @@ function SelectFilter({
|
|
|
1863
1882
|
onClick: () => setOpen((o) => !o),
|
|
1864
1883
|
"aria-expanded": open,
|
|
1865
1884
|
"aria-haspopup": "listbox",
|
|
1866
|
-
"aria-label": sm ? caption : void 0,
|
|
1885
|
+
"aria-label": sm && !inlineCaption ? caption : void 0,
|
|
1867
1886
|
disabled,
|
|
1868
1887
|
className: cx4(
|
|
1869
1888
|
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(),
|
|
@@ -1890,10 +1909,10 @@ function SelectFilter({
|
|
|
1890
1909
|
{
|
|
1891
1910
|
ref: popoverRef,
|
|
1892
1911
|
"data-testid": testIdPrefix && `${testIdPrefix}-popover`,
|
|
1893
|
-
style: { position: "fixed", top: pos.top, left: pos.left, width: fullWidth ? pos.width : void 0 },
|
|
1912
|
+
style: { position: "fixed", top: pos.top, left: pos.left, right: pos.right, width: fullWidth ? pos.width : void 0 },
|
|
1894
1913
|
className: cx4(
|
|
1895
1914
|
"z-[65] flex flex-col overflow-hidden rounded-card border border-border-default bg-surface shadow-overlay",
|
|
1896
|
-
!fullWidth && (sm ? "w-28" : "w-56")
|
|
1915
|
+
!fullWidth && (sm ? "w-max min-w-28 max-w-72" : "w-56")
|
|
1897
1916
|
),
|
|
1898
1917
|
role: loading || error ? "group" : "listbox",
|
|
1899
1918
|
"aria-label": caption,
|
|
@@ -3993,9 +4012,11 @@ function resolveRange(label, today = startOfToday()) {
|
|
|
3993
4012
|
}
|
|
3994
4013
|
return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
|
|
3995
4014
|
}
|
|
3996
|
-
function spanLabel2(label, today) {
|
|
4015
|
+
function spanLabel2(label, today, formatDate, formatRange) {
|
|
3997
4016
|
const [s, e] = resolveRange(label, today);
|
|
3998
|
-
|
|
4017
|
+
if (formatRange) return formatRange(s, e);
|
|
4018
|
+
const f = formatDate ?? fmtDate;
|
|
4019
|
+
return `${f(s)} \u2013 ${f(e)}`;
|
|
3999
4020
|
}
|
|
4000
4021
|
function MiniSelect({ value, onChange, options }) {
|
|
4001
4022
|
return /* @__PURE__ */ jsx39(
|
|
@@ -4020,7 +4041,9 @@ function DateRangePicker({
|
|
|
4020
4041
|
onRangeChange,
|
|
4021
4042
|
showFooter = false,
|
|
4022
4043
|
today,
|
|
4023
|
-
years
|
|
4044
|
+
years,
|
|
4045
|
+
formatDate,
|
|
4046
|
+
formatRange
|
|
4024
4047
|
}) {
|
|
4025
4048
|
const end = useMemo4(() => today ?? startOfToday(), [today]);
|
|
4026
4049
|
const yearOptions = years ?? [3, 2, 1, 0].map((n) => end.getFullYear() - n);
|
|
@@ -4079,7 +4102,7 @@ function DateRangePicker({
|
|
|
4079
4102
|
className: chipTriggerClass(),
|
|
4080
4103
|
children: [
|
|
4081
4104
|
/* @__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) }),
|
|
4105
|
+
/* @__PURE__ */ jsx39("span", { className: "text-control-caption text-text-tertiary", children: spanLabel2(value, end, formatDate, formatRange) }),
|
|
4083
4106
|
/* @__PURE__ */ jsx39("span", { className: "text-[12px] font-medium text-text-primary", children: value })
|
|
4084
4107
|
] }),
|
|
4085
4108
|
/* @__PURE__ */ jsx39(ChevronDown9, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-text-secondary transition-transform", open && "rotate-180") })
|
|
@@ -4159,7 +4182,10 @@ function MultiSelectFilter({
|
|
|
4159
4182
|
fullWidth = false,
|
|
4160
4183
|
loading = false,
|
|
4161
4184
|
error = false,
|
|
4162
|
-
onRetry
|
|
4185
|
+
onRetry,
|
|
4186
|
+
valueLabel,
|
|
4187
|
+
hints,
|
|
4188
|
+
note
|
|
4163
4189
|
}) {
|
|
4164
4190
|
const groupLeaves = (g) => g.children.length ? g.children : [{ id: g.id, label: g.label }];
|
|
4165
4191
|
const leafOptions = groups ? groups.flatMap(groupLeaves) : options;
|
|
@@ -4220,7 +4246,11 @@ function MultiSelectFilter({
|
|
|
4220
4246
|
};
|
|
4221
4247
|
const shown = open && !showFooter ? draft : selected;
|
|
4222
4248
|
const isAll = shown.length === 0 || fullIsAll && shown.length === leafOptions.length;
|
|
4223
|
-
const value = isAll ? allLabel : shown.length === 1 ? leafOptions.find((o) => o.id === shown[0])?.label ?? `${shown.length} selected` : `${shown.length} selected
|
|
4249
|
+
const value = valueLabel ?? (isAll ? allLabel : shown.length === 1 ? leafOptions.find((o) => o.id === shown[0])?.label ?? `${shown.length} selected` : `${shown.length} selected`);
|
|
4250
|
+
const labelled = (id, label) => hints?.[id] ? /* @__PURE__ */ jsxs36("span", { className: "flex flex-col", children: [
|
|
4251
|
+
/* @__PURE__ */ jsx40("span", { children: label }),
|
|
4252
|
+
/* @__PURE__ */ jsx40("span", { className: "text-xs font-normal text-text-tertiary", children: hints[id] })
|
|
4253
|
+
] }) : label;
|
|
4224
4254
|
const ql = q.trim().toLowerCase();
|
|
4225
4255
|
const items = options.filter((o) => isAvailable(o.id) && (!ql || o.label.toLowerCase().includes(ql)));
|
|
4226
4256
|
const visibleGroups = groups ? groups.map((g) => {
|
|
@@ -4288,7 +4318,7 @@ function MultiSelectFilter({
|
|
|
4288
4318
|
className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
|
|
4289
4319
|
children: [
|
|
4290
4320
|
/* @__PURE__ */ jsx40(CheckBoxBox, { checked: state === "all", indeterminate: state === "some" }),
|
|
4291
|
-
/* @__PURE__ */ jsx40("span", { className: cn("flex-1 text-[14px] text-text-primary", !plainParent && "font-semibold"), children: g.label }),
|
|
4321
|
+
/* @__PURE__ */ jsx40("span", { className: cn("flex-1 text-[14px] text-text-primary", !plainParent && "font-semibold"), children: labelled(g.id, g.label) }),
|
|
4292
4322
|
counts && /* @__PURE__ */ jsx40(OptionCount, { n: countFor(g.id) })
|
|
4293
4323
|
]
|
|
4294
4324
|
}
|
|
@@ -4303,7 +4333,7 @@ function MultiSelectFilter({
|
|
|
4303
4333
|
className: "flex w-full items-center gap-2.5 rounded-control py-2 pl-9 pr-2 text-left transition-colors hover:bg-subtle",
|
|
4304
4334
|
children: [
|
|
4305
4335
|
/* @__PURE__ */ jsx40(CheckBoxBox, { checked }),
|
|
4306
|
-
/* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: c.label }),
|
|
4336
|
+
/* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: labelled(c.id, c.label) }),
|
|
4307
4337
|
counts && /* @__PURE__ */ jsx40(OptionCount, { n: countFor(c.id) })
|
|
4308
4338
|
]
|
|
4309
4339
|
},
|
|
@@ -4321,7 +4351,7 @@ function MultiSelectFilter({
|
|
|
4321
4351
|
className: "flex w-full items-center gap-2.5 rounded-control px-2 py-2 text-left transition-colors hover:bg-subtle",
|
|
4322
4352
|
children: [
|
|
4323
4353
|
/* @__PURE__ */ jsx40(CheckBoxBox, { checked }),
|
|
4324
|
-
/* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: o.label }),
|
|
4354
|
+
/* @__PURE__ */ jsx40("span", { className: "flex-1 text-[14px] text-text-primary", children: labelled(o.id, o.label) }),
|
|
4325
4355
|
counts && /* @__PURE__ */ jsx40(OptionCount, { n: countFor(o.id) })
|
|
4326
4356
|
]
|
|
4327
4357
|
},
|
|
@@ -4330,6 +4360,7 @@ function MultiSelectFilter({
|
|
|
4330
4360
|
}),
|
|
4331
4361
|
(groups && !visibleGroups.length || !groups && !items.length) && /* @__PURE__ */ jsx40("div", { className: "py-6 text-center text-[13px] text-text-tertiary", children: "No matches." })
|
|
4332
4362
|
] }),
|
|
4363
|
+
note && /* @__PURE__ */ jsx40("p", { className: "border-t border-border-default px-3 py-2 text-xs text-text-tertiary", children: note }),
|
|
4333
4364
|
showFooter ? /* @__PURE__ */ jsx40(FilterDropdownFooter, { onClear: () => setDraft(clearValue), onApply: apply }) : min === 0 && draft.length > 0 && /* @__PURE__ */ jsx40("div", { className: "border-t border-border-default p-2", children: /* @__PURE__ */ jsxs36(
|
|
4334
4365
|
"button",
|
|
4335
4366
|
{
|