@itwin/itwinui-react 1.38.0 → 1.40.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.md +30 -0
- package/cjs/core/Carousel/Carousel.js +21 -12
- package/cjs/core/Carousel/CarouselContext.d.ts +4 -2
- package/cjs/core/Carousel/CarouselDotsList.js +1 -0
- package/cjs/core/Carousel/CarouselNavigation.js +8 -10
- package/cjs/core/Carousel/CarouselSlide.js +3 -7
- package/cjs/core/Carousel/CarouselSlider.js +23 -28
- package/cjs/core/ColorPicker/ColorPickerContext.d.ts +2 -2
- package/cjs/core/ComboBox/ComboBox.d.ts +17 -1
- package/cjs/core/ComboBox/ComboBox.js +50 -24
- package/cjs/core/ComboBox/ComboBoxDropdown.d.ts +5 -6
- package/cjs/core/ComboBox/ComboBoxInput.js +28 -9
- package/cjs/core/ComboBox/ComboBoxMenu.js +46 -2
- package/cjs/core/ComboBox/ComboBoxMenuItem.js +2 -3
- package/cjs/core/ComboBox/helpers.d.ts +8 -3
- package/cjs/core/ComboBox/helpers.js +1 -1
- package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
- package/cjs/core/Menu/MenuItemSkeleton.d.ts +32 -0
- package/cjs/core/Menu/MenuItemSkeleton.js +53 -0
- package/cjs/core/Menu/index.d.ts +2 -0
- package/cjs/core/Menu/index.js +3 -1
- package/cjs/core/Select/Select.js +1 -1
- package/cjs/core/Table/Table.js +68 -25
- package/cjs/core/Table/TableCell.js +10 -3
- package/cjs/core/Table/TablePaginator.js +1 -1
- package/cjs/core/Table/TableRowMemoized.js +5 -1
- package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +8 -0
- package/cjs/core/Table/actionHandlers/selectHandler.d.ts +4 -0
- package/cjs/core/Table/columns/selectionColumn.js +4 -2
- package/cjs/core/Table/filters/tableFilters.d.ts +3 -3
- package/cjs/core/Table/hooks/index.d.ts +1 -0
- package/cjs/core/Table/hooks/index.js +3 -1
- package/cjs/core/Table/hooks/useExpanderCell.js +11 -1
- package/cjs/core/Table/hooks/useStickyColumns.d.ts +2 -0
- package/cjs/core/Table/hooks/useStickyColumns.js +84 -0
- package/cjs/core/Table/utils.d.ts +1 -0
- package/cjs/core/Table/utils.js +36 -1
- package/cjs/core/Toast/Toaster.d.ts +1 -1
- package/cjs/core/Toast/Toaster.js +72 -29
- package/cjs/core/index.d.ts +2 -2
- package/cjs/core/index.js +4 -3
- package/cjs/core/utils/components/Popover.d.ts +1 -18
- package/cjs/core/utils/components/VirtualScroll.d.ts +35 -1
- package/cjs/core/utils/components/VirtualScroll.js +159 -26
- package/cjs/core/utils/components/VisuallyHidden.d.ts +9 -0
- package/cjs/core/utils/components/VisuallyHidden.js +44 -0
- package/cjs/core/utils/components/WithCSSTransition.d.ts +1 -2
- package/cjs/core/utils/components/icons.d.ts +4 -4
- package/cjs/core/utils/components/index.d.ts +1 -0
- package/cjs/core/utils/components/index.js +1 -0
- package/cjs/core/utils/hooks/useOverflow.js +4 -2
- package/cjs/core/utils/hooks/useTheme.d.ts +1 -1
- package/cjs/types/react-table-config.d.ts +9 -0
- package/esm/core/Carousel/Carousel.js +21 -12
- package/esm/core/Carousel/CarouselContext.d.ts +4 -2
- package/esm/core/Carousel/CarouselDotsList.js +1 -0
- package/esm/core/Carousel/CarouselNavigation.js +8 -10
- package/esm/core/Carousel/CarouselSlide.js +3 -7
- package/esm/core/Carousel/CarouselSlider.js +24 -29
- package/esm/core/ColorPicker/ColorPickerContext.d.ts +2 -2
- package/esm/core/ComboBox/ComboBox.d.ts +17 -1
- package/esm/core/ComboBox/ComboBox.js +50 -24
- package/esm/core/ComboBox/ComboBoxDropdown.d.ts +5 -6
- package/esm/core/ComboBox/ComboBoxInput.js +28 -9
- package/esm/core/ComboBox/ComboBoxMenu.js +47 -3
- package/esm/core/ComboBox/ComboBoxMenuItem.js +2 -3
- package/esm/core/ComboBox/helpers.d.ts +8 -3
- package/esm/core/ComboBox/helpers.js +1 -1
- package/esm/core/DatePicker/DatePicker.d.ts +1 -1
- package/esm/core/Menu/MenuItemSkeleton.d.ts +32 -0
- package/esm/core/Menu/MenuItemSkeleton.js +46 -0
- package/esm/core/Menu/index.d.ts +2 -0
- package/esm/core/Menu/index.js +1 -0
- package/esm/core/Select/Select.js +1 -1
- package/esm/core/Table/Table.js +70 -27
- package/esm/core/Table/TableCell.js +11 -4
- package/esm/core/Table/TablePaginator.js +1 -1
- package/esm/core/Table/TableRowMemoized.js +5 -1
- package/esm/core/Table/actionHandlers/resizeHandler.d.ts +8 -0
- package/esm/core/Table/actionHandlers/selectHandler.d.ts +4 -0
- package/esm/core/Table/columns/selectionColumn.js +4 -2
- package/esm/core/Table/filters/tableFilters.d.ts +3 -3
- package/esm/core/Table/hooks/index.d.ts +1 -0
- package/esm/core/Table/hooks/index.js +1 -0
- package/esm/core/Table/hooks/useExpanderCell.js +8 -1
- package/esm/core/Table/hooks/useStickyColumns.d.ts +2 -0
- package/esm/core/Table/hooks/useStickyColumns.js +80 -0
- package/esm/core/Table/utils.d.ts +1 -0
- package/esm/core/Table/utils.js +34 -0
- package/esm/core/Toast/Toaster.d.ts +1 -1
- package/esm/core/Toast/Toaster.js +50 -30
- package/esm/core/index.d.ts +2 -2
- package/esm/core/index.js +1 -1
- package/esm/core/utils/components/Popover.d.ts +1 -18
- package/esm/core/utils/components/VirtualScroll.d.ts +35 -1
- package/esm/core/utils/components/VirtualScroll.js +157 -25
- package/esm/core/utils/components/VisuallyHidden.d.ts +9 -0
- package/esm/core/utils/components/VisuallyHidden.js +38 -0
- package/esm/core/utils/components/WithCSSTransition.d.ts +1 -2
- package/esm/core/utils/components/icons.d.ts +4 -4
- package/esm/core/utils/components/index.d.ts +1 -0
- package/esm/core/utils/components/index.js +1 -0
- package/esm/core/utils/hooks/useOverflow.js +4 -2
- package/esm/core/utils/hooks/useTheme.d.ts +1 -1
- package/esm/types/react-table-config.d.ts +9 -0
- package/package.json +24 -39
|
@@ -26,24 +26,7 @@ export declare type PopoverProps = {
|
|
|
26
26
|
* with pre-configured props and plugins (e.g. lazy mounting, focus, etc).
|
|
27
27
|
* @private
|
|
28
28
|
*/
|
|
29
|
-
export declare const Popover: React.ForwardRefExoticComponent<Pick<
|
|
30
|
-
/**
|
|
31
|
-
* Controlled flag for whether the popover is visible.
|
|
32
|
-
*/
|
|
33
|
-
visible?: boolean | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Determines the events that cause the popover to show.
|
|
36
|
-
* Should not be used when `visible` is set.
|
|
37
|
-
* @see [tippy.js trigger prop](https://atomiks.github.io/tippyjs/v6/all-props/#trigger)
|
|
38
|
-
*/
|
|
39
|
-
trigger?: string | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Placement of the popover content.
|
|
42
|
-
* @default 'bottom-start'
|
|
43
|
-
* @see [tippy.js placement prop](https://atomiks.github.io/tippyjs/v6/all-props/#placement).
|
|
44
|
-
*/
|
|
45
|
-
placement?: import("@popperjs/core").Placement | undefined;
|
|
46
|
-
} & Omit<TippyProps, "placement" | "trigger" | "visible">, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<unknown>>;
|
|
29
|
+
export declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverProps, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<unknown>>;
|
|
47
30
|
/**
|
|
48
31
|
* Plugin to hide Popover when either Esc key is pressed,
|
|
49
32
|
* or when the content inside is not tabbable and Tab key is pressed.
|
|
@@ -16,6 +16,10 @@ export declare type VirtualScrollProps = {
|
|
|
16
16
|
* @default 10
|
|
17
17
|
*/
|
|
18
18
|
bufferSize?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Index of the first element on initial render.
|
|
21
|
+
*/
|
|
22
|
+
scrollToIndex?: number;
|
|
19
23
|
} & React.ComponentPropsWithRef<'div'>;
|
|
20
24
|
/**
|
|
21
25
|
* `VirtualScroll` component is used to render a huge amount of items in the DOM. It renders only the ones which are visible
|
|
@@ -38,5 +42,35 @@ export declare type VirtualScrollProps = {
|
|
|
38
42
|
* />
|
|
39
43
|
* @private
|
|
40
44
|
*/
|
|
41
|
-
export declare const VirtualScroll: React.ForwardRefExoticComponent<Pick<VirtualScrollProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "itemsLength" | "itemRenderer" | "bufferSize"> & React.RefAttributes<HTMLDivElement>>;
|
|
45
|
+
export declare const VirtualScroll: React.ForwardRefExoticComponent<Pick<VirtualScrollProps, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "itemsLength" | "itemRenderer" | "bufferSize" | "scrollToIndex"> & React.RefAttributes<HTMLDivElement>>;
|
|
46
|
+
/**
|
|
47
|
+
* `useVirtualization` is used for efficiently rendering only the visible rows from a large list.
|
|
48
|
+
* It returns `outerProps` and `innerProps`, which need to be applied on 2 container elements and `visibleChildren` which is a list of virtualized items.
|
|
49
|
+
* @example
|
|
50
|
+
* const itemRenderer = React.useCallback((index: number) => (
|
|
51
|
+
* <li key={index}>
|
|
52
|
+
* This is my item #{index}
|
|
53
|
+
* </li>
|
|
54
|
+
* ), [])
|
|
55
|
+
*
|
|
56
|
+
* const { outerProps, innerProps, visibleChildren } = useVirtualization({itemsLength: 1000, itemRenderer: itemRenderer});
|
|
57
|
+
* return (
|
|
58
|
+
* <div {...outerProps}>
|
|
59
|
+
* <ul {...innerProps}>
|
|
60
|
+
* {visibleChildren}
|
|
61
|
+
* </ul>
|
|
62
|
+
* </div>
|
|
63
|
+
* );
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
export declare const useVirtualization: (props: VirtualScrollProps) => {
|
|
67
|
+
outerProps: React.HTMLAttributes<HTMLElement>;
|
|
68
|
+
innerProps: {
|
|
69
|
+
readonly style: {
|
|
70
|
+
readonly willChange: "transform";
|
|
71
|
+
};
|
|
72
|
+
readonly ref: (instance: HTMLElement | null) => void;
|
|
73
|
+
};
|
|
74
|
+
visibleChildren: JSX.Element[];
|
|
75
|
+
};
|
|
42
76
|
export default VirtualScroll;
|
|
@@ -25,6 +25,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
25
25
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
26
|
*--------------------------------------------------------------------------------------------*/
|
|
27
27
|
import React from 'react';
|
|
28
|
+
import { mergeRefs } from '../hooks';
|
|
28
29
|
import { useResizeObserver } from '../hooks/useResizeObserver';
|
|
29
30
|
var getScrollableParent = function (element, ownerDocument) {
|
|
30
31
|
if (ownerDocument === void 0) { ownerDocument = document; }
|
|
@@ -46,6 +47,14 @@ var getElementHeight = function (element) {
|
|
|
46
47
|
var _a;
|
|
47
48
|
return (_a = element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height) !== null && _a !== void 0 ? _a : 0;
|
|
48
49
|
};
|
|
50
|
+
var getElementHeightWithMargins = function (element) {
|
|
51
|
+
if (!element) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
var margin = parseFloat(getElementStyle(element, 'margin-top')) +
|
|
55
|
+
parseFloat(getElementStyle(element, 'margin-bottom'));
|
|
56
|
+
return getElementHeight(element) + (isNaN(margin) ? 0 : margin);
|
|
57
|
+
};
|
|
49
58
|
var getNumberOfNodesInHeight = function (childHeight, totalHeight) {
|
|
50
59
|
if (!childHeight) {
|
|
51
60
|
return 0;
|
|
@@ -53,7 +62,10 @@ var getNumberOfNodesInHeight = function (childHeight, totalHeight) {
|
|
|
53
62
|
return Math.floor(totalHeight / childHeight);
|
|
54
63
|
};
|
|
55
64
|
var getTranslateValue = function (childHeight, startIndex) {
|
|
56
|
-
|
|
65
|
+
if (startIndex > 0) {
|
|
66
|
+
return childHeight * startIndex;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
57
69
|
};
|
|
58
70
|
var getVisibleNodeCount = function (childHeight, startIndex, childrenLength, scrollContainer) {
|
|
59
71
|
return Math.min(childrenLength - startIndex, getNumberOfNodesInHeight(childHeight, getElementHeight(scrollContainer)));
|
|
@@ -79,21 +91,55 @@ var getVisibleNodeCount = function (childHeight, startIndex, childrenLength, scr
|
|
|
79
91
|
* />
|
|
80
92
|
* @private
|
|
81
93
|
*/
|
|
82
|
-
export var VirtualScroll = React.forwardRef(function (
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
export var VirtualScroll = React.forwardRef(function (props, ref) {
|
|
95
|
+
var _a = useVirtualization(props), innerProps = _a.innerProps, outerProps = _a.outerProps, visibleChildren = _a.visibleChildren;
|
|
96
|
+
return (React.createElement("div", __assign({}, outerProps, { ref: ref }),
|
|
97
|
+
React.createElement("div", __assign({}, innerProps), visibleChildren)));
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* `useVirtualization` is used for efficiently rendering only the visible rows from a large list.
|
|
101
|
+
* It returns `outerProps` and `innerProps`, which need to be applied on 2 container elements and `visibleChildren` which is a list of virtualized items.
|
|
102
|
+
* @example
|
|
103
|
+
* const itemRenderer = React.useCallback((index: number) => (
|
|
104
|
+
* <li key={index}>
|
|
105
|
+
* This is my item #{index}
|
|
106
|
+
* </li>
|
|
107
|
+
* ), [])
|
|
108
|
+
*
|
|
109
|
+
* const { outerProps, innerProps, visibleChildren } = useVirtualization({itemsLength: 1000, itemRenderer: itemRenderer});
|
|
110
|
+
* return (
|
|
111
|
+
* <div {...outerProps}>
|
|
112
|
+
* <ul {...innerProps}>
|
|
113
|
+
* {visibleChildren}
|
|
114
|
+
* </ul>
|
|
115
|
+
* </div>
|
|
116
|
+
* );
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
export var useVirtualization = function (props) {
|
|
120
|
+
var itemsLength = props.itemsLength, itemRenderer = props.itemRenderer, _a = props.bufferSize, bufferSize = _a === void 0 ? 10 : _a, scrollToIndex = props.scrollToIndex, style = props.style, rest = __rest(props, ["itemsLength", "itemRenderer", "bufferSize", "scrollToIndex", "style"]);
|
|
121
|
+
var _b = React.useState(0), startNode = _b[0], setStartNode = _b[1];
|
|
122
|
+
var _c = React.useState(0), visibleNodeCount = _c[0], setVisibleNodeCount = _c[1];
|
|
86
123
|
var scrollContainer = React.useRef();
|
|
87
124
|
var parentRef = React.useRef(null);
|
|
88
|
-
var childHeight = React.useRef(0);
|
|
125
|
+
var childHeight = React.useRef({ first: 0, middle: 0, last: 0 });
|
|
89
126
|
var onScrollRef = React.useRef();
|
|
90
127
|
// Used only to recalculate on resize
|
|
91
|
-
var
|
|
128
|
+
var _d = React.useState(0), scrollContainerHeight = _d[0], setScrollContainerHeight = _d[1];
|
|
129
|
+
var visibleIndex = React.useRef({ start: 0, end: 0 });
|
|
130
|
+
// Used to mark when scroll container has height (updated by resize observer)
|
|
131
|
+
// because before that calculations are not right
|
|
132
|
+
var _e = React.useState(false), isMounted = _e[0], setIsMounted = _e[1];
|
|
92
133
|
var onResize = React.useCallback(function (_a) {
|
|
93
134
|
var height = _a.height;
|
|
135
|
+
// Initial value returned by resize observer is 0
|
|
136
|
+
// So wait for the next one
|
|
137
|
+
if (height > 0) {
|
|
138
|
+
setIsMounted(true);
|
|
139
|
+
}
|
|
94
140
|
setScrollContainerHeight(height);
|
|
95
141
|
}, []);
|
|
96
|
-
var
|
|
142
|
+
var _f = useResizeObserver(onResize), resizeRef = _f[0], resizeObserver = _f[1];
|
|
97
143
|
// Find scrollable parent
|
|
98
144
|
// Needed only on init
|
|
99
145
|
React.useLayoutEffect(function () {
|
|
@@ -102,6 +148,14 @@ export var VirtualScroll = React.forwardRef(function (_a, ref) {
|
|
|
102
148
|
scrollContainer.current = scrollableParent;
|
|
103
149
|
resizeRef(scrollableParent);
|
|
104
150
|
}, [resizeRef]);
|
|
151
|
+
// Stop watching resize, when virtual scroll is unmounted
|
|
152
|
+
React.useLayoutEffect(function () {
|
|
153
|
+
return function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); };
|
|
154
|
+
}, [resizeObserver]);
|
|
155
|
+
var getScrollableContainer = function () {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
return (_a = scrollContainer.current) !== null && _a !== void 0 ? _a : (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.scrollingElement;
|
|
158
|
+
};
|
|
105
159
|
var visibleChildren = React.useMemo(function () {
|
|
106
160
|
var arr = [];
|
|
107
161
|
var endIndex = Math.min(itemsLength, startNode + visibleNodeCount + bufferSize * 2);
|
|
@@ -112,27 +166,42 @@ export var VirtualScroll = React.forwardRef(function (_a, ref) {
|
|
|
112
166
|
}, [itemsLength, itemRenderer, bufferSize, startNode, visibleNodeCount]);
|
|
113
167
|
// Get child height when children available
|
|
114
168
|
React.useLayoutEffect(function () {
|
|
169
|
+
var _a, _b, _c, _d, _e, _f;
|
|
115
170
|
if (!parentRef.current || !visibleChildren.length) {
|
|
116
171
|
return;
|
|
117
172
|
}
|
|
118
173
|
var firstChild = parentRef.current.children.item(0);
|
|
119
|
-
|
|
174
|
+
var secondChild = parentRef.current.children.item(1);
|
|
175
|
+
var lastChild = parentRef.current.children.item(parentRef.current.children.length - 1);
|
|
176
|
+
var firstChildHeight = Number((_b = (_a = getElementHeightWithMargins(firstChild)) === null || _a === void 0 ? void 0 : _a.toFixed(2)) !== null && _b !== void 0 ? _b : 0);
|
|
177
|
+
childHeight.current = {
|
|
178
|
+
first: firstChildHeight,
|
|
179
|
+
middle: Number((_d = (_c = getElementHeightWithMargins(secondChild)) === null || _c === void 0 ? void 0 : _c.toFixed(2)) !== null && _d !== void 0 ? _d : firstChildHeight),
|
|
180
|
+
last: Number((_f = (_e = getElementHeightWithMargins(lastChild)) === null || _e === void 0 ? void 0 : _e.toFixed(2)) !== null && _f !== void 0 ? _f : firstChildHeight),
|
|
181
|
+
};
|
|
120
182
|
}, [visibleChildren.length]);
|
|
121
183
|
var updateVirtualScroll = React.useCallback(function () {
|
|
122
|
-
var
|
|
123
|
-
var scrollableContainer = (_a = scrollContainer.current) !== null && _a !== void 0 ? _a : (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.scrollingElement;
|
|
184
|
+
var scrollableContainer = getScrollableContainer();
|
|
124
185
|
if (!scrollableContainer) {
|
|
125
186
|
return;
|
|
126
187
|
}
|
|
127
|
-
var start = getNumberOfNodesInHeight(childHeight.current, scrollableContainer.scrollTop);
|
|
128
|
-
var
|
|
188
|
+
var start = getNumberOfNodesInHeight(childHeight.current.middle, Math.round(scrollableContainer.scrollTop));
|
|
189
|
+
var visibleNodes = getVisibleNodeCount(childHeight.current.middle, start, itemsLength, scrollableContainer);
|
|
190
|
+
// If there are less items at the end than buffer size
|
|
191
|
+
// show more items at the start.
|
|
192
|
+
// Have boundaries for edge cases, e.g. 1 item length
|
|
193
|
+
var startIndex = Math.min(Math.max(0, start - bufferSize), Math.max(0, itemsLength - bufferSize * 2 - visibleNodes));
|
|
194
|
+
visibleIndex.current = { start: start, end: start + visibleNodes };
|
|
129
195
|
setStartNode(startIndex);
|
|
130
|
-
setVisibleNodeCount(
|
|
196
|
+
setVisibleNodeCount(visibleNodes);
|
|
131
197
|
if (!parentRef.current) {
|
|
132
198
|
return;
|
|
133
199
|
}
|
|
134
|
-
parentRef.current.style.transform = "translateY(".concat(getTranslateValue(childHeight.current, startIndex), "px)");
|
|
200
|
+
parentRef.current.style.transform = "translateY(".concat(getTranslateValue(childHeight.current.middle, startIndex), "px)");
|
|
135
201
|
}, [bufferSize, itemsLength]);
|
|
202
|
+
var onScroll = React.useCallback(function () {
|
|
203
|
+
updateVirtualScroll();
|
|
204
|
+
}, [updateVirtualScroll]);
|
|
136
205
|
var removeScrollListener = React.useCallback(function () {
|
|
137
206
|
var _a, _b;
|
|
138
207
|
if (!onScrollRef.current) {
|
|
@@ -147,22 +216,85 @@ export var VirtualScroll = React.forwardRef(function (_a, ref) {
|
|
|
147
216
|
React.useLayoutEffect(function () {
|
|
148
217
|
var _a, _b;
|
|
149
218
|
removeScrollListener();
|
|
150
|
-
onScrollRef.current =
|
|
219
|
+
onScrollRef.current = onScroll;
|
|
151
220
|
if (!scrollContainer.current ||
|
|
152
221
|
scrollContainer.current === ((_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.body)) {
|
|
153
|
-
(_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.addEventListener('scroll',
|
|
222
|
+
(_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.addEventListener('scroll', onScroll);
|
|
154
223
|
}
|
|
155
224
|
else {
|
|
156
|
-
scrollContainer.current.addEventListener('scroll',
|
|
225
|
+
scrollContainer.current.addEventListener('scroll', onScroll);
|
|
157
226
|
}
|
|
158
227
|
return removeScrollListener;
|
|
159
|
-
}, [
|
|
228
|
+
}, [onScroll, removeScrollListener]);
|
|
229
|
+
React.useLayoutEffect(function () {
|
|
230
|
+
if (!isMounted) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
var scrollableContainer = getScrollableContainer();
|
|
234
|
+
if (!scrollableContainer || scrollToIndex == null) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
// if `scrollToIndex` is not visible, scroll to it
|
|
238
|
+
if (scrollToIndex > visibleIndex.current.end ||
|
|
239
|
+
scrollToIndex < visibleIndex.current.start) {
|
|
240
|
+
var indexDiff = scrollToIndex > visibleIndex.current.end
|
|
241
|
+
? scrollToIndex - visibleIndex.current.end
|
|
242
|
+
: scrollToIndex - visibleIndex.current.start;
|
|
243
|
+
if (scrollToIndex === 0) {
|
|
244
|
+
scrollableContainer.scrollTo({ top: 0 });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// If go down: add to the existing scrollTop needed height
|
|
248
|
+
// If go up: calculate the exact scroll top
|
|
249
|
+
scrollableContainer.scrollTo({
|
|
250
|
+
top: indexDiff > 0
|
|
251
|
+
? Math.ceil(scrollableContainer.scrollTop) +
|
|
252
|
+
indexDiff * childHeight.current.middle
|
|
253
|
+
: scrollToIndex * childHeight.current.middle,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
// if `scrollToIndex` is the first visible node
|
|
257
|
+
// ensure it is fully visible
|
|
258
|
+
if (scrollToIndex === visibleIndex.current.start) {
|
|
259
|
+
var roundedScrollTop = Math.round(scrollableContainer.scrollTop);
|
|
260
|
+
var diff = roundedScrollTop % childHeight.current.middle;
|
|
261
|
+
diff > 0 &&
|
|
262
|
+
scrollableContainer.scrollTo({
|
|
263
|
+
top: roundedScrollTop - diff,
|
|
264
|
+
});
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
// if `scrollToIndex` is the last visible node
|
|
268
|
+
// ensure it is fully visible
|
|
269
|
+
if (scrollToIndex === visibleIndex.current.end) {
|
|
270
|
+
var diff = (scrollableContainer.offsetHeight - childHeight.current.first) %
|
|
271
|
+
childHeight.current.middle;
|
|
272
|
+
var roundedScrollTop = Math.ceil(scrollableContainer.scrollTop);
|
|
273
|
+
var scrollTopMod = roundedScrollTop % childHeight.current.middle;
|
|
274
|
+
if (diff > 0 && scrollTopMod === 0) {
|
|
275
|
+
scrollableContainer.scrollTo({
|
|
276
|
+
top: roundedScrollTop + childHeight.current.middle - diff,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}, [scrollToIndex, isMounted]);
|
|
160
281
|
React.useLayoutEffect(function () {
|
|
282
|
+
if (!scrollContainerHeight) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
161
285
|
updateVirtualScroll();
|
|
162
|
-
}, [scrollContainerHeight,
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
286
|
+
}, [scrollContainerHeight, updateVirtualScroll]);
|
|
287
|
+
return {
|
|
288
|
+
outerProps: __assign({ style: __assign({ overflow: 'hidden', minHeight: itemsLength > 1
|
|
289
|
+
? Math.max(itemsLength - 2, 0) * childHeight.current.middle +
|
|
290
|
+
childHeight.current.first +
|
|
291
|
+
childHeight.current.last
|
|
292
|
+
: childHeight.current.middle, width: '100%' }, style) }, rest),
|
|
293
|
+
innerProps: {
|
|
294
|
+
style: { willChange: 'transform' },
|
|
295
|
+
ref: mergeRefs(parentRef), // convert object ref to callback ref for better types
|
|
296
|
+
},
|
|
297
|
+
visibleChildren: visibleChildren,
|
|
298
|
+
};
|
|
299
|
+
};
|
|
168
300
|
export default VirtualScroll;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare type VisuallyHiddenProps = React.ComponentPropsWithRef<'div'>;
|
|
3
|
+
/**
|
|
4
|
+
* Hides content visually but is still accessible to screen readers.
|
|
5
|
+
*/
|
|
6
|
+
export declare const VisuallyHidden: React.ForwardRefExoticComponent<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
7
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
8
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export default VisuallyHidden;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
/*---------------------------------------------------------------------------------------------
|
|
24
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
|
+
*--------------------------------------------------------------------------------------------*/
|
|
27
|
+
import React from 'react';
|
|
28
|
+
import cx from 'classnames';
|
|
29
|
+
import { useTheme } from '../hooks';
|
|
30
|
+
/**
|
|
31
|
+
* Hides content visually but is still accessible to screen readers.
|
|
32
|
+
*/
|
|
33
|
+
export var VisuallyHidden = React.forwardRef(function (props, ref) {
|
|
34
|
+
var className = props.className, rest = __rest(props, ["className"]);
|
|
35
|
+
useTheme();
|
|
36
|
+
return (React.createElement("div", __assign({ className: cx('iui-visually-hidden', className), ref: ref }, rest)));
|
|
37
|
+
});
|
|
38
|
+
export default VisuallyHidden;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CSSTransition } from 'react-transition-group';
|
|
3
2
|
import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
|
|
4
|
-
export declare const WithCSSTransition: (props: Partial<
|
|
3
|
+
export declare const WithCSSTransition: (props: Partial<CSSTransitionProps<undefined>> & {
|
|
5
4
|
children: JSX.Element;
|
|
6
5
|
dimension?: "width" | "height" | undefined;
|
|
7
6
|
}) => JSX.Element;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CommonProps } from '../props';
|
|
3
3
|
export declare const StatusIconMap: {
|
|
4
|
-
negative: (args?: CommonProps
|
|
5
|
-
positive: (args?: CommonProps
|
|
6
|
-
warning: (args?: CommonProps
|
|
7
|
-
informational: (args?: CommonProps
|
|
4
|
+
negative: (args?: CommonProps) => JSX.Element;
|
|
5
|
+
positive: (args?: CommonProps) => JSX.Element;
|
|
6
|
+
warning: (args?: CommonProps) => JSX.Element;
|
|
7
|
+
informational: (args?: CommonProps) => JSX.Element;
|
|
8
8
|
};
|
|
@@ -72,8 +72,10 @@ export var useOverflow = function (items, disabled, orientation) {
|
|
|
72
72
|
var childrenSize = Array.from(containerRef.current.children).reduce(function (sum, child) { return sum + child["offset".concat(dimension)]; }, 0);
|
|
73
73
|
var avgItemSize = childrenSize / visibleCount;
|
|
74
74
|
var visibleItems = Math.floor(availableSize / avgItemSize);
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
if (!isNaN(visibleItems)) {
|
|
76
|
+
// Doubling the visible items to overflow the container. Just to be safe.
|
|
77
|
+
setVisibleCount(Math.min(items.length, visibleItems * 2));
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
80
|
needsFullRerender.current = false;
|
|
79
81
|
}, [containerSize, visibleCount, disabled, items.length, orientation]);
|
|
@@ -19,4 +19,4 @@ export declare type ThemeType = 'light' | 'dark' | 'os';
|
|
|
19
19
|
* @param theme Light, dark, or based on OS setting.
|
|
20
20
|
* @param themeOptions Options that override default theming behavior.
|
|
21
21
|
*/
|
|
22
|
-
export declare const useTheme: (theme?: ThemeType
|
|
22
|
+
export declare const useTheme: (theme?: ThemeType, themeOptions?: ThemeOptions) => void;
|
|
@@ -46,6 +46,10 @@ declare module 'react-table' {
|
|
|
46
46
|
};
|
|
47
47
|
isTableResizing?: boolean;
|
|
48
48
|
columnReorderStartIndex: number;
|
|
49
|
+
sticky: {
|
|
50
|
+
isScrolledToRight?: boolean;
|
|
51
|
+
isScrolledToLeft?: boolean;
|
|
52
|
+
};
|
|
49
53
|
}
|
|
50
54
|
interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D>, UseResizeColumnsColumnOptions<D> {
|
|
51
55
|
/**
|
|
@@ -91,12 +95,17 @@ declare module 'react-table' {
|
|
|
91
95
|
* @default false
|
|
92
96
|
*/
|
|
93
97
|
disableToggleVisibility?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Side on which column should be sticked to.
|
|
100
|
+
*/
|
|
101
|
+
sticky?: 'left' | 'right';
|
|
94
102
|
}
|
|
95
103
|
interface ColumnInstance<D extends object = {}> extends UseFiltersColumnProps<D>, UseGroupByColumnProps<D>, UseResizeColumnsColumnProps<D>, UseSortByColumnProps<D> {
|
|
96
104
|
originalWidth: number;
|
|
97
105
|
resizeWidth?: number;
|
|
98
106
|
isResizerVisible?: boolean;
|
|
99
107
|
getDragAndDropProps: () => TableKeyedProps;
|
|
108
|
+
originalSticky?: 'left' | 'right' | 'none';
|
|
100
109
|
}
|
|
101
110
|
interface Cell<D extends object = {}> extends UseGroupByCellProps<D>, UseRowStateCellProps<D> {
|
|
102
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/itwinui-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0",
|
|
4
4
|
"author": "Bentley Systems",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -40,68 +40,53 @@
|
|
|
40
40
|
"lint": "eslint \"**/*.{js,ts,tsx}\" --max-warnings=0",
|
|
41
41
|
"lint:fix": "yarn lint --fix && node ../configs/copyrightLinter.js --fix \"*/**/*.{js,ts,tsx}\"",
|
|
42
42
|
"copy-files": "cpy \"../../{README,LICENSE}.md\" .",
|
|
43
|
-
"
|
|
44
|
-
"dev": "yarn storybook",
|
|
45
|
-
"build-storybook": "yarn copy-files && build-storybook"
|
|
43
|
+
"dev": "yarn build:watch"
|
|
46
44
|
},
|
|
47
45
|
"dependencies": {
|
|
48
|
-
"@itwin/itwinui-css": "^0.
|
|
49
|
-
"@itwin/itwinui-icons-react": "^1.
|
|
50
|
-
"@itwin/itwinui-illustrations-react": "^1.
|
|
46
|
+
"@itwin/itwinui-css": "^0.59.2",
|
|
47
|
+
"@itwin/itwinui-icons-react": "^1.10.1",
|
|
48
|
+
"@itwin/itwinui-illustrations-react": "^1.3.1",
|
|
51
49
|
"@tippyjs/react": "^4.2.5",
|
|
52
50
|
"@types/react-table": "^7.0.18",
|
|
53
51
|
"classnames": "^2.2.6",
|
|
54
52
|
"react-table": "^7.1.0",
|
|
55
|
-
"react-transition-group": "^4.
|
|
53
|
+
"react-transition-group": "^4.4.2"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
56
|
"@babel/core": "^7.12.10",
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@storybook/addons": "~6.4.19",
|
|
63
|
-
"@storybook/api": "~6.4.19",
|
|
64
|
-
"@storybook/builder-webpack5": "~6.4.19",
|
|
65
|
-
"@storybook/components": "~6.4.19",
|
|
66
|
-
"@storybook/core-events": "~6.4.19",
|
|
67
|
-
"@storybook/manager-webpack5": "~6.4.19",
|
|
68
|
-
"@storybook/preset-typescript": "^3.0.0",
|
|
69
|
-
"@storybook/react": "~6.4.19",
|
|
70
|
-
"@storybook/theming": "~6.4.19",
|
|
71
|
-
"@testing-library/jest-dom": "^5.14.1",
|
|
72
|
-
"@testing-library/react": "^12.0.0",
|
|
73
|
-
"@testing-library/react-hooks": "^7.0.1",
|
|
74
|
-
"@testing-library/user-event": "^13.5.0",
|
|
57
|
+
"@testing-library/jest-dom": "^5.16.4",
|
|
58
|
+
"@testing-library/react": "^13.2.0",
|
|
59
|
+
"@testing-library/user-event": "^14.1.1",
|
|
75
60
|
"@types/classnames": "^2.2.7",
|
|
76
61
|
"@types/jest": "^27.0.0",
|
|
77
62
|
"@types/node": "^10.12.2",
|
|
78
|
-
"@types/react": "^
|
|
79
|
-
"@types/react-dom": "^
|
|
80
|
-
"@types/react-transition-group": "^
|
|
63
|
+
"@types/react": "^18.0.6",
|
|
64
|
+
"@types/react-dom": "^18.0.2",
|
|
65
|
+
"@types/react-transition-group": "^4.4.4",
|
|
81
66
|
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
82
67
|
"@typescript-eslint/parser": "^5.17.0",
|
|
83
68
|
"babel-loader": "^8.2.2",
|
|
84
69
|
"concurrently": "^5.3.0",
|
|
85
70
|
"configs": "*",
|
|
86
|
-
"
|
|
71
|
+
"eslint": "^8.12.0",
|
|
72
|
+
"eslint-config-prettier": "^8.5.0",
|
|
87
73
|
"inquirer": "^6.2.2",
|
|
88
|
-
"jest": "^
|
|
89
|
-
"jest-cli": "^
|
|
90
|
-
"jest-
|
|
74
|
+
"jest": "^28.1.0",
|
|
75
|
+
"jest-cli": "^28.1.0",
|
|
76
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
77
|
+
"jest-junit": "^13.2.0",
|
|
91
78
|
"markdown-to-jsx": "6.11.4",
|
|
92
|
-
"react": "^
|
|
93
|
-
"react-dom": "^
|
|
94
|
-
"storybook-dark-mode": "^1.0.9",
|
|
79
|
+
"react": "^18.0.0",
|
|
80
|
+
"react-dom": "^18.0.0",
|
|
95
81
|
"tippy.js": "^6.3.1",
|
|
96
|
-
"ts-jest": "^
|
|
82
|
+
"ts-jest": "^28.0.2",
|
|
97
83
|
"ts-loader": "^9.2.8",
|
|
98
84
|
"ts-node": "^8.0.2",
|
|
99
|
-
"typescript": "^4.4.3"
|
|
100
|
-
"webpack": "5"
|
|
85
|
+
"typescript": "^4.4.3"
|
|
101
86
|
},
|
|
102
87
|
"peerDependencies": {
|
|
103
|
-
"react": "
|
|
104
|
-
"react-dom": "
|
|
88
|
+
"react": ">=16.8.6 < 19.0.0",
|
|
89
|
+
"react-dom": ">=16.8.6 < 19.0.0"
|
|
105
90
|
},
|
|
106
91
|
"lint-staged": {
|
|
107
92
|
"*.{tsx,ts,jsx,js}": [
|