@patternfly/react-data-view 6.4.0-prerelease.10 → 6.4.0-prerelease.11
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.
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export interface UseDataViewSelectionProps {
|
|
1
|
+
export interface UseDataViewSelectionProps<T = any> {
|
|
2
2
|
/** Function to compare items when checking if item is selected */
|
|
3
|
-
matchOption: (item:
|
|
3
|
+
matchOption: (item: T, another: T) => boolean;
|
|
4
4
|
/** Array of initially selected entries */
|
|
5
|
-
initialSelected?: (
|
|
5
|
+
initialSelected?: (T)[];
|
|
6
6
|
}
|
|
7
|
-
export declare const useDataViewSelection: (props?: UseDataViewSelectionProps) => {
|
|
8
|
-
selected:
|
|
9
|
-
onSelect: (isSelecting: boolean, items?:
|
|
10
|
-
isSelected: (item:
|
|
11
|
-
setSelected: (items:
|
|
7
|
+
export declare const useDataViewSelection: <T = any>(props?: UseDataViewSelectionProps<T>) => {
|
|
8
|
+
selected: T[];
|
|
9
|
+
onSelect: (isSelecting: boolean, items?: T[] | T) => void;
|
|
10
|
+
isSelected: (item: T) => boolean;
|
|
11
|
+
setSelected: (items: T[]) => void;
|
|
12
12
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export interface UseDataViewSelectionProps {
|
|
1
|
+
export interface UseDataViewSelectionProps<T = any> {
|
|
2
2
|
/** Function to compare items when checking if item is selected */
|
|
3
|
-
matchOption: (item:
|
|
3
|
+
matchOption: (item: T, another: T) => boolean;
|
|
4
4
|
/** Array of initially selected entries */
|
|
5
|
-
initialSelected?: (
|
|
5
|
+
initialSelected?: (T)[];
|
|
6
6
|
}
|
|
7
|
-
export declare const useDataViewSelection: (props?: UseDataViewSelectionProps) => {
|
|
8
|
-
selected:
|
|
9
|
-
onSelect: (isSelecting: boolean, items?:
|
|
10
|
-
isSelected: (item:
|
|
11
|
-
setSelected: (items:
|
|
7
|
+
export declare const useDataViewSelection: <T = any>(props?: UseDataViewSelectionProps<T>) => {
|
|
8
|
+
selected: T[];
|
|
9
|
+
onSelect: (isSelecting: boolean, items?: T[] | T) => void;
|
|
10
|
+
isSelected: (item: T) => boolean;
|
|
11
|
+
setSelected: (items: T[]) => void;
|
|
12
12
|
};
|
package/package.json
CHANGED
package/src/Hooks/selection.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
|
|
4
|
-
export interface UseDataViewSelectionProps {
|
|
4
|
+
export interface UseDataViewSelectionProps<T = any> {
|
|
5
5
|
/** Function to compare items when checking if item is selected */
|
|
6
|
-
matchOption: (item:
|
|
6
|
+
matchOption: (item: T, another: T) => boolean;
|
|
7
7
|
/** Array of initially selected entries */
|
|
8
|
-
initialSelected?: (
|
|
8
|
+
initialSelected?: (T)[];
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const useDataViewSelection = (props?: UseDataViewSelectionProps) => {
|
|
12
|
-
const [ selected, setSelected ] = useState<
|
|
11
|
+
export const useDataViewSelection = <T = any>(props?: UseDataViewSelectionProps<T>) => {
|
|
12
|
+
const [ selected, setSelected ] = useState<T[]>(props?.initialSelected ?? []);
|
|
13
13
|
const matchOption = props?.matchOption ? props.matchOption : (option, another) => (option === another);
|
|
14
14
|
|
|
15
|
-
const onSelect = (isSelecting: boolean, items?:
|
|
15
|
+
const onSelect = (isSelecting: boolean, items?: T[] | T) => {
|
|
16
16
|
isSelecting && items ?
|
|
17
17
|
setSelected(prev => {
|
|
18
18
|
const newSelectedItems = [ ...prev ];
|
|
@@ -22,9 +22,9 @@ export const useDataViewSelection = (props?: UseDataViewSelectionProps) => {
|
|
|
22
22
|
: setSelected(items ? prev => prev.filter(prevSelected => !(Array.isArray(items) ? items : [ items ]).some(item => matchOption(item, prevSelected))) : []);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const isSelected = (item:
|
|
25
|
+
const isSelected = (item: T): boolean => Boolean(selected.find(selected => matchOption(selected, item)));
|
|
26
26
|
|
|
27
|
-
const setSelectedItems = (items:
|
|
27
|
+
const setSelectedItems = (items: T[]) => {
|
|
28
28
|
setSelected(items);
|
|
29
29
|
};
|
|
30
30
|
|