@itwin/itwinui-react 1.45.0 → 1.47.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/cjs/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
  3. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
  4. package/cjs/core/ButtonGroup/ButtonGroup.js +1 -1
  5. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  6. package/cjs/core/DatePicker/DatePicker.d.ts +24 -4
  7. package/cjs/core/DatePicker/DatePicker.js +116 -19
  8. package/cjs/core/Dialog/Dialog.d.ts +5 -5
  9. package/cjs/core/Dialog/Dialog.js +38 -6
  10. package/cjs/core/Dialog/DialogBackdrop.d.ts +2 -2
  11. package/cjs/core/Dialog/DialogBackdrop.js +2 -2
  12. package/cjs/core/Dialog/DialogContext.d.ts +31 -0
  13. package/cjs/core/Dialog/DialogDragContext.d.ts +8 -0
  14. package/cjs/core/Dialog/DialogDragContext.js +28 -0
  15. package/cjs/core/Dialog/DialogMain.d.ts +2 -2
  16. package/cjs/core/Dialog/DialogMain.js +46 -6
  17. package/cjs/core/Dialog/DialogTitleBar.d.ts +2 -2
  18. package/cjs/core/Dialog/DialogTitleBar.js +12 -2
  19. package/cjs/core/Modal/Modal.js +1 -1
  20. package/cjs/core/Table/Table.d.ts +6 -0
  21. package/cjs/core/Table/Table.js +73 -17
  22. package/cjs/core/Table/actionHandlers/index.d.ts +1 -1
  23. package/cjs/core/Table/actionHandlers/index.js +2 -1
  24. package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
  25. package/cjs/core/Table/actionHandlers/selectHandler.d.ts +5 -0
  26. package/cjs/core/Table/actionHandlers/selectHandler.js +35 -2
  27. package/cjs/core/Table/filters/FilterToggle.d.ts +0 -1
  28. package/cjs/core/Table/filters/FilterToggle.js +3 -3
  29. package/cjs/core/Table/hooks/useResizeColumns.d.ts +33 -1
  30. package/cjs/core/Table/hooks/useResizeColumns.js +89 -29
  31. package/cjs/core/index.d.ts +3 -1
  32. package/cjs/core/index.js +6 -3
  33. package/cjs/core/utils/components/Resizer.d.ts +31 -0
  34. package/cjs/core/utils/components/Resizer.js +206 -0
  35. package/cjs/core/utils/components/VirtualScroll.js +26 -24
  36. package/cjs/core/utils/components/index.d.ts +1 -0
  37. package/cjs/core/utils/components/index.js +1 -0
  38. package/cjs/core/utils/functions/index.d.ts +1 -0
  39. package/cjs/core/utils/functions/index.js +1 -0
  40. package/cjs/core/utils/functions/styles.d.ts +6 -0
  41. package/cjs/core/utils/functions/styles.js +21 -0
  42. package/cjs/core/utils/hooks/useContainerWidth.d.ts +1 -1
  43. package/cjs/core/utils/hooks/useDragAndDrop.d.ts +14 -0
  44. package/cjs/core/utils/hooks/useDragAndDrop.js +110 -0
  45. package/cjs/core/utils/hooks/useEventListener.d.ts +1 -1
  46. package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
  47. package/cjs/core/utils/hooks/useResizeObserver.d.ts +1 -1
  48. package/cjs/types/react-table-config.d.ts +13 -1
  49. package/esm/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
  50. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
  51. package/esm/core/ButtonGroup/ButtonGroup.js +1 -1
  52. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  53. package/esm/core/DatePicker/DatePicker.d.ts +24 -4
  54. package/esm/core/DatePicker/DatePicker.js +116 -19
  55. package/esm/core/Dialog/Dialog.d.ts +5 -5
  56. package/esm/core/Dialog/Dialog.js +37 -5
  57. package/esm/core/Dialog/DialogBackdrop.d.ts +2 -2
  58. package/esm/core/Dialog/DialogBackdrop.js +2 -2
  59. package/esm/core/Dialog/DialogContext.d.ts +31 -0
  60. package/esm/core/Dialog/DialogDragContext.d.ts +8 -0
  61. package/esm/core/Dialog/DialogDragContext.js +21 -0
  62. package/esm/core/Dialog/DialogMain.d.ts +2 -2
  63. package/esm/core/Dialog/DialogMain.js +47 -7
  64. package/esm/core/Dialog/DialogTitleBar.d.ts +2 -2
  65. package/esm/core/Dialog/DialogTitleBar.js +12 -2
  66. package/esm/core/Modal/Modal.js +1 -1
  67. package/esm/core/Table/Table.d.ts +6 -0
  68. package/esm/core/Table/Table.js +76 -20
  69. package/esm/core/Table/actionHandlers/index.d.ts +1 -1
  70. package/esm/core/Table/actionHandlers/index.js +1 -1
  71. package/esm/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
  72. package/esm/core/Table/actionHandlers/selectHandler.d.ts +5 -0
  73. package/esm/core/Table/actionHandlers/selectHandler.js +33 -1
  74. package/esm/core/Table/filters/FilterToggle.d.ts +0 -1
  75. package/esm/core/Table/filters/FilterToggle.js +4 -4
  76. package/esm/core/Table/hooks/useResizeColumns.d.ts +33 -1
  77. package/esm/core/Table/hooks/useResizeColumns.js +89 -29
  78. package/esm/core/index.d.ts +3 -1
  79. package/esm/core/index.js +2 -1
  80. package/esm/core/utils/components/Resizer.d.ts +31 -0
  81. package/esm/core/utils/components/Resizer.js +199 -0
  82. package/esm/core/utils/components/VirtualScroll.js +26 -24
  83. package/esm/core/utils/components/index.d.ts +1 -0
  84. package/esm/core/utils/components/index.js +1 -0
  85. package/esm/core/utils/functions/index.d.ts +1 -0
  86. package/esm/core/utils/functions/index.js +1 -0
  87. package/esm/core/utils/functions/styles.d.ts +6 -0
  88. package/esm/core/utils/functions/styles.js +17 -0
  89. package/esm/core/utils/hooks/useContainerWidth.d.ts +1 -1
  90. package/esm/core/utils/hooks/useDragAndDrop.d.ts +14 -0
  91. package/esm/core/utils/hooks/useDragAndDrop.js +103 -0
  92. package/esm/core/utils/hooks/useEventListener.d.ts +1 -1
  93. package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
  94. package/esm/core/utils/hooks/useResizeObserver.d.ts +1 -1
  95. package/esm/types/react-table-config.d.ts +13 -1
  96. package/package.json +1 -1
