@microsoft/fabric-slicers 3.0.1 → 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/CHANGELOG +24 -2
- package/README.md +61 -22
- package/dist/index.d.ts +19 -8
- package/dist/index.js +282 -113
- package/package.json +2 -2
package/CHANGELOG
CHANGED
|
@@ -5,6 +5,28 @@ All notable changes to `@microsoft/fabric-slicers` will be documented in this fi
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## 3.0
|
|
8
|
+
## 3.1.0 - 2026-10-09
|
|
9
9
|
|
|
10
|
-
-
|
|
10
|
+
- Use shared slicers for DataGrid column filtering
|
|
11
|
+
- [Slicer] Interaction manager integration for List and drop down slicer
|
|
12
|
+
- Improve list slicer keyboard navigation and Range Home/End behavior
|
|
13
|
+
- Support external selections in list and dropdown slicers
|
|
14
|
+
- [Slicer] Preserve formatting when editing range inputs
|
|
15
|
+
- Use integer steps for whole-number range slicers
|
|
16
|
+
- [Slicer] Adding fade for list slicer
|
|
17
|
+
- Support host-managed selection and embedded RangeSlicer controls
|
|
18
|
+
- Fix RangeSlicer Home key at fractional minimums
|
|
19
|
+
- [Slicer] Editing clear button for range slicer
|
|
20
|
+
- Rename fabric slicers to Microsoft scope
|
|
21
|
+
- Add range slicer interaction events
|
|
22
|
+
- [Slicer] List slicer search bar focus bug fix
|
|
23
|
+
- [Slicers] Add the Dropdown slicer
|
|
24
|
+
- Add dynamic range slicer bins and automatic steps
|
|
25
|
+
- Add basic histogram to numeric range slicers
|
|
26
|
+
- [Slicers] Bug fix for clear button causing layout shift
|
|
27
|
+
- [Slicers 2/2] Add editable range inputs
|
|
28
|
+
- [Slicers] List slicer implementation
|
|
29
|
+
- [Slicers 1/2] Add a data-backed range slider
|
|
30
|
+
- Slicers adding basic contracts and skeleton implementation
|
|
31
|
+
- Scaffold ListSlicer package
|
|
32
|
+
- Set the Slicers package version to 1.0.0 for release.
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ React slicer components for Fabric Apps - Analytics.
|
|
|
6
6
|
|
|
7
7
|
> **Use when**: You need categorical selection or a numeric range control.
|
|
8
8
|
> **Components**: `ListSlicer`, `DropdownSlicer`, `RangeSlicer`.
|
|
9
|
-
> **Selection**: Starts with all values or the full range selected.
|
|
9
|
+
> **Selection**: Starts with all values or the full range selected unless supplied by the host. All slicers accept `selection` to restore or synchronize local state and emit interaction events for host-managed filtering.
|
|
10
10
|
> **Peer dependencies**: React 18 or 19, React DOM, and `@griffel/react`.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
@@ -25,11 +25,13 @@ Import components and types from `@microsoft/fabric-slicers`. All three componen
|
|
|
25
25
|
| `column` | `string` | yes | Table column to display; also the fallback title for flat data. |
|
|
26
26
|
| `title` | `string` | no | Overrides the column's display name or name. |
|
|
27
27
|
| `theme` | `VisualTheme` | no | Color, typography, and border overrides. Defaults to shared design tokens. |
|
|
28
|
-
| `displayOptions` | `SlicerDisplayOptions` | no | Shared
|
|
29
|
-
| `
|
|
28
|
+
| `displayOptions` | `SlicerDisplayOptions` | no | Shared `hideHeader` and `frameless` options, extended by each slicer. |
|
|
29
|
+
| `selection` | Component-specific | no | Restore or synchronize host-provided selection. See [External selections](#external-selections). |
|
|
30
|
+
| `onInteraction` | `InteractionEventCallback` | no | Selection and clear events for host-managed filtering. |
|
|
30
31
|
|
|
31
32
|
`DataTable`, `VisualTheme`, and `InteractionEventCallback` come from `@microsoft/fabric-visuals-core`.
|
|
32
33
|
`SlicerValue` supports strings, finite numbers, booleans, valid dates, `null`, and `undefined`.
|
|
34
|
+
`isSlicerValue` validates untyped data cells or interaction values against that contract.
|
|
33
35
|
Table column formats apply to displayed values.
|
|
34
36
|
|
|
35
37
|
## List slicer
|
|
@@ -58,6 +60,34 @@ Props type: `ListSlicerInputParams`. Its optional `displayOptions` uses `ListSli
|
|
|
58
60
|
| Option | Default | Description |
|
|
59
61
|
|--------|---------|-------------|
|
|
60
62
|
| `showSearch` | `true` | Show the search input. |
|
|
63
|
+
| `hideHeader` | `false` | Hide the title and Clear button when the host supplies its own header. |
|
|
64
|
+
| `frameless` | `false` | Remove the body's border, background, and padding when embedded in a host surface. |
|
|
65
|
+
|
|
66
|
+
### Host-owned list filtering
|
|
67
|
+
|
|
68
|
+
Embed `ListSlicer` with `selection` and `onInteraction` when the host owns filtering.
|
|
69
|
+
Use `displayOptions: { hideHeader: true, frameless: true }` when the host provides the surrounding
|
|
70
|
+
surface and Clear action, as DataGrid does. Raw values are retained internally for selection and
|
|
71
|
+
interaction events; formatted labels are presentation-only.
|
|
72
|
+
|
|
73
|
+
### Keyboard navigation
|
|
74
|
+
|
|
75
|
+
Select all and the matching values share one Tab stop, separate from Search.
|
|
76
|
+
Initial entry focuses Select all. Tab and Shift+Tab leave the checkboxes; returning
|
|
77
|
+
restores the last focused checkbox, falling back to Select all if that value is no longer present.
|
|
78
|
+
The same navigation works in the dropdown's shared selection list.
|
|
79
|
+
|
|
80
|
+
| Key | Action |
|
|
81
|
+
|-----|--------|
|
|
82
|
+
| Up / Down arrow | Move between Select all and the matching values without changing selection. Stops at either end. |
|
|
83
|
+
| Home / End | Focus Select all / the last matching value, including values outside the rendered virtual window. |
|
|
84
|
+
| Space / Enter | Toggle the focused value or Select all. |
|
|
85
|
+
|
|
86
|
+
Unmodified arrows and Home/End provide navigation based on the [documented Power BI slicer shortcuts](https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-accessibility-keyboard-shortcuts#slicer).
|
|
87
|
+
Shift+Arrow range selection is intentionally unsupported to keep keyboard handling simple;
|
|
88
|
+
use Space or Enter to toggle individual values. Modified navigation keys are left to the browser.
|
|
89
|
+
The shared Tab stop and inclusion of Select all are explicit interaction choices here, not specified by that documentation.
|
|
90
|
+
Search retains normal text-editing keys, and Escape still closes an open dropdown and returns focus to its trigger.
|
|
61
91
|
|
|
62
92
|
## Dropdown slicer
|
|
63
93
|
|
|
@@ -76,7 +106,7 @@ import { DropdownSlicer } from '@microsoft/fabric-slicers';
|
|
|
76
106
|
/>;
|
|
77
107
|
```
|
|
78
108
|
|
|
79
|
-
Props type: `DropdownSlicerInputParams`. It accepts the same `displayOptions` as List slicer.
|
|
109
|
+
Props type: `DropdownSlicerInputParams`. It accepts the same `selection` and `displayOptions` as List slicer.
|
|
80
110
|
|
|
81
111
|
## Range slicer
|
|
82
112
|
|
|
@@ -101,39 +131,48 @@ Props type: `RangeSlicerInputParams`. Additional options:
|
|
|
101
131
|
| `displayOptions.showHistogram` | `true` | Show the value distribution above the slider. |
|
|
102
132
|
| `displayOptions.hideHeader` | `false` | Hide the title and Clear button when the host supplies its own header. The range retains its accessible name. |
|
|
103
133
|
| `displayOptions.frameless` | `false` | Remove the body's border, background, and padding when embedded in a host surface. Input borders remain visible. |
|
|
104
|
-
| `selection` | Local state | Restore or synchronize host-provided inclusive bounds without emitting events. `null` resets the full range; infinities map to domain endpoints. |
|
|
105
134
|
| `step` | Automatic | Positive slider increment; does not restrict typed values. |
|
|
106
135
|
| `disabled` | `false` | Disable interaction. |
|
|
107
136
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
137
|
+
Home/End changes only the focused handle and keeps focus there, with either automatic or explicit steps:
|
|
138
|
+
the minimum handle moves to the domain minimum / current maximum, and the maximum handle moves to
|
|
139
|
+
the current minimum / domain maximum. Handles can meet without crossing; typed off-step bounds remain exact.
|
|
111
140
|
|
|
112
|
-
|
|
113
|
-
When `step` is omitted or invalid, the slider chooses a precision- and formatter-aware increment;
|
|
114
|
-
an explicit finite positive `step` overrides it.
|
|
115
|
-
Typed values can be any finite number within the current bounds, independent of the slider step.
|
|
141
|
+
## External selections
|
|
116
142
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
143
|
+
All slicers accept an optional `selection` prop to restore a saved selection or synchronize it while mounted.
|
|
144
|
+
Omit it to manage selection locally (initially all values or the full range).
|
|
145
|
+
Supply `null` to reset to all values or the full range, including newly arriving data.
|
|
146
|
+
Host updates do not emit interaction events. Local selection controls and Clear continue to work;
|
|
147
|
+
the next supplied selection update replaces that local state.
|
|
148
|
+
Keep selection arrays immutable and retain their reference on unrelated rerenders to preserve local edits.
|
|
149
|
+
|
|
150
|
+
| Component | Selection type | Meaning |
|
|
151
|
+
|-----------|----------------|---------|
|
|
152
|
+
| `ListSlicer`, `DropdownSlicer` | `readonly SlicerValue[] \| null` | Raw selected values. `[]` selects none. |
|
|
153
|
+
| `RangeSlicer` | `SlicerRange \| null` | Inclusive `[minimum, maximum]` bounds. Infinities leave that side unbounded. |
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
<ListSlicer data={['Action', 'Adventure', 'Role-playing']} column="genre" selection={['Action', 'Adventure']} />;
|
|
157
|
+
<DropdownSlicer data={['North', 'South', 'East', 'West']} column="region" selection={['North']} />;
|
|
158
|
+
<RangeSlicer data={[0, 20, 80, 100]} column="revenue" selection={[20, Infinity]} />;
|
|
159
|
+
```
|
|
121
160
|
|
|
122
161
|
### Interactions
|
|
123
162
|
|
|
124
163
|
Optional `onInteraction` uses `InteractionEventCallback` from `@microsoft/fabric-visuals-core`.
|
|
125
|
-
|
|
164
|
+
List and Dropdown slicers emit one `select` event per checkbox or search-scoped Select all change,
|
|
165
|
+
with a `set` predicate containing `column` as its name and the complete raw selected values.
|
|
166
|
+
An empty array selects nothing. Selecting all values or clearing emits `[{ action: 'clear' }]`.
|
|
167
|
+
|
|
168
|
+
Range slicers emit `select` on drag release, keyboard changes, or valid input commits (Enter/blur).
|
|
126
169
|
Unchanged, invalid, or cancelled edits do not emit.
|
|
127
170
|
|
|
128
|
-
|
|
171
|
+
Range selections contain one inclusive `range` predicate using `column` and raw numeric bounds.
|
|
129
172
|
Domain endpoints emit `min: -Infinity` or `max: Infinity` to leave that side unbounded.
|
|
130
173
|
Encode infinities explicitly when serializing; `JSON.stringify` converts them to `null`.
|
|
131
174
|
|
|
132
175
|
Clear or returning to the full range emits `[{ action: 'clear' }]`.
|
|
133
|
-
Selection stays local unless the host supplies `selection` to restore or synchronize it; the host applies events to other visuals.
|
|
134
|
-
With `selection`, refreshed data clamps the displayed handles to the available domain without changing the host's predicate or emitting events.
|
|
135
|
-
For example, `[20, Infinity]` displays as `[20, 100]` for a `[0, 100]` domain; `null` displays the full domain.
|
|
136
|
-
Otherwise keep `data` and `column` fixed while mounted; remount to change them.
|
|
137
176
|
|
|
138
177
|
## Theming
|
|
139
178
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { DataTable, VisualTheme, InteractionEventCallback } from '@microsoft/fabric-visuals-core';
|
|
3
3
|
|
|
4
|
-
/** Supported raw slicer values. */
|
|
4
|
+
/** Supported raw slicer values. Null and undefined share one blank entry in list and dropdown slicers. */
|
|
5
5
|
type SlicerValue = string | number | boolean | Date | null | undefined;
|
|
6
6
|
/** Display options shared by all slicers. */
|
|
7
7
|
interface SlicerDisplayOptions {
|
|
8
8
|
/** Hide the title and Clear button. Defaults to false. */
|
|
9
9
|
hideHeader?: boolean;
|
|
10
|
+
/** Remove the body frame and padding when the host provides the surrounding surface. Defaults to false. */
|
|
11
|
+
frameless?: boolean;
|
|
10
12
|
}
|
|
11
|
-
/** Shared inputs for all slicers.
|
|
13
|
+
/** Shared inputs for all slicers. Without a host selection, slicers start with all values selected. */
|
|
12
14
|
interface SlicerInputParams {
|
|
13
15
|
/** Structured tabular data or a flat collection of slicer values. */
|
|
14
16
|
data: DataTable | readonly SlicerValue[];
|
|
@@ -30,10 +32,15 @@ interface ListSlicerDisplayOptions extends SlicerDisplayOptions {
|
|
|
30
32
|
/** Inputs for the list slicer. */
|
|
31
33
|
interface ListSlicerInputParams extends SlicerInputParams {
|
|
32
34
|
displayOptions?: ListSlicerDisplayOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Raw selected values to restore or synchronize without emitting events.
|
|
37
|
+
* Null resets to all, including future values. An empty array selects none.
|
|
38
|
+
* Omitted leaves selection locally managed; supplying values does not disable local edits.
|
|
39
|
+
*/
|
|
40
|
+
selection?: readonly SlicerValue[] | null;
|
|
33
41
|
}
|
|
34
42
|
/** Inputs for the dropdown slicer. */
|
|
35
|
-
interface DropdownSlicerInputParams extends
|
|
36
|
-
displayOptions?: ListSlicerDisplayOptions;
|
|
43
|
+
interface DropdownSlicerInputParams extends ListSlicerInputParams {
|
|
37
44
|
}
|
|
38
45
|
/** Lower and upper bounds, inclusive. */
|
|
39
46
|
type SlicerRange = [number, number];
|
|
@@ -43,8 +50,6 @@ interface RangeSlicerDisplayOptions extends SlicerDisplayOptions {
|
|
|
43
50
|
showHistogram?: boolean;
|
|
44
51
|
/** Positive safe integer overriding the histogram bin count. Omitted or invalid values use automatic binning. */
|
|
45
52
|
binCount?: number;
|
|
46
|
-
/** Remove the body frame and padding when the host provides the surrounding surface. */
|
|
47
|
-
frameless?: boolean;
|
|
48
53
|
}
|
|
49
54
|
/** Numeric range slicer. Keep column fixed; data may refresh when the host supplies selection. */
|
|
50
55
|
interface RangeSlicerInputParams extends SlicerInputParams {
|
|
@@ -55,7 +60,10 @@ interface RangeSlicerInputParams extends SlicerInputParams {
|
|
|
55
60
|
* Null resets to the full range. Omitted leaves selection locally managed.
|
|
56
61
|
*/
|
|
57
62
|
selection?: SlicerRange | null;
|
|
58
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Finite positive keyboard and pointer increment. Omitted or invalid values use precision- and formatter-aware automatic steps,
|
|
65
|
+
* restricted to whole-number increments when all finite data values are integers. Typed values are not restricted by the step.
|
|
66
|
+
*/
|
|
59
67
|
step?: number;
|
|
60
68
|
disabled?: boolean;
|
|
61
69
|
}
|
|
@@ -66,4 +74,7 @@ declare function DropdownSlicer(props: DropdownSlicerInputParams): ReactElement;
|
|
|
66
74
|
|
|
67
75
|
declare function RangeSlicer({ data, column, title, theme, step, disabled, displayOptions, onInteraction, selection, }: RangeSlicerInputParams): ReactElement;
|
|
68
76
|
|
|
69
|
-
|
|
77
|
+
/** Narrows unvalidated data cells and interaction values to supported slicer values. */
|
|
78
|
+
declare function isSlicerValue(value: DataTable['rows'][number][number]): value is SlicerValue;
|
|
79
|
+
|
|
80
|
+
export { DropdownSlicer, type DropdownSlicerInputParams, ListSlicer, type ListSlicerDisplayOptions, type ListSlicerInputParams, RangeSlicer, type RangeSlicerDisplayOptions, type RangeSlicerInputParams, type SlicerDisplayOptions, type SlicerInputParams, type SlicerRange, type SlicerValue, isSlicerValue };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
// src/components/list-slicer/list-slicer.tsx
|
|
2
2
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
3
|
-
import { useCallback as
|
|
3
|
+
import { useCallback as useCallback4, useEffect as useEffect2, useId, useMemo as useMemo2, useRef as useRef3, useState as useState3 } from "react";
|
|
4
4
|
import { getString as getString3 } from "@microsoft/fabric-visuals-core";
|
|
5
5
|
|
|
6
6
|
// src/hooks/use-list-slicer.ts
|
|
7
|
-
import { useCallback, useMemo, useState } from "react";
|
|
7
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import { formatString, formatValue, getString, isDataTable } from "@microsoft/fabric-visuals-core";
|
|
9
|
+
|
|
10
|
+
// src/utils/slicer-value.ts
|
|
9
11
|
function isSlicerValue(value) {
|
|
10
12
|
return value == null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || value instanceof Date && Number.isFinite(value.getTime());
|
|
11
13
|
}
|
|
14
|
+
|
|
15
|
+
// src/hooks/use-list-slicer.ts
|
|
12
16
|
function valueKey(value) {
|
|
17
|
+
if (value == null) return "blank";
|
|
13
18
|
if (value instanceof Date) return `date:${value.getTime()}`;
|
|
14
19
|
return `${typeof value}:${String(value)}`;
|
|
15
20
|
}
|
|
@@ -48,43 +53,145 @@ function prepareListSlicerData({ data, column, title }) {
|
|
|
48
53
|
}
|
|
49
54
|
return { title: resolvedTitle, items };
|
|
50
55
|
}
|
|
51
|
-
function useListSlicer({ data, column, title }) {
|
|
56
|
+
function useListSlicer({ data, column, title, selection, onInteraction }) {
|
|
52
57
|
const prepared = useMemo(
|
|
53
58
|
() => prepareListSlicerData({ data, column, title }),
|
|
54
59
|
[data, column, title]
|
|
55
60
|
);
|
|
56
|
-
const
|
|
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]);
|
|
57
88
|
const isSelected = useCallback(
|
|
58
|
-
(key) =>
|
|
59
|
-
[
|
|
89
|
+
(key) => localSelection === "all" || localSelection.has(key),
|
|
90
|
+
[localSelection]
|
|
60
91
|
);
|
|
61
92
|
const selectedItems = useMemo(
|
|
62
93
|
() => prepared.items.filter((item) => isSelected(item.key)),
|
|
63
94
|
[prepared.items, isSelected]
|
|
64
95
|
);
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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]);
|
|
78
140
|
return {
|
|
79
141
|
...prepared,
|
|
80
142
|
selectedItems,
|
|
81
143
|
isSelected,
|
|
82
144
|
toggle,
|
|
145
|
+
toggleAll,
|
|
83
146
|
clear,
|
|
84
|
-
allSelected:
|
|
147
|
+
allSelected: localSelection === "all"
|
|
85
148
|
};
|
|
86
149
|
}
|
|
87
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
|
+
|
|
88
195
|
// src/components/shared/slicer-header.tsx
|
|
89
196
|
import { formatString as formatString2, getString as getString2 } from "@microsoft/fabric-visuals-core";
|
|
90
197
|
|
|
@@ -196,6 +303,7 @@ function SlicerHeader({ title, titleId, onClear, clearDisabled }) {
|
|
|
196
303
|
|
|
197
304
|
// src/components/ui/checkbox.tsx
|
|
198
305
|
import { Checkbox as CheckBox } from "radix-ui";
|
|
306
|
+
import { useCallback as useCallback3 } from "react";
|
|
199
307
|
import { mergeClasses as mergeClasses2 } from "@griffel/react";
|
|
200
308
|
|
|
201
309
|
// src/components/ui/ui-slicer-styles.ts
|
|
@@ -235,9 +343,17 @@ var useCheckboxStyles = makeStyles2(inVisualsLayer2({
|
|
|
235
343
|
|
|
236
344
|
// src/components/ui/checkbox.tsx
|
|
237
345
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
238
|
-
function Checkbox({ className, checked, ...props }) {
|
|
346
|
+
function Checkbox({ className, checked, onKeyDown, ...props }) {
|
|
239
347
|
const styles = useCheckboxStyles();
|
|
240
|
-
|
|
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(
|
|
241
357
|
"path",
|
|
242
358
|
{
|
|
243
359
|
d: checked === "indeterminate" ? "M2 6h8" : "m2 6 2.5 2.5L10 3",
|
|
@@ -265,6 +381,8 @@ function SearchIcon({ className }) {
|
|
|
265
381
|
import { makeStyles as makeStyles3 } from "@griffel/react";
|
|
266
382
|
import { inVisualsLayer as inVisualsLayer3, tokens as tokens3 } from "@microsoft/fabric-visuals-core";
|
|
267
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" },
|
|
268
386
|
search: {
|
|
269
387
|
display: "flex",
|
|
270
388
|
alignItems: "center",
|
|
@@ -350,10 +468,10 @@ var useListSlicerStyles = makeStyles3(inVisualsLayer3({
|
|
|
350
468
|
// src/components/list-slicer/list-slicer.tsx
|
|
351
469
|
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
352
470
|
var ROW_HEIGHT = 32;
|
|
353
|
-
function ListSlicerRow({ label, checked, onToggle, disabled, className }) {
|
|
471
|
+
function ListSlicerRow({ label, checked, onToggle, disabled, className, tabIndex, navigationIndex }) {
|
|
354
472
|
const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
|
|
355
473
|
const id = useId();
|
|
356
|
-
return /* @__PURE__ */ jsxs3("div", { className: mergeClasses(styles.row, className), children: [
|
|
474
|
+
return /* @__PURE__ */ jsxs3("div", { className: mergeClasses(styles.row, className), "data-slicer-index": navigationIndex, children: [
|
|
357
475
|
/* @__PURE__ */ jsx4(
|
|
358
476
|
Checkbox,
|
|
359
477
|
{
|
|
@@ -361,20 +479,25 @@ function ListSlicerRow({ label, checked, onToggle, disabled, className }) {
|
|
|
361
479
|
checked,
|
|
362
480
|
onCheckedChange: onToggle,
|
|
363
481
|
disabled,
|
|
364
|
-
"aria-label": label
|
|
482
|
+
"aria-label": label,
|
|
483
|
+
tabIndex
|
|
365
484
|
}
|
|
366
485
|
),
|
|
367
486
|
/* @__PURE__ */ jsx4("label", { className: styles.label, htmlFor: id, children: /* @__PURE__ */ jsx4("span", { className: styles.text, title: label, children: label }) })
|
|
368
487
|
] });
|
|
369
488
|
}
|
|
370
|
-
function ItemRow({ item, state }) {
|
|
371
|
-
const toggle =
|
|
489
|
+
function ItemRow({ item, state, tabIndex }) {
|
|
490
|
+
const toggle = useCallback4(
|
|
491
|
+
(checked) => state.toggle(item.key, checked === true),
|
|
492
|
+
[state, item.key]
|
|
493
|
+
);
|
|
372
494
|
return /* @__PURE__ */ jsx4(
|
|
373
495
|
ListSlicerRow,
|
|
374
496
|
{
|
|
375
497
|
label: item.label,
|
|
376
498
|
checked: state.isSelected(item.key),
|
|
377
|
-
onToggle: toggle
|
|
499
|
+
onToggle: toggle,
|
|
500
|
+
tabIndex
|
|
378
501
|
}
|
|
379
502
|
);
|
|
380
503
|
}
|
|
@@ -399,23 +522,30 @@ function ListSlicerContent({
|
|
|
399
522
|
const themeStyle = useMemo2(() => slicerThemeStyle(theme), [theme]);
|
|
400
523
|
const showSearch = displayOptions?.showSearch ?? true;
|
|
401
524
|
const hideHeader = displayOptions?.hideHeader ?? false;
|
|
402
|
-
const scrollRef =
|
|
525
|
+
const scrollRef = useRef3(null);
|
|
403
526
|
const scrollStyle = useMemo2(
|
|
404
527
|
() => ({ maxHeight: maxVisibleItems * ROW_HEIGHT }),
|
|
405
528
|
[maxVisibleItems]
|
|
406
529
|
);
|
|
407
|
-
const [search, setSearch] =
|
|
530
|
+
const [search, setSearch] = useState3("");
|
|
408
531
|
const items = useMemo2(() => {
|
|
409
532
|
const query = showSearch ? search.toLocaleLowerCase() : "";
|
|
410
533
|
return state.items.filter((item) => item.label.toLocaleLowerCase().includes(query));
|
|
411
534
|
}, [state.items, search, showSearch]);
|
|
412
|
-
const handleSearch =
|
|
535
|
+
const handleSearch = useCallback4((event) => {
|
|
413
536
|
setSearch(event.target.value);
|
|
414
537
|
if (scrollRef.current) scrollRef.current.scrollTop = 0;
|
|
415
538
|
}, []);
|
|
416
539
|
const selectedCount = items.filter((item) => state.isSelected(item.key)).length;
|
|
417
540
|
const checked = selectedCount === 0 ? false : selectedCount === items.length ? true : "indeterminate";
|
|
418
|
-
const toggleAll =
|
|
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);
|
|
419
549
|
const virtual = items.length > 50;
|
|
420
550
|
const virtualizer = useVirtualizer({
|
|
421
551
|
count: items.length,
|
|
@@ -423,6 +553,7 @@ function ListSlicerContent({
|
|
|
423
553
|
estimateSize: () => ROW_HEIGHT,
|
|
424
554
|
getItemKey: (index) => items[index].key,
|
|
425
555
|
overscan: 5,
|
|
556
|
+
rangeExtractor: navigation.rangeExtractor,
|
|
426
557
|
enabled: virtual
|
|
427
558
|
});
|
|
428
559
|
const totalHeight = virtualizer.getTotalSize();
|
|
@@ -430,8 +561,8 @@ function ListSlicerContent({
|
|
|
430
561
|
() => virtual ? { height: totalHeight } : void 0,
|
|
431
562
|
[virtual, totalHeight]
|
|
432
563
|
);
|
|
433
|
-
const [hasMoreBelow, setHasMoreBelow] =
|
|
434
|
-
|
|
564
|
+
const [hasMoreBelow, setHasMoreBelow] = useState3(false);
|
|
565
|
+
useEffect2(() => {
|
|
435
566
|
const scroll = scrollRef.current;
|
|
436
567
|
if (!scroll) return;
|
|
437
568
|
const updateFade = () => {
|
|
@@ -464,33 +595,60 @@ function ListSlicerContent({
|
|
|
464
595
|
clearDisabled: !!state.error || state.items.length === 0
|
|
465
596
|
}
|
|
466
597
|
),
|
|
467
|
-
/* @__PURE__ */ jsx4(
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
)
|
|
494
652
|
]
|
|
495
653
|
}
|
|
496
654
|
);
|
|
@@ -622,9 +780,9 @@ function DropdownSlicerContent(props) {
|
|
|
622
780
|
}
|
|
623
781
|
|
|
624
782
|
// src/components/range-slicer/range-slicer.tsx
|
|
625
|
-
import { useCallback as
|
|
783
|
+
import { useCallback as useCallback8, useId as useId5, useMemo as useMemo6 } from "react";
|
|
626
784
|
import { mergeClasses as mergeClasses3 } from "@griffel/react";
|
|
627
|
-
import { formatString as formatString8, formatValue as formatValue2, getString as getString5 } from "@microsoft/fabric-visuals-core";
|
|
785
|
+
import { formatNumericInput, formatString as formatString8, formatValue as formatValue2, getString as getString5, parseNumericInput } from "@microsoft/fabric-visuals-core";
|
|
628
786
|
|
|
629
787
|
// src/components/range-slicer/range-slicer-data.ts
|
|
630
788
|
import { formatString as formatString4, isDataTable as isDataTable2 } from "@microsoft/fabric-visuals-core";
|
|
@@ -637,6 +795,7 @@ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
|
|
|
637
795
|
title: column,
|
|
638
796
|
format: void 0,
|
|
639
797
|
domain: null,
|
|
798
|
+
hasOnlyIntegerValues: false,
|
|
640
799
|
histogram: [],
|
|
641
800
|
error: formatString4("Common_ColumnNotFound", column)
|
|
642
801
|
};
|
|
@@ -644,6 +803,7 @@ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
|
|
|
644
803
|
const definition = table.columns[columnIndex];
|
|
645
804
|
let minimum;
|
|
646
805
|
let maximum;
|
|
806
|
+
let hasOnlyIntegerValues = true;
|
|
647
807
|
let numericRowCount = 0;
|
|
648
808
|
const validBinCount = includeHistogram ? getValidHistogramBinCount(binCount) : void 0;
|
|
649
809
|
const distinctValues = includeHistogram && validBinCount === void 0 ? /* @__PURE__ */ new Set() : void 0;
|
|
@@ -652,6 +812,7 @@ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
|
|
|
652
812
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
653
813
|
minimum = minimum === void 0 ? value : Math.min(minimum, value);
|
|
654
814
|
maximum = maximum === void 0 ? value : Math.max(maximum, value);
|
|
815
|
+
hasOnlyIntegerValues = hasOnlyIntegerValues && Number.isInteger(value);
|
|
655
816
|
if (distinctValues) {
|
|
656
817
|
numericRowCount++;
|
|
657
818
|
if (distinctValues.size < maxAutomaticHistogramBinCount) distinctValues.add(value);
|
|
@@ -675,6 +836,7 @@ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
|
|
|
675
836
|
title: definition.displayName ?? definition.name,
|
|
676
837
|
format: definition.format,
|
|
677
838
|
domain,
|
|
839
|
+
hasOnlyIntegerValues: domain !== null && hasOnlyIntegerValues,
|
|
678
840
|
histogram
|
|
679
841
|
};
|
|
680
842
|
}
|
|
@@ -867,7 +1029,7 @@ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
|
|
|
867
1029
|
}));
|
|
868
1030
|
|
|
869
1031
|
// src/components/range-slicer/range-value-input.tsx
|
|
870
|
-
import { useCallback as
|
|
1032
|
+
import { useCallback as useCallback5, useId as useId3, useState as useState4 } from "react";
|
|
871
1033
|
import { formatString as formatString5 } from "@microsoft/fabric-visuals-core";
|
|
872
1034
|
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
873
1035
|
function RangeValueInput({
|
|
@@ -878,41 +1040,39 @@ function RangeValueInput({
|
|
|
878
1040
|
disabled,
|
|
879
1041
|
descriptionId,
|
|
880
1042
|
formatValue: formatValue3,
|
|
1043
|
+
parseValue,
|
|
881
1044
|
onCommit
|
|
882
1045
|
}) {
|
|
883
1046
|
const styles = useRangeSlicerStyles();
|
|
884
1047
|
const errorId = useId3();
|
|
885
|
-
const [draft, setDraft] =
|
|
886
|
-
const [error, setError] =
|
|
887
|
-
const
|
|
888
|
-
setDraft(String(value));
|
|
889
|
-
setError(void 0);
|
|
890
|
-
}, [value]);
|
|
891
|
-
const handleChange = useCallback3((event) => {
|
|
1048
|
+
const [draft, setDraft] = useState4();
|
|
1049
|
+
const [error, setError] = useState4();
|
|
1050
|
+
const handleChange = useCallback5((event) => {
|
|
892
1051
|
setDraft(event.currentTarget.value);
|
|
893
1052
|
setError(void 0);
|
|
894
1053
|
}, []);
|
|
895
|
-
const handleBlur =
|
|
1054
|
+
const handleBlur = useCallback5((event) => {
|
|
1055
|
+
if (draft === void 0) return;
|
|
896
1056
|
const text = event.currentTarget.value.trim();
|
|
897
|
-
const nextValue =
|
|
898
|
-
if (
|
|
1057
|
+
const nextValue = parseValue(text);
|
|
1058
|
+
if (nextValue !== void 0 && nextValue >= min && nextValue <= max) {
|
|
899
1059
|
onCommit(nextValue);
|
|
900
1060
|
setDraft(void 0);
|
|
901
1061
|
setError(void 0);
|
|
902
1062
|
} else {
|
|
903
1063
|
setError(formatString5("RangeSlicer_InvalidValue", formatValue3(min), formatValue3(max)));
|
|
904
1064
|
}
|
|
905
|
-
}, [min, max, formatValue3, onCommit]);
|
|
906
|
-
const handleKeyDown =
|
|
1065
|
+
}, [draft, min, max, formatValue3, parseValue, onCommit]);
|
|
1066
|
+
const handleKeyDown = useCallback5((event) => {
|
|
907
1067
|
if (event.key === "Enter") {
|
|
908
1068
|
event.preventDefault();
|
|
909
1069
|
event.currentTarget.blur();
|
|
910
1070
|
} else if (event.key === "Escape") {
|
|
911
1071
|
event.preventDefault();
|
|
912
|
-
setDraft(
|
|
1072
|
+
setDraft(void 0);
|
|
913
1073
|
setError(void 0);
|
|
914
1074
|
}
|
|
915
|
-
}, [
|
|
1075
|
+
}, []);
|
|
916
1076
|
return /* @__PURE__ */ jsxs5("div", { children: [
|
|
917
1077
|
/* @__PURE__ */ jsx7(
|
|
918
1078
|
"input",
|
|
@@ -925,7 +1085,6 @@ function RangeValueInput({
|
|
|
925
1085
|
"aria-invalid": Boolean(error),
|
|
926
1086
|
disabled,
|
|
927
1087
|
value: draft ?? formatValue3(value),
|
|
928
|
-
onFocus: handleFocus,
|
|
929
1088
|
onChange: handleChange,
|
|
930
1089
|
onBlur: handleBlur,
|
|
931
1090
|
onKeyDown: handleKeyDown
|
|
@@ -977,15 +1136,18 @@ function RangeHistogram({ counts, domain, selectedRange, title }) {
|
|
|
977
1136
|
|
|
978
1137
|
// src/components/range-slicer/range-slider.tsx
|
|
979
1138
|
import { Root as Slider, Track, Range, Thumb } from "@radix-ui/react-slider";
|
|
980
|
-
import { useCallback as
|
|
1139
|
+
import { useCallback as useCallback6, useMemo as useMemo4, useRef as useRef4 } from "react";
|
|
981
1140
|
import { formatString as formatString7 } from "@microsoft/fabric-visuals-core";
|
|
982
1141
|
|
|
983
1142
|
// src/components/range-slicer/range-slider-steps.ts
|
|
984
|
-
function getAutomaticRangeStep(domain, formatBound = String) {
|
|
1143
|
+
function getAutomaticRangeStep(domain, formatBound = String, hasOnlyIntegerValues = false) {
|
|
985
1144
|
const [minimum, maximum] = domain;
|
|
986
1145
|
if (minimum === maximum) return 1;
|
|
987
1146
|
const span = maximum - minimum;
|
|
988
1147
|
let step = getNiceStep(Math.max(span / 100, Number.MIN_VALUE));
|
|
1148
|
+
if (hasOnlyIntegerValues) {
|
|
1149
|
+
step = Math.max(1, Math.ceil(step));
|
|
1150
|
+
}
|
|
989
1151
|
while (step < span && hasRepeatedLabels(domain, step, formatBound)) {
|
|
990
1152
|
step = getNiceStep(step * 2);
|
|
991
1153
|
}
|
|
@@ -1015,6 +1177,7 @@ function RangeSlider({
|
|
|
1015
1177
|
domain,
|
|
1016
1178
|
selectedRange,
|
|
1017
1179
|
step,
|
|
1180
|
+
hasOnlyIntegerValues,
|
|
1018
1181
|
disabled,
|
|
1019
1182
|
title,
|
|
1020
1183
|
descriptionId,
|
|
@@ -1023,28 +1186,28 @@ function RangeSlider({
|
|
|
1023
1186
|
onValueCommit
|
|
1024
1187
|
}) {
|
|
1025
1188
|
const styles = useRangeSlicerStyles();
|
|
1026
|
-
const lowerThumb =
|
|
1027
|
-
const upperThumb =
|
|
1028
|
-
const usesAutomaticStep = step === void 0;
|
|
1189
|
+
const lowerThumb = useRef4(null);
|
|
1190
|
+
const upperThumb = useRef4(null);
|
|
1029
1191
|
const sliderStep = useMemo4(
|
|
1030
|
-
() => step ?? getAutomaticRangeStep(domain, formatBound),
|
|
1031
|
-
[domain, step, formatBound]
|
|
1192
|
+
() => step ?? getAutomaticRangeStep(domain, formatBound, hasOnlyIntegerValues),
|
|
1193
|
+
[domain, step, formatBound, hasOnlyIntegerValues]
|
|
1032
1194
|
);
|
|
1033
|
-
const handleKeyDown =
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
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) {
|
|
1041
1205
|
event.preventDefault();
|
|
1042
|
-
onValueChange(
|
|
1043
|
-
onValueCommit(
|
|
1044
|
-
upperThumb.current?.focus();
|
|
1206
|
+
onValueChange(nextRange);
|
|
1207
|
+
onValueCommit(nextRange);
|
|
1045
1208
|
}
|
|
1046
1209
|
}
|
|
1047
|
-
}, [
|
|
1210
|
+
}, [disabled, selectedRange, domain, onValueChange, onValueCommit]);
|
|
1048
1211
|
return /* @__PURE__ */ jsxs7(
|
|
1049
1212
|
Slider,
|
|
1050
1213
|
{
|
|
@@ -1091,7 +1254,7 @@ function RangeSlider({
|
|
|
1091
1254
|
}
|
|
1092
1255
|
|
|
1093
1256
|
// src/components/range-slicer/use-range-selection.ts
|
|
1094
|
-
import { useCallback as
|
|
1257
|
+
import { useCallback as useCallback7, useEffect as useEffect3, useMemo as useMemo5, useRef as useRef5, useState as useState5 } from "react";
|
|
1095
1258
|
function resolveSelection(domain, selection) {
|
|
1096
1259
|
if (selection) {
|
|
1097
1260
|
if (Number.isNaN(selection[0]) || Number.isNaN(selection[1]) || selection[0] > selection[1]) {
|
|
@@ -1108,13 +1271,13 @@ function resolveSelection(domain, selection) {
|
|
|
1108
1271
|
}
|
|
1109
1272
|
function useRangeSelection(domain, column, onInteraction, selection) {
|
|
1110
1273
|
const resolvedSelection = useMemo5(() => resolveSelection(domain, selection), [domain, selection]);
|
|
1111
|
-
const [selectedRange, setSelectedRange] =
|
|
1112
|
-
const lastCommittedRange =
|
|
1113
|
-
const [inputRevision, setInputRevision] =
|
|
1114
|
-
const incrementInputRevision =
|
|
1274
|
+
const [selectedRange, setSelectedRange] = useState5(resolvedSelection);
|
|
1275
|
+
const lastCommittedRange = useRef5(resolvedSelection);
|
|
1276
|
+
const [inputRevision, setInputRevision] = useState5(0);
|
|
1277
|
+
const incrementInputRevision = useCallback7(() => {
|
|
1115
1278
|
setInputRevision((revision) => revision + 1);
|
|
1116
1279
|
}, []);
|
|
1117
|
-
|
|
1280
|
+
useEffect3(() => {
|
|
1118
1281
|
if (selection !== void 0) {
|
|
1119
1282
|
const previousRange = lastCommittedRange.current;
|
|
1120
1283
|
if (previousRange?.[0] === resolvedSelection?.[0] && previousRange?.[1] === resolvedSelection?.[1]) return;
|
|
@@ -1123,7 +1286,7 @@ function useRangeSelection(domain, column, onInteraction, selection) {
|
|
|
1123
1286
|
incrementInputRevision();
|
|
1124
1287
|
}
|
|
1125
1288
|
}, [selection, resolvedSelection, incrementInputRevision]);
|
|
1126
|
-
const commitSelectedRange =
|
|
1289
|
+
const commitSelectedRange = useCallback7((values) => {
|
|
1127
1290
|
if (domain) {
|
|
1128
1291
|
setSelectedRange([values[0], values[1]]);
|
|
1129
1292
|
const previousRange = lastCommittedRange.current;
|
|
@@ -1148,11 +1311,11 @@ function useRangeSelection(domain, column, onInteraction, selection) {
|
|
|
1148
1311
|
}
|
|
1149
1312
|
}
|
|
1150
1313
|
}, [domain, column, onInteraction]);
|
|
1151
|
-
const handleSliderChange =
|
|
1314
|
+
const handleSliderChange = useCallback7((values) => {
|
|
1152
1315
|
setSelectedRange([values[0], values[1]]);
|
|
1153
1316
|
incrementInputRevision();
|
|
1154
1317
|
}, [incrementInputRevision]);
|
|
1155
|
-
const clearSelection =
|
|
1318
|
+
const clearSelection = useCallback7(() => {
|
|
1156
1319
|
setSelectedRange(domain);
|
|
1157
1320
|
lastCommittedRange.current = domain;
|
|
1158
1321
|
incrementInputRevision();
|
|
@@ -1211,11 +1374,13 @@ function RangeSlicer({
|
|
|
1211
1374
|
"--range-stroke": theme.stroke,
|
|
1212
1375
|
fontFamily: theme.typography?.label?.family
|
|
1213
1376
|
} : {}, [theme]);
|
|
1214
|
-
const formatBound =
|
|
1215
|
-
const
|
|
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) => {
|
|
1216
1381
|
if (selectedRange) commitSelectedRange([value, selectedRange[1]]);
|
|
1217
1382
|
}, [selectedRange, commitSelectedRange]);
|
|
1218
|
-
const handleUpperCommit =
|
|
1383
|
+
const handleUpperCommit = useCallback8((value) => {
|
|
1219
1384
|
if (selectedRange) commitSelectedRange([selectedRange[0], value]);
|
|
1220
1385
|
}, [selectedRange, commitSelectedRange]);
|
|
1221
1386
|
if (slicerData.error) return /* @__PURE__ */ jsx10("div", { role: "alert", children: slicerData.error });
|
|
@@ -1244,6 +1409,7 @@ function RangeSlicer({
|
|
|
1244
1409
|
domain: slicerData.domain,
|
|
1245
1410
|
selectedRange,
|
|
1246
1411
|
step: sliderStep,
|
|
1412
|
+
hasOnlyIntegerValues: slicerData.hasOnlyIntegerValues,
|
|
1247
1413
|
disabled: areControlsDisabled,
|
|
1248
1414
|
title: displayTitle,
|
|
1249
1415
|
descriptionId,
|
|
@@ -1262,7 +1428,8 @@ function RangeSlicer({
|
|
|
1262
1428
|
max: selectedRange[1],
|
|
1263
1429
|
disabled: areControlsDisabled,
|
|
1264
1430
|
descriptionId,
|
|
1265
|
-
formatValue:
|
|
1431
|
+
formatValue: formatInput,
|
|
1432
|
+
parseValue: parseInput,
|
|
1266
1433
|
onCommit: handleLowerCommit
|
|
1267
1434
|
},
|
|
1268
1435
|
`lower-${inputRevision}`
|
|
@@ -1277,7 +1444,8 @@ function RangeSlicer({
|
|
|
1277
1444
|
max: slicerData.domain[1],
|
|
1278
1445
|
disabled: areControlsDisabled,
|
|
1279
1446
|
descriptionId,
|
|
1280
|
-
formatValue:
|
|
1447
|
+
formatValue: formatInput,
|
|
1448
|
+
parseValue: parseInput,
|
|
1281
1449
|
onCommit: handleUpperCommit
|
|
1282
1450
|
},
|
|
1283
1451
|
`upper-${inputRevision}`
|
|
@@ -1292,5 +1460,6 @@ function RangeSlicer({
|
|
|
1292
1460
|
export {
|
|
1293
1461
|
DropdownSlicer,
|
|
1294
1462
|
ListSlicer,
|
|
1295
|
-
RangeSlicer
|
|
1463
|
+
RangeSlicer,
|
|
1464
|
+
isSlicerValue
|
|
1296
1465
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/fabric-slicers",
|
|
3
3
|
"description": "Slicer components for Fabric Apps - Analytics",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"author": "Microsoft",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"@tanstack/react-virtual": "^3.13.23",
|
|
28
28
|
"radix-ui": "^1.6.7",
|
|
29
29
|
"@radix-ui/react-slider": "^1.2.0",
|
|
30
|
-
"@microsoft/fabric-visuals-core": "4.
|
|
30
|
+
"@microsoft/fabric-visuals-core": "4.4.0"
|
|
31
31
|
}
|
|
32
32
|
}
|