@itwin/itwinui-react 1.33.0 → 1.34.1
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.md +25 -0
- package/cjs/core/ButtonGroup/ButtonGroup.d.ts +0 -2
- package/cjs/core/ButtonGroup/ButtonGroup.js +3 -4
- package/cjs/core/ComboBox/ComboBox.js +2 -2
- package/cjs/core/Slider/Slider.js +10 -1
- package/cjs/core/Table/Table.d.ts +5 -0
- package/cjs/core/Table/Table.js +8 -8
- package/cjs/core/Table/TableRowMemoized.js +1 -0
- package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
- package/cjs/core/Table/actionHandlers/selectHandler.d.ts +1 -0
- package/cjs/core/Table/filters/BaseFilter.js +1 -1
- package/cjs/core/Table/filters/FilterToggle.js +4 -4
- package/cjs/core/Table/hooks/index.d.ts +1 -0
- package/cjs/core/Table/hooks/index.js +3 -1
- package/cjs/core/Table/hooks/useColumnDragAndDrop.d.ts +2 -0
- package/cjs/core/Table/hooks/useColumnDragAndDrop.js +120 -0
- package/cjs/core/Table/hooks/useExpanderCell.js +1 -0
- package/cjs/core/Table/hooks/useResizeColumns.js +8 -4
- package/cjs/core/Table/hooks/useSelectionCell.js +2 -2
- package/cjs/core/ToggleSwitch/ToggleSwitch.js +13 -10
- package/cjs/core/UserIcon/UserIcon.js +1 -10
- package/cjs/core/utils/hooks/useIntersection.d.ts +4 -3
- package/cjs/core/utils/hooks/useIntersection.js +10 -5
- package/cjs/core/utils/hooks/useOverflow.d.ts +3 -2
- package/cjs/core/utils/hooks/useOverflow.js +24 -21
- package/cjs/types/react-table-config.d.ts +7 -0
- package/esm/core/ButtonGroup/ButtonGroup.d.ts +0 -2
- package/esm/core/ButtonGroup/ButtonGroup.js +3 -4
- package/esm/core/ComboBox/ComboBox.js +2 -2
- package/esm/core/Slider/Slider.js +10 -1
- package/esm/core/Table/Table.d.ts +5 -0
- package/esm/core/Table/Table.js +10 -10
- package/esm/core/Table/TableRowMemoized.js +1 -0
- package/esm/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
- package/esm/core/Table/actionHandlers/selectHandler.d.ts +1 -0
- package/esm/core/Table/filters/BaseFilter.js +1 -1
- package/esm/core/Table/filters/FilterToggle.js +4 -4
- package/esm/core/Table/hooks/index.d.ts +1 -0
- package/esm/core/Table/hooks/index.js +1 -0
- package/esm/core/Table/hooks/useColumnDragAndDrop.d.ts +2 -0
- package/esm/core/Table/hooks/useColumnDragAndDrop.js +116 -0
- package/esm/core/Table/hooks/useExpanderCell.js +1 -0
- package/esm/core/Table/hooks/useResizeColumns.js +8 -4
- package/esm/core/Table/hooks/useSelectionCell.js +2 -2
- package/esm/core/ToggleSwitch/ToggleSwitch.js +13 -10
- package/esm/core/UserIcon/UserIcon.js +1 -10
- package/esm/core/utils/hooks/useIntersection.d.ts +4 -3
- package/esm/core/utils/hooks/useIntersection.js +10 -5
- package/esm/core/utils/hooks/useOverflow.d.ts +3 -2
- package/esm/core/utils/hooks/useOverflow.js +24 -21
- package/esm/types/react-table-config.d.ts +7 -0
- package/package.json +15 -14
|
@@ -6,8 +6,9 @@ import React from 'react';
|
|
|
6
6
|
import { getWindow } from '../functions/dom';
|
|
7
7
|
/**
|
|
8
8
|
* Hook that uses `IntersectionObserver` to trigger `onIntersect` callback when element is in viewport.
|
|
9
|
-
* Callback is called only once.
|
|
10
|
-
*
|
|
9
|
+
* Callback is called only once by default (can be changed using the `once` parameter).
|
|
10
|
+
* @returns a callback ref that needs to be set on the element you want to observe.
|
|
11
|
+
* @private
|
|
11
12
|
* @example
|
|
12
13
|
* const onIntersection = React.useCallback(() => {
|
|
13
14
|
* console.log('Element is in viewport!');
|
|
@@ -15,8 +16,9 @@ import { getWindow } from '../functions/dom';
|
|
|
15
16
|
* const ref = useIntersection(onIntersection);
|
|
16
17
|
* return (<div ref={ref}>One of many elements</div>);
|
|
17
18
|
*/
|
|
18
|
-
export var useIntersection = function (onIntersect, options) {
|
|
19
|
+
export var useIntersection = function (onIntersect, options, once) {
|
|
19
20
|
if (options === void 0) { options = {}; }
|
|
21
|
+
if (once === void 0) { once = true; }
|
|
20
22
|
var root = options.root, rootMargin = options.rootMargin, threshold = options.threshold;
|
|
21
23
|
var observer = React.useRef();
|
|
22
24
|
var setRef = React.useCallback(function (node) {
|
|
@@ -33,11 +35,14 @@ export var useIntersection = function (onIntersect, options) {
|
|
|
33
35
|
observer.current = new IntersectionObserver(function (_a, obs) {
|
|
34
36
|
var entry = _a[0];
|
|
35
37
|
if (entry.isIntersecting) {
|
|
36
|
-
|
|
38
|
+
if (once) {
|
|
39
|
+
obs.disconnect();
|
|
40
|
+
}
|
|
37
41
|
onIntersect();
|
|
38
42
|
}
|
|
39
43
|
}, { root: root, rootMargin: rootMargin, threshold: threshold });
|
|
40
44
|
observer.current.observe(node);
|
|
41
|
-
}, [onIntersect, root, rootMargin, threshold]);
|
|
45
|
+
}, [onIntersect, once, root, rootMargin, threshold]);
|
|
46
|
+
React.useEffect(function () { return function () { var _a; return (_a = observer.current) === null || _a === void 0 ? void 0 : _a.disconnect(); }; }, []);
|
|
42
47
|
return setRef;
|
|
43
48
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Hook that observes the size of an element and returns the number of items
|
|
4
|
-
* that should be visible based on the
|
|
4
|
+
* that should be visible based on the size of the container element.
|
|
5
5
|
*
|
|
6
6
|
* The returned number should be used to render the element with fewer items.
|
|
7
7
|
*
|
|
8
8
|
* @private
|
|
9
9
|
* @param items Items that this element contains.
|
|
10
10
|
* @param disabled Set to true to disconnect the observer.
|
|
11
|
+
* @param dimension 'horizontal' (default) or 'vertical'
|
|
11
12
|
* @returns [callback ref to set on container, stateful count of visible items]
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
@@ -20,4 +21,4 @@ import React from 'react';
|
|
|
20
21
|
* </div>
|
|
21
22
|
* );
|
|
22
23
|
*/
|
|
23
|
-
export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean) => readonly [(instance: T | null) => void, number];
|
|
24
|
+
export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: 'horizontal' | 'vertical') => readonly [(instance: T | null) => void, number];
|
|
@@ -8,13 +8,14 @@ import { useResizeObserver } from './useResizeObserver';
|
|
|
8
8
|
var STARTING_MAX_ITEMS_COUNT = 20;
|
|
9
9
|
/**
|
|
10
10
|
* Hook that observes the size of an element and returns the number of items
|
|
11
|
-
* that should be visible based on the
|
|
11
|
+
* that should be visible based on the size of the container element.
|
|
12
12
|
*
|
|
13
13
|
* The returned number should be used to render the element with fewer items.
|
|
14
14
|
*
|
|
15
15
|
* @private
|
|
16
16
|
* @param items Items that this element contains.
|
|
17
17
|
* @param disabled Set to true to disconnect the observer.
|
|
18
|
+
* @param dimension 'horizontal' (default) or 'vertical'
|
|
18
19
|
* @returns [callback ref to set on container, stateful count of visible items]
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
@@ -27,20 +28,21 @@ var STARTING_MAX_ITEMS_COUNT = 20;
|
|
|
27
28
|
* </div>
|
|
28
29
|
* );
|
|
29
30
|
*/
|
|
30
|
-
export var useOverflow = function (items, disabled) {
|
|
31
|
+
export var useOverflow = function (items, disabled, orientation) {
|
|
31
32
|
if (disabled === void 0) { disabled = false; }
|
|
33
|
+
if (orientation === void 0) { orientation = 'horizontal'; }
|
|
32
34
|
var containerRef = React.useRef(null);
|
|
33
35
|
var _a = React.useState(function () {
|
|
34
36
|
return disabled ? items.length : Math.min(items.length, STARTING_MAX_ITEMS_COUNT);
|
|
35
37
|
}), visibleCount = _a[0], setVisibleCount = _a[1];
|
|
36
38
|
var needsFullRerender = React.useRef(true);
|
|
37
|
-
var _b = React.useState(0),
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var width = _a.width;
|
|
41
|
-
return
|
|
42
|
-
}, []);
|
|
43
|
-
var _c = useResizeObserver(
|
|
39
|
+
var _b = React.useState(0), containerSize = _b[0], setContainerSize = _b[1];
|
|
40
|
+
var previousContainerSize = React.useRef(0);
|
|
41
|
+
var updateContainerSize = React.useCallback(function (_a) {
|
|
42
|
+
var width = _a.width, height = _a.height;
|
|
43
|
+
return setContainerSize(orientation === 'horizontal' ? width : height);
|
|
44
|
+
}, [orientation]);
|
|
45
|
+
var _c = useResizeObserver(updateContainerSize), resizeRef = _c[0], observer = _c[1];
|
|
44
46
|
var resizeObserverRef = React.useRef(observer);
|
|
45
47
|
React.useLayoutEffect(function () {
|
|
46
48
|
if (disabled) {
|
|
@@ -50,7 +52,7 @@ export var useOverflow = function (items, disabled) {
|
|
|
50
52
|
setVisibleCount(Math.min(items.length, STARTING_MAX_ITEMS_COUNT));
|
|
51
53
|
needsFullRerender.current = true;
|
|
52
54
|
}
|
|
53
|
-
}, [
|
|
55
|
+
}, [containerSize, disabled, items]);
|
|
54
56
|
var mergedRefs = useMergedRefs(containerRef, resizeRef);
|
|
55
57
|
React.useLayoutEffect(function () {
|
|
56
58
|
var _a;
|
|
@@ -58,24 +60,25 @@ export var useOverflow = function (items, disabled) {
|
|
|
58
60
|
(_a = resizeObserverRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var
|
|
63
|
+
var dimension = orientation === 'horizontal' ? 'Width' : 'Height';
|
|
64
|
+
var availableSize = containerRef.current["offset" + dimension];
|
|
65
|
+
var requiredSize = containerRef.current["scroll" + dimension];
|
|
66
|
+
if (availableSize < requiredSize) {
|
|
67
|
+
var avgItemSize = requiredSize / visibleCount;
|
|
68
|
+
var visibleItems = Math.floor(availableSize / avgItemSize);
|
|
66
69
|
setVisibleCount(visibleItems);
|
|
67
70
|
}
|
|
68
71
|
else if (needsFullRerender.current) {
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var visibleItems = Math.floor(
|
|
72
|
+
var childrenSize = Array.from(containerRef.current.children).reduce(function (sum, child) { return sum + child["offset" + dimension]; }, 0);
|
|
73
|
+
var avgItemSize = childrenSize / visibleCount;
|
|
74
|
+
var visibleItems = Math.floor(availableSize / avgItemSize);
|
|
72
75
|
// Doubling the visible items to overflow the container. Just to be safe.
|
|
73
76
|
setVisibleCount(Math.min(items.length, visibleItems * 2));
|
|
74
77
|
}
|
|
75
78
|
needsFullRerender.current = false;
|
|
76
|
-
}, [
|
|
79
|
+
}, [containerSize, visibleCount, disabled, items.length, orientation]);
|
|
77
80
|
React.useLayoutEffect(function () {
|
|
78
|
-
|
|
79
|
-
}, [
|
|
81
|
+
previousContainerSize.current = containerSize;
|
|
82
|
+
}, [containerSize]);
|
|
80
83
|
return [mergedRefs, visibleCount];
|
|
81
84
|
};
|
|
@@ -32,6 +32,7 @@ declare module 'react-table' {
|
|
|
32
32
|
isResizingColumn?: string;
|
|
33
33
|
};
|
|
34
34
|
isTableResizing?: boolean;
|
|
35
|
+
columnReorderStartIndex: number;
|
|
35
36
|
}
|
|
36
37
|
interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D>, UseResizeColumnsColumnOptions<D> {
|
|
37
38
|
/**
|
|
@@ -67,11 +68,17 @@ declare module 'react-table' {
|
|
|
67
68
|
* }
|
|
68
69
|
*/
|
|
69
70
|
cellRenderer?: (props: CellRendererProps<D>) => React.ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* If true, column can't be reordered.
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
disableReordering?: boolean;
|
|
70
76
|
}
|
|
71
77
|
interface ColumnInstance<D extends object = {}> extends UseFiltersColumnProps<D>, UseGroupByColumnProps<D>, UseResizeColumnsColumnProps<D>, UseSortByColumnProps<D> {
|
|
72
78
|
originalWidth: number;
|
|
73
79
|
resizeWidth?: number;
|
|
74
80
|
isResizerVisible?: boolean;
|
|
81
|
+
getDragAndDropProps: () => TableKeyedProps;
|
|
75
82
|
}
|
|
76
83
|
interface Cell<D extends object = {}> extends UseGroupByCellProps<D>, UseRowStateCellProps<D> {
|
|
77
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/itwinui-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.1",
|
|
4
4
|
"author": "Bentley Systems",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"build-storybook": "build-storybook"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@itwin/itwinui-css": "^0.
|
|
43
|
+
"@itwin/itwinui-css": "^0.52.0",
|
|
44
44
|
"@itwin/itwinui-icons-react": "^1.5.0",
|
|
45
45
|
"@itwin/itwinui-illustrations-react": "^1.0.1",
|
|
46
46
|
"@tippyjs/react": "^4.2.5",
|
|
@@ -51,17 +51,17 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/core": "^7.12.10",
|
|
54
|
-
"@storybook/addon-essentials": "~6.
|
|
55
|
-
"@storybook/addon-storysource": "~6.
|
|
56
|
-
"@storybook/addons": "~6.
|
|
57
|
-
"@storybook/api": "~6.
|
|
58
|
-
"@storybook/builder-webpack5": "~6.
|
|
59
|
-
"@storybook/components": "~6.
|
|
60
|
-
"@storybook/core-events": "~6.
|
|
61
|
-
"@storybook/manager-webpack5": "~6.
|
|
54
|
+
"@storybook/addon-essentials": "~6.4.19",
|
|
55
|
+
"@storybook/addon-storysource": "~6.4.19",
|
|
56
|
+
"@storybook/addons": "~6.4.19",
|
|
57
|
+
"@storybook/api": "~6.4.19",
|
|
58
|
+
"@storybook/builder-webpack5": "~6.4.19",
|
|
59
|
+
"@storybook/components": "~6.4.19",
|
|
60
|
+
"@storybook/core-events": "~6.4.19",
|
|
61
|
+
"@storybook/manager-webpack5": "~6.4.19",
|
|
62
62
|
"@storybook/preset-typescript": "^3.0.0",
|
|
63
|
-
"@storybook/react": "~6.
|
|
64
|
-
"@storybook/theming": "~6.
|
|
63
|
+
"@storybook/react": "~6.4.19",
|
|
64
|
+
"@storybook/theming": "~6.4.19",
|
|
65
65
|
"@testing-library/jest-dom": "^5.14.1",
|
|
66
66
|
"@testing-library/react": "^12.0.0",
|
|
67
67
|
"@testing-library/react-hooks": "^7.0.1",
|
|
@@ -77,12 +77,13 @@
|
|
|
77
77
|
"babel-loader": "^8.2.2",
|
|
78
78
|
"concurrently": "^5.3.0",
|
|
79
79
|
"cpx": "^1.5.0",
|
|
80
|
-
"creevey": "^0.
|
|
80
|
+
"creevey": "^0.8.0-beta.0",
|
|
81
81
|
"eslint": "^7.32.0",
|
|
82
82
|
"eslint-config-prettier": "^8.3.0",
|
|
83
83
|
"eslint-plugin-prettier": "^4.0.0",
|
|
84
84
|
"eslint-plugin-react": "^7.25.1",
|
|
85
85
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
86
|
+
"eslint-plugin-storybook": "^0.5.7",
|
|
86
87
|
"fast-glob": "^3.2.5",
|
|
87
88
|
"husky": "^4.0.0",
|
|
88
89
|
"inquirer": "^6.2.2",
|
|
@@ -96,7 +97,7 @@
|
|
|
96
97
|
"react": "^17.0.2",
|
|
97
98
|
"react-dom": "^17.0.2",
|
|
98
99
|
"rimraf": "^2.6.2",
|
|
99
|
-
"storybook-dark-mode": "^1.0.
|
|
100
|
+
"storybook-dark-mode": "^1.0.9",
|
|
100
101
|
"tippy.js": "^6.3.1",
|
|
101
102
|
"ts-jest": "^27.0.4",
|
|
102
103
|
"ts-loader": "^8.0.1",
|