@@ -20,6 +20,8 @@ export { ComboBox } from './ComboBox';
20
20
  export type { ComboBoxProps } from './ComboBox';
21
21
  export { DatePicker, generateLocalizedStrings } from './DatePicker';
22
22
  export type { DatePickerProps } from './DatePicker';
23
+ export { Dialog } from './Dialog';
24
+ export type { DialogProps, DialogButtonBarProps, DialogContentProps, DialogMainProps, DialogTitleBarProps, } from './Dialog';
23
25
  export { DropdownMenu } from './DropdownMenu';
24
26
  export type { DropdownMenuProps } from './DropdownMenu';
25
27
  export { ErrorPage } from './ErrorPage';
@@ -72,7 +74,7 @@ export { StatusMessage } from './StatusMessage';
72
74
  export type { StatusMessageProps } from './StatusMessage';
73
75
  export { Surface } from './Surface';
74
76
  export type { SurfaceProps } from './Surface';
75
- export { Table, tableFilters, FilterButtonBar, DefaultCell, EditableCell, TablePaginator, ActionColumn, ExpanderColumn, SelectionColumn, } from './Table';
77
+ export { Table, tableFilters, BaseFilter, FilterButtonBar, DefaultCell, EditableCell, TablePaginator, ActionColumn, ExpanderColumn, SelectionColumn, } from './Table';
76
78
  export type { TableProps, TableFilterProps, TableFilterValue, DateRangeFilterOptions, FilterButtonBarProps, DefaultCellProps, EditableCellProps, TablePaginatorProps, TablePaginatorRendererProps, } from './Table';
77
79
  export { Tag, TagContainer } from './Tag';
78
80
  export type { TagProps, TagContainerProps } from './Tag';
