@microsoft/fabric-slicers 0.0.0-stage → 3.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/dist/index.js ADDED
@@ -0,0 +1,1465 @@
1
+ // src/components/list-slicer/list-slicer.tsx
2
+ import { useVirtualizer } from "@tanstack/react-virtual";
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";
5
+
6
+ // src/hooks/use-list-slicer.ts
7
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
+ import { formatString, formatValue, getString, isDataTable } from "@microsoft/fabric-visuals-core";
9
+
10
+ // src/utils/slicer-value.ts
11
+ function isSlicerValue(value) {
12
+ return value == null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || value instanceof Date && Number.isFinite(value.getTime());
13
+ }
14
+
15
+ // src/hooks/use-list-slicer.ts
16
+ function valueKey(value) {
17
+ if (value == null) return "blank";
18
+ if (value instanceof Date) return `date:${value.getTime()}`;
19
+ return `${typeof value}:${String(value)}`;
20
+ }
21
+ function prepareListSlicerData({ data, column, title }) {
22
+ let resolvedTitle = title ?? column;
23
+ let format;
24
+ let valueCount;
25
+ let valueAt;
26
+ if (isDataTable(data)) {
27
+ const columnIndex = data.columns.findIndex((candidate) => candidate.name === column);
28
+ if (columnIndex < 0) {
29
+ return { title: resolvedTitle, items: [], error: formatString("Slicer_MissingColumn", column) };
30
+ }
31
+ resolvedTitle = title ?? data.columns[columnIndex].displayName ?? column;
32
+ format = data.columns[columnIndex].format;
33
+ valueCount = data.rows.length;
34
+ valueAt = (index) => data.rows[index][columnIndex];
35
+ } else if (Array.isArray(data)) {
36
+ valueCount = data.length;
37
+ valueAt = (index) => data[index];
38
+ } else {
39
+ return { title: resolvedTitle, items: [], error: getString("Slicer_InvalidData") };
40
+ }
41
+ const items = [];
42
+ const seenKeys = /* @__PURE__ */ new Set();
43
+ for (let index = 0; index < valueCount; index++) {
44
+ const value = valueAt(index);
45
+ if (!isSlicerValue(value)) {
46
+ return { title: resolvedTitle, items: [], error: getString("Slicer_InvalidData") };
47
+ }
48
+ const key = valueKey(value);
49
+ if (seenKeys.has(key)) continue;
50
+ seenKeys.add(key);
51
+ const label = value == null || value === "" ? getString("Slicer_Blank") : String(formatValue(value, format));
52
+ items.push({ key, value, label });
53
+ }
54
+ return { title: resolvedTitle, items };
55
+ }
56
+ function useListSlicer({ data, column, title, selection, onInteraction }) {
57
+ const prepared = useMemo(
58
+ () => prepareListSlicerData({ data, column, title }),
59
+ [data, column, title]
60
+ );
61
+ const valuesByKey = useMemo(
62
+ () => new Map(prepared.items.map((item) => [item.key, item.value])),
63
+ [prepared.items]
64
+ );
65
+ const resolvedSelection = useMemo(() => {
66
+ if (selection !== void 0) {
67
+ if (selection === null) return "all";
68
+ if (!selection.every(isSlicerValue)) {
69
+ throw new Error("Slicer selection must contain text, finite numbers, booleans, valid dates, or blanks.");
70
+ }
71
+ const resolved = /* @__PURE__ */ new Map();
72
+ for (const value of selection) {
73
+ const key = valueKey(value);
74
+ if (!resolved.has(key)) resolved.set(key, value);
75
+ }
76
+ return resolved;
77
+ }
78
+ return void 0;
79
+ }, [selection]);
80
+ const [localSelection, setLocalSelection] = useState(resolvedSelection ?? "all");
81
+ const selectionRef = useRef(resolvedSelection ?? "all");
82
+ useEffect(() => {
83
+ if (resolvedSelection !== void 0) {
84
+ selectionRef.current = resolvedSelection;
85
+ setLocalSelection(resolvedSelection);
86
+ }
87
+ }, [resolvedSelection]);
88
+ const isSelected = useCallback(
89
+ (key) => localSelection === "all" || localSelection.has(key),
90
+ [localSelection]
91
+ );
92
+ const selectedItems = useMemo(
93
+ () => prepared.items.filter((item) => isSelected(item.key)),
94
+ [prepared.items, isSelected]
95
+ );
96
+ const updateSelection = useCallback((next) => {
97
+ const normalized = next !== "all" && prepared.items.length > 0 && next.size >= prepared.items.length && prepared.items.every((item) => next.has(item.key)) ? "all" : next;
98
+ selectionRef.current = normalized;
99
+ setLocalSelection(normalized);
100
+ if (!onInteraction) return;
101
+ const event = normalized === "all" ? { action: "clear" } : {
102
+ action: "select",
103
+ selections: [{ predicates: [{ type: "set", name: column, values: [...normalized.values()] }] }]
104
+ };
105
+ onInteraction([event]);
106
+ }, [column, onInteraction, prepared.items]);
107
+ const clear = useCallback(() => {
108
+ if (selectionRef.current !== "all") updateSelection("all");
109
+ }, [updateSelection]);
110
+ const toggle = useCallback((key, checked) => {
111
+ if (!valuesByKey.has(key)) throw new Error(`Cannot update an unknown slicer key: ${key}`);
112
+ const previous = selectionRef.current;
113
+ if ((previous === "all" || previous.has(key)) === checked) return;
114
+ const next = new Map(previous === "all" ? valuesByKey : previous);
115
+ if (checked) next.set(key, valuesByKey.get(key));
116
+ else next.delete(key);
117
+ updateSelection(next);
118
+ }, [valuesByKey, updateSelection]);
119
+ const toggleAll = useCallback((checked, keys) => {
120
+ if (valuesByKey.size === 0 || keys?.length === 0) return;
121
+ if (keys === void 0 && checked) {
122
+ clear();
123
+ return;
124
+ }
125
+ const previous = selectionRef.current;
126
+ if (keys === void 0 && previous === "all") {
127
+ updateSelection(/* @__PURE__ */ new Map());
128
+ return;
129
+ }
130
+ let next;
131
+ for (const key of keys ?? valuesByKey.keys()) {
132
+ if (!valuesByKey.has(key)) throw new Error(`Cannot update an unknown slicer key: ${key}`);
133
+ if ((previous === "all" || previous.has(key)) === checked) continue;
134
+ next ??= new Map(previous === "all" ? valuesByKey : previous);
135
+ if (checked) next.set(key, valuesByKey.get(key));
136
+ else next.delete(key);
137
+ }
138
+ if (next) updateSelection(next);
139
+ }, [valuesByKey, clear, updateSelection]);
140
+ return {
141
+ ...prepared,
142
+ selectedItems,
143
+ isSelected,
144
+ toggle,
145
+ toggleAll,
146
+ clear,
147
+ allSelected: localSelection === "all"
148
+ };
149
+ }
150
+
151
+ // src/hooks/use-list-navigation.ts
152
+ import { defaultRangeExtractor } from "@tanstack/react-virtual";
153
+ import { useCallback as useCallback2, useLayoutEffect, useRef as useRef2, useState as useState2 } from "react";
154
+ function useListNavigation(items) {
155
+ const panelRef = useRef2(null);
156
+ const [activeKey, setActiveKey] = useState2(null);
157
+ const activeIndex = items.findIndex((item) => item.key === activeKey);
158
+ const pendingFocusKey = useRef2(void 0);
159
+ const rangeExtractor = useCallback2((range) => {
160
+ const visibleIndices = defaultRangeExtractor(range);
161
+ return activeIndex >= 0 ? [.../* @__PURE__ */ new Set([...visibleIndices, activeIndex])].sort((left, right) => left - right) : visibleIndices;
162
+ }, [activeIndex]);
163
+ useLayoutEffect(() => {
164
+ if (pendingFocusKey.current !== void 0 && pendingFocusKey.current === (items[activeIndex]?.key ?? null)) {
165
+ const checkbox = panelRef.current?.querySelector(`[data-slicer-index="${activeIndex}"] [role="checkbox"]`);
166
+ checkbox?.focus();
167
+ pendingFocusKey.current = void 0;
168
+ }
169
+ }, [activeIndex, items]);
170
+ const handleFocus = useCallback2((event) => {
171
+ const row = event.target.closest("[data-slicer-index]");
172
+ if (row) {
173
+ setActiveKey(items[Number(row.dataset.slicerIndex)]?.key ?? null);
174
+ }
175
+ }, [items]);
176
+ const handleKeyDown = useCallback2((event) => {
177
+ const isCheckboxTarget = event.target instanceof HTMLButtonElement && event.target.getAttribute("role") === "checkbox";
178
+ const isNavigationKey = event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End";
179
+ if (isCheckboxTarget && isNavigationKey && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
180
+ if (event.defaultPrevented || items.length === 0) return;
181
+ event.preventDefault();
182
+ event.stopPropagation();
183
+ let nextIndex;
184
+ if (event.key === "Home") nextIndex = -1;
185
+ else if (event.key === "End") nextIndex = items.length - 1;
186
+ else nextIndex = Math.max(-1, Math.min(items.length - 1, activeIndex + (event.key === "ArrowDown" ? 1 : -1)));
187
+ if (nextIndex === activeIndex) return;
188
+ pendingFocusKey.current = items[nextIndex]?.key ?? null;
189
+ setActiveKey(pendingFocusKey.current);
190
+ }
191
+ }, [items, activeIndex]);
192
+ return { panelRef, activeIndex, rangeExtractor, handleFocus, handleKeyDown };
193
+ }
194
+
195
+ // src/components/shared/slicer-header.tsx
196
+ import { formatString as formatString2, getString as getString2 } from "@microsoft/fabric-visuals-core";
197
+
198
+ // src/components/shared/slicer-styles.ts
199
+ import { makeStyles } from "@griffel/react";
200
+ import { fontFamily, injectDesignTokens, inVisualsLayer, normalizeCssLength, tokens } from "@microsoft/fabric-visuals-core";
201
+ import { mergeClasses } from "@griffel/react";
202
+ injectDesignTokens();
203
+ function slicerThemeStyle(theme) {
204
+ if (!theme) return {};
205
+ return {
206
+ "--slicer-foreground": theme.foreground,
207
+ "--slicer-secondary": theme.foregroundSecondary,
208
+ "--slicer-brand": theme.brandBackground,
209
+ "--slicer-link": theme.brandForeground,
210
+ "--slicer-background": theme.background,
211
+ "--slicer-muted": theme.backgroundSecondary,
212
+ "--slicer-hover": theme.backgroundHover,
213
+ "--slicer-stroke": theme.border?.color ?? theme.stroke,
214
+ "--slicer-radius": normalizeCssLength(theme.border?.radius) ?? "8px",
215
+ "--slicer-font": theme.typography?.label?.family ?? fontFamily.base,
216
+ "--slicer-size": `${theme.typography?.label?.size ?? 14}px`,
217
+ "--slicer-weight": theme.typography?.label?.weight ?? 400,
218
+ "--slicer-heading-font": theme.typography?.heading?.family ?? fontFamily.heading,
219
+ "--slicer-heading-size": `${theme.typography?.heading?.size ?? 14}px`,
220
+ "--slicer-heading-weight": theme.typography?.heading?.weight ?? 600
221
+ };
222
+ }
223
+ var useSlicerStyles = makeStyles(inVisualsLayer({
224
+ typography: {
225
+ fontFamily: `var(--slicer-font, ${tokens.fontBase})`,
226
+ fontSize: `var(--slicer-size, ${tokens.text300})`,
227
+ fontWeight: `var(--slicer-weight, ${tokens.fontWeightRegular})`,
228
+ color: `var(--slicer-foreground, ${tokens.colorForeground})`,
229
+ lineHeight: "20px",
230
+ "& button, & input": { fontFamily: "inherit", fontSize: "inherit" },
231
+ "& button:focus-visible, & input:focus-visible": {
232
+ outline: `2px solid var(--slicer-link, ${tokens.colorBrandForeground})`,
233
+ outlineOffset: "2px"
234
+ }
235
+ },
236
+ root: { display: "flex", flexDirection: "column", gap: "8px", minWidth: 0, minHeight: 0, width: "100%" },
237
+ fillHeight: { height: "100%", maxHeight: "100%" },
238
+ header: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", flexShrink: 0 },
239
+ title: {
240
+ margin: 0,
241
+ overflow: "hidden",
242
+ textOverflow: "ellipsis",
243
+ whiteSpace: "nowrap",
244
+ fontFamily: `var(--slicer-heading-font, ${tokens.fontHeading})`,
245
+ fontSize: `var(--slicer-heading-size, ${tokens.text300})`,
246
+ fontWeight: `var(--slicer-heading-weight, ${tokens.fontWeightSemibold})`
247
+ },
248
+ clear: {
249
+ border: 0,
250
+ backgroundColor: "transparent",
251
+ color: `var(--slicer-link, ${tokens.colorBrandForeground})`,
252
+ cursor: "pointer",
253
+ padding: "2px",
254
+ fontFamily: "inherit",
255
+ fontSize: "12px",
256
+ flexShrink: 0,
257
+ ":focus-visible": {
258
+ outline: `2px solid var(--slicer-link, ${tokens.colorBrandForeground})`,
259
+ outlineOffset: "2px"
260
+ },
261
+ ":disabled": { opacity: 0.5, cursor: "default" }
262
+ },
263
+ clearHidden: { visibility: "hidden" },
264
+ panel: {
265
+ display: "flex",
266
+ flexDirection: "column",
267
+ minHeight: 0,
268
+ minWidth: 0,
269
+ backgroundColor: `var(--slicer-background, ${tokens.colorBackground})`,
270
+ border: `1px solid var(--slicer-stroke, ${tokens.colorBorder})`,
271
+ borderRadius: `var(--slicer-radius, ${tokens.radiusXl})`,
272
+ padding: "8px",
273
+ boxSizing: "border-box",
274
+ overflow: "hidden",
275
+ flexGrow: 1
276
+ },
277
+ text: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", flexGrow: 1 },
278
+ message: { padding: "16px 8px", color: `var(--slicer-secondary, ${tokens.colorMutedForeground})`, overflowWrap: "anywhere" },
279
+ icon: { flexShrink: 0, display: "block" }
280
+ }));
281
+
282
+ // src/components/shared/slicer-header.tsx
283
+ import { jsx, jsxs } from "react/jsx-runtime";
284
+ function SlicerHeader({ title, titleId, onClear, clearDisabled }) {
285
+ const styles = useSlicerStyles();
286
+ return /* @__PURE__ */ jsxs("div", { className: styles.header, children: [
287
+ /* @__PURE__ */ jsx("h3", { id: titleId, className: styles.title, title, children: title }),
288
+ /* @__PURE__ */ jsx(
289
+ "button",
290
+ {
291
+ type: "button",
292
+ className: mergeClasses(styles.clear, !onClear && styles.clearHidden),
293
+ "aria-hidden": !onClear,
294
+ "aria-label": formatString2("Slicer_ClearLabel", title),
295
+ disabled: !onClear || clearDisabled,
296
+ onClick: onClear,
297
+ title: getString2("Slicer_ClearDescription"),
298
+ children: getString2("Slicer_Clear")
299
+ }
300
+ )
301
+ ] });
302
+ }
303
+
304
+ // src/components/ui/checkbox.tsx
305
+ import { Checkbox as CheckBox } from "radix-ui";
306
+ import { useCallback as useCallback3 } from "react";
307
+ import { mergeClasses as mergeClasses2 } from "@griffel/react";
308
+
309
+ // src/components/ui/ui-slicer-styles.ts
310
+ import { makeStyles as makeStyles2, shorthands } from "@griffel/react";
311
+ import { inVisualsLayer as inVisualsLayer2, tokens as tokens2 } from "@microsoft/fabric-visuals-core";
312
+ var useCheckboxStyles = makeStyles2(inVisualsLayer2({
313
+ checkbox: {
314
+ width: "16px",
315
+ height: "16px",
316
+ borderRadius: "4px",
317
+ border: `1px solid var(--slicer-stroke, ${tokens2.colorBorder})`,
318
+ padding: 0,
319
+ display: "inline-flex",
320
+ alignItems: "center",
321
+ justifyContent: "center",
322
+ flexShrink: 0,
323
+ cursor: "pointer",
324
+ backgroundColor: `var(--slicer-background, ${tokens2.colorBackground})`,
325
+ color: "#ffffff",
326
+ '&[data-state="checked"], &[data-state="indeterminate"]': {
327
+ backgroundColor: `var(--slicer-brand, ${tokens2.colorBrand})`,
328
+ ...shorthands.borderColor(`var(--slicer-brand, ${tokens2.colorBrand})`)
329
+ },
330
+ ":disabled": { opacity: 0.5, cursor: "default" },
331
+ "@media (forced-colors: active)": {
332
+ ...shorthands.borderColor("ButtonText"),
333
+ '&[data-state="checked"], &[data-state="indeterminate"]': {
334
+ backgroundColor: "Highlight",
335
+ color: "HighlightText",
336
+ ...shorthands.borderColor("Highlight"),
337
+ forcedColorAdjust: "none"
338
+ }
339
+ }
340
+ },
341
+ indicator: { display: "flex" }
342
+ }));
343
+
344
+ // src/components/ui/checkbox.tsx
345
+ import { jsx as jsx2 } from "react/jsx-runtime";
346
+ function Checkbox({ className, checked, onKeyDown, ...props }) {
347
+ const styles = useCheckboxStyles();
348
+ const handleKeyDown = useCallback3((event) => {
349
+ onKeyDown?.(event);
350
+ if (event.key === "Enter" && !event.defaultPrevented) {
351
+ event.preventDefault();
352
+ event.stopPropagation();
353
+ event.currentTarget.click();
354
+ }
355
+ }, [onKeyDown]);
356
+ return /* @__PURE__ */ jsx2(CheckBox.Root, { ...props, checked, onKeyDown: handleKeyDown, className: mergeClasses2(styles.checkbox, className), children: /* @__PURE__ */ jsx2(CheckBox.Indicator, { className: styles.indicator, children: /* @__PURE__ */ jsx2("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx2(
357
+ "path",
358
+ {
359
+ d: checked === "indeterminate" ? "M2 6h8" : "m2 6 2.5 2.5L10 3",
360
+ stroke: "currentColor",
361
+ strokeWidth: "1.5",
362
+ strokeLinecap: "round",
363
+ strokeLinejoin: "round"
364
+ }
365
+ ) }) }) });
366
+ }
367
+
368
+ // src/components/ui/icons.tsx
369
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
370
+ function ChevronDownIcon({ className }) {
371
+ return /* @__PURE__ */ jsx3("svg", { className, width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx3("path", { d: "m4 6 4 4 4-4", stroke: "currentColor", strokeWidth: "1.5" }) });
372
+ }
373
+ function SearchIcon({ className }) {
374
+ return /* @__PURE__ */ jsxs2("svg", { className, width: "16", height: "16", viewBox: "0 0 16 16", "aria-hidden": "true", children: [
375
+ /* @__PURE__ */ jsx3("circle", { cx: "6.5", cy: "6.5", r: "4.5", fill: "none", stroke: "currentColor" }),
376
+ /* @__PURE__ */ jsx3("path", { d: "m10 10 4 4", stroke: "currentColor" })
377
+ ] });
378
+ }
379
+
380
+ // src/components/list-slicer/list-slicer-styles.ts
381
+ import { makeStyles as makeStyles3 } from "@griffel/react";
382
+ import { inVisualsLayer as inVisualsLayer3, tokens as tokens3 } from "@microsoft/fabric-visuals-core";
383
+ var useListSlicerStyles = makeStyles3(inVisualsLayer3({
384
+ // Without panel padding, outward focus rings need visible overflow; the value list owns scrolling.
385
+ frameless: { border: 0, borderRadius: 0, padding: 0, backgroundColor: "transparent", overflow: "visible" },
386
+ search: {
387
+ display: "flex",
388
+ alignItems: "center",
389
+ gap: "6px",
390
+ flexShrink: 0,
391
+ backgroundColor: `var(--slicer-muted, ${tokens3.colorMuted})`,
392
+ border: `1px solid var(--slicer-stroke, ${tokens3.colorBorder})`,
393
+ borderRadius: `var(--slicer-radius, ${tokens3.radiusXl})`,
394
+ padding: "4px 8px",
395
+ marginBottom: "4px",
396
+ color: `var(--slicer-secondary, ${tokens3.colorMutedForeground})`,
397
+ ":focus-within": {
398
+ outline: `2px solid var(--slicer-link, ${tokens3.colorBrandForeground})`,
399
+ outlineOffset: "1px",
400
+ "& > input:focus-visible": { outline: "none" }
401
+ }
402
+ },
403
+ input: {
404
+ width: "100%",
405
+ minWidth: 0,
406
+ height: "22px",
407
+ padding: 0,
408
+ border: 0,
409
+ color: `var(--slicer-foreground, ${tokens3.colorForeground})`,
410
+ backgroundColor: "transparent",
411
+ "::placeholder": { color: `var(--slicer-secondary, ${tokens3.colorMutedForeground})` }
412
+ },
413
+ scroll: {
414
+ overflowY: "auto",
415
+ minHeight: 0,
416
+ scrollbarWidth: "thin",
417
+ "@supports selector(::-webkit-scrollbar)": {
418
+ // A non-auto scrollbar-width overrides the thumb's minimum height in Chromium.
419
+ scrollbarWidth: "auto",
420
+ "::-webkit-scrollbar": { width: "6px" },
421
+ "::-webkit-scrollbar-thumb": {
422
+ minHeight: "32px",
423
+ borderRadius: "3px",
424
+ backgroundColor: `var(--slicer-secondary, ${tokens3.colorMutedForeground})`
425
+ },
426
+ "::-webkit-scrollbar-track": { backgroundColor: "transparent" },
427
+ "@media (forced-colors: active)": {
428
+ "::-webkit-scrollbar-thumb": {
429
+ backgroundColor: "CanvasText",
430
+ forcedColorAdjust: "none"
431
+ },
432
+ "::-webkit-scrollbar-track": {
433
+ backgroundColor: "Canvas",
434
+ forcedColorAdjust: "none"
435
+ }
436
+ }
437
+ }
438
+ },
439
+ scrollFade: {
440
+ maskImage: "linear-gradient(to bottom, #000 calc(100% - 32px), transparent)",
441
+ ":has(:focus-visible)": { maskImage: "none" },
442
+ "@media (forced-colors: active)": { maskImage: "none" }
443
+ },
444
+ list: { listStyleType: "none", padding: 0, margin: 0, position: "relative" },
445
+ row: {
446
+ display: "flex",
447
+ alignItems: "center",
448
+ gap: "8px",
449
+ padding: "0 8px",
450
+ height: "32px",
451
+ boxSizing: "border-box",
452
+ borderRadius: "4px",
453
+ minWidth: 0,
454
+ ":hover": { backgroundColor: `var(--slicer-hover, ${tokens3.colorHover})` }
455
+ },
456
+ selectAll: { flexShrink: 0, fontWeight: 600 },
457
+ label: {
458
+ display: "flex",
459
+ alignItems: "center",
460
+ gap: "8px",
461
+ height: "100%",
462
+ cursor: "pointer",
463
+ minWidth: 0,
464
+ flexGrow: 1
465
+ }
466
+ }));
467
+
468
+ // src/components/list-slicer/list-slicer.tsx
469
+ import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
470
+ var ROW_HEIGHT = 32;
471
+ function ListSlicerRow({ label, checked, onToggle, disabled, className, tabIndex, navigationIndex }) {
472
+ const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
473
+ const id = useId();
474
+ return /* @__PURE__ */ jsxs3("div", { className: mergeClasses(styles.row, className), "data-slicer-index": navigationIndex, children: [
475
+ /* @__PURE__ */ jsx4(
476
+ Checkbox,
477
+ {
478
+ id,
479
+ checked,
480
+ onCheckedChange: onToggle,
481
+ disabled,
482
+ "aria-label": label,
483
+ tabIndex
484
+ }
485
+ ),
486
+ /* @__PURE__ */ jsx4("label", { className: styles.label, htmlFor: id, children: /* @__PURE__ */ jsx4("span", { className: styles.text, title: label, children: label }) })
487
+ ] });
488
+ }
489
+ function ItemRow({ item, state, tabIndex }) {
490
+ const toggle = useCallback4(
491
+ (checked) => state.toggle(item.key, checked === true),
492
+ [state, item.key]
493
+ );
494
+ return /* @__PURE__ */ jsx4(
495
+ ListSlicerRow,
496
+ {
497
+ label: item.label,
498
+ checked: state.isSelected(item.key),
499
+ onToggle: toggle,
500
+ tabIndex
501
+ }
502
+ );
503
+ }
504
+ function virtualRowStyle(start) {
505
+ return { position: "absolute", top: 0, left: 0, width: "100%", height: ROW_HEIGHT, transform: `translateY(${start}px)` };
506
+ }
507
+ function ListSlicer(props) {
508
+ return /* @__PURE__ */ jsx4(StatefulListSlicer, { ...props }, props.column);
509
+ }
510
+ function StatefulListSlicer(props) {
511
+ const state = useListSlicer(props);
512
+ return /* @__PURE__ */ jsx4(ListSlicerContent, { state, theme: props.theme, displayOptions: props.displayOptions });
513
+ }
514
+ function ListSlicerContent({
515
+ state,
516
+ theme,
517
+ displayOptions,
518
+ maxVisibleItems = 8
519
+ }) {
520
+ const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
521
+ const titleId = useId();
522
+ const themeStyle = useMemo2(() => slicerThemeStyle(theme), [theme]);
523
+ const showSearch = displayOptions?.showSearch ?? true;
524
+ const hideHeader = displayOptions?.hideHeader ?? false;
525
+ const scrollRef = useRef3(null);
526
+ const scrollStyle = useMemo2(
527
+ () => ({ maxHeight: maxVisibleItems * ROW_HEIGHT }),
528
+ [maxVisibleItems]
529
+ );
530
+ const [search, setSearch] = useState3("");
531
+ const items = useMemo2(() => {
532
+ const query = showSearch ? search.toLocaleLowerCase() : "";
533
+ return state.items.filter((item) => item.label.toLocaleLowerCase().includes(query));
534
+ }, [state.items, search, showSearch]);
535
+ const handleSearch = useCallback4((event) => {
536
+ setSearch(event.target.value);
537
+ if (scrollRef.current) scrollRef.current.scrollTop = 0;
538
+ }, []);
539
+ const selectedCount = items.filter((item) => state.isSelected(item.key)).length;
540
+ const checked = selectedCount === 0 ? false : selectedCount === items.length ? true : "indeterminate";
541
+ const toggleAll = useCallback4(
542
+ (nextChecked) => state.toggleAll(
543
+ nextChecked === true,
544
+ items.length === state.items.length ? void 0 : items.map((item) => item.key)
545
+ ),
546
+ [state, items]
547
+ );
548
+ const navigation = useListNavigation(items);
549
+ const virtual = items.length > 50;
550
+ const virtualizer = useVirtualizer({
551
+ count: items.length,
552
+ getScrollElement: () => scrollRef.current,
553
+ estimateSize: () => ROW_HEIGHT,
554
+ getItemKey: (index) => items[index].key,
555
+ overscan: 5,
556
+ rangeExtractor: navigation.rangeExtractor,
557
+ enabled: virtual
558
+ });
559
+ const totalHeight = virtualizer.getTotalSize();
560
+ const listStyle = useMemo2(
561
+ () => virtual ? { height: totalHeight } : void 0,
562
+ [virtual, totalHeight]
563
+ );
564
+ const [hasMoreBelow, setHasMoreBelow] = useState3(false);
565
+ useEffect2(() => {
566
+ const scroll = scrollRef.current;
567
+ if (!scroll) return;
568
+ const updateFade = () => {
569
+ setHasMoreBelow(items.length > 0 && scroll.scrollHeight - scroll.clientHeight - scroll.scrollTop > 1);
570
+ };
571
+ const observer = new ResizeObserver(updateFade);
572
+ observer.observe(scroll);
573
+ if (scroll.firstElementChild) observer.observe(scroll.firstElementChild);
574
+ scroll.addEventListener("scroll", updateFade, { passive: true });
575
+ updateFade();
576
+ return () => {
577
+ observer.disconnect();
578
+ scroll.removeEventListener("scroll", updateFade);
579
+ };
580
+ }, [items.length, state.error]);
581
+ return /* @__PURE__ */ jsxs3(
582
+ "section",
583
+ {
584
+ className: mergeClasses(styles.typography, styles.root, !hideHeader && styles.fillHeight),
585
+ style: themeStyle,
586
+ "aria-labelledby": hideHeader ? void 0 : titleId,
587
+ "aria-label": hideHeader ? state.title : void 0,
588
+ children: [
589
+ !hideHeader && /* @__PURE__ */ jsx4(
590
+ SlicerHeader,
591
+ {
592
+ title: state.title,
593
+ titleId,
594
+ onClear: state.allSelected ? void 0 : state.clear,
595
+ clearDisabled: !!state.error || state.items.length === 0
596
+ }
597
+ ),
598
+ /* @__PURE__ */ jsx4(
599
+ "div",
600
+ {
601
+ ref: navigation.panelRef,
602
+ className: mergeClasses(styles.panel, displayOptions?.frameless && styles.frameless),
603
+ role: "group",
604
+ "aria-label": state.title,
605
+ onFocus: navigation.handleFocus,
606
+ onKeyDown: navigation.handleKeyDown,
607
+ children: state.error ? /* @__PURE__ */ jsx4("div", { role: "alert", className: styles.message, children: state.error }) : /* @__PURE__ */ jsxs3(Fragment, { children: [
608
+ showSearch && /* @__PURE__ */ jsxs3("div", { className: styles.search, children: [
609
+ /* @__PURE__ */ jsx4(SearchIcon, { className: styles.icon }),
610
+ /* @__PURE__ */ jsx4(
611
+ "input",
612
+ {
613
+ type: "search",
614
+ className: styles.input,
615
+ placeholder: getString3("Slicer_Search"),
616
+ "aria-label": getString3("Slicer_Search"),
617
+ value: search,
618
+ onChange: handleSearch
619
+ }
620
+ )
621
+ ] }),
622
+ /* @__PURE__ */ jsx4(
623
+ ListSlicerRow,
624
+ {
625
+ className: styles.selectAll,
626
+ label: getString3("Slicer_SelectAll"),
627
+ checked,
628
+ onToggle: toggleAll,
629
+ disabled: items.length === 0,
630
+ navigationIndex: -1,
631
+ tabIndex: navigation.activeIndex === -1 && items.length > 0 ? 0 : -1
632
+ }
633
+ ),
634
+ /* @__PURE__ */ jsx4("div", { ref: scrollRef, tabIndex: -1, className: mergeClasses(styles.scroll, hasMoreBelow && styles.scrollFade), style: scrollStyle, children: 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), "aria-posinset": row.index + 1, "aria-setsize": items.length, children: /* @__PURE__ */ jsx4(
635
+ ItemRow,
636
+ {
637
+ item: items[row.index],
638
+ state,
639
+ tabIndex: row.index === navigation.activeIndex ? 0 : -1
640
+ }
641
+ ) }, row.key)) : items.map((item, index) => /* @__PURE__ */ jsx4("li", { "data-slicer-index": index, children: /* @__PURE__ */ jsx4(
642
+ ItemRow,
643
+ {
644
+ item,
645
+ state,
646
+ tabIndex: index === navigation.activeIndex ? 0 : -1
647
+ }
648
+ ) }, item.key)) }) })
649
+ ] })
650
+ }
651
+ )
652
+ ]
653
+ }
654
+ );
655
+ }
656
+
657
+ // src/components/dropdown-slicer/dropdown-slicer.tsx
658
+ import { useId as useId2, useMemo as useMemo3 } from "react";
659
+ import { formatString as formatString3, getString as getString4 } from "@microsoft/fabric-visuals-core";
660
+
661
+ // src/components/ui/popover.tsx
662
+ import { Popover as PopoverPrimitive } from "radix-ui";
663
+ import { makeStyles as makeStyles4 } from "@griffel/react";
664
+ import { inVisualsLayer as inVisualsLayer4, tokens as tokens4 } from "@microsoft/fabric-visuals-core";
665
+ import { jsx as jsx5 } from "react/jsx-runtime";
666
+ var usePopoverStyles = makeStyles4(inVisualsLayer4({
667
+ popover: {
668
+ width: "var(--radix-popover-trigger-width)",
669
+ maxWidth: "min(calc(100vw - 16px), var(--radix-popover-content-available-width))",
670
+ maxHeight: "var(--radix-popover-content-available-height)",
671
+ display: "flex",
672
+ outline: "none",
673
+ zIndex: 1e3,
674
+ borderRadius: `var(--slicer-radius, ${tokens4.radiusXl})`,
675
+ boxShadow: "0 2px 6px rgba(0, 0, 0, 0.16)"
676
+ }
677
+ }));
678
+ var Popover = PopoverPrimitive.Root;
679
+ var PopoverTrigger = PopoverPrimitive.Trigger;
680
+ function PopoverContent({ className, ...props }) {
681
+ const styles = { ...useSlicerStyles(), ...usePopoverStyles() };
682
+ return /* @__PURE__ */ jsx5(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx5(
683
+ PopoverPrimitive.Content,
684
+ {
685
+ align: "start",
686
+ side: "bottom",
687
+ sideOffset: 4,
688
+ avoidCollisions: false,
689
+ collisionPadding: 8,
690
+ ...props,
691
+ className: mergeClasses(styles.typography, styles.popover, className)
692
+ }
693
+ ) });
694
+ }
695
+
696
+ // src/components/dropdown-slicer/dropdown-slicer-styles.ts
697
+ import { makeStyles as makeStyles5 } from "@griffel/react";
698
+ import { inVisualsLayer as inVisualsLayer5, tokens as tokens5 } from "@microsoft/fabric-visuals-core";
699
+ var useDropdownStyles = makeStyles5(inVisualsLayer5({
700
+ trigger: {
701
+ display: "flex",
702
+ alignItems: "center",
703
+ justifyContent: "space-between",
704
+ gap: "8px",
705
+ width: "100%",
706
+ minWidth: 0,
707
+ height: "32px",
708
+ padding: "4px 10px",
709
+ backgroundColor: `var(--slicer-background, ${tokens5.colorBackground})`,
710
+ color: `var(--slicer-foreground, ${tokens5.colorForeground})`,
711
+ border: `1px solid var(--slicer-stroke, ${tokens5.colorBorder})`,
712
+ borderRadius: `var(--slicer-radius, ${tokens5.radiusXl})`,
713
+ textAlign: "start",
714
+ cursor: "pointer",
715
+ ":hover": { backgroundColor: `var(--slicer-hover, ${tokens5.colorHover})` }
716
+ }
717
+ }));
718
+
719
+ // src/components/dropdown-slicer/dropdown-slicer.tsx
720
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
721
+ function DropdownSlicer(props) {
722
+ return /* @__PURE__ */ jsx6(DropdownSlicerContent, { ...props }, props.column);
723
+ }
724
+ function DropdownSlicerContent(props) {
725
+ const state = useListSlicer(props);
726
+ const styles = { ...useSlicerStyles(), ...useDropdownStyles() };
727
+ const titleId = useId2();
728
+ const summaryId = useId2();
729
+ const themeStyle = useMemo3(() => slicerThemeStyle(props.theme), [props.theme]);
730
+ const hideHeader = props.displayOptions?.hideHeader ?? false;
731
+ const listDisplayOptions = useMemo3(
732
+ () => ({ ...props.displayOptions, hideHeader: true }),
733
+ [props.displayOptions]
734
+ );
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 ? formatString3("Slicer_SelectionCount", state.selectedItems.length, state.items.length) : state.selectedItems.map((item) => item.label).join(", ");
736
+ return /* @__PURE__ */ jsxs4(
737
+ "section",
738
+ {
739
+ className: mergeClasses(styles.typography, styles.root),
740
+ style: themeStyle,
741
+ "aria-labelledby": hideHeader ? void 0 : titleId,
742
+ "aria-label": hideHeader ? state.title : void 0,
743
+ children: [
744
+ !hideHeader && /* @__PURE__ */ jsx6(
745
+ SlicerHeader,
746
+ {
747
+ title: state.title,
748
+ titleId,
749
+ onClear: state.allSelected ? void 0 : state.clear,
750
+ clearDisabled: !!state.error || state.items.length === 0
751
+ }
752
+ ),
753
+ state.error ? /* @__PURE__ */ jsx6(ListSlicerContent, { state, theme: props.theme, displayOptions: listDisplayOptions }) : /* @__PURE__ */ jsxs4(Popover, { children: [
754
+ /* @__PURE__ */ jsx6(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs4(
755
+ "button",
756
+ {
757
+ type: "button",
758
+ className: styles.trigger,
759
+ "aria-labelledby": hideHeader ? void 0 : `${titleId} ${summaryId}`,
760
+ "aria-label": hideHeader ? `${state.title} ${summary}` : void 0,
761
+ children: [
762
+ /* @__PURE__ */ jsx6("span", { id: summaryId, className: styles.text, title: summary, children: summary }),
763
+ /* @__PURE__ */ jsx6(ChevronDownIcon, { className: styles.icon })
764
+ ]
765
+ }
766
+ ) }),
767
+ /* @__PURE__ */ jsx6(PopoverContent, { style: themeStyle, "aria-label": state.title, children: /* @__PURE__ */ jsx6(
768
+ ListSlicerContent,
769
+ {
770
+ state,
771
+ theme: props.theme,
772
+ displayOptions: listDisplayOptions,
773
+ maxVisibleItems: 10
774
+ }
775
+ ) })
776
+ ] })
777
+ ]
778
+ }
779
+ );
780
+ }
781
+
782
+ // src/components/range-slicer/range-slicer.tsx
783
+ import { useCallback as useCallback8, useId as useId5, useMemo as useMemo6 } from "react";
784
+ import { mergeClasses as mergeClasses3 } from "@griffel/react";
785
+ import { formatNumericInput, formatString as formatString8, formatValue as formatValue2, getString as getString5, parseNumericInput } from "@microsoft/fabric-visuals-core";
786
+
787
+ // src/components/range-slicer/range-slicer-data.ts
788
+ import { formatString as formatString4, isDataTable as isDataTable2 } from "@microsoft/fabric-visuals-core";
789
+ var maxAutomaticHistogramBinCount = 24;
790
+ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
791
+ const table = isDataTable2(data) ? data : { columns: [{ name: column }], rows: data.map((value) => [value]) };
792
+ const columnIndex = table.columns.findIndex((definition2) => definition2.name === column);
793
+ if (columnIndex < 0) {
794
+ return {
795
+ title: column,
796
+ format: void 0,
797
+ domain: null,
798
+ hasOnlyIntegerValues: false,
799
+ histogram: [],
800
+ error: formatString4("Common_ColumnNotFound", column)
801
+ };
802
+ }
803
+ const definition = table.columns[columnIndex];
804
+ let minimum;
805
+ let maximum;
806
+ let hasOnlyIntegerValues = true;
807
+ let numericRowCount = 0;
808
+ const validBinCount = includeHistogram ? getValidHistogramBinCount(binCount) : void 0;
809
+ const distinctValues = includeHistogram && validBinCount === void 0 ? /* @__PURE__ */ new Set() : void 0;
810
+ for (const row of table.rows) {
811
+ const value = row[columnIndex];
812
+ if (typeof value === "number" && Number.isFinite(value)) {
813
+ minimum = minimum === void 0 ? value : Math.min(minimum, value);
814
+ maximum = maximum === void 0 ? value : Math.max(maximum, value);
815
+ hasOnlyIntegerValues = hasOnlyIntegerValues && Number.isInteger(value);
816
+ if (distinctValues) {
817
+ numericRowCount++;
818
+ if (distinctValues.size < maxAutomaticHistogramBinCount) distinctValues.add(value);
819
+ }
820
+ }
821
+ }
822
+ const domain = minimum !== void 0 && maximum !== void 0 ? [minimum, maximum] : null;
823
+ let histogram = [];
824
+ if (includeHistogram && domain) {
825
+ const histogramBinCount = domain[0] === domain[1] ? 1 : validBinCount ?? Math.min(Math.ceil(Math.log2(numericRowCount) + 1), distinctValues?.size ?? 0);
826
+ histogram = Array.from({ length: histogramBinCount }, () => 0);
827
+ for (const row of table.rows) {
828
+ const value = row[columnIndex];
829
+ if (typeof value === "number" && Number.isFinite(value)) {
830
+ const binIndex = Math.min(histogram.length - 1, Math.floor(getRangePosition(value, domain) * histogram.length));
831
+ histogram[binIndex]++;
832
+ }
833
+ }
834
+ }
835
+ return {
836
+ title: definition.displayName ?? definition.name,
837
+ format: definition.format,
838
+ domain,
839
+ hasOnlyIntegerValues: domain !== null && hasOnlyIntegerValues,
840
+ histogram
841
+ };
842
+ }
843
+ function getValidHistogramBinCount(binCount) {
844
+ return binCount !== void 0 && Number.isSafeInteger(binCount) && binCount > 0 ? binCount : void 0;
845
+ }
846
+ function getRangePosition(value, domain) {
847
+ const [minimum, maximum] = domain;
848
+ if (minimum === maximum) return 0.5;
849
+ const span = maximum - minimum;
850
+ return Number.isFinite(span) ? (value - minimum) / span : (value / 2 - minimum / 2) / (maximum / 2 - minimum / 2);
851
+ }
852
+
853
+ // src/components/range-slicer/range-slicer-styles.ts
854
+ import { makeStyles as makeStyles6, shorthands as shorthands2 } from "@griffel/react";
855
+ import { borderRadius, fontFamily as fontFamily2, fontSize, injectDesignTokens as injectDesignTokens2, inVisualsLayer as inVisualsLayer6, lineHeight, spacing, tokens as tokens6 } from "@microsoft/fabric-visuals-core";
856
+ injectDesignTokens2();
857
+ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
858
+ root: {
859
+ "--range-foreground": tokens6.colorForeground,
860
+ "--range-secondary": tokens6.colorMutedForeground,
861
+ "--range-accent": tokens6.colorBrandForeground,
862
+ "--range-background": tokens6.colorBackground,
863
+ "--range-stroke": tokens6.colorBorder,
864
+ "--range-error": tokens6.colorDestructive,
865
+ display: "flex",
866
+ flexDirection: "column",
867
+ gap: spacing.s,
868
+ width: "300px",
869
+ maxWidth: "100%",
870
+ minWidth: 0,
871
+ fontFamily: fontFamily2.base,
872
+ fontSize: fontSize[300],
873
+ lineHeight: lineHeight[300],
874
+ color: "var(--range-foreground)",
875
+ "& [data-disabled]": {
876
+ cursor: "not-allowed"
877
+ },
878
+ // Supply system colors explicitly because the track and thumbs disable automatic color adjustment.
879
+ "@media (forced-colors: active)": {
880
+ "& *": {
881
+ "--range-accent": "Highlight",
882
+ "--range-background": "Canvas",
883
+ "--range-foreground": "CanvasText",
884
+ "--range-secondary": "CanvasText",
885
+ "--range-stroke": "GrayText",
886
+ "--range-error": "CanvasText"
887
+ }
888
+ }
889
+ },
890
+ body: {
891
+ boxSizing: "border-box",
892
+ padding: spacing.mNudge,
893
+ border: "1px solid var(--range-stroke)",
894
+ borderRadius: borderRadius.xLarge,
895
+ backgroundColor: "var(--range-background)"
896
+ },
897
+ framelessBody: {
898
+ padding: 0,
899
+ border: "none",
900
+ borderRadius: 0,
901
+ backgroundColor: "transparent"
902
+ },
903
+ empty: {
904
+ margin: 0,
905
+ color: "var(--range-secondary)",
906
+ fontSize: fontSize[200]
907
+ },
908
+ histogram: {
909
+ // Match the track inset so histogram values align with the thumb centers.
910
+ marginInline: spacing.m,
911
+ height: "40px",
912
+ "& svg": {
913
+ display: "block",
914
+ // These fills already use system colors in forced-color mode.
915
+ forcedColorAdjust: "none"
916
+ }
917
+ },
918
+ // Share the track and range colors so both layers follow themes and forced-color overrides.
919
+ histogramMuted: {
920
+ fill: "var(--range-stroke)"
921
+ },
922
+ histogramSelected: {
923
+ fill: "var(--range-accent)"
924
+ },
925
+ slider: {
926
+ position: "relative",
927
+ display: "flex",
928
+ alignItems: "center",
929
+ height: spacing.xxl,
930
+ touchAction: "none",
931
+ userSelect: "none",
932
+ cursor: "pointer"
933
+ },
934
+ track: {
935
+ position: "relative",
936
+ flexGrow: 1,
937
+ height: "3px",
938
+ marginInline: spacing.m,
939
+ backgroundColor: "var(--range-stroke)",
940
+ borderRadius: borderRadius.circular,
941
+ forcedColorAdjust: "none"
942
+ },
943
+ range: {
944
+ position: "absolute",
945
+ height: "100%",
946
+ backgroundColor: "var(--range-accent)",
947
+ borderRadius: borderRadius.circular
948
+ },
949
+ thumb: {
950
+ display: "block",
951
+ position: "relative",
952
+ width: spacing.xxl,
953
+ height: spacing.xxl,
954
+ borderRadius: borderRadius.circular,
955
+ outline: "none",
956
+ forcedColorAdjust: "none",
957
+ // Draw a small visible handle while retaining a larger pointer target.
958
+ "::before": {
959
+ content: '""',
960
+ position: "absolute",
961
+ inset: "6px",
962
+ border: "1px solid var(--range-accent)",
963
+ borderRadius: borderRadius.circular,
964
+ backgroundColor: "var(--range-background)"
965
+ },
966
+ ":hover::before": {
967
+ borderWidth: "2px"
968
+ },
969
+ ":focus-visible": {
970
+ outline: "2px solid var(--range-accent)",
971
+ outlineOffset: "1px"
972
+ }
973
+ },
974
+ inputs: {
975
+ display: "grid",
976
+ gridTemplateColumns: "minmax(0, 1fr) auto minmax(0, 1fr)",
977
+ alignItems: "start",
978
+ gap: spacing.s
979
+ },
980
+ input: {
981
+ boxSizing: "border-box",
982
+ width: "100%",
983
+ minWidth: 0,
984
+ height: "28px",
985
+ paddingInline: spacing.s,
986
+ border: "1px solid var(--range-stroke)",
987
+ borderRadius: borderRadius.xLarge,
988
+ color: "var(--range-foreground)",
989
+ backgroundColor: "var(--range-background)",
990
+ fontFamily: "inherit",
991
+ fontSize: "inherit",
992
+ fontVariantNumeric: "tabular-nums",
993
+ ":focus-visible": {
994
+ outline: "2px solid var(--range-accent)",
995
+ outlineOffset: "1px"
996
+ },
997
+ ":disabled": {
998
+ color: "var(--range-secondary)",
999
+ cursor: "not-allowed"
1000
+ },
1001
+ '&[aria-invalid="true"]': {
1002
+ ...shorthands2.borderColor("var(--range-error)"),
1003
+ color: "var(--range-error)",
1004
+ outlineColor: "var(--range-error)",
1005
+ boxShadow: "0 0 0 3px color-mix(in srgb, var(--range-error) 20%, transparent)"
1006
+ }
1007
+ },
1008
+ separator: {
1009
+ lineHeight: "28px",
1010
+ fontSize: fontSize[200],
1011
+ color: "var(--range-secondary)"
1012
+ },
1013
+ fullRange: {
1014
+ margin: 0,
1015
+ marginTop: spacing.s,
1016
+ color: "var(--range-secondary)",
1017
+ fontSize: fontSize[200],
1018
+ lineHeight: lineHeight[200],
1019
+ overflowWrap: "anywhere"
1020
+ },
1021
+ error: {
1022
+ display: "block",
1023
+ marginTop: spacing.xs,
1024
+ color: "var(--range-error)",
1025
+ fontSize: fontSize[300],
1026
+ lineHeight: lineHeight[300],
1027
+ overflowWrap: "anywhere"
1028
+ }
1029
+ }));
1030
+
1031
+ // src/components/range-slicer/range-value-input.tsx
1032
+ import { useCallback as useCallback5, useId as useId3, useState as useState4 } from "react";
1033
+ import { formatString as formatString5 } from "@microsoft/fabric-visuals-core";
1034
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1035
+ function RangeValueInput({
1036
+ label,
1037
+ value,
1038
+ min,
1039
+ max,
1040
+ disabled,
1041
+ descriptionId,
1042
+ formatValue: formatValue3,
1043
+ parseValue,
1044
+ onCommit
1045
+ }) {
1046
+ const styles = useRangeSlicerStyles();
1047
+ const errorId = useId3();
1048
+ const [draft, setDraft] = useState4();
1049
+ const [error, setError] = useState4();
1050
+ const handleChange = useCallback5((event) => {
1051
+ setDraft(event.currentTarget.value);
1052
+ setError(void 0);
1053
+ }, []);
1054
+ const handleBlur = useCallback5((event) => {
1055
+ if (draft === void 0) return;
1056
+ const text = event.currentTarget.value.trim();
1057
+ const nextValue = parseValue(text);
1058
+ if (nextValue !== void 0 && nextValue >= min && nextValue <= max) {
1059
+ onCommit(nextValue);
1060
+ setDraft(void 0);
1061
+ setError(void 0);
1062
+ } else {
1063
+ setError(formatString5("RangeSlicer_InvalidValue", formatValue3(min), formatValue3(max)));
1064
+ }
1065
+ }, [draft, min, max, formatValue3, parseValue, onCommit]);
1066
+ const handleKeyDown = useCallback5((event) => {
1067
+ if (event.key === "Enter") {
1068
+ event.preventDefault();
1069
+ event.currentTarget.blur();
1070
+ } else if (event.key === "Escape") {
1071
+ event.preventDefault();
1072
+ setDraft(void 0);
1073
+ setError(void 0);
1074
+ }
1075
+ }, []);
1076
+ return /* @__PURE__ */ jsxs5("div", { children: [
1077
+ /* @__PURE__ */ jsx7(
1078
+ "input",
1079
+ {
1080
+ className: styles.input,
1081
+ type: "text",
1082
+ inputMode: "decimal",
1083
+ "aria-label": label,
1084
+ "aria-describedby": error ? `${descriptionId} ${errorId}` : descriptionId,
1085
+ "aria-invalid": Boolean(error),
1086
+ disabled,
1087
+ value: draft ?? formatValue3(value),
1088
+ onChange: handleChange,
1089
+ onBlur: handleBlur,
1090
+ onKeyDown: handleKeyDown
1091
+ }
1092
+ ),
1093
+ error && /* @__PURE__ */ jsx7("span", { className: styles.error, id: errorId, role: "alert", children: error })
1094
+ ] });
1095
+ }
1096
+
1097
+ // src/components/range-slicer/range-histogram.tsx
1098
+ import { useId as useId4 } from "react";
1099
+ import { formatString as formatString6 } from "@microsoft/fabric-visuals-core";
1100
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1101
+ var histogramWidth = 240;
1102
+ var histogramHeight = 40;
1103
+ function RangeHistogram({ counts, domain, selectedRange, title }) {
1104
+ const styles = useRangeSlicerStyles();
1105
+ const clipId = useId4();
1106
+ const maximumCount = Math.max(...counts);
1107
+ const isFixedRange = domain[0] === domain[1];
1108
+ const binWidth = isFixedRange ? 10 : histogramWidth / counts.length;
1109
+ const gap = Math.min(2, binWidth * 0.2);
1110
+ const startX = isFixedRange ? (histogramWidth - binWidth) / 2 : 0;
1111
+ const bars = counts.map((count, index) => {
1112
+ const height = count / maximumCount * histogramHeight;
1113
+ const x = startX + index * binWidth + gap / 2;
1114
+ return /* @__PURE__ */ jsx8("rect", { x, y: histogramHeight - height, width: binWidth - gap, height }, x);
1115
+ });
1116
+ const selectionStart = isFixedRange ? 0 : getRangePosition(selectedRange[0], domain) * histogramWidth;
1117
+ const selectionEnd = isFixedRange ? histogramWidth : getRangePosition(selectedRange[1], domain) * histogramWidth;
1118
+ return /* @__PURE__ */ jsx8("div", { className: styles.histogram, children: /* @__PURE__ */ jsxs6(
1119
+ "svg",
1120
+ {
1121
+ width: "100%",
1122
+ height: histogramHeight,
1123
+ viewBox: `0 0 ${histogramWidth} ${histogramHeight}`,
1124
+ preserveAspectRatio: "none",
1125
+ role: "img",
1126
+ "aria-label": formatString6("RangeSlicer_DistributionLabel", title),
1127
+ focusable: "false",
1128
+ children: [
1129
+ /* @__PURE__ */ jsx8("defs", { children: /* @__PURE__ */ jsx8("clipPath", { id: clipId, children: /* @__PURE__ */ jsx8("rect", { x: selectionStart, y: 0, width: selectionEnd - selectionStart, height: histogramHeight }) }) }),
1130
+ /* @__PURE__ */ jsx8("g", { className: styles.histogramMuted, children: bars }),
1131
+ /* @__PURE__ */ jsx8("g", { className: styles.histogramSelected, clipPath: `url(#${clipId})`, children: bars })
1132
+ ]
1133
+ }
1134
+ ) });
1135
+ }
1136
+
1137
+ // src/components/range-slicer/range-slider.tsx
1138
+ import { Root as Slider, Track, Range, Thumb } from "@radix-ui/react-slider";
1139
+ import { useCallback as useCallback6, useMemo as useMemo4, useRef as useRef4 } from "react";
1140
+ import { formatString as formatString7 } from "@microsoft/fabric-visuals-core";
1141
+
1142
+ // src/components/range-slicer/range-slider-steps.ts
1143
+ function getAutomaticRangeStep(domain, formatBound = String, hasOnlyIntegerValues = false) {
1144
+ const [minimum, maximum] = domain;
1145
+ if (minimum === maximum) return 1;
1146
+ const span = maximum - minimum;
1147
+ let step = getNiceStep(Math.max(span / 100, Number.MIN_VALUE));
1148
+ if (hasOnlyIntegerValues) {
1149
+ step = Math.max(1, Math.ceil(step));
1150
+ }
1151
+ while (step < span && hasRepeatedLabels(domain, step, formatBound)) {
1152
+ step = getNiceStep(step * 2);
1153
+ }
1154
+ return step;
1155
+ }
1156
+ function getNiceStep(rawStep) {
1157
+ const magnitude = 10 ** Math.floor(Math.log10(rawStep));
1158
+ if (magnitude === 0) return rawStep;
1159
+ const fraction = rawStep / magnitude;
1160
+ const factor = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
1161
+ return factor * magnitude;
1162
+ }
1163
+ function hasRepeatedLabels(domain, step, formatBound) {
1164
+ const [minimum, maximum] = domain;
1165
+ let previousLabel = formatBound(minimum);
1166
+ for (let index = 1; minimum + index * step < maximum; index++) {
1167
+ const label = formatBound(minimum + index * step);
1168
+ if (label === previousLabel) return true;
1169
+ previousLabel = label;
1170
+ }
1171
+ return previousLabel === formatBound(maximum);
1172
+ }
1173
+
1174
+ // src/components/range-slicer/range-slider.tsx
1175
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1176
+ function RangeSlider({
1177
+ domain,
1178
+ selectedRange,
1179
+ step,
1180
+ hasOnlyIntegerValues,
1181
+ disabled,
1182
+ title,
1183
+ descriptionId,
1184
+ formatBound,
1185
+ onValueChange,
1186
+ onValueCommit
1187
+ }) {
1188
+ const styles = useRangeSlicerStyles();
1189
+ const lowerThumb = useRef4(null);
1190
+ const upperThumb = useRef4(null);
1191
+ const sliderStep = useMemo4(
1192
+ () => step ?? getAutomaticRangeStep(domain, formatBound, hasOnlyIntegerValues),
1193
+ [domain, step, formatBound, hasOnlyIntegerValues]
1194
+ );
1195
+ const handleKeyDown = useCallback6((event) => {
1196
+ const isEndpointKey = event.key === "Home" || event.key === "End";
1197
+ if (isEndpointKey && !disabled) {
1198
+ let nextRange;
1199
+ if (event.target === lowerThumb.current) {
1200
+ nextRange = [event.key === "Home" ? domain[0] : selectedRange[1], selectedRange[1]];
1201
+ } else if (event.target === upperThumb.current) {
1202
+ nextRange = [selectedRange[0], event.key === "Home" ? selectedRange[0] : domain[1]];
1203
+ }
1204
+ if (nextRange) {
1205
+ event.preventDefault();
1206
+ onValueChange(nextRange);
1207
+ onValueCommit(nextRange);
1208
+ }
1209
+ }
1210
+ }, [disabled, selectedRange, domain, onValueChange, onValueCommit]);
1211
+ return /* @__PURE__ */ jsxs7(
1212
+ Slider,
1213
+ {
1214
+ className: styles.slider,
1215
+ min: domain[0],
1216
+ max: domain[1],
1217
+ step: sliderStep,
1218
+ value: selectedRange,
1219
+ disabled,
1220
+ onValueChange,
1221
+ onValueCommit,
1222
+ onKeyDown: handleKeyDown,
1223
+ children: [
1224
+ /* @__PURE__ */ jsx9(Track, { className: styles.track, children: /* @__PURE__ */ jsx9(Range, { className: styles.range }) }),
1225
+ /* @__PURE__ */ jsx9(
1226
+ Thumb,
1227
+ {
1228
+ ref: lowerThumb,
1229
+ className: styles.thumb,
1230
+ "aria-label": formatString7("RangeSlicer_MinimumLabel", title),
1231
+ "aria-valuemin": domain[0],
1232
+ "aria-valuemax": domain[1],
1233
+ "aria-valuenow": selectedRange[0],
1234
+ "aria-valuetext": formatBound(selectedRange[0]),
1235
+ "aria-describedby": descriptionId
1236
+ }
1237
+ ),
1238
+ /* @__PURE__ */ jsx9(
1239
+ Thumb,
1240
+ {
1241
+ ref: upperThumb,
1242
+ className: styles.thumb,
1243
+ "aria-label": formatString7("RangeSlicer_MaximumLabel", title),
1244
+ "aria-valuemin": domain[0],
1245
+ "aria-valuemax": domain[1],
1246
+ "aria-valuenow": selectedRange[1],
1247
+ "aria-valuetext": formatBound(selectedRange[1]),
1248
+ "aria-describedby": descriptionId
1249
+ }
1250
+ )
1251
+ ]
1252
+ }
1253
+ );
1254
+ }
1255
+
1256
+ // src/components/range-slicer/use-range-selection.ts
1257
+ import { useCallback as useCallback7, useEffect as useEffect3, useMemo as useMemo5, useRef as useRef5, useState as useState5 } from "react";
1258
+ function resolveSelection(domain, selection) {
1259
+ if (selection) {
1260
+ if (Number.isNaN(selection[0]) || Number.isNaN(selection[1]) || selection[0] > selection[1]) {
1261
+ throw new Error("RangeSlicer selection must contain ordered numeric bounds.");
1262
+ }
1263
+ if (domain) {
1264
+ return [
1265
+ Math.max(domain[0], Math.min(domain[1], selection[0])),
1266
+ Math.max(domain[0], Math.min(domain[1], selection[1]))
1267
+ ];
1268
+ }
1269
+ }
1270
+ return domain;
1271
+ }
1272
+ function useRangeSelection(domain, column, onInteraction, selection) {
1273
+ const resolvedSelection = useMemo5(() => resolveSelection(domain, selection), [domain, selection]);
1274
+ const [selectedRange, setSelectedRange] = useState5(resolvedSelection);
1275
+ const lastCommittedRange = useRef5(resolvedSelection);
1276
+ const [inputRevision, setInputRevision] = useState5(0);
1277
+ const incrementInputRevision = useCallback7(() => {
1278
+ setInputRevision((revision) => revision + 1);
1279
+ }, []);
1280
+ useEffect3(() => {
1281
+ if (selection !== void 0) {
1282
+ const previousRange = lastCommittedRange.current;
1283
+ if (previousRange?.[0] === resolvedSelection?.[0] && previousRange?.[1] === resolvedSelection?.[1]) return;
1284
+ lastCommittedRange.current = resolvedSelection;
1285
+ setSelectedRange(resolvedSelection);
1286
+ incrementInputRevision();
1287
+ }
1288
+ }, [selection, resolvedSelection, incrementInputRevision]);
1289
+ const commitSelectedRange = useCallback7((values) => {
1290
+ if (domain) {
1291
+ setSelectedRange([values[0], values[1]]);
1292
+ const previousRange = lastCommittedRange.current;
1293
+ if (previousRange && previousRange[0] === values[0] && previousRange[1] === values[1]) return;
1294
+ lastCommittedRange.current = [values[0], values[1]];
1295
+ if (onInteraction) {
1296
+ const isLowerBoundAtDomainMinimum = values[0] === domain[0];
1297
+ const isUpperBoundAtDomainMaximum = values[1] === domain[1];
1298
+ const isFullRange = isLowerBoundAtDomainMinimum && isUpperBoundAtDomainMaximum;
1299
+ const event = isFullRange ? { action: "clear" } : {
1300
+ action: "select",
1301
+ selections: [{
1302
+ predicates: [{
1303
+ type: "range",
1304
+ name: column,
1305
+ min: isLowerBoundAtDomainMinimum ? -Infinity : values[0],
1306
+ max: isUpperBoundAtDomainMaximum ? Infinity : values[1]
1307
+ }]
1308
+ }]
1309
+ };
1310
+ onInteraction([event]);
1311
+ }
1312
+ }
1313
+ }, [domain, column, onInteraction]);
1314
+ const handleSliderChange = useCallback7((values) => {
1315
+ setSelectedRange([values[0], values[1]]);
1316
+ incrementInputRevision();
1317
+ }, [incrementInputRevision]);
1318
+ const clearSelection = useCallback7(() => {
1319
+ setSelectedRange(domain);
1320
+ lastCommittedRange.current = domain;
1321
+ incrementInputRevision();
1322
+ onInteraction?.([{ action: "clear" }]);
1323
+ }, [domain, onInteraction, incrementInputRevision]);
1324
+ return {
1325
+ selectedRange,
1326
+ inputRevision,
1327
+ handleSliderChange,
1328
+ commitSelectedRange,
1329
+ clearSelection
1330
+ };
1331
+ }
1332
+
1333
+ // src/components/range-slicer/range-slicer.tsx
1334
+ import { Fragment as Fragment2, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
1335
+ function RangeSlicer({
1336
+ data,
1337
+ column,
1338
+ title,
1339
+ theme,
1340
+ step,
1341
+ disabled = false,
1342
+ displayOptions,
1343
+ onInteraction,
1344
+ selection
1345
+ }) {
1346
+ const styles = useRangeSlicerStyles();
1347
+ const id = useId5();
1348
+ const titleId = `${id}-title`;
1349
+ const descriptionId = `${id}-description`;
1350
+ const hideHeader = displayOptions?.hideHeader ?? false;
1351
+ const showHistogram = displayOptions?.showHistogram ?? true;
1352
+ const binCount = showHistogram ? displayOptions?.binCount : void 0;
1353
+ const slicerData = useMemo6(
1354
+ () => readRangeSlicerData(data, column, showHistogram, binCount),
1355
+ [data, column, showHistogram, binCount]
1356
+ );
1357
+ const { selectedRange, inputRevision, handleSliderChange, commitSelectedRange, clearSelection } = useRangeSelection(
1358
+ slicerData.domain,
1359
+ column,
1360
+ onInteraction,
1361
+ selection
1362
+ );
1363
+ const displayTitle = title ?? slicerData.title;
1364
+ 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
+ const sliderStep = step !== void 0 && Number.isFinite(step) && step > 0 ? step : void 0;
1368
+ const themeStyle = useMemo6(() => theme ? {
1369
+ ...slicerThemeStyle(theme),
1370
+ "--range-foreground": theme.foreground,
1371
+ "--range-secondary": theme.foregroundSecondary,
1372
+ "--range-accent": theme.brandForeground,
1373
+ "--range-background": theme.background,
1374
+ "--range-stroke": theme.stroke,
1375
+ fontFamily: theme.typography?.label?.family
1376
+ } : {}, [theme]);
1377
+ const formatBound = useCallback8((value) => String(formatValue2(value, slicerData.format)), [slicerData.format]);
1378
+ const formatInput = useCallback8((value) => formatNumericInput(value, slicerData.format), [slicerData.format]);
1379
+ const parseInput = useCallback8((text) => parseNumericInput(text, slicerData.format), [slicerData.format]);
1380
+ const handleLowerCommit = useCallback8((value) => {
1381
+ if (selectedRange) commitSelectedRange([value, selectedRange[1]]);
1382
+ }, [selectedRange, commitSelectedRange]);
1383
+ const handleUpperCommit = useCallback8((value) => {
1384
+ if (selectedRange) commitSelectedRange([selectedRange[0], value]);
1385
+ }, [selectedRange, commitSelectedRange]);
1386
+ if (slicerData.error) return /* @__PURE__ */ jsx10("div", { role: "alert", children: slicerData.error });
1387
+ return /* @__PURE__ */ jsxs8(
1388
+ "section",
1389
+ {
1390
+ className: styles.root,
1391
+ style: themeStyle,
1392
+ "aria-labelledby": hideHeader ? void 0 : titleId,
1393
+ "aria-label": hideHeader ? displayTitle : void 0,
1394
+ children: [
1395
+ !hideHeader && /* @__PURE__ */ jsx10(
1396
+ SlicerHeader,
1397
+ {
1398
+ title: displayTitle,
1399
+ titleId,
1400
+ onClear: hasSelection ? clearSelection : void 0,
1401
+ clearDisabled: areControlsDisabled
1402
+ }
1403
+ ),
1404
+ /* @__PURE__ */ jsx10("div", { className: mergeClasses3(styles.body, displayOptions?.frameless && styles.framelessBody), children: selectedRange && slicerData.domain ? /* @__PURE__ */ jsxs8(Fragment2, { children: [
1405
+ showHistogram && /* @__PURE__ */ jsx10(RangeHistogram, { counts: slicerData.histogram, domain: slicerData.domain, selectedRange, title: displayTitle }),
1406
+ isFixedRange ? /* @__PURE__ */ jsx10("div", { className: styles.slider, "aria-hidden": "true", children: /* @__PURE__ */ jsx10("div", { className: styles.track }) }) : /* @__PURE__ */ jsx10(
1407
+ RangeSlider,
1408
+ {
1409
+ domain: slicerData.domain,
1410
+ selectedRange,
1411
+ step: sliderStep,
1412
+ hasOnlyIntegerValues: slicerData.hasOnlyIntegerValues,
1413
+ disabled: areControlsDisabled,
1414
+ title: displayTitle,
1415
+ descriptionId,
1416
+ formatBound,
1417
+ onValueChange: handleSliderChange,
1418
+ onValueCommit: commitSelectedRange
1419
+ }
1420
+ ),
1421
+ /* @__PURE__ */ jsxs8("div", { className: styles.inputs, children: [
1422
+ /* @__PURE__ */ jsx10(
1423
+ RangeValueInput,
1424
+ {
1425
+ label: formatString8("RangeSlicer_MinimumLabel", displayTitle),
1426
+ value: selectedRange[0],
1427
+ min: slicerData.domain[0],
1428
+ max: selectedRange[1],
1429
+ disabled: areControlsDisabled,
1430
+ descriptionId,
1431
+ formatValue: formatInput,
1432
+ parseValue: parseInput,
1433
+ onCommit: handleLowerCommit
1434
+ },
1435
+ `lower-${inputRevision}`
1436
+ ),
1437
+ /* @__PURE__ */ jsx10("span", { className: styles.separator, children: getString5("RangeSlicer_To") }),
1438
+ /* @__PURE__ */ jsx10(
1439
+ RangeValueInput,
1440
+ {
1441
+ label: formatString8("RangeSlicer_MaximumLabel", displayTitle),
1442
+ value: selectedRange[1],
1443
+ min: selectedRange[0],
1444
+ max: slicerData.domain[1],
1445
+ disabled: areControlsDisabled,
1446
+ descriptionId,
1447
+ formatValue: formatInput,
1448
+ parseValue: parseInput,
1449
+ onCommit: handleUpperCommit
1450
+ },
1451
+ `upper-${inputRevision}`
1452
+ )
1453
+ ] }),
1454
+ /* @__PURE__ */ jsx10("p", { id: descriptionId, className: styles.fullRange, children: formatString8("RangeSlicer_FullRange", formatBound(slicerData.domain[0]), formatBound(slicerData.domain[1])) })
1455
+ ] }) : /* @__PURE__ */ jsx10("p", { className: styles.empty, role: "status", children: getString5("Common_NoNumericValues") }) })
1456
+ ]
1457
+ }
1458
+ );
1459
+ }
1460
+ export {
1461
+ DropdownSlicer,
1462
+ ListSlicer,
1463
+ RangeSlicer,
1464
+ isSlicerValue
1465
+ };