@patternfly/react-data-view 6.4.0-prerelease.10 → 6.4.0-prerelease.12
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/cjs/DataViewTh/DataViewTh.d.ts +4 -4
- package/dist/cjs/DataViewTh/DataViewTh.js +8 -1
- package/dist/cjs/Hooks/selection.d.ts +8 -8
- package/dist/esm/DataViewTh/DataViewTh.d.ts +4 -4
- package/dist/esm/DataViewTh/DataViewTh.js +8 -1
- package/dist/esm/Hooks/selection.d.ts +8 -8
- package/package.json +1 -1
- package/src/DataViewTh/DataViewTh.tsx +15 -7
- package/src/Hooks/selection.ts +8 -8
|
@@ -5,13 +5,13 @@ export interface DataViewThResizableProps {
|
|
|
5
5
|
isResizable?: boolean;
|
|
6
6
|
/** Callback after the column is resized. Returns the triggering event, the column id passed in via cell props, and the new width of the column. */
|
|
7
7
|
onResize?: (event: ReactMouseEvent | MouseEvent | ReactKeyboardEvent | KeyboardEvent | TouchEvent, id: string | number | undefined, width: number) => void;
|
|
8
|
-
/**
|
|
8
|
+
/** Starting width in pixels of the column */
|
|
9
9
|
width?: number;
|
|
10
|
-
/** Minimum width of the column */
|
|
10
|
+
/** Minimum resize width in pixels of the column */
|
|
11
11
|
minWidth?: number;
|
|
12
|
-
/** Increment for keyboard navigation */
|
|
12
|
+
/** Increment in pixels for keyboard navigation */
|
|
13
13
|
increment?: number;
|
|
14
|
-
/** Increment for keyboard navigation while shift is held */
|
|
14
|
+
/** Increment in pixels for keyboard navigation while shift is held */
|
|
15
15
|
shiftIncrement?: number;
|
|
16
16
|
/** Provides an accessible name for the resizable column via a human readable string. */
|
|
17
17
|
resizeButtonAriaLabel?: string;
|
|
@@ -216,7 +216,14 @@ const DataViewTh = (_a) => {
|
|
|
216
216
|
onResize && onResize(e, thProps === null || thProps === void 0 ? void 0 : thProps.id, newSize);
|
|
217
217
|
};
|
|
218
218
|
const resizableContent = ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { "aria-live": "polite", className: "pf-v6-screen-reader", children: screenReaderText }), (0, jsx_runtime_1.jsx)(react_core_1.Button, { ref: resizeButtonRef, variant: "plain", hasNoPadding: true, icon: (0, jsx_runtime_1.jsx)(ResizeIcon, {}), onMouseDown: handleMousedown, onKeyDown: handleKeys, onTouchStart: handleTouchStart, "aria-label": resizeButtonAriaLabel, className: classes.dataViewResizableButton })] }));
|
|
219
|
-
|
|
219
|
+
const classNames = [];
|
|
220
|
+
if (thProps === null || thProps === void 0 ? void 0 : thProps.className) {
|
|
221
|
+
classNames.push(thProps.className);
|
|
222
|
+
}
|
|
223
|
+
if (dataViewThClassName) {
|
|
224
|
+
classNames.push(dataViewThClassName);
|
|
225
|
+
}
|
|
226
|
+
return ((0, jsx_runtime_1.jsx)(react_table_1.Th, Object.assign({ modifier: "truncate" }, thProps, props, { ref: thRef, style: width > 0 ? Object.assign(Object.assign({}, thProps === null || thProps === void 0 ? void 0 : thProps.style), { minWidth: width }) : thProps === null || thProps === void 0 ? void 0 : thProps.style, className: classNames.length > 0 ? classNames.join(' ') : undefined }, (isResizable && { additionalContent: resizableContent }), { children: content })));
|
|
220
227
|
};
|
|
221
228
|
exports.DataViewTh = DataViewTh;
|
|
222
229
|
exports.default = exports.DataViewTh;
|
|
@@ -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
|
};
|
|
@@ -5,13 +5,13 @@ export interface DataViewThResizableProps {
|
|
|
5
5
|
isResizable?: boolean;
|
|
6
6
|
/** Callback after the column is resized. Returns the triggering event, the column id passed in via cell props, and the new width of the column. */
|
|
7
7
|
onResize?: (event: ReactMouseEvent | MouseEvent | ReactKeyboardEvent | KeyboardEvent | TouchEvent, id: string | number | undefined, width: number) => void;
|
|
8
|
-
/**
|
|
8
|
+
/** Starting width in pixels of the column */
|
|
9
9
|
width?: number;
|
|
10
|
-
/** Minimum width of the column */
|
|
10
|
+
/** Minimum resize width in pixels of the column */
|
|
11
11
|
minWidth?: number;
|
|
12
|
-
/** Increment for keyboard navigation */
|
|
12
|
+
/** Increment in pixels for keyboard navigation */
|
|
13
13
|
increment?: number;
|
|
14
|
-
/** Increment for keyboard navigation while shift is held */
|
|
14
|
+
/** Increment in pixels for keyboard navigation while shift is held */
|
|
15
15
|
shiftIncrement?: number;
|
|
16
16
|
/** Provides an accessible name for the resizable column via a human readable string. */
|
|
17
17
|
resizeButtonAriaLabel?: string;
|
|
@@ -210,6 +210,13 @@ export const DataViewTh = (_a) => {
|
|
|
210
210
|
onResize && onResize(e, thProps === null || thProps === void 0 ? void 0 : thProps.id, newSize);
|
|
211
211
|
};
|
|
212
212
|
const resizableContent = (_jsxs(Fragment, { children: [_jsx("div", { "aria-live": "polite", className: "pf-v6-screen-reader", children: screenReaderText }), _jsx(Button, { ref: resizeButtonRef, variant: "plain", hasNoPadding: true, icon: _jsx(ResizeIcon, {}), onMouseDown: handleMousedown, onKeyDown: handleKeys, onTouchStart: handleTouchStart, "aria-label": resizeButtonAriaLabel, className: classes.dataViewResizableButton })] }));
|
|
213
|
-
|
|
213
|
+
const classNames = [];
|
|
214
|
+
if (thProps === null || thProps === void 0 ? void 0 : thProps.className) {
|
|
215
|
+
classNames.push(thProps.className);
|
|
216
|
+
}
|
|
217
|
+
if (dataViewThClassName) {
|
|
218
|
+
classNames.push(dataViewThClassName);
|
|
219
|
+
}
|
|
220
|
+
return (_jsx(Th, Object.assign({ modifier: "truncate" }, thProps, props, { ref: thRef, style: width > 0 ? Object.assign(Object.assign({}, thProps === null || thProps === void 0 ? void 0 : thProps.style), { minWidth: width }) : thProps === null || thProps === void 0 ? void 0 : thProps.style, className: classNames.length > 0 ? classNames.join(' ') : undefined }, (isResizable && { additionalContent: resizableContent }), { children: content })));
|
|
214
221
|
};
|
|
215
222
|
export default DataViewTh;
|
|
@@ -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
|
@@ -58,13 +58,13 @@ export interface DataViewThResizableProps {
|
|
|
58
58
|
id: string | number | undefined,
|
|
59
59
|
width: number
|
|
60
60
|
) => void;
|
|
61
|
-
/**
|
|
61
|
+
/** Starting width in pixels of the column */
|
|
62
62
|
width?: number;
|
|
63
|
-
/** Minimum width of the column */
|
|
63
|
+
/** Minimum resize width in pixels of the column */
|
|
64
64
|
minWidth?: number;
|
|
65
|
-
/** Increment for keyboard navigation */
|
|
65
|
+
/** Increment in pixels for keyboard navigation */
|
|
66
66
|
increment?: number;
|
|
67
|
-
/** Increment for keyboard navigation while shift is held */
|
|
67
|
+
/** Increment in pixels for keyboard navigation while shift is held */
|
|
68
68
|
shiftIncrement?: number;
|
|
69
69
|
/** Provides an accessible name for the resizable column via a human readable string. */
|
|
70
70
|
resizeButtonAriaLabel?: string;
|
|
@@ -324,14 +324,22 @@ export const DataViewTh: FC<DataViewThProps> = ({
|
|
|
324
324
|
</Fragment>
|
|
325
325
|
);
|
|
326
326
|
|
|
327
|
+
const classNames: string[] = [];
|
|
328
|
+
if (thProps?.className) {
|
|
329
|
+
classNames.push(thProps.className);
|
|
330
|
+
}
|
|
331
|
+
if (dataViewThClassName) {
|
|
332
|
+
classNames.push(dataViewThClassName);
|
|
333
|
+
}
|
|
334
|
+
|
|
327
335
|
return (
|
|
328
336
|
<Th
|
|
337
|
+
modifier="truncate"
|
|
329
338
|
{...thProps}
|
|
330
339
|
{...props}
|
|
331
|
-
style={width > 0 ? { minWidth: width } : undefined}
|
|
332
340
|
ref={thRef}
|
|
333
|
-
|
|
334
|
-
className={
|
|
341
|
+
style={width > 0 ? { ...thProps?.style, minWidth: width } : thProps?.style}
|
|
342
|
+
className={classNames.length > 0 ? classNames.join(' ') : undefined}
|
|
335
343
|
{...(isResizable && { additionalContent: resizableContent })}
|
|
336
344
|
>
|
|
337
345
|
{content}
|
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
|
|