package/esm/core/index.js CHANGED
@@ -13,6 +13,7 @@ export { Checkbox } from './Checkbox';
13
13
  export { ColorPicker, ColorSwatch, ColorBuilder, ColorInputPanel, ColorPalette, } from './ColorPicker';
14
14
  export { ComboBox } from './ComboBox';
15
15
  export { DatePicker, generateLocalizedStrings } from './DatePicker';
16
+ export { Dialog } from './Dialog';
16
17
  export { DropdownMenu } from './DropdownMenu';
17
18
  export { ErrorPage } from './ErrorPage';
18
19
  export { ExpandableBlock } from './ExpandableBlock';
@@ -39,7 +40,7 @@ export { SkipToContentLink } from './SkipToContentLink';
39
40
  export { Slider } from './Slider';
40
41
  export { StatusMessage } from './StatusMessage';
41
42
  export { Surface } from './Surface';
42
- export { Table, tableFilters, FilterButtonBar, DefaultCell, EditableCell, TablePaginator, ActionColumn, ExpanderColumn, SelectionColumn, } from './Table';
43
+ export { Table, tableFilters, BaseFilter, FilterButtonBar, DefaultCell, EditableCell, TablePaginator, ActionColumn, ExpanderColumn, SelectionColumn, } from './Table';
43
44
  export { Tag, TagContainer } from './Tag';
44
45
  export { Textarea } from './Textarea';
