@microsoft/fabric-slicers 3.1.0 → 4.1.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/CHANGELOG +18 -0
- package/README.md +46 -8
- package/dist/index.d.ts +34 -3
- package/dist/index.js +1350 -166
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/components/list-slicer/list-slicer.tsx
|
|
2
2
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
3
3
|
import { useCallback as useCallback4, useEffect as useEffect2, useId, useMemo as useMemo2, useRef as useRef3, useState as useState3 } from "react";
|
|
4
|
-
import { getString as getString3 } from "@microsoft/fabric-visuals-core";
|
|
4
|
+
import { formatString as formatString3, getString as getString3 } from "@microsoft/fabric-visuals-core";
|
|
5
5
|
|
|
6
6
|
// src/hooks/use-list-slicer.ts
|
|
7
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
-
import { formatString, formatValue, getString, isDataTable } from "@microsoft/fabric-visuals-core";
|
|
8
|
+
import { formatString, formatValue, getString, isDataTable, toInteractionValue } from "@microsoft/fabric-visuals-core";
|
|
9
9
|
|
|
10
10
|
// src/utils/slicer-value.ts
|
|
11
11
|
function isSlicerValue(value) {
|
|
@@ -93,17 +93,32 @@ function useListSlicer({ data, column, title, selection, onInteraction }) {
|
|
|
93
93
|
() => prepared.items.filter((item) => isSelected(item.key)),
|
|
94
94
|
[prepared.items, isSelected]
|
|
95
95
|
);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
setLocalSelection(normalized);
|
|
96
|
+
const commitSelection = useCallback((next) => {
|
|
97
|
+
selectionRef.current = next;
|
|
98
|
+
setLocalSelection(next);
|
|
100
99
|
if (!onInteraction) return;
|
|
101
|
-
const event =
|
|
100
|
+
const event = next === "all" || next.size === 0 ? { action: "clear" } : {
|
|
102
101
|
action: "select",
|
|
103
|
-
selections: [{
|
|
102
|
+
selections: [{
|
|
103
|
+
predicates: [{
|
|
104
|
+
type: "set",
|
|
105
|
+
fieldId: column,
|
|
106
|
+
values: [...next.values()].map(toInteractionValue)
|
|
107
|
+
}]
|
|
108
|
+
}]
|
|
104
109
|
};
|
|
105
110
|
onInteraction([event]);
|
|
106
|
-
}, [column, onInteraction
|
|
111
|
+
}, [column, onInteraction]);
|
|
112
|
+
const updateSelection = useCallback((next) => {
|
|
113
|
+
const normalized = next !== "all" && prepared.items.length > 0 && next.size >= prepared.items.length && prepared.items.every((item) => next.has(item.key)) ? "all" : next;
|
|
114
|
+
commitSelection(normalized);
|
|
115
|
+
}, [commitSelection, prepared.items]);
|
|
116
|
+
const selectOnly = useCallback((key) => {
|
|
117
|
+
if (!valuesByKey.has(key)) throw new Error(`Cannot update an unknown slicer key: ${key}`);
|
|
118
|
+
const previous = selectionRef.current;
|
|
119
|
+
if (previous !== "all" && previous.size === 1 && previous.has(key)) return;
|
|
120
|
+
commitSelection(/* @__PURE__ */ new Map([[key, valuesByKey.get(key)]]));
|
|
121
|
+
}, [valuesByKey, commitSelection]);
|
|
107
122
|
const clear = useCallback(() => {
|
|
108
123
|
if (selectionRef.current !== "all") updateSelection("all");
|
|
109
124
|
}, [updateSelection]);
|
|
@@ -142,6 +157,7 @@ function useListSlicer({ data, column, title, selection, onInteraction }) {
|
|
|
142
157
|
selectedItems,
|
|
143
158
|
isSelected,
|
|
144
159
|
toggle,
|
|
160
|
+
selectOnly,
|
|
145
161
|
toggleAll,
|
|
146
162
|
clear,
|
|
147
163
|
allSelected: localSelection === "all"
|
|
@@ -174,10 +190,20 @@ function useListNavigation(items) {
|
|
|
174
190
|
}
|
|
175
191
|
}, [items]);
|
|
176
192
|
const handleKeyDown = useCallback2((event) => {
|
|
177
|
-
const
|
|
178
|
-
const isNavigationKey = event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End";
|
|
179
|
-
if (
|
|
193
|
+
const isRowControl = event.target instanceof HTMLButtonElement && (event.target.getAttribute("role") === "checkbox" || event.target.hasAttribute("data-slicer-only"));
|
|
194
|
+
const isNavigationKey = event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End" || event.key === "ArrowRight" || event.key === "ArrowLeft";
|
|
195
|
+
if (isRowControl && isNavigationKey && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
|
|
180
196
|
if (event.defaultPrevented || items.length === 0) return;
|
|
197
|
+
if (event.key === "ArrowRight" || event.key === "ArrowLeft") {
|
|
198
|
+
const selector = event.key === "ArrowRight" ? "[data-slicer-only]" : '[role="checkbox"]';
|
|
199
|
+
const control = event.currentTarget.querySelector(`[data-slicer-index="${activeIndex}"] ${selector}`);
|
|
200
|
+
if (control) {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
event.stopPropagation();
|
|
203
|
+
control.focus();
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
181
207
|
event.preventDefault();
|
|
182
208
|
event.stopPropagation();
|
|
183
209
|
let nextIndex;
|
|
@@ -376,6 +402,12 @@ function SearchIcon({ className }) {
|
|
|
376
402
|
/* @__PURE__ */ jsx3("path", { d: "m10 10 4 4", stroke: "currentColor" })
|
|
377
403
|
] });
|
|
378
404
|
}
|
|
405
|
+
function CalendarIcon({ className }) {
|
|
406
|
+
return /* @__PURE__ */ jsxs2("svg", { className, width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
|
|
407
|
+
/* @__PURE__ */ jsx3("rect", { x: "2", y: "3", width: "12", height: "11", rx: "1", stroke: "currentColor" }),
|
|
408
|
+
/* @__PURE__ */ jsx3("path", { d: "M5 1.5v3M11 1.5v3M2 6h12M5 9h2M9 9h2M5 11.5h2", stroke: "currentColor" })
|
|
409
|
+
] });
|
|
410
|
+
}
|
|
379
411
|
|
|
380
412
|
// src/components/list-slicer/list-slicer-styles.ts
|
|
381
413
|
import { makeStyles as makeStyles3 } from "@griffel/react";
|
|
@@ -451,7 +483,9 @@ var useListSlicerStyles = makeStyles3(inVisualsLayer3({
|
|
|
451
483
|
boxSizing: "border-box",
|
|
452
484
|
borderRadius: "4px",
|
|
453
485
|
minWidth: 0,
|
|
454
|
-
|
|
486
|
+
position: "relative",
|
|
487
|
+
":hover": { backgroundColor: `var(--slicer-hover, ${tokens3.colorHover})` },
|
|
488
|
+
"&:hover > [data-slicer-only], &:has(:focus-visible) > [data-slicer-only]": { position: "static", opacity: 1, pointerEvents: "auto" }
|
|
455
489
|
},
|
|
456
490
|
selectAll: { flexShrink: 0, fontWeight: 600 },
|
|
457
491
|
label: {
|
|
@@ -462,13 +496,39 @@ var useListSlicerStyles = makeStyles3(inVisualsLayer3({
|
|
|
462
496
|
cursor: "pointer",
|
|
463
497
|
minWidth: 0,
|
|
464
498
|
flexGrow: 1
|
|
499
|
+
},
|
|
500
|
+
only: {
|
|
501
|
+
height: tokens3.spacingXxl,
|
|
502
|
+
minWidth: "44px",
|
|
503
|
+
padding: `0 ${tokens3.spacingM}`,
|
|
504
|
+
flexShrink: 0,
|
|
505
|
+
border: 0,
|
|
506
|
+
borderRadius: tokens3.radiusFull,
|
|
507
|
+
cursor: "pointer",
|
|
508
|
+
whiteSpace: "nowrap",
|
|
509
|
+
backgroundColor: `var(--slicer-muted, ${tokens3.colorMuted})`,
|
|
510
|
+
color: `var(--slicer-link, ${tokens3.colorBrandForeground})`,
|
|
511
|
+
// Keep hidden actions keyboard-focusable without reserving label space.
|
|
512
|
+
position: "absolute",
|
|
513
|
+
insetInlineEnd: tokens3.spacingS,
|
|
514
|
+
opacity: 0,
|
|
515
|
+
pointerEvents: "none",
|
|
516
|
+
":focus-visible": { position: "static", opacity: 1, pointerEvents: "auto" },
|
|
517
|
+
":active": {
|
|
518
|
+
backgroundColor: `color-mix(in srgb, var(--slicer-muted, ${tokens3.colorMuted}) 90%, currentColor)`
|
|
519
|
+
},
|
|
520
|
+
"@media (forced-colors: active)": {
|
|
521
|
+
backgroundColor: "ButtonFace",
|
|
522
|
+
color: "ButtonText",
|
|
523
|
+
":active": { backgroundColor: "Highlight", color: "HighlightText" }
|
|
524
|
+
}
|
|
465
525
|
}
|
|
466
526
|
}));
|
|
467
527
|
|
|
468
528
|
// src/components/list-slicer/list-slicer.tsx
|
|
469
529
|
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
470
530
|
var ROW_HEIGHT = 32;
|
|
471
|
-
function ListSlicerRow({ label, checked, onToggle, disabled, className, tabIndex, navigationIndex }) {
|
|
531
|
+
function ListSlicerRow({ label, checked, onToggle, onSelectOnly, disabled, className, tabIndex, navigationIndex }) {
|
|
472
532
|
const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
|
|
473
533
|
const id = useId();
|
|
474
534
|
return /* @__PURE__ */ jsxs3("div", { className: mergeClasses(styles.row, className), "data-slicer-index": navigationIndex, children: [
|
|
@@ -483,7 +543,20 @@ function ListSlicerRow({ label, checked, onToggle, disabled, className, tabIndex
|
|
|
483
543
|
tabIndex
|
|
484
544
|
}
|
|
485
545
|
),
|
|
486
|
-
/* @__PURE__ */ jsx4("label", { className: styles.label, htmlFor: id, children: /* @__PURE__ */ jsx4("span", { className: styles.text, title: label, children: label }) })
|
|
546
|
+
/* @__PURE__ */ jsx4("label", { className: styles.label, htmlFor: id, children: /* @__PURE__ */ jsx4("span", { className: styles.text, title: label, children: label }) }),
|
|
547
|
+
onSelectOnly && /* @__PURE__ */ jsx4(
|
|
548
|
+
"button",
|
|
549
|
+
{
|
|
550
|
+
type: "button",
|
|
551
|
+
className: styles.only,
|
|
552
|
+
"data-slicer-only": "",
|
|
553
|
+
"aria-label": formatString3("Slicer_OnlyLabel", label),
|
|
554
|
+
onClick: onSelectOnly,
|
|
555
|
+
tabIndex,
|
|
556
|
+
disabled,
|
|
557
|
+
children: getString3("Slicer_Only")
|
|
558
|
+
}
|
|
559
|
+
)
|
|
487
560
|
] });
|
|
488
561
|
}
|
|
489
562
|
function ItemRow({ item, state, tabIndex }) {
|
|
@@ -491,12 +564,14 @@ function ItemRow({ item, state, tabIndex }) {
|
|
|
491
564
|
(checked) => state.toggle(item.key, checked === true),
|
|
492
565
|
[state, item.key]
|
|
493
566
|
);
|
|
567
|
+
const selectOnly = useCallback4(() => state.selectOnly(item.key), [state, item.key]);
|
|
494
568
|
return /* @__PURE__ */ jsx4(
|
|
495
569
|
ListSlicerRow,
|
|
496
570
|
{
|
|
497
571
|
label: item.label,
|
|
498
572
|
checked: state.isSelected(item.key),
|
|
499
573
|
onToggle: toggle,
|
|
574
|
+
onSelectOnly: selectOnly,
|
|
500
575
|
tabIndex
|
|
501
576
|
}
|
|
502
577
|
);
|
|
@@ -509,13 +584,14 @@ function ListSlicer(props) {
|
|
|
509
584
|
}
|
|
510
585
|
function StatefulListSlicer(props) {
|
|
511
586
|
const state = useListSlicer(props);
|
|
512
|
-
return /* @__PURE__ */ jsx4(ListSlicerContent, { state, theme: props.theme, displayOptions: props.displayOptions });
|
|
587
|
+
return /* @__PURE__ */ jsx4(ListSlicerContent, { state, theme: props.theme, displayOptions: props.displayOptions, isSelectionBoundary: true });
|
|
513
588
|
}
|
|
514
589
|
function ListSlicerContent({
|
|
515
590
|
state,
|
|
516
591
|
theme,
|
|
517
592
|
displayOptions,
|
|
518
|
-
maxVisibleItems = 8
|
|
593
|
+
maxVisibleItems = 8,
|
|
594
|
+
isSelectionBoundary = false
|
|
519
595
|
}) {
|
|
520
596
|
const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
|
|
521
597
|
const titleId = useId();
|
|
@@ -524,7 +600,8 @@ function ListSlicerContent({
|
|
|
524
600
|
const hideHeader = displayOptions?.hideHeader ?? false;
|
|
525
601
|
const scrollRef = useRef3(null);
|
|
526
602
|
const scrollStyle = useMemo2(
|
|
527
|
-
|
|
603
|
+
// Include Select all without reducing the initial number of visible values.
|
|
604
|
+
() => ({ maxHeight: (maxVisibleItems + 1) * ROW_HEIGHT }),
|
|
528
605
|
[maxVisibleItems]
|
|
529
606
|
);
|
|
530
607
|
const [search, setSearch] = useState3("");
|
|
@@ -552,6 +629,7 @@ function ListSlicerContent({
|
|
|
552
629
|
getScrollElement: () => scrollRef.current,
|
|
553
630
|
estimateSize: () => ROW_HEIGHT,
|
|
554
631
|
getItemKey: (index) => items[index].key,
|
|
632
|
+
scrollMargin: ROW_HEIGHT,
|
|
555
633
|
overscan: 5,
|
|
556
634
|
rangeExtractor: navigation.rangeExtractor,
|
|
557
635
|
enabled: virtual
|
|
@@ -570,7 +648,7 @@ function ListSlicerContent({
|
|
|
570
648
|
};
|
|
571
649
|
const observer = new ResizeObserver(updateFade);
|
|
572
650
|
observer.observe(scroll);
|
|
573
|
-
if (scroll.
|
|
651
|
+
if (scroll.lastElementChild) observer.observe(scroll.lastElementChild);
|
|
574
652
|
scroll.addEventListener("scroll", updateFade, { passive: true });
|
|
575
653
|
updateFade();
|
|
576
654
|
return () => {
|
|
@@ -581,6 +659,7 @@ function ListSlicerContent({
|
|
|
581
659
|
return /* @__PURE__ */ jsxs3(
|
|
582
660
|
"section",
|
|
583
661
|
{
|
|
662
|
+
"data-lyra-selection-boundary": isSelectionBoundary ? "" : void 0,
|
|
584
663
|
className: mergeClasses(styles.typography, styles.root, !hideHeader && styles.fillHeight),
|
|
585
664
|
style: themeStyle,
|
|
586
665
|
"aria-labelledby": hideHeader ? void 0 : titleId,
|
|
@@ -592,7 +671,7 @@ function ListSlicerContent({
|
|
|
592
671
|
title: state.title,
|
|
593
672
|
titleId,
|
|
594
673
|
onClear: state.allSelected ? void 0 : state.clear,
|
|
595
|
-
clearDisabled: !!state.error
|
|
674
|
+
clearDisabled: !!state.error
|
|
596
675
|
}
|
|
597
676
|
),
|
|
598
677
|
/* @__PURE__ */ jsx4(
|
|
@@ -619,33 +698,35 @@ function ListSlicerContent({
|
|
|
619
698
|
}
|
|
620
699
|
)
|
|
621
700
|
] }),
|
|
622
|
-
/* @__PURE__ */
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
701
|
+
/* @__PURE__ */ jsxs3("div", { ref: scrollRef, tabIndex: -1, className: mergeClasses(styles.scroll, hasMoreBelow && styles.scrollFade), style: scrollStyle, children: [
|
|
702
|
+
/* @__PURE__ */ jsx4(
|
|
703
|
+
ListSlicerRow,
|
|
704
|
+
{
|
|
705
|
+
className: styles.selectAll,
|
|
706
|
+
label: getString3("Slicer_SelectAll"),
|
|
707
|
+
checked,
|
|
708
|
+
onToggle: toggleAll,
|
|
709
|
+
disabled: items.length === 0,
|
|
710
|
+
navigationIndex: -1,
|
|
711
|
+
tabIndex: navigation.activeIndex === -1 && items.length > 0 ? 0 : -1
|
|
712
|
+
}
|
|
713
|
+
),
|
|
714
|
+
items.length === 0 ? /* @__PURE__ */ jsx4("div", { role: "status", className: styles.message, children: getString3(state.items.length === 0 ? "Slicer_NoData" : "Slicer_NoResults") }) : /* @__PURE__ */ jsx4("ul", { className: styles.list, style: listStyle, "aria-label": state.title, children: virtual ? virtualizer.getVirtualItems().map((row) => /* @__PURE__ */ jsx4("li", { "data-slicer-index": row.index, style: virtualRowStyle(row.start - ROW_HEIGHT), "aria-posinset": row.index + 1, "aria-setsize": items.length, children: /* @__PURE__ */ jsx4(
|
|
715
|
+
ItemRow,
|
|
716
|
+
{
|
|
717
|
+
item: items[row.index],
|
|
718
|
+
state,
|
|
719
|
+
tabIndex: row.index === navigation.activeIndex ? 0 : -1
|
|
720
|
+
}
|
|
721
|
+
) }, row.key)) : items.map((item, index) => /* @__PURE__ */ jsx4("li", { "data-slicer-index": index, children: /* @__PURE__ */ jsx4(
|
|
722
|
+
ItemRow,
|
|
723
|
+
{
|
|
724
|
+
item,
|
|
725
|
+
state,
|
|
726
|
+
tabIndex: index === navigation.activeIndex ? 0 : -1
|
|
727
|
+
}
|
|
728
|
+
) }, item.key)) })
|
|
729
|
+
] })
|
|
649
730
|
] })
|
|
650
731
|
}
|
|
651
732
|
)
|
|
@@ -656,7 +737,7 @@ function ListSlicerContent({
|
|
|
656
737
|
|
|
657
738
|
// src/components/dropdown-slicer/dropdown-slicer.tsx
|
|
658
739
|
import { useId as useId2, useMemo as useMemo3 } from "react";
|
|
659
|
-
import { formatString as
|
|
740
|
+
import { formatString as formatString4, getString as getString4 } from "@microsoft/fabric-visuals-core";
|
|
660
741
|
|
|
661
742
|
// src/components/ui/popover.tsx
|
|
662
743
|
import { Popover as PopoverPrimitive } from "radix-ui";
|
|
@@ -732,10 +813,11 @@ function DropdownSlicerContent(props) {
|
|
|
732
813
|
() => ({ ...props.displayOptions, hideHeader: true }),
|
|
733
814
|
[props.displayOptions]
|
|
734
815
|
);
|
|
735
|
-
const summary = state.items.length === 0 ? getString4("Slicer_NoData") : state.allSelected ? getString4("Slicer_All") : state.selectedItems.length === 0 ? getString4("Slicer_None") : state.selectedItems.length > 2 ?
|
|
816
|
+
const summary = state.items.length === 0 ? getString4("Slicer_NoData") : state.allSelected ? getString4("Slicer_All") : state.selectedItems.length === 0 ? getString4("Slicer_None") : state.selectedItems.length > 2 ? formatString4("Slicer_SelectionCount", state.selectedItems.length, state.items.length) : state.selectedItems.map((item) => item.label).join(", ");
|
|
736
817
|
return /* @__PURE__ */ jsxs4(
|
|
737
818
|
"section",
|
|
738
819
|
{
|
|
820
|
+
"data-lyra-selection-boundary": "",
|
|
739
821
|
className: mergeClasses(styles.typography, styles.root),
|
|
740
822
|
style: themeStyle,
|
|
741
823
|
"aria-labelledby": hideHeader ? void 0 : titleId,
|
|
@@ -747,7 +829,7 @@ function DropdownSlicerContent(props) {
|
|
|
747
829
|
title: state.title,
|
|
748
830
|
titleId,
|
|
749
831
|
onClear: state.allSelected ? void 0 : state.clear,
|
|
750
|
-
clearDisabled: !!state.error
|
|
832
|
+
clearDisabled: !!state.error
|
|
751
833
|
}
|
|
752
834
|
),
|
|
753
835
|
state.error ? /* @__PURE__ */ jsx6(ListSlicerContent, { state, theme: props.theme, displayOptions: listDisplayOptions }) : /* @__PURE__ */ jsxs4(Popover, { children: [
|
|
@@ -779,13 +861,1098 @@ function DropdownSlicerContent(props) {
|
|
|
779
861
|
);
|
|
780
862
|
}
|
|
781
863
|
|
|
864
|
+
// src/components/date-slicer/date-slicer.tsx
|
|
865
|
+
import { useCallback as useCallback9, useEffect as useEffect4, useId as useId3, useMemo as useMemo7, useState as useState8 } from "react";
|
|
866
|
+
import { formatString as formatString9, getString as getString10 } from "@microsoft/fabric-visuals-core";
|
|
867
|
+
|
|
868
|
+
// src/components/date-slicer/date-slicer-calendar.tsx
|
|
869
|
+
import { useCallback as useCallback6, useMemo as useMemo5, useRef as useRef4, useState as useState5 } from "react";
|
|
870
|
+
import { DayPicker, defaultDateLib, formatMonthDropdown } from "@daypicker/react";
|
|
871
|
+
import { compareCalendarDates as compareCalendarDates3, formatString as formatString7, getString as getString7 } from "@microsoft/fabric-visuals-core";
|
|
872
|
+
|
|
873
|
+
// src/components/date-slicer/date-slicer-navigation.tsx
|
|
874
|
+
import { Chevron } from "@daypicker/react";
|
|
875
|
+
import { formatString as formatString5, getString as getString5 } from "@microsoft/fabric-visuals-core";
|
|
876
|
+
|
|
877
|
+
// src/components/date-slicer/date-slicer-styles.ts
|
|
878
|
+
import { makeStyles as makeStyles6 } from "@griffel/react";
|
|
879
|
+
import { borderRadius, fontSize, fontWeight, injectDesignTokens as injectDesignTokens2, inVisualsLayer as inVisualsLayer6, spacing, tokens as tokens6 } from "@microsoft/fabric-visuals-core";
|
|
880
|
+
injectDesignTokens2();
|
|
881
|
+
var useDateSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
882
|
+
root: {
|
|
883
|
+
// A full-width navigation row must not enlarge the calendar's intrinsic width beyond its day grids.
|
|
884
|
+
width: `calc(var(--date-month-count) * 252px + (var(--date-month-count) - 1) * ${spacing.l})`,
|
|
885
|
+
minWidth: 0,
|
|
886
|
+
maxWidth: "100%",
|
|
887
|
+
color: `var(--slicer-foreground, ${tokens6.colorForeground})`,
|
|
888
|
+
fontFamily: `var(--slicer-font, ${tokens6.fontBase})`,
|
|
889
|
+
fontSize: `var(--slicer-size, ${tokens6.text300})`,
|
|
890
|
+
display: "flex",
|
|
891
|
+
flexDirection: "column",
|
|
892
|
+
gap: spacing.s,
|
|
893
|
+
"@media (max-width: 600px)": {
|
|
894
|
+
width: "100%"
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
dayPickerRoot: {
|
|
898
|
+
width: "100%"
|
|
899
|
+
},
|
|
900
|
+
months: {
|
|
901
|
+
display: "grid",
|
|
902
|
+
// Reflow whole panels, then share remaining width rather than leaving a narrow column beside the presets.
|
|
903
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(252px, 1fr))",
|
|
904
|
+
alignItems: "start",
|
|
905
|
+
gap: spacing.l
|
|
906
|
+
},
|
|
907
|
+
month: {
|
|
908
|
+
// Seven columns at 36px each keep day buttons large enough to click on narrow screens.
|
|
909
|
+
width: "100%",
|
|
910
|
+
minWidth: 0
|
|
911
|
+
},
|
|
912
|
+
caption: {
|
|
913
|
+
display: "flex",
|
|
914
|
+
alignItems: "center",
|
|
915
|
+
justifyContent: "center",
|
|
916
|
+
minHeight: "24px",
|
|
917
|
+
marginBottom: spacing.xs
|
|
918
|
+
},
|
|
919
|
+
captionLabel: {
|
|
920
|
+
fontFamily: `var(--slicer-heading-font, ${tokens6.fontHeading})`,
|
|
921
|
+
fontSize: fontSize[200],
|
|
922
|
+
fontWeight: fontWeight.semibold,
|
|
923
|
+
color: `var(--slicer-secondary, ${tokens6.colorMutedForeground})`,
|
|
924
|
+
overflowWrap: "anywhere",
|
|
925
|
+
lineHeight: "20px"
|
|
926
|
+
},
|
|
927
|
+
hiddenCaption: {
|
|
928
|
+
display: "none"
|
|
929
|
+
},
|
|
930
|
+
navigation: {
|
|
931
|
+
display: "grid",
|
|
932
|
+
gridTemplateColumns: "36px minmax(0, 1fr) 36px",
|
|
933
|
+
alignItems: "center",
|
|
934
|
+
columnGap: spacing.s,
|
|
935
|
+
width: "100%"
|
|
936
|
+
},
|
|
937
|
+
windowButton: {
|
|
938
|
+
justifySelf: "center",
|
|
939
|
+
width: "auto",
|
|
940
|
+
height: "auto",
|
|
941
|
+
minHeight: "36px",
|
|
942
|
+
minWidth: 0,
|
|
943
|
+
padding: `${spacing.xs} ${spacing.s}`,
|
|
944
|
+
fontFamily: `var(--slicer-heading-font, ${tokens6.fontHeading})`,
|
|
945
|
+
fontSize: "inherit",
|
|
946
|
+
fontWeight: fontWeight.semibold,
|
|
947
|
+
lineHeight: "20px",
|
|
948
|
+
overflowWrap: "anywhere",
|
|
949
|
+
textAlign: "center"
|
|
950
|
+
},
|
|
951
|
+
periodGrid: {
|
|
952
|
+
width: "100%",
|
|
953
|
+
tableLayout: "fixed",
|
|
954
|
+
borderSpacing: spacing.xs,
|
|
955
|
+
"& td": { padding: 0 }
|
|
956
|
+
},
|
|
957
|
+
periodButton: {
|
|
958
|
+
width: "100%",
|
|
959
|
+
minHeight: "44px",
|
|
960
|
+
padding: `${spacing.xs} ${spacing.xs}`,
|
|
961
|
+
border: "1px solid transparent",
|
|
962
|
+
borderRadius: borderRadius.medium,
|
|
963
|
+
backgroundColor: "transparent",
|
|
964
|
+
color: "inherit",
|
|
965
|
+
font: "inherit",
|
|
966
|
+
overflowWrap: "anywhere",
|
|
967
|
+
cursor: "pointer",
|
|
968
|
+
":hover:not(:disabled)": {
|
|
969
|
+
backgroundColor: `var(--slicer-hover, ${tokens6.colorHover})`
|
|
970
|
+
},
|
|
971
|
+
":focus-visible": {
|
|
972
|
+
outline: `2px solid var(--slicer-link, ${tokens6.colorBrandForeground})`,
|
|
973
|
+
outlineOffset: "1px"
|
|
974
|
+
},
|
|
975
|
+
":disabled": {
|
|
976
|
+
color: `var(--slicer-secondary, ${tokens6.colorMutedForeground})`,
|
|
977
|
+
cursor: "default",
|
|
978
|
+
opacity: 0.5
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
selectedPeriod: {
|
|
982
|
+
backgroundColor: `color-mix(in srgb, var(--slicer-brand, ${tokens6.colorBrand}) 15%, var(--slicer-background, ${tokens6.colorBackground}))`
|
|
983
|
+
},
|
|
984
|
+
periodEndpoint: {
|
|
985
|
+
backgroundColor: `var(--slicer-brand, ${tokens6.colorBrand})`,
|
|
986
|
+
color: tokens6.colorPrimaryForeground,
|
|
987
|
+
fontWeight: fontWeight.semibold,
|
|
988
|
+
":hover:not(:disabled)": {
|
|
989
|
+
backgroundColor: `var(--slicer-brand, ${tokens6.colorBrand})`
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
navigationButton: {
|
|
993
|
+
display: "inline-flex",
|
|
994
|
+
justifyContent: "center",
|
|
995
|
+
alignItems: "center",
|
|
996
|
+
width: "36px",
|
|
997
|
+
height: "36px",
|
|
998
|
+
padding: 0,
|
|
999
|
+
border: 0,
|
|
1000
|
+
borderRadius: borderRadius.medium,
|
|
1001
|
+
color: "inherit",
|
|
1002
|
+
backgroundColor: "transparent",
|
|
1003
|
+
cursor: "pointer",
|
|
1004
|
+
':hover:not([aria-disabled="true"])': {
|
|
1005
|
+
backgroundColor: `var(--slicer-hover, ${tokens6.colorHover})`
|
|
1006
|
+
},
|
|
1007
|
+
":focus-visible": {
|
|
1008
|
+
outline: `2px solid var(--slicer-link, ${tokens6.colorBrandForeground})`,
|
|
1009
|
+
outlineOffset: "1px"
|
|
1010
|
+
},
|
|
1011
|
+
'&[aria-disabled="true"]': {
|
|
1012
|
+
color: `var(--slicer-secondary, ${tokens6.colorMutedForeground})`,
|
|
1013
|
+
cursor: "default",
|
|
1014
|
+
opacity: 0.5
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
chevron: {
|
|
1018
|
+
width: "20px",
|
|
1019
|
+
height: "20px",
|
|
1020
|
+
fill: "currentColor"
|
|
1021
|
+
},
|
|
1022
|
+
grid: {
|
|
1023
|
+
width: "100%",
|
|
1024
|
+
borderCollapse: "collapse",
|
|
1025
|
+
tableLayout: "fixed"
|
|
1026
|
+
},
|
|
1027
|
+
weekday: {
|
|
1028
|
+
height: "32px",
|
|
1029
|
+
padding: 0,
|
|
1030
|
+
fontSize: fontSize[200],
|
|
1031
|
+
fontWeight: fontWeight.regular,
|
|
1032
|
+
color: `var(--slicer-secondary, ${tokens6.colorMutedForeground})`,
|
|
1033
|
+
textAlign: "center",
|
|
1034
|
+
overflowWrap: "anywhere"
|
|
1035
|
+
},
|
|
1036
|
+
day: {
|
|
1037
|
+
padding: 0,
|
|
1038
|
+
width: "36px",
|
|
1039
|
+
height: "36px",
|
|
1040
|
+
textAlign: "center"
|
|
1041
|
+
},
|
|
1042
|
+
dayButton: {
|
|
1043
|
+
display: "block",
|
|
1044
|
+
width: "100%",
|
|
1045
|
+
minWidth: "36px",
|
|
1046
|
+
height: "36px",
|
|
1047
|
+
margin: 0,
|
|
1048
|
+
padding: 0,
|
|
1049
|
+
border: "1px solid transparent",
|
|
1050
|
+
borderRadius: borderRadius.medium,
|
|
1051
|
+
backgroundColor: "transparent",
|
|
1052
|
+
color: "inherit",
|
|
1053
|
+
fontFamily: "inherit",
|
|
1054
|
+
fontSize: "inherit",
|
|
1055
|
+
fontVariantNumeric: "tabular-nums",
|
|
1056
|
+
cursor: "pointer",
|
|
1057
|
+
':hover:not(:disabled):not([aria-disabled="true"])': {
|
|
1058
|
+
border: `1px solid var(--slicer-link, ${tokens6.colorBrandForeground})`
|
|
1059
|
+
},
|
|
1060
|
+
":focus-visible": {
|
|
1061
|
+
position: "relative",
|
|
1062
|
+
outline: `2px solid var(--slicer-link, ${tokens6.colorBrandForeground})`,
|
|
1063
|
+
outlineOffset: "1px",
|
|
1064
|
+
zIndex: 1
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
disabled: {
|
|
1068
|
+
color: `var(--slicer-secondary, ${tokens6.colorMutedForeground})`,
|
|
1069
|
+
"& button": { cursor: "not-allowed", opacity: 0.5 }
|
|
1070
|
+
},
|
|
1071
|
+
hidden: { visibility: "hidden" },
|
|
1072
|
+
selected: {
|
|
1073
|
+
backgroundColor: `color-mix(in srgb, var(--slicer-brand, ${tokens6.colorBrand}) 15%, var(--slicer-background, ${tokens6.colorBackground}))`,
|
|
1074
|
+
color: `var(--slicer-foreground, ${tokens6.colorForeground})`
|
|
1075
|
+
},
|
|
1076
|
+
rangeStart: {
|
|
1077
|
+
borderStartStartRadius: borderRadius.medium,
|
|
1078
|
+
borderEndStartRadius: borderRadius.medium,
|
|
1079
|
+
"& button": {
|
|
1080
|
+
backgroundColor: `var(--slicer-brand, ${tokens6.colorBrand})`,
|
|
1081
|
+
color: tokens6.colorPrimaryForeground,
|
|
1082
|
+
fontWeight: fontWeight.semibold
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
rangeEnd: {
|
|
1086
|
+
borderStartEndRadius: borderRadius.medium,
|
|
1087
|
+
borderEndEndRadius: borderRadius.medium,
|
|
1088
|
+
"& button": {
|
|
1089
|
+
backgroundColor: `var(--slicer-brand, ${tokens6.colorBrand})`,
|
|
1090
|
+
color: tokens6.colorPrimaryForeground,
|
|
1091
|
+
fontWeight: fontWeight.semibold
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
today: {
|
|
1095
|
+
"& button": { textDecorationLine: "underline", textUnderlineOffset: "3px" }
|
|
1096
|
+
}
|
|
1097
|
+
}));
|
|
1098
|
+
|
|
1099
|
+
// src/components/date-slicer/date-slicer-navigation.tsx
|
|
1100
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1101
|
+
function DateSlicerNavigation({
|
|
1102
|
+
label,
|
|
1103
|
+
pickLabel,
|
|
1104
|
+
previousLabel,
|
|
1105
|
+
nextLabel,
|
|
1106
|
+
canGoPrevious,
|
|
1107
|
+
canGoNext,
|
|
1108
|
+
onPrevious,
|
|
1109
|
+
onNext,
|
|
1110
|
+
onPick,
|
|
1111
|
+
headerRef
|
|
1112
|
+
}) {
|
|
1113
|
+
const styles = useDateSlicerStyles();
|
|
1114
|
+
return /* @__PURE__ */ jsxs5("nav", { className: styles.navigation, "aria-label": getString5("DateSlicer_CalendarNavigation"), children: [
|
|
1115
|
+
/* @__PURE__ */ jsx7(
|
|
1116
|
+
"button",
|
|
1117
|
+
{
|
|
1118
|
+
type: "button",
|
|
1119
|
+
className: styles.navigationButton,
|
|
1120
|
+
"aria-label": previousLabel,
|
|
1121
|
+
"aria-disabled": !canGoPrevious || void 0,
|
|
1122
|
+
tabIndex: canGoPrevious ? void 0 : -1,
|
|
1123
|
+
onClick: canGoPrevious ? onPrevious : void 0,
|
|
1124
|
+
children: /* @__PURE__ */ jsx7(Chevron, { className: styles.chevron, orientation: "left" })
|
|
1125
|
+
}
|
|
1126
|
+
),
|
|
1127
|
+
/* @__PURE__ */ jsx7(
|
|
1128
|
+
"button",
|
|
1129
|
+
{
|
|
1130
|
+
ref: headerRef,
|
|
1131
|
+
type: "button",
|
|
1132
|
+
className: mergeClasses(styles.navigationButton, styles.windowButton),
|
|
1133
|
+
title: pickLabel,
|
|
1134
|
+
"aria-label": formatString5("DateSlicer_ViewLabel", label, pickLabel),
|
|
1135
|
+
onClick: onPick,
|
|
1136
|
+
children: label
|
|
1137
|
+
}
|
|
1138
|
+
),
|
|
1139
|
+
/* @__PURE__ */ jsx7(
|
|
1140
|
+
"button",
|
|
1141
|
+
{
|
|
1142
|
+
type: "button",
|
|
1143
|
+
className: styles.navigationButton,
|
|
1144
|
+
"aria-label": nextLabel,
|
|
1145
|
+
"aria-disabled": !canGoNext || void 0,
|
|
1146
|
+
tabIndex: canGoNext ? void 0 : -1,
|
|
1147
|
+
onClick: canGoNext ? onNext : void 0,
|
|
1148
|
+
children: /* @__PURE__ */ jsx7(Chevron, { className: styles.chevron, orientation: "right" })
|
|
1149
|
+
}
|
|
1150
|
+
)
|
|
1151
|
+
] });
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/components/date-slicer/date-slicer-period-grid.tsx
|
|
1155
|
+
import { useCallback as useCallback5, useMemo as useMemo4, useState as useState4 } from "react";
|
|
1156
|
+
import { compareCalendarDates as compareCalendarDates2 } from "@microsoft/fabric-visuals-core";
|
|
1157
|
+
|
|
1158
|
+
// src/components/date-slicer/date-slicer-utils.ts
|
|
1159
|
+
import { UTCDate } from "@date-fns/utc";
|
|
1160
|
+
import { compareCalendarDates, formatCalendarDate, formatString as formatString6, getString as getString6, isValidCalendarDate, parseCalendarDate } from "@microsoft/fabric-visuals-core";
|
|
1161
|
+
function isValidRange(range) {
|
|
1162
|
+
return range.every((date) => isValidCalendarDate(date.year, date.month, date.day)) && compareCalendarDates(range[0], range[1]) <= 0;
|
|
1163
|
+
}
|
|
1164
|
+
function dateRangesEqual(first, second) {
|
|
1165
|
+
if (first && second) {
|
|
1166
|
+
return compareCalendarDates(first[0], second[0]) === 0 && compareCalendarDates(first[1], second[1]) === 0;
|
|
1167
|
+
}
|
|
1168
|
+
return first === second;
|
|
1169
|
+
}
|
|
1170
|
+
function intersectDateRanges(domain, selection) {
|
|
1171
|
+
if (domain && selection) {
|
|
1172
|
+
const start = compareCalendarDates(domain[0], selection[0]) > 0 ? domain[0] : selection[0];
|
|
1173
|
+
const end = compareCalendarDates(domain[1], selection[1]) < 0 ? domain[1] : selection[1];
|
|
1174
|
+
if (compareCalendarDates(start, end) <= 0) return [start, end];
|
|
1175
|
+
}
|
|
1176
|
+
return void 0;
|
|
1177
|
+
}
|
|
1178
|
+
function toDayPickerDate(date) {
|
|
1179
|
+
const calendarDate = new UTCDate(0);
|
|
1180
|
+
calendarDate.setFullYear(date.year, date.month - 1, date.day);
|
|
1181
|
+
return calendarDate;
|
|
1182
|
+
}
|
|
1183
|
+
function toCalendarDate(date) {
|
|
1184
|
+
return { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };
|
|
1185
|
+
}
|
|
1186
|
+
function localToday() {
|
|
1187
|
+
return toCalendarDate(/* @__PURE__ */ new Date());
|
|
1188
|
+
}
|
|
1189
|
+
function monthIndex(date) {
|
|
1190
|
+
return date.year * 12 + date.month - 1;
|
|
1191
|
+
}
|
|
1192
|
+
function calendarMonthFromIndex(index) {
|
|
1193
|
+
return { year: Math.floor(index / 12), month: index % 12 + 1, day: 1 };
|
|
1194
|
+
}
|
|
1195
|
+
function datePeriodRange(date, period) {
|
|
1196
|
+
const firstMonth = period === "year" ? 1 : date.month;
|
|
1197
|
+
const lastMonth = period === "year" ? 12 : date.month;
|
|
1198
|
+
return [
|
|
1199
|
+
{ year: date.year, month: firstMonth, day: 1 },
|
|
1200
|
+
normalizeCalendarDate(date.year, lastMonth + 1, 0)
|
|
1201
|
+
];
|
|
1202
|
+
}
|
|
1203
|
+
function dateSummary(day) {
|
|
1204
|
+
return formatString6("DateSlicer_DateSummary", day.month, day.day, String(day.year).padStart(4, "0"));
|
|
1205
|
+
}
|
|
1206
|
+
function parseSelectionDate(value) {
|
|
1207
|
+
if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
1208
|
+
return parseCalendarDate(value);
|
|
1209
|
+
}
|
|
1210
|
+
return void 0;
|
|
1211
|
+
}
|
|
1212
|
+
function readHostSelection(selection) {
|
|
1213
|
+
if (selection === void 0 || selection === null) return { range: selection };
|
|
1214
|
+
if (Array.isArray(selection) && selection.length === 2) {
|
|
1215
|
+
const start = parseSelectionDate(selection[0]);
|
|
1216
|
+
const end = parseSelectionDate(selection[1]);
|
|
1217
|
+
if (start && end && compareCalendarDates(start, end) <= 0) return { range: [start, end] };
|
|
1218
|
+
}
|
|
1219
|
+
return { error: getString6("DateSlicer_InvalidSelection") };
|
|
1220
|
+
}
|
|
1221
|
+
function createDateRangePredicate(range, column, dataType) {
|
|
1222
|
+
const startDate = formatCalendarDate(range[0]);
|
|
1223
|
+
if (dataType === "datetime") {
|
|
1224
|
+
const endDate = range[1];
|
|
1225
|
+
let nextDay;
|
|
1226
|
+
if (isValidCalendarDate(endDate.year, endDate.month, endDate.day + 1)) {
|
|
1227
|
+
nextDay = { ...endDate, day: endDate.day + 1 };
|
|
1228
|
+
} else if (endDate.month < 12) {
|
|
1229
|
+
nextDay = { year: endDate.year, month: endDate.month + 1, day: 1 };
|
|
1230
|
+
} else if (endDate.year < 9999) {
|
|
1231
|
+
nextDay = { year: endDate.year + 1, month: 1, day: 1 };
|
|
1232
|
+
}
|
|
1233
|
+
return {
|
|
1234
|
+
type: "range",
|
|
1235
|
+
fieldId: column,
|
|
1236
|
+
min: { kind: "value", value: `${startDate}T00:00:00` },
|
|
1237
|
+
...nextDay ? { max: { kind: "value", value: `${formatCalendarDate(nextDay)}T00:00:00`, inclusive: false } } : {}
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
return {
|
|
1241
|
+
type: "range",
|
|
1242
|
+
fieldId: column,
|
|
1243
|
+
min: { kind: "value", value: startDate },
|
|
1244
|
+
max: { kind: "value", value: formatCalendarDate(range[1]) }
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
function normalizeCalendarDate(year, month, day) {
|
|
1248
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
1249
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
1250
|
+
return { year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() };
|
|
1251
|
+
}
|
|
1252
|
+
function resolveDatePreset(preset, today, domain) {
|
|
1253
|
+
if (domain) {
|
|
1254
|
+
const { year, month, day } = today;
|
|
1255
|
+
const quarterStartMonth = Math.floor((month - 1) / 3) * 3 + 1;
|
|
1256
|
+
let range;
|
|
1257
|
+
switch (preset) {
|
|
1258
|
+
case "last7Days":
|
|
1259
|
+
range = [normalizeCalendarDate(year, month, day - 6), today];
|
|
1260
|
+
break;
|
|
1261
|
+
case "last30Days":
|
|
1262
|
+
range = [normalizeCalendarDate(year, month, day - 29), today];
|
|
1263
|
+
break;
|
|
1264
|
+
case "monthToDate":
|
|
1265
|
+
range = [{ year, month, day: 1 }, today];
|
|
1266
|
+
break;
|
|
1267
|
+
case "lastMonth":
|
|
1268
|
+
range = [normalizeCalendarDate(year, month - 1, 1), normalizeCalendarDate(year, month, 0)];
|
|
1269
|
+
break;
|
|
1270
|
+
case "quarterToDate":
|
|
1271
|
+
range = [{ year, month: quarterStartMonth, day: 1 }, today];
|
|
1272
|
+
break;
|
|
1273
|
+
case "lastQuarter":
|
|
1274
|
+
range = [normalizeCalendarDate(year, quarterStartMonth - 3, 1), normalizeCalendarDate(year, quarterStartMonth, 0)];
|
|
1275
|
+
break;
|
|
1276
|
+
case "yearToDate":
|
|
1277
|
+
range = [{ year, month: 1, day: 1 }, today];
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
return intersectDateRanges(domain, range);
|
|
1281
|
+
}
|
|
1282
|
+
return void 0;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// src/components/date-slicer/date-slicer-period-grid.tsx
|
|
1286
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1287
|
+
function DateSlicerPeriodGrid({ label, cells, columns, unit, domain, selected, onActivate }) {
|
|
1288
|
+
const styles = useDateSlicerStyles();
|
|
1289
|
+
const [focusedIndex, setFocusedIndex] = useState4(null);
|
|
1290
|
+
const periods = useMemo4(() => cells.map((cell) => {
|
|
1291
|
+
const range = datePeriodRange(cell.date, unit);
|
|
1292
|
+
const boundedRange = intersectDateRanges(domain, range);
|
|
1293
|
+
const isSelected = Boolean(boundedRange && selected && compareCalendarDates2(selected[0], boundedRange[0]) <= 0 && compareCalendarDates2(selected[1], boundedRange[1]) >= 0);
|
|
1294
|
+
const isEndpoint = Boolean(isSelected && boundedRange && selected && (compareCalendarDates2(selected[0], boundedRange[0]) === 0 || compareCalendarDates2(selected[1], boundedRange[1]) === 0));
|
|
1295
|
+
return { ...cell, range, isDisabled: !boundedRange, isSelected, isEndpoint };
|
|
1296
|
+
}), [cells, unit, domain, selected]);
|
|
1297
|
+
const firstSelectedIndex = periods.findIndex((period) => period.isSelected);
|
|
1298
|
+
const firstEnabledIndex = periods.findIndex((period) => !period.isDisabled);
|
|
1299
|
+
const activeIndex = focusedIndex !== null && periods[focusedIndex] && !periods[focusedIndex].isDisabled ? focusedIndex : firstSelectedIndex >= 0 ? firstSelectedIndex : firstEnabledIndex;
|
|
1300
|
+
const handleClick = useCallback5((event) => {
|
|
1301
|
+
const period = periods[Number(event.currentTarget.value)];
|
|
1302
|
+
if (!period.isDisabled) onActivate(period.range, unit);
|
|
1303
|
+
}, [periods, unit, onActivate]);
|
|
1304
|
+
const handleFocus = useCallback5((event) => {
|
|
1305
|
+
setFocusedIndex(Number(event.currentTarget.value));
|
|
1306
|
+
}, []);
|
|
1307
|
+
const handleKeyDown = useCallback5((event) => {
|
|
1308
|
+
if (event.target instanceof HTMLButtonElement) {
|
|
1309
|
+
const index = Number(event.target.value);
|
|
1310
|
+
let nextIndex = index;
|
|
1311
|
+
let step = 1;
|
|
1312
|
+
switch (event.key) {
|
|
1313
|
+
case "ArrowLeft":
|
|
1314
|
+
step = -1;
|
|
1315
|
+
nextIndex -= 1;
|
|
1316
|
+
break;
|
|
1317
|
+
case "ArrowRight":
|
|
1318
|
+
nextIndex += 1;
|
|
1319
|
+
break;
|
|
1320
|
+
case "ArrowUp":
|
|
1321
|
+
step = -columns;
|
|
1322
|
+
nextIndex -= columns;
|
|
1323
|
+
break;
|
|
1324
|
+
case "ArrowDown":
|
|
1325
|
+
step = columns;
|
|
1326
|
+
nextIndex += columns;
|
|
1327
|
+
break;
|
|
1328
|
+
case "Home":
|
|
1329
|
+
nextIndex = event.ctrlKey ? 0 : Math.floor(index / columns) * columns;
|
|
1330
|
+
break;
|
|
1331
|
+
case "End":
|
|
1332
|
+
step = -1;
|
|
1333
|
+
nextIndex = event.ctrlKey ? periods.length - 1 : Math.min(periods.length - 1, Math.floor(index / columns) * columns + columns - 1);
|
|
1334
|
+
break;
|
|
1335
|
+
default:
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
event.preventDefault();
|
|
1339
|
+
while (nextIndex >= 0 && nextIndex < periods.length && periods[nextIndex].isDisabled) nextIndex += step;
|
|
1340
|
+
if (nextIndex >= 0 && nextIndex < periods.length) {
|
|
1341
|
+
event.currentTarget.querySelector(`button[value="${nextIndex}"]`)?.focus();
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}, [columns, periods]);
|
|
1345
|
+
return /* @__PURE__ */ jsx8("table", { className: styles.periodGrid, role: "grid", "aria-label": label, "aria-multiselectable": true, onKeyDown: handleKeyDown, children: /* @__PURE__ */ jsx8("tbody", { children: Array.from({ length: Math.ceil(periods.length / columns) }, (_, row) => /* @__PURE__ */ jsx8("tr", { role: "row", children: periods.slice(row * columns, (row + 1) * columns).map((period, column) => {
|
|
1346
|
+
const index = row * columns + column;
|
|
1347
|
+
return /* @__PURE__ */ jsx8("td", { role: "gridcell", "aria-selected": period.isSelected, children: /* @__PURE__ */ jsx8(
|
|
1348
|
+
"button",
|
|
1349
|
+
{
|
|
1350
|
+
type: "button",
|
|
1351
|
+
value: index,
|
|
1352
|
+
className: mergeClasses(styles.periodButton, period.isSelected && styles.selectedPeriod, period.isEndpoint && styles.periodEndpoint),
|
|
1353
|
+
"aria-label": period.accessibleLabel,
|
|
1354
|
+
disabled: period.isDisabled,
|
|
1355
|
+
tabIndex: index === activeIndex ? 0 : -1,
|
|
1356
|
+
onFocus: handleFocus,
|
|
1357
|
+
onClick: handleClick,
|
|
1358
|
+
children: period.label
|
|
1359
|
+
}
|
|
1360
|
+
) }, period.accessibleLabel);
|
|
1361
|
+
}) }, row)) }) });
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// src/components/date-slicer/date-slicer-calendar.tsx
|
|
1365
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1366
|
+
var calendarFormatters = {
|
|
1367
|
+
formatCaption: (date) => formatMonthDropdown(date)
|
|
1368
|
+
};
|
|
1369
|
+
var yearPageSize = 12;
|
|
1370
|
+
function yearLabel(year) {
|
|
1371
|
+
return String(year).padStart(4, "0");
|
|
1372
|
+
}
|
|
1373
|
+
function yearWindowLabel(first, last) {
|
|
1374
|
+
return first === last ? yearLabel(first) : formatString7("DateSlicer_YearWindow", yearLabel(first), yearLabel(last));
|
|
1375
|
+
}
|
|
1376
|
+
function monthWindowLabel(firstMonth, count) {
|
|
1377
|
+
const first = calendarMonthFromIndex(firstMonth);
|
|
1378
|
+
const last = calendarMonthFromIndex(firstMonth + count - 1);
|
|
1379
|
+
const firstName = formatMonthDropdown(toDayPickerDate(first));
|
|
1380
|
+
const lastName = formatMonthDropdown(toDayPickerDate(last));
|
|
1381
|
+
if (count === 1) return formatString7("DateSlicer_MonthYear", firstName, yearLabel(first.year));
|
|
1382
|
+
return first.year === last.year ? formatString7("DateSlicer_MonthWindow", firstName, lastName, yearLabel(first.year)) : formatString7("DateSlicer_CrossYearWindow", firstName, yearLabel(first.year), lastName, yearLabel(last.year));
|
|
1383
|
+
}
|
|
1384
|
+
function DateSlicerCalendar(props) {
|
|
1385
|
+
const hasValidRanges = isValidRange(props.domain) && (!props.selected || isValidRange(props.selected));
|
|
1386
|
+
if (hasValidRanges) {
|
|
1387
|
+
const numberOfMonths = props.numberOfMonths ?? 3;
|
|
1388
|
+
const hasValidMonthCount = Number.isSafeInteger(numberOfMonths) && numberOfMonths > 0;
|
|
1389
|
+
const domainMonthKey = `${monthIndex(props.domain[0])}:${monthIndex(props.domain[1])}`;
|
|
1390
|
+
return /* @__PURE__ */ jsx9(BoundedDateCalendar, { ...props, numberOfMonths: hasValidMonthCount ? numberOfMonths : 3 }, domainMonthKey);
|
|
1391
|
+
}
|
|
1392
|
+
return /* @__PURE__ */ jsx9("div", { role: "alert", children: getString7("DateSlicer_InvalidCalendarRange") });
|
|
1393
|
+
}
|
|
1394
|
+
function BoundedDateCalendar({
|
|
1395
|
+
domain,
|
|
1396
|
+
selected,
|
|
1397
|
+
numberOfMonths = 3,
|
|
1398
|
+
theme,
|
|
1399
|
+
onDayActivate,
|
|
1400
|
+
onPeriodActivate
|
|
1401
|
+
}) {
|
|
1402
|
+
const styles = useDateSlicerStyles();
|
|
1403
|
+
const today = localToday();
|
|
1404
|
+
const firstDomainMonth = monthIndex(domain[0]);
|
|
1405
|
+
const lastDomainMonth = monthIndex(domain[1]);
|
|
1406
|
+
const visibleMonthCount = Math.min(numberOfMonths, lastDomainMonth - firstDomainMonth + 1);
|
|
1407
|
+
const lastWindowMonth = lastDomainMonth - visibleMonthCount + 1;
|
|
1408
|
+
const initialMonth = Math.max(firstDomainMonth, Math.min(monthIndex(selected?.[0] ?? today), lastDomainMonth));
|
|
1409
|
+
const [view, setView] = useState5("days");
|
|
1410
|
+
const [browsedMonth, setBrowsedMonth] = useState5(initialMonth);
|
|
1411
|
+
const firstMonth = Math.min(browsedMonth, lastWindowMonth);
|
|
1412
|
+
const browsedYear = Math.floor(browsedMonth / 12);
|
|
1413
|
+
const yearPageStart = Math.floor(browsedYear / yearPageSize) * yearPageSize;
|
|
1414
|
+
const headerRef = useRef4(null);
|
|
1415
|
+
const columnCount = view === "days" ? visibleMonthCount : 1;
|
|
1416
|
+
const calendarStyle = useMemo5(() => ({
|
|
1417
|
+
...slicerThemeStyle(theme),
|
|
1418
|
+
"--date-month-count": columnCount
|
|
1419
|
+
}), [theme, columnCount]);
|
|
1420
|
+
const displayedMonth = useMemo5(() => toDayPickerDate(calendarMonthFromIndex(firstMonth)), [firstMonth]);
|
|
1421
|
+
const handleMonthChange = useCallback6((month) => {
|
|
1422
|
+
setBrowsedMonth(Math.max(firstDomainMonth, Math.min(monthIndex(toCalendarDate(month)), lastWindowMonth)));
|
|
1423
|
+
}, [firstDomainMonth, lastWindowMonth]);
|
|
1424
|
+
const navigate = useCallback6((direction) => {
|
|
1425
|
+
const startMonth = view === "days" ? firstMonth : view === "months" ? browsedMonth : yearPageStart * 12;
|
|
1426
|
+
const stepMonths = view === "days" ? 1 : view === "months" ? 12 : yearPageSize * 12;
|
|
1427
|
+
const lastMonth = view === "days" ? lastWindowMonth : lastDomainMonth;
|
|
1428
|
+
setBrowsedMonth(Math.max(firstDomainMonth, Math.min(startMonth + direction * stepMonths, lastMonth)));
|
|
1429
|
+
}, [view, firstMonth, browsedMonth, yearPageStart, firstDomainMonth, lastWindowMonth, lastDomainMonth]);
|
|
1430
|
+
const handlePrevious = useCallback6(() => navigate(-1), [navigate]);
|
|
1431
|
+
const handleNext = useCallback6(() => navigate(1), [navigate]);
|
|
1432
|
+
const handlePick = useCallback6(() => {
|
|
1433
|
+
setView(view === "months" ? "years" : "months");
|
|
1434
|
+
}, [view]);
|
|
1435
|
+
const handlePeriodActivate = useCallback6((range, unit) => {
|
|
1436
|
+
const completedRange = onPeriodActivate?.(range, unit);
|
|
1437
|
+
if (completedRange) {
|
|
1438
|
+
setBrowsedMonth(Math.max(firstDomainMonth, Math.min(monthIndex(completedRange[0]), lastDomainMonth)));
|
|
1439
|
+
setView(unit === "year" ? "months" : "days");
|
|
1440
|
+
headerRef.current?.focus();
|
|
1441
|
+
}
|
|
1442
|
+
}, [onPeriodActivate, firstDomainMonth, lastDomainMonth]);
|
|
1443
|
+
const monthCells = useMemo5(() => Array.from(
|
|
1444
|
+
{ length: 12 },
|
|
1445
|
+
(_, month) => {
|
|
1446
|
+
const date = { year: browsedYear, month: month + 1, day: 1 };
|
|
1447
|
+
return {
|
|
1448
|
+
date,
|
|
1449
|
+
label: defaultDateLib.format(toDayPickerDate(date), "LLL"),
|
|
1450
|
+
accessibleLabel: formatString7("DateSlicer_MonthYear", formatMonthDropdown(toDayPickerDate(date)), yearLabel(browsedYear))
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
), [browsedYear]);
|
|
1454
|
+
const yearCells = useMemo5(() => Array.from(
|
|
1455
|
+
{ length: Math.min(yearPageSize, 1e4 - yearPageStart) },
|
|
1456
|
+
(_, offset) => {
|
|
1457
|
+
const year = yearPageStart + offset;
|
|
1458
|
+
return { date: { year, month: 1, day: 1 }, label: yearLabel(year), accessibleLabel: yearLabel(year) };
|
|
1459
|
+
}
|
|
1460
|
+
), [yearPageStart]);
|
|
1461
|
+
const windowLabel = view === "days" ? monthWindowLabel(firstMonth, visibleMonthCount) : view === "months" ? yearLabel(browsedYear) : yearWindowLabel(yearPageStart, yearPageStart + yearCells.length - 1);
|
|
1462
|
+
const canGoPrevious = view === "days" ? firstMonth > firstDomainMonth : view === "months" ? browsedYear > domain[0].year : yearPageStart > domain[0].year;
|
|
1463
|
+
const canGoNext = view === "days" ? firstMonth < lastWindowMonth : view === "months" ? browsedYear < domain[1].year : yearPageStart + yearPageSize <= domain[1].year;
|
|
1464
|
+
const [minimumDay, maximumDay] = domain;
|
|
1465
|
+
const lowerDate = useMemo5(() => toDayPickerDate(minimumDay), [minimumDay]);
|
|
1466
|
+
const upperDate = useMemo5(() => toDayPickerDate(maximumDay), [maximumDay]);
|
|
1467
|
+
const disabledDays = useMemo5(() => [{ before: lowerDate }, { after: upperDate }], [lowerDate, upperDate]);
|
|
1468
|
+
const handleDayClick = useCallback6((date, modifiers) => {
|
|
1469
|
+
const day = toCalendarDate(date);
|
|
1470
|
+
const isWithinDomain = compareCalendarDates3(day, minimumDay) >= 0 && compareCalendarDates3(day, maximumDay) <= 0;
|
|
1471
|
+
if (!modifiers.disabled && isWithinDomain) {
|
|
1472
|
+
onDayActivate?.(day);
|
|
1473
|
+
}
|
|
1474
|
+
}, [minimumDay, maximumDay, onDayActivate]);
|
|
1475
|
+
const selectedStart = selected?.[0];
|
|
1476
|
+
const selectedEnd = selected?.[1];
|
|
1477
|
+
const calendarModifiers = useMemo5(() => {
|
|
1478
|
+
if (selectedStart && selectedEnd) {
|
|
1479
|
+
const from = toDayPickerDate(selectedStart);
|
|
1480
|
+
const to = toDayPickerDate(selectedEnd);
|
|
1481
|
+
return {
|
|
1482
|
+
selected: { from, to },
|
|
1483
|
+
range_start: from,
|
|
1484
|
+
range_end: to
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
return {};
|
|
1488
|
+
}, [selectedStart, selectedEnd]);
|
|
1489
|
+
const calendarClassNames = useMemo5(() => ({
|
|
1490
|
+
root: styles.dayPickerRoot,
|
|
1491
|
+
months: styles.months,
|
|
1492
|
+
month: styles.month,
|
|
1493
|
+
month_caption: visibleMonthCount === 1 ? styles.hiddenCaption : styles.caption,
|
|
1494
|
+
caption_label: styles.captionLabel,
|
|
1495
|
+
month_grid: styles.grid,
|
|
1496
|
+
weekday: styles.weekday,
|
|
1497
|
+
day: styles.day,
|
|
1498
|
+
day_button: styles.dayButton,
|
|
1499
|
+
disabled: styles.disabled,
|
|
1500
|
+
hidden: styles.hidden,
|
|
1501
|
+
selected: styles.selected,
|
|
1502
|
+
range_start: styles.rangeStart,
|
|
1503
|
+
range_end: styles.rangeEnd,
|
|
1504
|
+
today: styles.today
|
|
1505
|
+
}), [styles, visibleMonthCount]);
|
|
1506
|
+
return /* @__PURE__ */ jsxs6("div", { className: styles.root, style: calendarStyle, children: [
|
|
1507
|
+
/* @__PURE__ */ jsx9(
|
|
1508
|
+
DateSlicerNavigation,
|
|
1509
|
+
{
|
|
1510
|
+
label: windowLabel,
|
|
1511
|
+
pickLabel: getString7(view === "days" ? "DateSlicer_PickByMonth" : view === "months" ? "DateSlicer_PickByYear" : "DateSlicer_BackToMonths"),
|
|
1512
|
+
previousLabel: getString7(view === "days" ? "DateSlicer_PreviousMonth" : view === "months" ? "DateSlicer_PreviousYear" : "DateSlicer_PreviousYears"),
|
|
1513
|
+
nextLabel: getString7(view === "days" ? "DateSlicer_NextMonth" : view === "months" ? "DateSlicer_NextYear" : "DateSlicer_NextYears"),
|
|
1514
|
+
canGoPrevious,
|
|
1515
|
+
canGoNext,
|
|
1516
|
+
onPrevious: handlePrevious,
|
|
1517
|
+
onNext: handleNext,
|
|
1518
|
+
onPick: handlePick,
|
|
1519
|
+
headerRef
|
|
1520
|
+
}
|
|
1521
|
+
),
|
|
1522
|
+
view === "days" ? /* @__PURE__ */ jsx9(
|
|
1523
|
+
DayPicker,
|
|
1524
|
+
{
|
|
1525
|
+
hideNavigation: true,
|
|
1526
|
+
formatters: calendarFormatters,
|
|
1527
|
+
classNames: calendarClassNames,
|
|
1528
|
+
today: toDayPickerDate(today),
|
|
1529
|
+
month: displayedMonth,
|
|
1530
|
+
onMonthChange: handleMonthChange,
|
|
1531
|
+
startMonth: lowerDate,
|
|
1532
|
+
endMonth: upperDate,
|
|
1533
|
+
numberOfMonths: visibleMonthCount,
|
|
1534
|
+
disabled: disabledDays,
|
|
1535
|
+
modifiers: calendarModifiers,
|
|
1536
|
+
onDayClick: handleDayClick
|
|
1537
|
+
}
|
|
1538
|
+
) : /* @__PURE__ */ jsx9(
|
|
1539
|
+
DateSlicerPeriodGrid,
|
|
1540
|
+
{
|
|
1541
|
+
label: view === "months" ? formatString7("DateSlicer_MonthsInYear", yearLabel(browsedYear)) : formatString7("DateSlicer_YearsInWindow", windowLabel),
|
|
1542
|
+
cells: view === "months" ? monthCells : yearCells,
|
|
1543
|
+
columns: view === "months" ? 3 : 4,
|
|
1544
|
+
unit: view === "months" ? "month" : "year",
|
|
1545
|
+
domain,
|
|
1546
|
+
selected,
|
|
1547
|
+
onActivate: handlePeriodActivate
|
|
1548
|
+
},
|
|
1549
|
+
`${view}:${view === "months" ? browsedYear : yearPageStart}`
|
|
1550
|
+
)
|
|
1551
|
+
] });
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// src/components/date-slicer/date-slicer-data.ts
|
|
1555
|
+
import { compareCalendarDates as compareCalendarDates4, formatString as formatString8, getString as getString8, isDateFormat, parseCalendarDate as parseCalendarDate2 } from "@microsoft/fabric-visuals-core";
|
|
1556
|
+
function isDateColumnFormat(format) {
|
|
1557
|
+
const normalizedFormat = format.trim().toLowerCase();
|
|
1558
|
+
return normalizedFormat === "short date" || normalizedFormat === "long date" || normalizedFormat === "general date" || isDateFormat(format);
|
|
1559
|
+
}
|
|
1560
|
+
function readDateSlicerData(data, column) {
|
|
1561
|
+
const columnIndex = data.columns.findIndex((definition2) => definition2.name === column);
|
|
1562
|
+
if (columnIndex < 0) {
|
|
1563
|
+
return { title: column, format: void 0, domain: null, error: formatString8("Common_ColumnNotFound", column) };
|
|
1564
|
+
}
|
|
1565
|
+
const definition = data.columns[columnIndex];
|
|
1566
|
+
const metadata = { title: definition.displayName ?? definition.name, format: definition.format };
|
|
1567
|
+
if (definition.format?.trim() && !isDateColumnFormat(definition.format)) {
|
|
1568
|
+
return { ...metadata, domain: null, error: getString8("DateSlicer_NonDateFormat") };
|
|
1569
|
+
}
|
|
1570
|
+
let minimumDate;
|
|
1571
|
+
let maximumDate;
|
|
1572
|
+
for (const row of data.rows) {
|
|
1573
|
+
const value = row[columnIndex];
|
|
1574
|
+
if (value === null || value === void 0 || typeof value === "string" && value.trim() === "") continue;
|
|
1575
|
+
const calendarDate = typeof value === "string" ? parseCalendarDate2(value) : void 0;
|
|
1576
|
+
if (calendarDate === void 0) {
|
|
1577
|
+
return { ...metadata, domain: null, error: getString8("DateSlicer_InvalidDateValues") };
|
|
1578
|
+
}
|
|
1579
|
+
if (minimumDate === void 0 || compareCalendarDates4(calendarDate, minimumDate) < 0) minimumDate = calendarDate;
|
|
1580
|
+
if (maximumDate === void 0 || compareCalendarDates4(calendarDate, maximumDate) > 0) maximumDate = calendarDate;
|
|
1581
|
+
}
|
|
1582
|
+
if (minimumDate !== void 0 && maximumDate !== void 0) {
|
|
1583
|
+
return { ...metadata, domain: [minimumDate, maximumDate] };
|
|
1584
|
+
}
|
|
1585
|
+
return { ...metadata, domain: null, error: getString8("DateSlicer_NoDateValues") };
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// src/components/date-slicer/date-slicer-dropdown-styles.ts
|
|
1589
|
+
import { makeStyles as makeStyles7 } from "@griffel/react";
|
|
1590
|
+
import { borderRadius as borderRadius2, fontWeight as fontWeight2, inVisualsLayer as inVisualsLayer7, spacing as spacing2, tokens as tokens7 } from "@microsoft/fabric-visuals-core";
|
|
1591
|
+
var useDateSlicerDropdownStyles = makeStyles7(inVisualsLayer7({
|
|
1592
|
+
dateTrigger: {
|
|
1593
|
+
":disabled": { opacity: 0.5, cursor: "default", backgroundColor: "transparent" }
|
|
1594
|
+
},
|
|
1595
|
+
// Only remove the button's frame. The popup is rendered separately and still needs a background and border.
|
|
1596
|
+
framelessTrigger: {
|
|
1597
|
+
border: "none",
|
|
1598
|
+
borderRadius: 0,
|
|
1599
|
+
paddingInline: 0,
|
|
1600
|
+
backgroundColor: "transparent"
|
|
1601
|
+
},
|
|
1602
|
+
datePopover: {
|
|
1603
|
+
width: "max-content",
|
|
1604
|
+
// Limit the whole picker, including shortcuts, to the space Radix finds above or below the button.
|
|
1605
|
+
"& > div": { maxHeight: "min(70vh, 640px, var(--radix-popover-content-available-height))" },
|
|
1606
|
+
"@media (max-width: 600px)": {
|
|
1607
|
+
width: "calc(100vw - 16px)"
|
|
1608
|
+
}
|
|
1609
|
+
},
|
|
1610
|
+
picker: {
|
|
1611
|
+
display: "flex",
|
|
1612
|
+
alignItems: "stretch",
|
|
1613
|
+
minWidth: 0,
|
|
1614
|
+
maxWidth: "100%",
|
|
1615
|
+
padding: spacing2.m,
|
|
1616
|
+
gap: spacing2.m,
|
|
1617
|
+
border: `1px solid var(--slicer-stroke, ${tokens7.colorBorder})`,
|
|
1618
|
+
borderRadius: `var(--slicer-radius, ${tokens7.radiusXl})`,
|
|
1619
|
+
backgroundColor: `var(--slicer-background, ${tokens7.colorBackground})`,
|
|
1620
|
+
// Presets and stacked months share one collision-aware scroll area.
|
|
1621
|
+
overflow: "auto",
|
|
1622
|
+
overscrollBehavior: "contain",
|
|
1623
|
+
boxSizing: "border-box",
|
|
1624
|
+
"@media (max-width: 600px)": {
|
|
1625
|
+
flexDirection: "column",
|
|
1626
|
+
gap: spacing2.s
|
|
1627
|
+
}
|
|
1628
|
+
},
|
|
1629
|
+
calendarContainer: {
|
|
1630
|
+
minWidth: "252px",
|
|
1631
|
+
flexGrow: 1
|
|
1632
|
+
},
|
|
1633
|
+
presets: {
|
|
1634
|
+
display: "flex",
|
|
1635
|
+
flexDirection: "column",
|
|
1636
|
+
flexShrink: 0,
|
|
1637
|
+
alignItems: "stretch",
|
|
1638
|
+
gap: spacing2.xs,
|
|
1639
|
+
width: "148px",
|
|
1640
|
+
paddingInlineEnd: spacing2.m,
|
|
1641
|
+
borderRight: `1px solid var(--slicer-stroke, ${tokens7.colorBorder})`,
|
|
1642
|
+
"@media (max-width: 600px)": {
|
|
1643
|
+
display: "grid",
|
|
1644
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(112px, 1fr))",
|
|
1645
|
+
width: "auto",
|
|
1646
|
+
paddingInlineEnd: 0,
|
|
1647
|
+
paddingBottom: spacing2.s,
|
|
1648
|
+
borderRight: "none",
|
|
1649
|
+
borderBottom: `1px solid var(--slicer-stroke, ${tokens7.colorBorder})`
|
|
1650
|
+
}
|
|
1651
|
+
},
|
|
1652
|
+
presetButton: {
|
|
1653
|
+
minHeight: "36px",
|
|
1654
|
+
padding: `${spacing2.xs} ${spacing2.s}`,
|
|
1655
|
+
border: "1px solid transparent",
|
|
1656
|
+
borderRadius: borderRadius2.medium,
|
|
1657
|
+
backgroundColor: "transparent",
|
|
1658
|
+
color: "inherit",
|
|
1659
|
+
font: "inherit",
|
|
1660
|
+
textAlign: "start",
|
|
1661
|
+
overflowWrap: "anywhere",
|
|
1662
|
+
cursor: "pointer",
|
|
1663
|
+
":hover:not(:disabled)": {
|
|
1664
|
+
backgroundColor: `var(--slicer-hover, ${tokens7.colorHover})`
|
|
1665
|
+
},
|
|
1666
|
+
":focus-visible": {
|
|
1667
|
+
outline: `2px solid var(--slicer-link, ${tokens7.colorBrandForeground})`,
|
|
1668
|
+
outlineOffset: "1px"
|
|
1669
|
+
},
|
|
1670
|
+
":disabled": {
|
|
1671
|
+
color: `var(--slicer-secondary, ${tokens7.colorMutedForeground})`,
|
|
1672
|
+
opacity: 0.5,
|
|
1673
|
+
cursor: "default"
|
|
1674
|
+
},
|
|
1675
|
+
'&[aria-pressed="true"]': {
|
|
1676
|
+
backgroundColor: `color-mix(in srgb, var(--slicer-brand, ${tokens7.colorBrand}) 15%, var(--slicer-background, ${tokens7.colorBackground}))`,
|
|
1677
|
+
fontWeight: fontWeight2.semibold,
|
|
1678
|
+
border: `1px solid var(--slicer-link, ${tokens7.colorBrandForeground})`
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}));
|
|
1682
|
+
|
|
1683
|
+
// src/components/date-slicer/date-slicer-preset-list.tsx
|
|
1684
|
+
import { useCallback as useCallback7, useState as useState6 } from "react";
|
|
1685
|
+
import { getString as getString9 } from "@microsoft/fabric-visuals-core";
|
|
1686
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1687
|
+
var presets = [
|
|
1688
|
+
{ id: "last7Days", label: "DateSlicer_Last7Days" },
|
|
1689
|
+
{ id: "last30Days", label: "DateSlicer_Last30Days" },
|
|
1690
|
+
{ id: "monthToDate", label: "DateSlicer_MonthToDate" },
|
|
1691
|
+
{ id: "lastMonth", label: "DateSlicer_LastMonth" },
|
|
1692
|
+
{ id: "quarterToDate", label: "DateSlicer_QuarterToDate" },
|
|
1693
|
+
{ id: "lastQuarter", label: "DateSlicer_LastQuarter" },
|
|
1694
|
+
{ id: "yearToDate", label: "DateSlicer_YearToDate" }
|
|
1695
|
+
];
|
|
1696
|
+
function DateSlicerPresetButton({ id, label, isDisabled, isSelected, onSelect }) {
|
|
1697
|
+
const styles = useDateSlicerDropdownStyles();
|
|
1698
|
+
const handleClick = useCallback7(() => onSelect(id), [id, onSelect]);
|
|
1699
|
+
return /* @__PURE__ */ jsx10(
|
|
1700
|
+
"button",
|
|
1701
|
+
{
|
|
1702
|
+
type: "button",
|
|
1703
|
+
className: styles.presetButton,
|
|
1704
|
+
disabled: isDisabled,
|
|
1705
|
+
"aria-pressed": isSelected,
|
|
1706
|
+
onClick: handleClick,
|
|
1707
|
+
children: getString9(label)
|
|
1708
|
+
}
|
|
1709
|
+
);
|
|
1710
|
+
}
|
|
1711
|
+
function DateSlicerPresetList({ domain, committedRange, selectedPreset, onSelect }) {
|
|
1712
|
+
const styles = useDateSlicerDropdownStyles();
|
|
1713
|
+
const [today, setToday] = useState6(localToday);
|
|
1714
|
+
const selectPreset = useCallback7((id) => {
|
|
1715
|
+
const currentToday = localToday();
|
|
1716
|
+
setToday(currentToday);
|
|
1717
|
+
const range = resolveDatePreset(id, currentToday, domain);
|
|
1718
|
+
if (range) onSelect(id, range);
|
|
1719
|
+
}, [domain, onSelect]);
|
|
1720
|
+
const hasApplicablePreset = presets.some(({ id }) => resolveDatePreset(id, today, domain) !== void 0);
|
|
1721
|
+
return hasApplicablePreset ? /* @__PURE__ */ jsx10("div", { className: styles.presets, role: "group", "aria-label": getString9("DateSlicer_Presets"), children: presets.map(({ id, label }) => {
|
|
1722
|
+
const range = resolveDatePreset(id, today, domain);
|
|
1723
|
+
const isSelected = id === selectedPreset && range !== void 0 && dateRangesEqual(range, committedRange);
|
|
1724
|
+
return /* @__PURE__ */ jsx10(
|
|
1725
|
+
DateSlicerPresetButton,
|
|
1726
|
+
{
|
|
1727
|
+
id,
|
|
1728
|
+
label,
|
|
1729
|
+
isDisabled: !range,
|
|
1730
|
+
isSelected,
|
|
1731
|
+
onSelect: selectPreset
|
|
1732
|
+
},
|
|
1733
|
+
id
|
|
1734
|
+
);
|
|
1735
|
+
}) }) : null;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
// src/components/date-slicer/use-date-selection.ts
|
|
1739
|
+
import { useCallback as useCallback8, useEffect as useEffect3, useMemo as useMemo6, useRef as useRef5, useState as useState7 } from "react";
|
|
1740
|
+
import { compareCalendarDates as compareCalendarDates5 } from "@microsoft/fabric-visuals-core";
|
|
1741
|
+
function useDateSelection(domain, column, disabled, selection, onInteraction, dataType = "date") {
|
|
1742
|
+
const hostSelection = useMemo6(
|
|
1743
|
+
() => readHostSelection(selection),
|
|
1744
|
+
[selection]
|
|
1745
|
+
);
|
|
1746
|
+
const [selectionState, setSelectionState] = useState7({
|
|
1747
|
+
committedRange: hostSelection.range ?? null,
|
|
1748
|
+
draft: null,
|
|
1749
|
+
selectedPreset: null
|
|
1750
|
+
});
|
|
1751
|
+
const selectionRef = useRef5(selectionState);
|
|
1752
|
+
const previousHostRange = useRef5(hostSelection.range);
|
|
1753
|
+
const previousDomain = useRef5(domain);
|
|
1754
|
+
const updateSelection = useCallback8((next) => {
|
|
1755
|
+
selectionRef.current = next;
|
|
1756
|
+
setSelectionState(next);
|
|
1757
|
+
}, []);
|
|
1758
|
+
const cancelDraft = useCallback8(() => {
|
|
1759
|
+
if (selectionRef.current.draft) {
|
|
1760
|
+
updateSelection({ ...selectionRef.current, draft: null });
|
|
1761
|
+
}
|
|
1762
|
+
}, [updateSelection]);
|
|
1763
|
+
useEffect3(() => {
|
|
1764
|
+
if (!dateRangesEqual(previousHostRange.current, hostSelection.range)) {
|
|
1765
|
+
previousHostRange.current = hostSelection.range;
|
|
1766
|
+
if (hostSelection.range !== void 0 && !dateRangesEqual(selectionRef.current.committedRange, hostSelection.range)) {
|
|
1767
|
+
updateSelection({ committedRange: hostSelection.range, draft: null, selectedPreset: null });
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}, [hostSelection.range, updateSelection]);
|
|
1771
|
+
useEffect3(() => {
|
|
1772
|
+
if (!dateRangesEqual(previousDomain.current, domain) || disabled || hostSelection.error) {
|
|
1773
|
+
cancelDraft();
|
|
1774
|
+
}
|
|
1775
|
+
previousDomain.current = domain;
|
|
1776
|
+
}, [domain, disabled, hostSelection.error, cancelDraft]);
|
|
1777
|
+
const commitRange = useCallback8((completedRange, preset) => {
|
|
1778
|
+
if (domain && !disabled && !hostSelection.error) {
|
|
1779
|
+
const isUnchanged = dateRangesEqual(selectionRef.current.committedRange, completedRange);
|
|
1780
|
+
updateSelection({ committedRange: completedRange, draft: null, selectedPreset: preset ?? null });
|
|
1781
|
+
if (isUnchanged) return;
|
|
1782
|
+
const event = {
|
|
1783
|
+
action: "select",
|
|
1784
|
+
selections: [{
|
|
1785
|
+
predicates: [createDateRangePredicate(completedRange, column, dataType)]
|
|
1786
|
+
}]
|
|
1787
|
+
};
|
|
1788
|
+
onInteraction?.([event]);
|
|
1789
|
+
}
|
|
1790
|
+
}, [domain, column, disabled, hostSelection.error, onInteraction, updateSelection, dataType]);
|
|
1791
|
+
const activateRangeEndpoint = useCallback8((range, unit) => {
|
|
1792
|
+
if (domain && !disabled && !hostSelection.error) {
|
|
1793
|
+
const boundedRange = intersectDateRanges(domain, range);
|
|
1794
|
+
if (boundedRange) {
|
|
1795
|
+
const draft2 = selectionRef.current.draft;
|
|
1796
|
+
if (draft2?.unit === unit) {
|
|
1797
|
+
const completedRange = [
|
|
1798
|
+
compareCalendarDates5(draft2.range[0], boundedRange[0]) < 0 ? draft2.range[0] : boundedRange[0],
|
|
1799
|
+
compareCalendarDates5(draft2.range[1], boundedRange[1]) > 0 ? draft2.range[1] : boundedRange[1]
|
|
1800
|
+
];
|
|
1801
|
+
commitRange(completedRange);
|
|
1802
|
+
return completedRange;
|
|
1803
|
+
} else {
|
|
1804
|
+
updateSelection({
|
|
1805
|
+
committedRange: selectionRef.current.committedRange,
|
|
1806
|
+
draft: { range: boundedRange, unit },
|
|
1807
|
+
selectedPreset: null
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
return void 0;
|
|
1813
|
+
}, [domain, disabled, hostSelection.error, commitRange, updateSelection]);
|
|
1814
|
+
const activateDay = useCallback8((day) => {
|
|
1815
|
+
activateRangeEndpoint([day, day], "day");
|
|
1816
|
+
}, [activateRangeEndpoint]);
|
|
1817
|
+
const clearSelection = useCallback8(() => {
|
|
1818
|
+
if (domain && !disabled && !hostSelection.error) {
|
|
1819
|
+
updateSelection({ committedRange: null, draft: null, selectedPreset: null });
|
|
1820
|
+
onInteraction?.([{ action: "clear" }]);
|
|
1821
|
+
}
|
|
1822
|
+
}, [domain, disabled, hostSelection.error, onInteraction, updateSelection]);
|
|
1823
|
+
const { committedRange, draft, selectedPreset } = selectionState;
|
|
1824
|
+
return {
|
|
1825
|
+
committedRange,
|
|
1826
|
+
selectedPreset,
|
|
1827
|
+
// Clip only DateSlicerCalendar's highlight; summary and interaction bounds remain intact.
|
|
1828
|
+
displayedRange: intersectDateRanges(domain, draft?.range ?? committedRange),
|
|
1829
|
+
error: hostSelection.error,
|
|
1830
|
+
activateDay,
|
|
1831
|
+
activatePeriod: activateRangeEndpoint,
|
|
1832
|
+
commitRange,
|
|
1833
|
+
cancelDraft,
|
|
1834
|
+
clearSelection
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
// src/components/date-slicer/date-slicer.tsx
|
|
1839
|
+
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1840
|
+
function DateSlicer(props) {
|
|
1841
|
+
return /* @__PURE__ */ jsx11(DateSlicerContent, { ...props }, props.column);
|
|
1842
|
+
}
|
|
1843
|
+
function DateSlicerContent({
|
|
1844
|
+
data,
|
|
1845
|
+
column,
|
|
1846
|
+
title,
|
|
1847
|
+
theme,
|
|
1848
|
+
disabled = false,
|
|
1849
|
+
displayOptions,
|
|
1850
|
+
onInteraction,
|
|
1851
|
+
selection,
|
|
1852
|
+
dataType = "date"
|
|
1853
|
+
}) {
|
|
1854
|
+
const styles = { ...useSlicerStyles(), ...useDropdownStyles(), ...useDateSlicerDropdownStyles() };
|
|
1855
|
+
const titleId = useId3();
|
|
1856
|
+
const summaryId = useId3();
|
|
1857
|
+
const themeStyle = useMemo7(() => slicerThemeStyle(theme), [theme]);
|
|
1858
|
+
const slicerData = useMemo7(() => readDateSlicerData(data, column), [data, column]);
|
|
1859
|
+
const { committedRange, displayedRange, selectedPreset, error: selectionError, activateDay, activatePeriod, commitRange, cancelDraft, clearSelection } = useDateSelection(
|
|
1860
|
+
slicerData.domain,
|
|
1861
|
+
column,
|
|
1862
|
+
disabled,
|
|
1863
|
+
selection,
|
|
1864
|
+
onInteraction,
|
|
1865
|
+
dataType
|
|
1866
|
+
);
|
|
1867
|
+
const [isOpen, setIsOpen] = useState8(false);
|
|
1868
|
+
const [presetNavigationVersion, setPresetNavigationVersion] = useState8(0);
|
|
1869
|
+
const error = slicerData.error ?? selectionError;
|
|
1870
|
+
const canSelect = slicerData.domain !== null && !disabled && !error;
|
|
1871
|
+
const hideHeader = displayOptions?.hideHeader ?? false;
|
|
1872
|
+
const showPresets = displayOptions?.showPresets ?? true;
|
|
1873
|
+
const displayTitle = title ?? slicerData.title;
|
|
1874
|
+
const summary = committedRange ? formatString9("DateSlicer_RangeSummary", dateSummary(committedRange[0]), dateSummary(committedRange[1])) : getString10("DateSlicer_AllDates");
|
|
1875
|
+
const handleOpenChange = useCallback9((open) => {
|
|
1876
|
+
setIsOpen(open);
|
|
1877
|
+
if (!open) cancelDraft();
|
|
1878
|
+
}, [cancelDraft]);
|
|
1879
|
+
const handlePresetSelect = useCallback9((preset, range) => {
|
|
1880
|
+
commitRange(range, preset);
|
|
1881
|
+
setPresetNavigationVersion((version) => version + 1);
|
|
1882
|
+
}, [commitRange]);
|
|
1883
|
+
useEffect4(() => {
|
|
1884
|
+
if (!canSelect) handleOpenChange(false);
|
|
1885
|
+
}, [canSelect, handleOpenChange]);
|
|
1886
|
+
return /* @__PURE__ */ jsxs7(
|
|
1887
|
+
"section",
|
|
1888
|
+
{
|
|
1889
|
+
"data-lyra-selection-boundary": "",
|
|
1890
|
+
className: mergeClasses(styles.typography, styles.root),
|
|
1891
|
+
style: themeStyle,
|
|
1892
|
+
"aria-labelledby": hideHeader ? void 0 : titleId,
|
|
1893
|
+
"aria-label": hideHeader ? displayTitle : void 0,
|
|
1894
|
+
children: [
|
|
1895
|
+
!hideHeader && /* @__PURE__ */ jsx11(
|
|
1896
|
+
SlicerHeader,
|
|
1897
|
+
{
|
|
1898
|
+
title: displayTitle,
|
|
1899
|
+
titleId,
|
|
1900
|
+
onClear: committedRange ? clearSelection : void 0,
|
|
1901
|
+
clearDisabled: !canSelect
|
|
1902
|
+
}
|
|
1903
|
+
),
|
|
1904
|
+
error ? /* @__PURE__ */ jsx11("div", { role: "alert", className: styles.message, children: error }) : /* @__PURE__ */ jsxs7(Popover, { open: isOpen && canSelect, onOpenChange: handleOpenChange, children: [
|
|
1905
|
+
/* @__PURE__ */ jsx11(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs7(
|
|
1906
|
+
"button",
|
|
1907
|
+
{
|
|
1908
|
+
type: "button",
|
|
1909
|
+
className: mergeClasses(styles.trigger, styles.dateTrigger, displayOptions?.frameless && styles.framelessTrigger),
|
|
1910
|
+
disabled: !canSelect,
|
|
1911
|
+
"aria-labelledby": hideHeader ? void 0 : `${titleId} ${summaryId}`,
|
|
1912
|
+
"aria-label": hideHeader ? `${displayTitle} ${summary}` : void 0,
|
|
1913
|
+
children: [
|
|
1914
|
+
/* @__PURE__ */ jsx11(CalendarIcon, { className: styles.icon }),
|
|
1915
|
+
/* @__PURE__ */ jsx11("span", { id: summaryId, className: styles.text, title: summary, children: summary }),
|
|
1916
|
+
/* @__PURE__ */ jsx11(ChevronDownIcon, { className: styles.icon })
|
|
1917
|
+
]
|
|
1918
|
+
}
|
|
1919
|
+
) }),
|
|
1920
|
+
/* @__PURE__ */ jsx11(PopoverContent, { className: styles.datePopover, style: themeStyle, "aria-label": displayTitle, avoidCollisions: true, children: slicerData.domain && /* @__PURE__ */ jsxs7("div", { className: styles.picker, children: [
|
|
1921
|
+
showPresets && /* @__PURE__ */ jsx11(
|
|
1922
|
+
DateSlicerPresetList,
|
|
1923
|
+
{
|
|
1924
|
+
domain: slicerData.domain,
|
|
1925
|
+
committedRange,
|
|
1926
|
+
selectedPreset,
|
|
1927
|
+
onSelect: handlePresetSelect
|
|
1928
|
+
}
|
|
1929
|
+
),
|
|
1930
|
+
/* @__PURE__ */ jsx11("div", { className: styles.calendarContainer, children: /* @__PURE__ */ jsx11(
|
|
1931
|
+
DateSlicerCalendar,
|
|
1932
|
+
{
|
|
1933
|
+
domain: slicerData.domain,
|
|
1934
|
+
selected: displayedRange,
|
|
1935
|
+
numberOfMonths: displayOptions?.numberOfMonths,
|
|
1936
|
+
theme,
|
|
1937
|
+
onDayActivate: activateDay,
|
|
1938
|
+
onPeriodActivate: activatePeriod
|
|
1939
|
+
},
|
|
1940
|
+
`${displayOptions?.numberOfMonths}:${presetNavigationVersion}`
|
|
1941
|
+
) })
|
|
1942
|
+
] }) })
|
|
1943
|
+
] })
|
|
1944
|
+
]
|
|
1945
|
+
}
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
782
1949
|
// src/components/range-slicer/range-slicer.tsx
|
|
783
|
-
import { useCallback as
|
|
1950
|
+
import { useCallback as useCallback13, useId as useId6, useMemo as useMemo10 } from "react";
|
|
784
1951
|
import { mergeClasses as mergeClasses3 } from "@griffel/react";
|
|
785
|
-
import { formatNumericInput, formatString as
|
|
1952
|
+
import { formatNumericInput, formatString as formatString14, formatValue as formatValue2, getString as getString11, parseNumericInput } from "@microsoft/fabric-visuals-core";
|
|
786
1953
|
|
|
787
1954
|
// src/components/range-slicer/range-slicer-data.ts
|
|
788
|
-
import { formatString as
|
|
1955
|
+
import { formatString as formatString10, isDataTable as isDataTable2 } from "@microsoft/fabric-visuals-core";
|
|
789
1956
|
var maxAutomaticHistogramBinCount = 24;
|
|
790
1957
|
function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
|
|
791
1958
|
const table = isDataTable2(data) ? data : { columns: [{ name: column }], rows: data.map((value) => [value]) };
|
|
@@ -797,7 +1964,7 @@ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
|
|
|
797
1964
|
domain: null,
|
|
798
1965
|
hasOnlyIntegerValues: false,
|
|
799
1966
|
histogram: [],
|
|
800
|
-
error:
|
|
1967
|
+
error: formatString10("Common_ColumnNotFound", column)
|
|
801
1968
|
};
|
|
802
1969
|
}
|
|
803
1970
|
const definition = table.columns[columnIndex];
|
|
@@ -851,25 +2018,25 @@ function getRangePosition(value, domain) {
|
|
|
851
2018
|
}
|
|
852
2019
|
|
|
853
2020
|
// src/components/range-slicer/range-slicer-styles.ts
|
|
854
|
-
import { makeStyles as
|
|
855
|
-
import { borderRadius, fontFamily as fontFamily2, fontSize, injectDesignTokens as
|
|
856
|
-
|
|
857
|
-
var useRangeSlicerStyles =
|
|
2021
|
+
import { makeStyles as makeStyles8, shorthands as shorthands2 } from "@griffel/react";
|
|
2022
|
+
import { borderRadius as borderRadius3, fontFamily as fontFamily2, fontSize as fontSize2, injectDesignTokens as injectDesignTokens3, inVisualsLayer as inVisualsLayer8, lineHeight, spacing as spacing3, tokens as tokens8 } from "@microsoft/fabric-visuals-core";
|
|
2023
|
+
injectDesignTokens3();
|
|
2024
|
+
var useRangeSlicerStyles = makeStyles8(inVisualsLayer8({
|
|
858
2025
|
root: {
|
|
859
|
-
"--range-foreground":
|
|
860
|
-
"--range-secondary":
|
|
861
|
-
"--range-accent":
|
|
862
|
-
"--range-background":
|
|
863
|
-
"--range-stroke":
|
|
864
|
-
"--range-error":
|
|
2026
|
+
"--range-foreground": tokens8.colorForeground,
|
|
2027
|
+
"--range-secondary": tokens8.colorMutedForeground,
|
|
2028
|
+
"--range-accent": tokens8.colorBrandForeground,
|
|
2029
|
+
"--range-background": tokens8.colorBackground,
|
|
2030
|
+
"--range-stroke": tokens8.colorBorder,
|
|
2031
|
+
"--range-error": tokens8.colorDestructive,
|
|
865
2032
|
display: "flex",
|
|
866
2033
|
flexDirection: "column",
|
|
867
|
-
gap:
|
|
2034
|
+
gap: spacing3.s,
|
|
868
2035
|
width: "300px",
|
|
869
2036
|
maxWidth: "100%",
|
|
870
2037
|
minWidth: 0,
|
|
871
2038
|
fontFamily: fontFamily2.base,
|
|
872
|
-
fontSize:
|
|
2039
|
+
fontSize: fontSize2[300],
|
|
873
2040
|
lineHeight: lineHeight[300],
|
|
874
2041
|
color: "var(--range-foreground)",
|
|
875
2042
|
"& [data-disabled]": {
|
|
@@ -889,9 +2056,9 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
889
2056
|
},
|
|
890
2057
|
body: {
|
|
891
2058
|
boxSizing: "border-box",
|
|
892
|
-
padding:
|
|
2059
|
+
padding: spacing3.mNudge,
|
|
893
2060
|
border: "1px solid var(--range-stroke)",
|
|
894
|
-
borderRadius:
|
|
2061
|
+
borderRadius: borderRadius3.xLarge,
|
|
895
2062
|
backgroundColor: "var(--range-background)"
|
|
896
2063
|
},
|
|
897
2064
|
framelessBody: {
|
|
@@ -903,11 +2070,11 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
903
2070
|
empty: {
|
|
904
2071
|
margin: 0,
|
|
905
2072
|
color: "var(--range-secondary)",
|
|
906
|
-
fontSize:
|
|
2073
|
+
fontSize: fontSize2[200]
|
|
907
2074
|
},
|
|
908
2075
|
histogram: {
|
|
909
2076
|
// Match the track inset so histogram values align with the thumb centers.
|
|
910
|
-
marginInline:
|
|
2077
|
+
marginInline: spacing3.m,
|
|
911
2078
|
height: "40px",
|
|
912
2079
|
"& svg": {
|
|
913
2080
|
display: "block",
|
|
@@ -926,7 +2093,7 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
926
2093
|
position: "relative",
|
|
927
2094
|
display: "flex",
|
|
928
2095
|
alignItems: "center",
|
|
929
|
-
height:
|
|
2096
|
+
height: spacing3.xxl,
|
|
930
2097
|
touchAction: "none",
|
|
931
2098
|
userSelect: "none",
|
|
932
2099
|
cursor: "pointer"
|
|
@@ -935,23 +2102,23 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
935
2102
|
position: "relative",
|
|
936
2103
|
flexGrow: 1,
|
|
937
2104
|
height: "3px",
|
|
938
|
-
marginInline:
|
|
2105
|
+
marginInline: spacing3.m,
|
|
939
2106
|
backgroundColor: "var(--range-stroke)",
|
|
940
|
-
borderRadius:
|
|
2107
|
+
borderRadius: borderRadius3.circular,
|
|
941
2108
|
forcedColorAdjust: "none"
|
|
942
2109
|
},
|
|
943
2110
|
range: {
|
|
944
2111
|
position: "absolute",
|
|
945
2112
|
height: "100%",
|
|
946
2113
|
backgroundColor: "var(--range-accent)",
|
|
947
|
-
borderRadius:
|
|
2114
|
+
borderRadius: borderRadius3.circular
|
|
948
2115
|
},
|
|
949
2116
|
thumb: {
|
|
950
2117
|
display: "block",
|
|
951
2118
|
position: "relative",
|
|
952
|
-
width:
|
|
953
|
-
height:
|
|
954
|
-
borderRadius:
|
|
2119
|
+
width: spacing3.xxl,
|
|
2120
|
+
height: spacing3.xxl,
|
|
2121
|
+
borderRadius: borderRadius3.circular,
|
|
955
2122
|
outline: "none",
|
|
956
2123
|
forcedColorAdjust: "none",
|
|
957
2124
|
// Draw a small visible handle while retaining a larger pointer target.
|
|
@@ -960,7 +2127,7 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
960
2127
|
position: "absolute",
|
|
961
2128
|
inset: "6px",
|
|
962
2129
|
border: "1px solid var(--range-accent)",
|
|
963
|
-
borderRadius:
|
|
2130
|
+
borderRadius: borderRadius3.circular,
|
|
964
2131
|
backgroundColor: "var(--range-background)"
|
|
965
2132
|
},
|
|
966
2133
|
":hover::before": {
|
|
@@ -975,16 +2142,16 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
975
2142
|
display: "grid",
|
|
976
2143
|
gridTemplateColumns: "minmax(0, 1fr) auto minmax(0, 1fr)",
|
|
977
2144
|
alignItems: "start",
|
|
978
|
-
gap:
|
|
2145
|
+
gap: spacing3.s
|
|
979
2146
|
},
|
|
980
2147
|
input: {
|
|
981
2148
|
boxSizing: "border-box",
|
|
982
2149
|
width: "100%",
|
|
983
2150
|
minWidth: 0,
|
|
984
2151
|
height: "28px",
|
|
985
|
-
paddingInline:
|
|
2152
|
+
paddingInline: spacing3.s,
|
|
986
2153
|
border: "1px solid var(--range-stroke)",
|
|
987
|
-
borderRadius:
|
|
2154
|
+
borderRadius: borderRadius3.xLarge,
|
|
988
2155
|
color: "var(--range-foreground)",
|
|
989
2156
|
backgroundColor: "var(--range-background)",
|
|
990
2157
|
fontFamily: "inherit",
|
|
@@ -1007,31 +2174,31 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
1007
2174
|
},
|
|
1008
2175
|
separator: {
|
|
1009
2176
|
lineHeight: "28px",
|
|
1010
|
-
fontSize:
|
|
2177
|
+
fontSize: fontSize2[200],
|
|
1011
2178
|
color: "var(--range-secondary)"
|
|
1012
2179
|
},
|
|
1013
2180
|
fullRange: {
|
|
1014
2181
|
margin: 0,
|
|
1015
|
-
marginTop:
|
|
2182
|
+
marginTop: spacing3.s,
|
|
1016
2183
|
color: "var(--range-secondary)",
|
|
1017
|
-
fontSize:
|
|
2184
|
+
fontSize: fontSize2[200],
|
|
1018
2185
|
lineHeight: lineHeight[200],
|
|
1019
2186
|
overflowWrap: "anywhere"
|
|
1020
2187
|
},
|
|
1021
2188
|
error: {
|
|
1022
2189
|
display: "block",
|
|
1023
|
-
marginTop:
|
|
2190
|
+
marginTop: spacing3.xs,
|
|
1024
2191
|
color: "var(--range-error)",
|
|
1025
|
-
fontSize:
|
|
2192
|
+
fontSize: fontSize2[300],
|
|
1026
2193
|
lineHeight: lineHeight[300],
|
|
1027
2194
|
overflowWrap: "anywhere"
|
|
1028
2195
|
}
|
|
1029
2196
|
}));
|
|
1030
2197
|
|
|
1031
2198
|
// src/components/range-slicer/range-value-input.tsx
|
|
1032
|
-
import { useCallback as
|
|
1033
|
-
import { formatString as
|
|
1034
|
-
import { jsx as
|
|
2199
|
+
import { useCallback as useCallback10, useId as useId4, useState as useState9 } from "react";
|
|
2200
|
+
import { formatString as formatString11 } from "@microsoft/fabric-visuals-core";
|
|
2201
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1035
2202
|
function RangeValueInput({
|
|
1036
2203
|
label,
|
|
1037
2204
|
value,
|
|
@@ -1044,14 +2211,14 @@ function RangeValueInput({
|
|
|
1044
2211
|
onCommit
|
|
1045
2212
|
}) {
|
|
1046
2213
|
const styles = useRangeSlicerStyles();
|
|
1047
|
-
const errorId =
|
|
1048
|
-
const [draft, setDraft] =
|
|
1049
|
-
const [error, setError] =
|
|
1050
|
-
const handleChange =
|
|
2214
|
+
const errorId = useId4();
|
|
2215
|
+
const [draft, setDraft] = useState9();
|
|
2216
|
+
const [error, setError] = useState9();
|
|
2217
|
+
const handleChange = useCallback10((event) => {
|
|
1051
2218
|
setDraft(event.currentTarget.value);
|
|
1052
2219
|
setError(void 0);
|
|
1053
2220
|
}, []);
|
|
1054
|
-
const handleBlur =
|
|
2221
|
+
const handleBlur = useCallback10((event) => {
|
|
1055
2222
|
if (draft === void 0) return;
|
|
1056
2223
|
const text = event.currentTarget.value.trim();
|
|
1057
2224
|
const nextValue = parseValue(text);
|
|
@@ -1060,10 +2227,10 @@ function RangeValueInput({
|
|
|
1060
2227
|
setDraft(void 0);
|
|
1061
2228
|
setError(void 0);
|
|
1062
2229
|
} else {
|
|
1063
|
-
setError(
|
|
2230
|
+
setError(formatString11("RangeSlicer_InvalidValue", formatValue3(min), formatValue3(max)));
|
|
1064
2231
|
}
|
|
1065
2232
|
}, [draft, min, max, formatValue3, parseValue, onCommit]);
|
|
1066
|
-
const handleKeyDown =
|
|
2233
|
+
const handleKeyDown = useCallback10((event) => {
|
|
1067
2234
|
if (event.key === "Enter") {
|
|
1068
2235
|
event.preventDefault();
|
|
1069
2236
|
event.currentTarget.blur();
|
|
@@ -1073,8 +2240,8 @@ function RangeValueInput({
|
|
|
1073
2240
|
setError(void 0);
|
|
1074
2241
|
}
|
|
1075
2242
|
}, []);
|
|
1076
|
-
return /* @__PURE__ */
|
|
1077
|
-
/* @__PURE__ */
|
|
2243
|
+
return /* @__PURE__ */ jsxs8("div", { children: [
|
|
2244
|
+
/* @__PURE__ */ jsx12(
|
|
1078
2245
|
"input",
|
|
1079
2246
|
{
|
|
1080
2247
|
className: styles.input,
|
|
@@ -1090,19 +2257,19 @@ function RangeValueInput({
|
|
|
1090
2257
|
onKeyDown: handleKeyDown
|
|
1091
2258
|
}
|
|
1092
2259
|
),
|
|
1093
|
-
error && /* @__PURE__ */
|
|
2260
|
+
error && /* @__PURE__ */ jsx12("span", { className: styles.error, id: errorId, role: "alert", children: error })
|
|
1094
2261
|
] });
|
|
1095
2262
|
}
|
|
1096
2263
|
|
|
1097
2264
|
// src/components/range-slicer/range-histogram.tsx
|
|
1098
|
-
import { useId as
|
|
1099
|
-
import { formatString as
|
|
1100
|
-
import { jsx as
|
|
2265
|
+
import { useId as useId5 } from "react";
|
|
2266
|
+
import { formatString as formatString12 } from "@microsoft/fabric-visuals-core";
|
|
2267
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1101
2268
|
var histogramWidth = 240;
|
|
1102
2269
|
var histogramHeight = 40;
|
|
1103
2270
|
function RangeHistogram({ counts, domain, selectedRange, title }) {
|
|
1104
2271
|
const styles = useRangeSlicerStyles();
|
|
1105
|
-
const clipId =
|
|
2272
|
+
const clipId = useId5();
|
|
1106
2273
|
const maximumCount = Math.max(...counts);
|
|
1107
2274
|
const isFixedRange = domain[0] === domain[1];
|
|
1108
2275
|
const binWidth = isFixedRange ? 10 : histogramWidth / counts.length;
|
|
@@ -1111,11 +2278,11 @@ function RangeHistogram({ counts, domain, selectedRange, title }) {
|
|
|
1111
2278
|
const bars = counts.map((count, index) => {
|
|
1112
2279
|
const height = count / maximumCount * histogramHeight;
|
|
1113
2280
|
const x = startX + index * binWidth + gap / 2;
|
|
1114
|
-
return /* @__PURE__ */
|
|
2281
|
+
return /* @__PURE__ */ jsx13("rect", { x, y: histogramHeight - height, width: binWidth - gap, height }, x);
|
|
1115
2282
|
});
|
|
1116
2283
|
const selectionStart = isFixedRange ? 0 : getRangePosition(selectedRange[0], domain) * histogramWidth;
|
|
1117
2284
|
const selectionEnd = isFixedRange ? histogramWidth : getRangePosition(selectedRange[1], domain) * histogramWidth;
|
|
1118
|
-
return /* @__PURE__ */
|
|
2285
|
+
return /* @__PURE__ */ jsx13("div", { className: styles.histogram, children: /* @__PURE__ */ jsxs9(
|
|
1119
2286
|
"svg",
|
|
1120
2287
|
{
|
|
1121
2288
|
width: "100%",
|
|
@@ -1123,12 +2290,12 @@ function RangeHistogram({ counts, domain, selectedRange, title }) {
|
|
|
1123
2290
|
viewBox: `0 0 ${histogramWidth} ${histogramHeight}`,
|
|
1124
2291
|
preserveAspectRatio: "none",
|
|
1125
2292
|
role: "img",
|
|
1126
|
-
"aria-label":
|
|
2293
|
+
"aria-label": formatString12("RangeSlicer_DistributionLabel", title),
|
|
1127
2294
|
focusable: "false",
|
|
1128
2295
|
children: [
|
|
1129
|
-
/* @__PURE__ */
|
|
1130
|
-
/* @__PURE__ */
|
|
1131
|
-
/* @__PURE__ */
|
|
2296
|
+
/* @__PURE__ */ jsx13("defs", { children: /* @__PURE__ */ jsx13("clipPath", { id: clipId, children: /* @__PURE__ */ jsx13("rect", { x: selectionStart, y: 0, width: selectionEnd - selectionStart, height: histogramHeight }) }) }),
|
|
2297
|
+
/* @__PURE__ */ jsx13("g", { className: styles.histogramMuted, children: bars }),
|
|
2298
|
+
/* @__PURE__ */ jsx13("g", { className: styles.histogramSelected, clipPath: `url(#${clipId})`, children: bars })
|
|
1132
2299
|
]
|
|
1133
2300
|
}
|
|
1134
2301
|
) });
|
|
@@ -1136,8 +2303,8 @@ function RangeHistogram({ counts, domain, selectedRange, title }) {
|
|
|
1136
2303
|
|
|
1137
2304
|
// src/components/range-slicer/range-slider.tsx
|
|
1138
2305
|
import { Root as Slider, Track, Range, Thumb } from "@radix-ui/react-slider";
|
|
1139
|
-
import { useCallback as
|
|
1140
|
-
import { formatString as
|
|
2306
|
+
import { useCallback as useCallback11, useMemo as useMemo8, useRef as useRef6 } from "react";
|
|
2307
|
+
import { formatString as formatString13 } from "@microsoft/fabric-visuals-core";
|
|
1141
2308
|
|
|
1142
2309
|
// src/components/range-slicer/range-slider-steps.ts
|
|
1143
2310
|
function getAutomaticRangeStep(domain, formatBound = String, hasOnlyIntegerValues = false) {
|
|
@@ -1172,7 +2339,7 @@ function hasRepeatedLabels(domain, step, formatBound) {
|
|
|
1172
2339
|
}
|
|
1173
2340
|
|
|
1174
2341
|
// src/components/range-slicer/range-slider.tsx
|
|
1175
|
-
import { jsx as
|
|
2342
|
+
import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1176
2343
|
function RangeSlider({
|
|
1177
2344
|
domain,
|
|
1178
2345
|
selectedRange,
|
|
@@ -1186,13 +2353,13 @@ function RangeSlider({
|
|
|
1186
2353
|
onValueCommit
|
|
1187
2354
|
}) {
|
|
1188
2355
|
const styles = useRangeSlicerStyles();
|
|
1189
|
-
const lowerThumb =
|
|
1190
|
-
const upperThumb =
|
|
1191
|
-
const sliderStep =
|
|
2356
|
+
const lowerThumb = useRef6(null);
|
|
2357
|
+
const upperThumb = useRef6(null);
|
|
2358
|
+
const sliderStep = useMemo8(
|
|
1192
2359
|
() => step ?? getAutomaticRangeStep(domain, formatBound, hasOnlyIntegerValues),
|
|
1193
2360
|
[domain, step, formatBound, hasOnlyIntegerValues]
|
|
1194
2361
|
);
|
|
1195
|
-
const handleKeyDown =
|
|
2362
|
+
const handleKeyDown = useCallback11((event) => {
|
|
1196
2363
|
const isEndpointKey = event.key === "Home" || event.key === "End";
|
|
1197
2364
|
if (isEndpointKey && !disabled) {
|
|
1198
2365
|
let nextRange;
|
|
@@ -1208,7 +2375,7 @@ function RangeSlider({
|
|
|
1208
2375
|
}
|
|
1209
2376
|
}
|
|
1210
2377
|
}, [disabled, selectedRange, domain, onValueChange, onValueCommit]);
|
|
1211
|
-
return /* @__PURE__ */
|
|
2378
|
+
return /* @__PURE__ */ jsxs10(
|
|
1212
2379
|
Slider,
|
|
1213
2380
|
{
|
|
1214
2381
|
className: styles.slider,
|
|
@@ -1221,13 +2388,13 @@ function RangeSlider({
|
|
|
1221
2388
|
onValueCommit,
|
|
1222
2389
|
onKeyDown: handleKeyDown,
|
|
1223
2390
|
children: [
|
|
1224
|
-
/* @__PURE__ */
|
|
1225
|
-
/* @__PURE__ */
|
|
2391
|
+
/* @__PURE__ */ jsx14(Track, { className: styles.track, children: /* @__PURE__ */ jsx14(Range, { className: styles.range }) }),
|
|
2392
|
+
/* @__PURE__ */ jsx14(
|
|
1226
2393
|
Thumb,
|
|
1227
2394
|
{
|
|
1228
2395
|
ref: lowerThumb,
|
|
1229
2396
|
className: styles.thumb,
|
|
1230
|
-
"aria-label":
|
|
2397
|
+
"aria-label": formatString13("RangeSlicer_MinimumLabel", title),
|
|
1231
2398
|
"aria-valuemin": domain[0],
|
|
1232
2399
|
"aria-valuemax": domain[1],
|
|
1233
2400
|
"aria-valuenow": selectedRange[0],
|
|
@@ -1235,12 +2402,12 @@ function RangeSlider({
|
|
|
1235
2402
|
"aria-describedby": descriptionId
|
|
1236
2403
|
}
|
|
1237
2404
|
),
|
|
1238
|
-
/* @__PURE__ */
|
|
2405
|
+
/* @__PURE__ */ jsx14(
|
|
1239
2406
|
Thumb,
|
|
1240
2407
|
{
|
|
1241
2408
|
ref: upperThumb,
|
|
1242
2409
|
className: styles.thumb,
|
|
1243
|
-
"aria-label":
|
|
2410
|
+
"aria-label": formatString13("RangeSlicer_MaximumLabel", title),
|
|
1244
2411
|
"aria-valuemin": domain[0],
|
|
1245
2412
|
"aria-valuemax": domain[1],
|
|
1246
2413
|
"aria-valuenow": selectedRange[1],
|
|
@@ -1254,7 +2421,8 @@ function RangeSlider({
|
|
|
1254
2421
|
}
|
|
1255
2422
|
|
|
1256
2423
|
// src/components/range-slicer/use-range-selection.ts
|
|
1257
|
-
import { useCallback as
|
|
2424
|
+
import { useCallback as useCallback12, useEffect as useEffect5, useMemo as useMemo9, useRef as useRef7, useState as useState10 } from "react";
|
|
2425
|
+
import debounce from "lodash.debounce";
|
|
1258
2426
|
function resolveSelection(domain, selection) {
|
|
1259
2427
|
if (selection) {
|
|
1260
2428
|
if (Number.isNaN(selection[0]) || Number.isNaN(selection[1]) || selection[0] > selection[1]) {
|
|
@@ -1269,15 +2437,28 @@ function resolveSelection(domain, selection) {
|
|
|
1269
2437
|
}
|
|
1270
2438
|
return domain;
|
|
1271
2439
|
}
|
|
1272
|
-
function useRangeSelection(domain, column, onInteraction, selection) {
|
|
1273
|
-
const resolvedSelection =
|
|
1274
|
-
const [selectedRange, setSelectedRange] =
|
|
1275
|
-
const lastCommittedRange =
|
|
1276
|
-
const [inputRevision, setInputRevision] =
|
|
1277
|
-
const
|
|
2440
|
+
function useRangeSelection(domain, column, onInteraction, selection, disabled = false) {
|
|
2441
|
+
const resolvedSelection = useMemo9(() => resolveSelection(domain, selection), [domain, selection]);
|
|
2442
|
+
const [selectedRange, setSelectedRange] = useState10(resolvedSelection);
|
|
2443
|
+
const lastCommittedRange = useRef7(resolvedSelection);
|
|
2444
|
+
const [inputRevision, setInputRevision] = useState10(0);
|
|
2445
|
+
const latestOnInteraction = useRef7(onInteraction);
|
|
2446
|
+
useEffect5(() => {
|
|
2447
|
+
latestOnInteraction.current = onInteraction;
|
|
2448
|
+
}, [onInteraction]);
|
|
2449
|
+
const debouncedInteraction = useMemo9(() => debounce((events) => {
|
|
2450
|
+
latestOnInteraction.current?.(events);
|
|
2451
|
+
}, 200), []);
|
|
2452
|
+
const domainMinimum = domain?.[0];
|
|
2453
|
+
const domainMaximum = domain?.[1];
|
|
2454
|
+
useEffect5(() => {
|
|
2455
|
+
debouncedInteraction.cancel();
|
|
2456
|
+
return debouncedInteraction.cancel;
|
|
2457
|
+
}, [debouncedInteraction, domainMinimum, domainMaximum, column, selection, disabled]);
|
|
2458
|
+
const incrementInputRevision = useCallback12(() => {
|
|
1278
2459
|
setInputRevision((revision) => revision + 1);
|
|
1279
2460
|
}, []);
|
|
1280
|
-
|
|
2461
|
+
useEffect5(() => {
|
|
1281
2462
|
if (selection !== void 0) {
|
|
1282
2463
|
const previousRange = lastCommittedRange.current;
|
|
1283
2464
|
if (previousRange?.[0] === resolvedSelection?.[0] && previousRange?.[1] === resolvedSelection?.[1]) return;
|
|
@@ -1286,7 +2467,7 @@ function useRangeSelection(domain, column, onInteraction, selection) {
|
|
|
1286
2467
|
incrementInputRevision();
|
|
1287
2468
|
}
|
|
1288
2469
|
}, [selection, resolvedSelection, incrementInputRevision]);
|
|
1289
|
-
const commitSelectedRange =
|
|
2470
|
+
const commitSelectedRange = useCallback12((values) => {
|
|
1290
2471
|
if (domain) {
|
|
1291
2472
|
setSelectedRange([values[0], values[1]]);
|
|
1292
2473
|
const previousRange = lastCommittedRange.current;
|
|
@@ -1301,26 +2482,26 @@ function useRangeSelection(domain, column, onInteraction, selection) {
|
|
|
1301
2482
|
selections: [{
|
|
1302
2483
|
predicates: [{
|
|
1303
2484
|
type: "range",
|
|
1304
|
-
|
|
1305
|
-
min:
|
|
1306
|
-
max:
|
|
2485
|
+
fieldId: column,
|
|
2486
|
+
...isLowerBoundAtDomainMinimum ? {} : { min: { kind: "value", value: values[0] } },
|
|
2487
|
+
...isUpperBoundAtDomainMaximum ? {} : { max: { kind: "value", value: values[1] } }
|
|
1307
2488
|
}]
|
|
1308
2489
|
}]
|
|
1309
2490
|
};
|
|
1310
|
-
|
|
2491
|
+
debouncedInteraction([event]);
|
|
1311
2492
|
}
|
|
1312
2493
|
}
|
|
1313
|
-
}, [domain, column, onInteraction]);
|
|
1314
|
-
const handleSliderChange =
|
|
2494
|
+
}, [domain, column, onInteraction, debouncedInteraction]);
|
|
2495
|
+
const handleSliderChange = useCallback12((values) => {
|
|
1315
2496
|
setSelectedRange([values[0], values[1]]);
|
|
1316
2497
|
incrementInputRevision();
|
|
1317
2498
|
}, [incrementInputRevision]);
|
|
1318
|
-
const clearSelection =
|
|
2499
|
+
const clearSelection = useCallback12(() => {
|
|
1319
2500
|
setSelectedRange(domain);
|
|
1320
2501
|
lastCommittedRange.current = domain;
|
|
1321
2502
|
incrementInputRevision();
|
|
1322
|
-
onInteraction
|
|
1323
|
-
}, [domain, onInteraction, incrementInputRevision]);
|
|
2503
|
+
if (onInteraction) debouncedInteraction([{ action: "clear" }]);
|
|
2504
|
+
}, [domain, onInteraction, debouncedInteraction, incrementInputRevision]);
|
|
1324
2505
|
return {
|
|
1325
2506
|
selectedRange,
|
|
1326
2507
|
inputRevision,
|
|
@@ -1331,7 +2512,7 @@ function useRangeSelection(domain, column, onInteraction, selection) {
|
|
|
1331
2512
|
}
|
|
1332
2513
|
|
|
1333
2514
|
// src/components/range-slicer/range-slicer.tsx
|
|
1334
|
-
import { Fragment as Fragment2, jsx as
|
|
2515
|
+
import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1335
2516
|
function RangeSlicer({
|
|
1336
2517
|
data,
|
|
1337
2518
|
column,
|
|
@@ -1344,28 +2525,29 @@ function RangeSlicer({
|
|
|
1344
2525
|
selection
|
|
1345
2526
|
}) {
|
|
1346
2527
|
const styles = useRangeSlicerStyles();
|
|
1347
|
-
const id =
|
|
2528
|
+
const id = useId6();
|
|
1348
2529
|
const titleId = `${id}-title`;
|
|
1349
2530
|
const descriptionId = `${id}-description`;
|
|
1350
2531
|
const hideHeader = displayOptions?.hideHeader ?? false;
|
|
1351
2532
|
const showHistogram = displayOptions?.showHistogram ?? true;
|
|
1352
2533
|
const binCount = showHistogram ? displayOptions?.binCount : void 0;
|
|
1353
|
-
const slicerData =
|
|
2534
|
+
const slicerData = useMemo10(
|
|
1354
2535
|
() => readRangeSlicerData(data, column, showHistogram, binCount),
|
|
1355
2536
|
[data, column, showHistogram, binCount]
|
|
1356
2537
|
);
|
|
2538
|
+
const isFixedRange = slicerData.domain !== null && slicerData.domain[0] === slicerData.domain[1];
|
|
2539
|
+
const areControlsDisabled = disabled || isFixedRange;
|
|
1357
2540
|
const { selectedRange, inputRevision, handleSliderChange, commitSelectedRange, clearSelection } = useRangeSelection(
|
|
1358
2541
|
slicerData.domain,
|
|
1359
2542
|
column,
|
|
1360
2543
|
onInteraction,
|
|
1361
|
-
selection
|
|
2544
|
+
selection,
|
|
2545
|
+
areControlsDisabled
|
|
1362
2546
|
);
|
|
1363
2547
|
const displayTitle = title ?? slicerData.title;
|
|
1364
2548
|
const hasSelection = selectedRange !== null && slicerData.domain !== null && (selectedRange[0] !== slicerData.domain[0] || selectedRange[1] !== slicerData.domain[1]);
|
|
1365
|
-
const isFixedRange = slicerData.domain !== null && slicerData.domain[0] === slicerData.domain[1];
|
|
1366
|
-
const areControlsDisabled = disabled || isFixedRange;
|
|
1367
2549
|
const sliderStep = step !== void 0 && Number.isFinite(step) && step > 0 ? step : void 0;
|
|
1368
|
-
const themeStyle =
|
|
2550
|
+
const themeStyle = useMemo10(() => theme ? {
|
|
1369
2551
|
...slicerThemeStyle(theme),
|
|
1370
2552
|
"--range-foreground": theme.foreground,
|
|
1371
2553
|
"--range-secondary": theme.foregroundSecondary,
|
|
@@ -1374,25 +2556,26 @@ function RangeSlicer({
|
|
|
1374
2556
|
"--range-stroke": theme.stroke,
|
|
1375
2557
|
fontFamily: theme.typography?.label?.family
|
|
1376
2558
|
} : {}, [theme]);
|
|
1377
|
-
const formatBound =
|
|
1378
|
-
const formatInput =
|
|
1379
|
-
const parseInput =
|
|
1380
|
-
const handleLowerCommit =
|
|
2559
|
+
const formatBound = useCallback13((value) => String(formatValue2(value, slicerData.format)), [slicerData.format]);
|
|
2560
|
+
const formatInput = useCallback13((value) => formatNumericInput(value, slicerData.format), [slicerData.format]);
|
|
2561
|
+
const parseInput = useCallback13((text) => parseNumericInput(text, slicerData.format), [slicerData.format]);
|
|
2562
|
+
const handleLowerCommit = useCallback13((value) => {
|
|
1381
2563
|
if (selectedRange) commitSelectedRange([value, selectedRange[1]]);
|
|
1382
2564
|
}, [selectedRange, commitSelectedRange]);
|
|
1383
|
-
const handleUpperCommit =
|
|
2565
|
+
const handleUpperCommit = useCallback13((value) => {
|
|
1384
2566
|
if (selectedRange) commitSelectedRange([selectedRange[0], value]);
|
|
1385
2567
|
}, [selectedRange, commitSelectedRange]);
|
|
1386
|
-
if (slicerData.error) return /* @__PURE__ */
|
|
1387
|
-
return /* @__PURE__ */
|
|
2568
|
+
if (slicerData.error) return /* @__PURE__ */ jsx15("div", { role: "alert", "data-lyra-selection-boundary": "", children: slicerData.error });
|
|
2569
|
+
return /* @__PURE__ */ jsxs11(
|
|
1388
2570
|
"section",
|
|
1389
2571
|
{
|
|
2572
|
+
"data-lyra-selection-boundary": "",
|
|
1390
2573
|
className: styles.root,
|
|
1391
2574
|
style: themeStyle,
|
|
1392
2575
|
"aria-labelledby": hideHeader ? void 0 : titleId,
|
|
1393
2576
|
"aria-label": hideHeader ? displayTitle : void 0,
|
|
1394
2577
|
children: [
|
|
1395
|
-
!hideHeader && /* @__PURE__ */
|
|
2578
|
+
!hideHeader && /* @__PURE__ */ jsx15(
|
|
1396
2579
|
SlicerHeader,
|
|
1397
2580
|
{
|
|
1398
2581
|
title: displayTitle,
|
|
@@ -1401,9 +2584,9 @@ function RangeSlicer({
|
|
|
1401
2584
|
clearDisabled: areControlsDisabled
|
|
1402
2585
|
}
|
|
1403
2586
|
),
|
|
1404
|
-
/* @__PURE__ */
|
|
1405
|
-
showHistogram && /* @__PURE__ */
|
|
1406
|
-
isFixedRange ? /* @__PURE__ */
|
|
2587
|
+
/* @__PURE__ */ jsx15("div", { className: mergeClasses3(styles.body, displayOptions?.frameless && styles.framelessBody), children: selectedRange && slicerData.domain ? /* @__PURE__ */ jsxs11(Fragment2, { children: [
|
|
2588
|
+
showHistogram && /* @__PURE__ */ jsx15(RangeHistogram, { counts: slicerData.histogram, domain: slicerData.domain, selectedRange, title: displayTitle }),
|
|
2589
|
+
isFixedRange ? /* @__PURE__ */ jsx15("div", { className: styles.slider, "aria-hidden": "true", children: /* @__PURE__ */ jsx15("div", { className: styles.track }) }) : /* @__PURE__ */ jsx15(
|
|
1407
2590
|
RangeSlider,
|
|
1408
2591
|
{
|
|
1409
2592
|
domain: slicerData.domain,
|
|
@@ -1418,11 +2601,11 @@ function RangeSlicer({
|
|
|
1418
2601
|
onValueCommit: commitSelectedRange
|
|
1419
2602
|
}
|
|
1420
2603
|
),
|
|
1421
|
-
/* @__PURE__ */
|
|
1422
|
-
/* @__PURE__ */
|
|
2604
|
+
/* @__PURE__ */ jsxs11("div", { className: styles.inputs, children: [
|
|
2605
|
+
/* @__PURE__ */ jsx15(
|
|
1423
2606
|
RangeValueInput,
|
|
1424
2607
|
{
|
|
1425
|
-
label:
|
|
2608
|
+
label: formatString14("RangeSlicer_MinimumLabel", displayTitle),
|
|
1426
2609
|
value: selectedRange[0],
|
|
1427
2610
|
min: slicerData.domain[0],
|
|
1428
2611
|
max: selectedRange[1],
|
|
@@ -1434,11 +2617,11 @@ function RangeSlicer({
|
|
|
1434
2617
|
},
|
|
1435
2618
|
`lower-${inputRevision}`
|
|
1436
2619
|
),
|
|
1437
|
-
/* @__PURE__ */
|
|
1438
|
-
/* @__PURE__ */
|
|
2620
|
+
/* @__PURE__ */ jsx15("span", { className: styles.separator, children: getString11("RangeSlicer_To") }),
|
|
2621
|
+
/* @__PURE__ */ jsx15(
|
|
1439
2622
|
RangeValueInput,
|
|
1440
2623
|
{
|
|
1441
|
-
label:
|
|
2624
|
+
label: formatString14("RangeSlicer_MaximumLabel", displayTitle),
|
|
1442
2625
|
value: selectedRange[1],
|
|
1443
2626
|
min: selectedRange[0],
|
|
1444
2627
|
max: slicerData.domain[1],
|
|
@@ -1451,13 +2634,14 @@ function RangeSlicer({
|
|
|
1451
2634
|
`upper-${inputRevision}`
|
|
1452
2635
|
)
|
|
1453
2636
|
] }),
|
|
1454
|
-
/* @__PURE__ */
|
|
1455
|
-
] }) : /* @__PURE__ */
|
|
2637
|
+
/* @__PURE__ */ jsx15("p", { id: descriptionId, className: styles.fullRange, children: formatString14("RangeSlicer_FullRange", formatBound(slicerData.domain[0]), formatBound(slicerData.domain[1])) })
|
|
2638
|
+
] }) : /* @__PURE__ */ jsx15("p", { className: styles.empty, role: "status", children: getString11("Common_NoNumericValues") }) })
|
|
1456
2639
|
]
|
|
1457
2640
|
}
|
|
1458
2641
|
);
|
|
1459
2642
|
}
|
|
1460
2643
|
export {
|
|
2644
|
+
DateSlicer,
|
|
1461
2645
|
DropdownSlicer,
|
|
1462
2646
|
ListSlicer,
|
|
1463
2647
|
RangeSlicer,
|