45
46
  export { Tile } from './Tile';
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export declare type ResizerProps = {
3
+ /**
4
+ * Ref of the element that is being resized.
5
+ */
6
+ elementRef: React.RefObject<HTMLElement>;
7
+ /**
8
+ * Ref of the container element in order to avoid resizing past container boundaries.
9
+ * If not passed, viewport will be used.
10
+ */
11
+ containerRef?: React.RefObject<HTMLElement>;
12
+ /**
13
+ * Callback that is being called on resize end.
14
+ * Useful to preserve state if element is being closed.
15
+ */
16
+ onResizeEnd?: (style: React.CSSProperties) => void;
17
+ };
18
+ /**
19
+ * Component that allows to resize parent element.
20
+ * Parent must have `position: relative`.
21
+ * @private
22
+ * @example
23
+ * const ref = React.useRef<HTMLDivElement>(null);
24
+ * return (
25
+ * <div ref={ref} style={{ position: 'relative' }}>
26
+ * <Resizer elementRef={ref} />
27
+ * </div>
28
+ * );
29
+ */
30
+ export declare const Resizer: (props: ResizerProps) => JSX.Element;
31
+ export default Resizer;
@@ -0,0 +1,199 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import React from 'react';
6
+ import { getBoundedValue, getTranslateValues } from '../functions';
7
+ /**
8
+ * Component that allows to resize parent element.
9
+ * Parent must have `position: relative`.
10
+ * @private
11
+ * @example
12
+ * const ref = React.useRef<HTMLDivElement>(null);
13
+ * return (
14
+ * <div ref={ref} style={{ position: 'relative' }}>
15
+ * <Resizer elementRef={ref} />
16
+ * </div>
17
+ * );
18
+ */
19
+ export var Resizer = function (props) {
20
+ var elementRef = props.elementRef, containerRef = props.containerRef, onResizeEnd = props.onResizeEnd;
21
+ var onResizePointerDown = function (event) {
22
+ if (!elementRef.current || event.button !== 0) {
23
+ return;
24
+ }
25
+ var initialPointerX = event.clientX;
26
+ var initialPointerY = event.clientY;
27
+ var _a = getTranslateValues(elementRef.current), initialTranslateX = _a[0], initialTranslateY = _a[1];
28
+ var _b = elementRef.current.getBoundingClientRect(), initialWidth = _b.width, initialHeight = _b.height;
29
+ var width = "".concat(initialWidth, "px");
30
+ var height = "".concat(initialHeight, "px");
31
+ var translateX = initialTranslateX;
32
+ var translateY = initialTranslateY;
33
+ var minWidth = parseFloat(getComputedStyle(elementRef.current).minWidth);
34
+ var minHeight = parseFloat(getComputedStyle(elementRef.current).minHeight);
35
+ var resizer = event.currentTarget.dataset.iuiResizer;
36
+ var originalUserSelect = elementRef.current.ownerDocument.body.style.userSelect;
37
+ elementRef.current.ownerDocument.body.style.userSelect = 'none';
38
+ var onResizePointerMove = function (event) {
39
+ var _a, _b, _c, _d, _e, _f, _g;
40
+ if (!elementRef.current) {
41
+ return;
42
+ }
43
+ var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
44
+ var clientX = getBoundedValue(event.clientX, (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) !== null && _b !== void 0 ? _b : 0, (_d = (_c = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _c !== void 0 ? _c : elementRef.current.ownerDocument.documentElement.clientWidth) !== null && _d !== void 0 ? _d : 0);
45
+ var clientY = getBoundedValue(event.clientY, (_e = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _e !== void 0 ? _e : 0, (_g = (_f = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _f !== void 0 ? _f : elementRef.current.ownerDocument.documentElement.clientHeight) !== null && _g !== void 0 ? _g : 0);
46
+ var diffX = initialPointerX - clientX;
47
+ var diffY = initialPointerY - clientY;
48
+ switch (resizer) {
49
+ case 'top-left': {
50
+ var newHeight = initialHeight + diffY;
51
+ if (newHeight >= minHeight) {
52
+ height = elementRef.current.style.height = "".concat(newHeight, "px");
53
+ translateY = initialTranslateY - diffY;
54
+ }
55
+ var newWidth = initialWidth + diffX;
56
+ if (newWidth >= minWidth) {
57
+ width = elementRef.current.style.width = "".concat(newWidth, "px");
58
+ translateX = initialTranslateX - diffX;
59
+ }
60
+ elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
61
+ break;
62
+ }
63
+ case 'top': {
64
+ var newHeight = initialHeight + diffY;
65
+ if (newHeight < minHeight) {
66
+ break;
67
+ }
68
+ height = elementRef.current.style.height = "".concat(newHeight, "px");
69
+ translateY = initialTranslateY - diffY;
70
+ elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
71
+ break;
72
+ }
73
+ case 'top-right': {
74
+ var newHeight = initialHeight + diffY;
75
+ if (newHeight >= minHeight) {
76
+ height = elementRef.current.style.height = "".concat(newHeight, "px");
77
+ translateY = initialTranslateY - diffY;
78
+ }
79
+ width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
80
+ elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
81
+ break;
82
+ }
83
+ case 'right': {
84
+ width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
85
+ break;
86
+ }
87
+ case 'bottom-right': {
88
+ width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
89
+ height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
90
+ break;
91
+ }
92
+ case 'bottom': {
93
+ height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
94
+ break;
95
+ }
96
+ case 'bottom-left': {
97
+ var newWidth = initialWidth + diffX;
98
+ if (newWidth >= minWidth) {
99
+ width = elementRef.current.style.width = "".concat(newWidth, "px");
100
+ translateX = initialTranslateX - diffX;
101
+ }
102
+ height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
103
+ elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
104
+ break;
105
+ }
106
+ case 'left': {
107
+ var newWidth = initialWidth + diffX;
108
+ if (newWidth < minWidth) {
109
+ break;
110
+ }
111
+ width = elementRef.current.style.width = "".concat(newWidth, "px");
112
+ translateX = initialTranslateX - diffX;
113
+ elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
114
+ break;
115
+ }
116
+ default:
117
+ break;
118
+ }
119
+ };
120
+ elementRef.current.ownerDocument.addEventListener('pointermove', onResizePointerMove);
121
+ elementRef.current.ownerDocument.addEventListener('pointerup', function () {
122
+ document.removeEventListener('pointermove', onResizePointerMove);
123
+ if (elementRef.current) {
124
+ elementRef.current.ownerDocument.body.style.userSelect = originalUserSelect;
125
+ onResizeEnd === null || onResizeEnd === void 0 ? void 0 : onResizeEnd({
126
+ width: width,
127
+ height: height,
128
+ transform: "translate(".concat(translateX, "px, ").concat(translateY, "px)"),
129
+ });
130
+ }
131
+ }, { once: true });
132
+ };
133
+ return (React.createElement(React.Fragment, null,
134
+ React.createElement("div", { "data-iui-resizer": 'top-left', onPointerDown: onResizePointerDown, style: {
135
+ position: 'absolute',
136
+ top: -4,
137
+ left: -4,
138
+ width: 12,
139
+ height: 12,
140
+ cursor: 'nw-resize',
141
+ } }),
142
+ React.createElement("div", { "data-iui-resizer": 'top', onPointerDown: onResizePointerDown, style: {
143
+ position: 'absolute',
144
+ top: -4,
145
+ left: 8,
146
+ right: 8,
147
+ height: 8,
148
+ cursor: 'n-resize',
149
+ } }),
150
+ React.createElement("div", { "data-iui-resizer": 'top-right', onPointerDown: onResizePointerDown, style: {
151
+ position: 'absolute',
152
+ top: -4,
153
+ right: -4,
154
+ width: 12,
155
+ height: 12,
156
+ cursor: 'ne-resize',
157
+ } }),
158
+ React.createElement("div", { "data-iui-resizer": 'right', onPointerDown: onResizePointerDown, style: {
159
+ position: 'absolute',
160
+ top: 8,
161
+ right: -4,
162
+ bottom: 8,
163
+ width: 8,
164
+ cursor: 'e-resize',
165
+ } }),
166
+ React.createElement("div", { "data-iui-resizer": 'bottom-right', onPointerDown: onResizePointerDown, style: {
167
+ position: 'absolute',
168
+ bottom: -4,
169
+ right: -4,
170
+ width: 12,
171
+ height: 12,
172
+ cursor: 'se-resize',
173
+ } }),
174
+ React.createElement("div", { "data-iui-resizer": 'bottom', onPointerDown: onResizePointerDown, style: {
175
+ position: 'absolute',
176
+ bottom: -4,
177
+ left: 8,
178
+ right: 8,
179
+ height: 8,
180
+ cursor: 's-resize',
181
+ } }),
182
+ React.createElement("div", { "data-iui-resizer": 'bottom-left', onPointerDown: onResizePointerDown, style: {
183
+ position: 'absolute',
184
+ bottom: -4,
185
+ left: -4,
186
+ width: 12,
187
+ height: 12,
188
+ cursor: 'sw-resize',
189
+ } }),
190
+ React.createElement("div", { "data-iui-resizer": 'left', onPointerDown: onResizePointerDown, style: {
191
+ position: 'absolute',
192
+ top: 8,
193
+ left: -4,
194
+ bottom: 8,
195
+ width: 8,
196
+ cursor: 'w-resize',
197
+ } })));
198
+ };
199
+ export default Resizer;
@@ -130,28 +130,6 @@ export var useVirtualization = function (props) {
130
130
  // Used to mark when scroll container has height (updated by resize observer)
131
131
  // because before that calculations are not right
132
132
  var _e = React.useState(false), isMounted = _e[0], setIsMounted = _e[1];
133
- var onResize = React.useCallback(function (_a) {
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
- }
140
- setScrollContainerHeight(height);
141
- }, []);
142
- var _f = useResizeObserver(onResize), resizeRef = _f[0], resizeObserver = _f[1];
143
- // Find scrollable parent
144
- // Needed only on init
145
- React.useLayoutEffect(function () {
146
- var _a;
147
- var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
148
- scrollContainer.current = scrollableParent;
149
- resizeRef(scrollableParent);
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
133
  var getScrollableContainer = function () {
156
134
  var _a, _b;
157
135
  return (_a = scrollContainer.current) !== null && _a !== void 0 ? _a : (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.scrollingElement;
@@ -164,8 +142,7 @@ export var useVirtualization = function (props) {
164
142
  }
165
143
  return arr;
166
144
  }, [itemsLength, itemRenderer, bufferSize, startNode, visibleNodeCount]);
167
- // Get child height when children available
168
- React.useLayoutEffect(function () {
145
+ var updateChildHeight = React.useCallback(function () {
169
146
  var _a, _b, _c, _d, _e, _f;
170
147
  if (!parentRef.current || !visibleChildren.length) {
171
148
  return;
@@ -180,6 +157,31 @@ export var useVirtualization = function (props) {
180
157
  last: Number((_f = (_e = getElementHeightWithMargins(lastChild)) === null || _e === void 0 ? void 0 : _e.toFixed(2)) !== null && _f !== void 0 ? _f : firstChildHeight),
181
158
  };
182
159
  }, [visibleChildren.length]);
160
+ var onResize = React.useCallback(function (_a) {
161
+ var height = _a.height;
162
+ // Initial value returned by resize observer is 0
163
+ // So wait for the next one
164
+ if (height > 0) {
165
+ setIsMounted(true);
166
+ }
167
+ setScrollContainerHeight(height);
168
+ updateChildHeight();
169
+ }, [updateChildHeight]);
170
+ var _f = useResizeObserver(onResize), resizeRef = _f[0], resizeObserver = _f[1];
171
+ // Find scrollable parent
172
+ // Needed only on init
173
+ React.useLayoutEffect(function () {
174
+ var _a;
175
+ var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
176
+ scrollContainer.current = scrollableParent;
177
+ resizeRef(scrollableParent);
178
+ }, [resizeRef]);
179
+ // Stop watching resize, when virtual scroll is unmounted
180
+ React.useLayoutEffect(function () {
181
+ return function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); };
182
+ }, [resizeObserver]);
183
+ // Get child height when children available
184
+ React.useLayoutEffect(function () { return updateChildHeight(); }, [updateChildHeight]);
183
185
  var updateVirtualScroll = React.useCallback(function () {
184
186
  var scrollableContainer = getScrollableContainer();
185
187
  if (!scrollableContainer) {
@@ -1,4 +1,5 @@
1
1
  export * from './Popover';
2
+ export * from './Resizer';
2
3
  export * from './FocusTrap';
3
4
  export * from './InputContainer';
4
5
  export * from './icons';
@@ -3,6 +3,7 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  export * from './Popover';
6
+ export * from './Resizer';
6
7
  export * from './FocusTrap';
7
8
  export * from './InputContainer';
8
9
  export * from './icons';
@@ -2,3 +2,4 @@ export * from './dom';
2
2
  export * from './colors';
3
3
  export * from './numbers';
4
4
  export * from './focusable';
5
+ export * from './styles';
@@ -6,3 +6,4 @@ export * from './dom';
6
6
  export * from './colors';
7
7
  export * from './numbers';
8
8
  export * from './focusable';
9
+ export * from './styles';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns translate values as an array of a given element.
3
+ * @param element HTML element you want to get translate value of
4
+ * @returns Translate values in pixels in a array `[translateX, translateY]`
5
+ */
6
+ export declare const getTranslateValues: (element: HTMLElement | null | undefined) => number[];
@@ -0,0 +1,17 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /**
6
+ * Returns translate values as an array of a given element.
7
+ * @param element HTML element you want to get translate value of
8
+ * @returns Translate values in pixels in a array `[translateX, translateY]`
9
+ */
10
+ export var getTranslateValues = function (element) {
11
+ if (!element) {
12
+ return [];
13
+ }
14
+ var transformValue = getComputedStyle(element).getPropertyValue('transform');
15
+ var matrix = new DOMMatrix(transformValue);
16
+ return [matrix.m41, matrix.m42];
17
+ };
@@ -13,5 +13,5 @@
13
13
  * ... // do something with width
14
14
  * return <div ref={ref}>...</div>;
15
15
  */
16
- export declare const useContainerWidth: <T extends HTMLElement>(watchResizes?: boolean) => readonly [(instance: HTMLElement | null) => void, number];
16
+ export declare const useContainerWidth: <T extends HTMLElement>(watchResizes?: boolean) => readonly [(instance: HTMLElement | null | undefined) => void, number];
17
17
  export default useContainerWidth;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ /**
3
+ * Helper hook that handles elements drag logic.
4
+ * @param elementRef Element ref that is draggable.
5
+ * @param containerRect Bounding rectangle of container element that element can't go outside. If not passed window is used as a container.
6
+ * @returns
7
+ * `onPointerDown` - handler that is called when pointer is down and handles all the dragging logic.
8
+ * `transform` - current transform of the element, it is used to preserve drag position when element visibility is being toggled.
9
+ */
10
+ export declare const useDragAndDrop: (elementRef: React.RefObject<HTMLElement>, containerRef?: React.RefObject<HTMLElement>, enabled?: boolean) => {
11
+ onPointerDown: (e: React.PointerEvent<HTMLElement>) => void;
12
+ transform: string;
13
+ };
14
+ export default useDragAndDrop;
@@ -0,0 +1,103 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import React from 'react';
6
+ import { getTranslateValues, getWindow } from '../functions';
7
+ import { useEventListener } from './useEventListener';
8
+ import { useResizeObserver } from './useResizeObserver';
9
+ var getContainerRect = function (containerRef) {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11
+ var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
12
+ return {
13
+ top: (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _b !== void 0 ? _b : 0,
14
+ right: (_e = (_c = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _c !== void 0 ? _c : (_d = getWindow()) === null || _d === void 0 ? void 0 : _d.innerWidth) !== null && _e !== void 0 ? _e : 0,
15
+ bottom: (_h = (_f = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _f !== void 0 ? _f : (_g = getWindow()) === null || _g === void 0 ? void 0 : _g.innerHeight) !== null && _h !== void 0 ? _h : 0,
16
+ left: (_j = containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) !== null && _j !== void 0 ? _j : 0,
17
+ };
18
+ };
19
+ /**
20
+ * Helper hook that handles elements drag logic.
21
+ * @param elementRef Element ref that is draggable.
22
+ * @param containerRect Bounding rectangle of container element that element can't go outside. If not passed window is used as a container.
23
+ * @returns
24
+ * `onPointerDown` - handler that is called when pointer is down and handles all the dragging logic.
25
+ * `transform` - current transform of the element, it is used to preserve drag position when element visibility is being toggled.
26
+ */
27
+ export var useDragAndDrop = function (elementRef, containerRef, enabled) {
28
+ if (enabled === void 0) { enabled = true; }
29
+ var grabOffsetX = React.useRef(0);
30
+ var grabOffsetY = React.useRef(0);
31
+ var translateX = React.useRef();
32
+ var translateY = React.useRef();
33
+ var containerRectRef = React.useRef(getContainerRect(containerRef));
34
+ var adjustTransform = React.useCallback(function () {
35
+ var _a;
36
+ if (!elementRef.current || !enabled) {
37
+ return;
38
+ }
39
+ var _b = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(), top = _b.top, right = _b.right, bottom = _b.bottom, left = _b.left;
40
+ var _c = getTranslateValues(elementRef.current), newTranslateX = _c[0], newTranslateY = _c[1];
41
+ containerRectRef.current = getContainerRect(containerRef);
42
+ if (bottom > containerRectRef.current.bottom) {
43
+ newTranslateY -= bottom - containerRectRef.current.bottom;
44
+ }
45
+ if (top < containerRectRef.current.top) {
46
+ newTranslateY += containerRectRef.current.top - top;
47
+ }
48
+ if (right > containerRectRef.current.right) {
49
+ newTranslateX -= right - containerRectRef.current.right;
50
+ }
51
+ if (left < containerRectRef.current.left) {
52
+ newTranslateX += containerRectRef.current.left - left;
53
+ }
54
+ translateX.current = newTranslateX;
55
+ translateY.current = newTranslateY;
56
+ elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
57
+ }, [containerRef, elementRef, enabled]);
58
+ var _a = useResizeObserver(adjustTransform), resizeRef = _a[0], resizeObserver = _a[1];
59
+ resizeRef(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current);
60
+ React.useEffect(function () {
61
+ return function () {
62
+ resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
63
+ };
64
+ }, [resizeObserver]);
65
+ useEventListener('resize', function () {
66
+ adjustTransform();
67
+ if (translateX.current != null && translateY.current != null) {
68
+ setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
69
+ }
70
+ }, getWindow());
71
+ var _b = React.useState(''), transform = _b[0], setTransform = _b[1];
72
+ var onPointerMove = React.useRef(function (event) {
73
+ if (!elementRef.current) {
74
+ return;
75
+ }
76
+ var newTranslateX = event.clientX - grabOffsetX.current;
77
+ var newTranslateY = event.clientY - grabOffsetY.current;
78
+ elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
79
+ adjustTransform();
80
+ });
81
+ var originalUserSelect = React.useRef('');
82
+ var onPointerDown = React.useCallback(function (e) {
83
+ if (!elementRef.current || e.button !== 0 || !enabled) {
84
+ return;
85
+ }
86
+ var _a = getTranslateValues(elementRef.current), x = _a[0], y = _a[1];
87
+ grabOffsetX.current = e.clientX - x;
88
+ grabOffsetY.current = e.clientY - y;
89
+ originalUserSelect.current = elementRef.current.style.userSelect;
90
+ // Prevents from selecting inner content when dragging.
91
+ elementRef.current.style.userSelect = 'none';
92
+ elementRef.current.ownerDocument.addEventListener('pointermove', onPointerMove.current);
93
+ elementRef.current.ownerDocument.addEventListener('pointerup', function () {
94
+ setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
95
+ document.removeEventListener('pointermove', onPointerMove.current);
96
+ if (elementRef.current) {
97
+ elementRef.current.style.userSelect = originalUserSelect.current;
98
+ }
99
+ }, { once: true });
100
+ }, [elementRef, enabled]);
101
+ return { onPointerDown: onPointerDown, transform: transform };
102
+ };
103
+ export default useDragAndDrop;
@@ -7,4 +7,4 @@
7
7
  * containerRef.current?.ownerDocument,
8
8
  * );
9
9
  */
10
- export declare const useEventListener: (eventName: string, handler: (event: Event) => void, element: HTMLElement | Document | undefined) => void;
10
+ export declare const useEventListener: (eventName: string, handler: (event: Event) => void, element: HTMLElement | Document | Window | undefined) => void;
@@ -21,4 +21,4 @@ import React from 'react';
21
21
  * </div>
22
22
  * );
23
23
  */
24
- export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: 'horizontal' | 'vertical') => 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 | undefined) => void, number];
@@ -10,4 +10,4 @@
10
10
  * ...
11
11
  * return <div ref={ref}>...</div>;
12
12
  */
13
- export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null) => void, ResizeObserver | undefined];
13
+ export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null | undefined) => void, ResizeObserver | undefined];
@@ -19,7 +19,7 @@ declare module 'react-table' {
19
19
  */
20
20
  isDisabled?: (rowData: D) => boolean;
21
21
  };
22
- interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
22
+ interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, UseGlobalFiltersOptions<D>, UseGlobalFiltersColumnOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
23
23
  /**
24
24
  * Table data list.
25
25
  * Must be memoized.
@@ -28,11 +28,22 @@ declare module 'react-table' {
28
28
  * If some rows don't have sub-data, it is recommended to pass an empty array to `subRows` for consistent spacing.
29
29
  */
30
30
  data: D[];
31
+ /**
32
+ * Column's resize mode.
33
+ * - `fit` - when resizing it affects current and the next column,
34
+ * e.g. when increasing width of current column, next column's width will decrease.
35
+ * - `expand` - when resizing it affects only the current column,
36
+ * e.g. when increasing width of the current column, next column's width remains the same.
37
+ * @default 'fit'
38
+ */
39
+ columnResizeMode?: 'fit' | 'expand';
31
40
  }
32
41
  interface Hooks<D extends object = {}> extends UseExpandedHooks<D>, UseGroupByHooks<D>, UseRowSelectHooks<D>, UseSortByHooks<D> {
33
42
  }
34
43
  interface TableInstance<D extends object = {}> extends UseColumnOrderInstanceProps<D>, UseExpandedInstanceProps<D>, UseFiltersInstanceProps<D>, UseGlobalFiltersInstanceProps<D>, UseGroupByInstanceProps<D>, UsePaginationInstanceProps<D>, UseRowSelectInstanceProps<D>, UseRowStateInstanceProps<D>, UseSortByInstanceProps<D> {
35
44
  initialRows: Row<D>[];
45
+ columnResizeMode: TableOptions['columnResizeMode'];
46
+ tableWidth: number;
36
47
  }
37
48
  interface TableState<D extends object = {}> extends UseColumnOrderState<D>, UseExpandedState<D>, UseFiltersState<D>, UseGlobalFiltersState<D>, UseGroupByState<D>, UsePaginationState<D>, UseRowSelectState<D>, UseRowStateState<D>, UseSortByState<D> {
38
49
  columnResizing: {
@@ -50,6 +61,7 @@ declare module 'react-table' {
50
61
  isScrolledToRight?: boolean;
51
62
  isScrolledToLeft?: boolean;
52
63
  };
64
+ lastSelectedRowId?: string;
53
65
  }
54
66
  interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D>, UseResizeColumnsColumnOptions<D> {
55
67
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "1.45.0",
3
+ "version": "1.47.0",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "main": "cjs/index.js",