@itwin/itwinui-react 1.44.0 → 1.46.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 (101) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +2 -2
  3. package/cjs/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
  4. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
  5. package/cjs/core/ButtonGroup/ButtonGroup.js +1 -1
  6. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  7. package/cjs/core/DatePicker/DatePicker.d.ts +24 -4
  8. package/cjs/core/DatePicker/DatePicker.js +116 -19
  9. package/cjs/core/Dialog/Dialog.d.ts +5 -5
  10. package/cjs/core/Dialog/Dialog.js +38 -6
  11. package/cjs/core/Dialog/DialogBackdrop.d.ts +2 -2
  12. package/cjs/core/Dialog/DialogBackdrop.js +2 -2
  13. package/cjs/core/Dialog/DialogContext.d.ts +31 -0
  14. package/cjs/core/Dialog/DialogDragContext.d.ts +8 -0
  15. package/cjs/core/Dialog/DialogDragContext.js +28 -0
  16. package/cjs/core/Dialog/DialogMain.d.ts +2 -2
  17. package/cjs/core/Dialog/DialogMain.js +46 -6
  18. package/cjs/core/Dialog/DialogTitleBar.d.ts +2 -2
  19. package/cjs/core/Dialog/DialogTitleBar.js +12 -2
  20. package/cjs/core/Modal/Modal.js +1 -1
  21. package/cjs/core/Table/Table.d.ts +9 -1
  22. package/cjs/core/Table/Table.js +51 -6
  23. package/cjs/core/Table/TableRowMemoized.d.ts +10 -2
  24. package/cjs/core/Table/TableRowMemoized.js +23 -7
  25. package/cjs/core/Table/actionHandlers/index.d.ts +1 -1
  26. package/cjs/core/Table/actionHandlers/index.js +2 -1
  27. package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
  28. package/cjs/core/Table/actionHandlers/selectHandler.d.ts +5 -0
  29. package/cjs/core/Table/actionHandlers/selectHandler.js +35 -2
  30. package/cjs/core/Table/cells/DefaultCell.d.ts +14 -1
  31. package/cjs/core/Table/cells/DefaultCell.js +10 -4
  32. package/cjs/core/index.d.ts +3 -1
  33. package/cjs/core/index.js +6 -3
  34. package/cjs/core/utils/components/MiddleTextTruncation.d.ts +15 -1
  35. package/cjs/core/utils/components/MiddleTextTruncation.js +14 -3
  36. package/cjs/core/utils/components/Resizer.d.ts +31 -0
  37. package/cjs/core/utils/components/Resizer.js +206 -0
  38. package/cjs/core/utils/components/VirtualScroll.js +26 -24
  39. package/cjs/core/utils/components/index.d.ts +1 -0
  40. package/cjs/core/utils/components/index.js +1 -0
  41. package/cjs/core/utils/functions/index.d.ts +1 -0
  42. package/cjs/core/utils/functions/index.js +1 -0
  43. package/cjs/core/utils/functions/styles.d.ts +6 -0
  44. package/cjs/core/utils/functions/styles.js +21 -0
  45. package/cjs/core/utils/hooks/useContainerWidth.d.ts +1 -1
  46. package/cjs/core/utils/hooks/useDragAndDrop.d.ts +14 -0
  47. package/cjs/core/utils/hooks/useDragAndDrop.js +110 -0
  48. package/cjs/core/utils/hooks/useEventListener.d.ts +1 -1
  49. package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
  50. package/cjs/core/utils/hooks/useResizeObserver.d.ts +1 -1
  51. package/cjs/types/react-table-config.d.ts +2 -1
  52. package/esm/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
  53. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
  54. package/esm/core/ButtonGroup/ButtonGroup.js +1 -1
  55. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  56. package/esm/core/DatePicker/DatePicker.d.ts +24 -4
  57. package/esm/core/DatePicker/DatePicker.js +116 -19
  58. package/esm/core/Dialog/Dialog.d.ts +5 -5
  59. package/esm/core/Dialog/Dialog.js +37 -5
  60. package/esm/core/Dialog/DialogBackdrop.d.ts +2 -2
  61. package/esm/core/Dialog/DialogBackdrop.js +2 -2
  62. package/esm/core/Dialog/DialogContext.d.ts +31 -0
  63. package/esm/core/Dialog/DialogDragContext.d.ts +8 -0
  64. package/esm/core/Dialog/DialogDragContext.js +21 -0
  65. package/esm/core/Dialog/DialogMain.d.ts +2 -2
  66. package/esm/core/Dialog/DialogMain.js +47 -7
  67. package/esm/core/Dialog/DialogTitleBar.d.ts +2 -2
  68. package/esm/core/Dialog/DialogTitleBar.js +12 -2
  69. package/esm/core/Modal/Modal.js +1 -1
  70. package/esm/core/Table/Table.d.ts +9 -1
  71. package/esm/core/Table/Table.js +53 -8
  72. package/esm/core/Table/TableRowMemoized.d.ts +10 -2
  73. package/esm/core/Table/TableRowMemoized.js +23 -7
  74. package/esm/core/Table/actionHandlers/index.d.ts +1 -1
  75. package/esm/core/Table/actionHandlers/index.js +1 -1
  76. package/esm/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
  77. package/esm/core/Table/actionHandlers/selectHandler.d.ts +5 -0
  78. package/esm/core/Table/actionHandlers/selectHandler.js +33 -1
  79. package/esm/core/Table/cells/DefaultCell.d.ts +14 -1
  80. package/esm/core/Table/cells/DefaultCell.js +10 -4
  81. package/esm/core/index.d.ts +3 -1
  82. package/esm/core/index.js +2 -1
  83. package/esm/core/utils/components/MiddleTextTruncation.d.ts +15 -1
  84. package/esm/core/utils/components/MiddleTextTruncation.js +14 -3
  85. package/esm/core/utils/components/Resizer.d.ts +31 -0
  86. package/esm/core/utils/components/Resizer.js +199 -0
  87. package/esm/core/utils/components/VirtualScroll.js +26 -24
  88. package/esm/core/utils/components/index.d.ts +1 -0
  89. package/esm/core/utils/components/index.js +1 -0
  90. package/esm/core/utils/functions/index.d.ts +1 -0
  91. package/esm/core/utils/functions/index.js +1 -0
  92. package/esm/core/utils/functions/styles.d.ts +6 -0
  93. package/esm/core/utils/functions/styles.js +17 -0
  94. package/esm/core/utils/hooks/useContainerWidth.d.ts +1 -1
  95. package/esm/core/utils/hooks/useDragAndDrop.d.ts +14 -0
  96. package/esm/core/utils/hooks/useDragAndDrop.js +103 -0
  97. package/esm/core/utils/hooks/useEventListener.d.ts +1 -1
  98. package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
  99. package/esm/core/utils/hooks/useResizeObserver.d.ts +1 -1
  100. package/esm/types/react-table-config.d.ts +2 -1
  101. package/package.json +1 -1
@@ -4,5 +4,5 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  export { onExpandHandler } from './expandHandler';
6
6
  export { onFilterHandler } from './filterHandler';
7
- export { onSelectHandler, onSingleSelectHandler } from './selectHandler';
7
+ export { onSelectHandler, onSingleSelectHandler, onShiftSelectHandler, } from './selectHandler';
8
8
  export { onTableResizeStart, onTableResizeEnd } from './resizeHandler';
@@ -16,6 +16,7 @@ export declare const onTableResizeStart: <T extends Record<string, unknown>>(sta
16
16
  isScrolledToRight?: boolean | undefined;
17
17
  isScrolledToLeft?: boolean | undefined;
18
18
  };
19
+ lastSelectedRowId?: string | undefined;
19
20
  columnOrder: import("react-table").IdType<T>[];
20
21
  expanded: Record<import("react-table").IdType<T>, boolean>;
21
22
  filters: import("react-table").Filters<T>;
@@ -46,6 +47,7 @@ export declare const onTableResizeEnd: <T extends Record<string, unknown>>(state
46
47
  isScrolledToRight?: boolean | undefined;
47
48
  isScrolledToLeft?: boolean | undefined;
48
49
  };
50
+ lastSelectedRowId?: string | undefined;
49
51
  columnOrder: import("react-table").IdType<T>[];
50
52
  expanded: Record<import("react-table").IdType<T>, boolean>;
51
53
  filters: import("react-table").Filters<T>;
@@ -7,6 +7,7 @@ export declare const onSelectHandler: <T extends Record<string, unknown>>(newSta
7
7
  * Handles selection when clicked on a row.
8
8
  */
9
9
  export declare const onSingleSelectHandler: <T extends Record<string, unknown>>(state: TableState<T>, action: ActionType, instance?: TableInstance<T> | undefined, onSelect?: ((selectedData: T[] | undefined, tableState?: TableState<T> | undefined) => void) | undefined, isRowDisabled?: ((rowData: T) => boolean) | undefined) => {
10
+ lastSelectedRowId: any;
10
11
  selectedRowIds: Record<string, boolean>;
11
12
  hiddenColumns?: import("react-table").IdType<T>[] | undefined;
12
13
  columnResizing: {
@@ -36,3 +37,7 @@ export declare const onSingleSelectHandler: <T extends Record<string, unknown>>(
36
37
  }>;
37
38
  sortBy: import("react-table").SortingRule<T>[];
38
39
  };
40
+ /**
41
+ * Handles selection when clicked on a row while shift key is pressed.
42
+ */
43
+ export declare const onShiftSelectHandler: <T extends Record<string, unknown>>(state: TableState<T>, action: ActionType, instance?: TableInstance<T> | undefined, onSelect?: ((selectedData: T[] | undefined, tableState?: TableState<T> | undefined) => void) | undefined, isRowDisabled?: ((rowData: T) => boolean) | undefined) => TableState<T>;
@@ -57,11 +57,43 @@ export var onSingleSelectHandler = function (state, action, instance, onSelect,
57
57
  };
58
58
  handleRow_1(instance.rowsById[action.id]);
59
59
  }
60
- var newState = __assign(__assign({}, state), { selectedRowIds: selectedRowIds });
60
+ var newState = __assign(__assign({}, state), { lastSelectedRowId: action.id, selectedRowIds: selectedRowIds });
61
61
  // Passing to `onSelectHandler` to handle filtered sub-rows
62
62
  onSelectHandler(newState, instance, onSelect, isRowDisabled);
63
63
  return newState;
64
64
  };
65
+ /**
66
+ * Handles selection when clicked on a row while shift key is pressed.
67
+ */
68
+ export var onShiftSelectHandler = function (state, action, instance, onSelect, isRowDisabled) {
69
+ if (instance == null) {
70
+ return state;
71
+ }
72
+ var startIndex = Math.max(0, instance.flatRows.findIndex(function (row) { return row.id === state.lastSelectedRowId; }));
73
+ var endIndex = Math.max(0, instance.flatRows.findIndex(function (row) { return row.id === action.id; }));
74
+ if (startIndex > endIndex) {
75
+ var temp = startIndex;
76
+ startIndex = endIndex;
77
+ endIndex = temp;
78
+ }
79
+ var selectedRowIds = {};
80
+ // 1. Select all rows between start and end
81
+ instance.flatRows
82
+ .slice(startIndex, endIndex + 1)
83
+ .forEach(function (r) { return (selectedRowIds[r.id] = true); });
84
+ // 2. Select all children of the last row (endIndex)
85
+ // Since lastRow's children come after endIndex + 1 (not selected in step 1)
86
+ var handleRow = function (row) {
87
+ selectedRowIds[row.id] = true;
88
+ row.subRows.forEach(function (r) { return handleRow(r); });
89
+ };
90
+ handleRow(instance.flatRows[endIndex]);
91
+ var newState = __assign(__assign({}, state), { selectedRowIds: selectedRowIds });
92
+ // 3.1 Deselect all selected disabled rows and their children
93
+ // 3.2 Convert all partially selected rows marked with tick mark to horizontal line
94
+ onSelectHandler(newState, instance, onSelect, isRowDisabled);
95
+ return newState;
96
+ };
65
97
  var getSelectedData = function (selectedRowIds, instance) {
66
98
  var selectedData = [];
67
99
  var setSelectedData = function (row) {
@@ -1,6 +1,19 @@
1
1
  import React from 'react';
2
2
  import { CellRendererProps } from 'react-table';
3
- export declare type DefaultCellProps<T extends Record<string, unknown>> = CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
3
+ export declare type DefaultCellProps<T extends Record<string, unknown>> = {
4
+ /**
5
+ * Custom icon to be displayed at the beginning of the cell.
6
+ */
7
+ startIcon?: JSX.Element;
8
+ /**
9
+ * Custom icon to be displayed at the end of the cell.
10
+ */
11
+ endIcon?: JSX.Element;
12
+ /**
13
+ * Status of the cell.
14
+ */
15
+ status?: 'positive' | 'negative' | 'warning';
16
+ } & CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
4
17
  /**
5
18
  * Default cell.
6
19
  * It should be passed to `cellRenderer`.
@@ -38,11 +38,17 @@ import cx from 'classnames';
38
38
  * }
39
39
  */
40
40
  export var DefaultCell = function (props) {
41
+ var _a;
41
42
  // Omitting `cellProps`
42
43
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
- var _a = props.cellElementProps, cellElementClassName = _a.className, cellElementStyle = _a.style, cellElementProps = __rest(_a, ["className", "style"]), children = props.children, cellProps = props.cellProps, isDisabled = props.isDisabled, className = props.className, style = props.style, rest = __rest(props, ["cellElementProps", "children", "cellProps", "isDisabled", "className", "style"]);
44
- return (React.createElement("div", __assign({}, cellElementProps, rest, { className: cx(cellElementClassName, className, {
45
- 'iui-disabled': isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(cellProps.row.original),
46
- }), style: __assign(__assign({}, cellElementStyle), style) }), children));
44
+ var _b = props.cellElementProps, cellElementClassName = _b.className, cellElementStyle = _b.style, cellElementProps = __rest(_b, ["className", "style"]), children = props.children, startIcon = props.startIcon, endIcon = props.endIcon, cellProps = props.cellProps, isDisabled = props.isDisabled, className = props.className, style = props.style, status = props.status, rest = __rest(props, ["cellElementProps", "children", "startIcon", "endIcon", "cellProps", "isDisabled", "className", "style", "status"]);
45
+ return (React.createElement("div", __assign({}, cellElementProps, rest, { className: cx(cellElementClassName, className, (_a = {
46
+ 'iui-disabled': isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(cellProps.row.original)
47
+ },
48
+ _a["iui-".concat(status)] = !!status,
49
+ _a)), style: __assign(__assign({}, cellElementStyle), style) }),
50
+ startIcon && React.createElement("div", { className: 'iui-cell-start-icon' }, startIcon),
51
+ children,
52
+ endIcon && React.createElement("div", { className: 'iui-cell-end-icon' }, endIcon)));
47
53
  };
48
54
  export default DefaultCell;
@@ -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';
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { CommonProps } from '../props';
3
3
  export declare type MiddleTextTruncationProps = {
4
4
  /**
@@ -10,12 +10,26 @@ export declare type MiddleTextTruncationProps = {
10
10
  * @default 6
11
11
  */
12
12
  endCharsCount?: number;
13
+ /**
14
+ * Custom renderer for the truncated text.
15
+ */
16
+ textRenderer?: (truncatedText: string, originalText: string) => React.ReactNode;
13
17
  } & CommonProps;
14
18
  /**
15
19
  * Truncates text with the ellipsis in the middle,
16
20
  * leaving defined number of chars at the end.
17
21
  * @example
18
22
  * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
23
+ * @example
24
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' endCharsCount={10} />
25
+ * @example
26
+ * <MiddleTextTruncation
27
+ * text='ThisIsMyVeryLongFileName.dgn'
28
+ * textRenderer={React.useCallback(
29
+ * (truncatedText) => <b>{truncatedText}</b>,
30
+ * []
31
+ * )}
32
+ * />
19
33
  */
20
34
  export declare const MiddleTextTruncation: (props: MiddleTextTruncationProps) => JSX.Element;
21
35
  export default MiddleTextTruncation;
@@ -32,10 +32,21 @@ var ELLIPSIS_CHAR = '…';
32
32
  * leaving defined number of chars at the end.
33
33
  * @example
34
34
  * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
35
+ * @example
36
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' endCharsCount={10} />
37
+ * @example
38
+ * <MiddleTextTruncation
39
+ * text='ThisIsMyVeryLongFileName.dgn'
40
+ * textRenderer={React.useCallback(
41
+ * (truncatedText) => <b>{truncatedText}</b>,
42
+ * []
43
+ * )}
44
+ * />
35
45
  */
36
46
  export var MiddleTextTruncation = function (props) {
37
- var text = props.text, _a = props.endCharsCount, endCharsCount = _a === void 0 ? 6 : _a, style = props.style, rest = __rest(props, ["text", "endCharsCount", "style"]);
38
- var _b = useOverflow(text), ref = _b[0], visibleCount = _b[1];
47
+ var _a;
48
+ var text = props.text, _b = props.endCharsCount, endCharsCount = _b === void 0 ? 6 : _b, textRenderer = props.textRenderer, style = props.style, rest = __rest(props, ["text", "endCharsCount", "textRenderer", "style"]);
49
+ var _c = useOverflow(text), ref = _c[0], visibleCount = _c[1];
39
50
  var truncatedText = React.useMemo(function () {
40
51
  if (visibleCount < text.length) {
41
52
  return "".concat(text.substring(0, visibleCount - endCharsCount - ELLIPSIS_CHAR.length)).concat(ELLIPSIS_CHAR).concat(text.substring(text.length - endCharsCount));
@@ -44,6 +55,6 @@ export var MiddleTextTruncation = function (props) {
44
55
  return text;
45
56
  }
46
57
  }, [endCharsCount, text, visibleCount]);
47
- return (React.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), truncatedText));
58
+ return (React.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), (_a = textRenderer === null || textRenderer === void 0 ? void 0 : textRenderer(truncatedText, text)) !== null && _a !== void 0 ? _a : truncatedText));
48
59
  };
49
60
  export default MiddleTextTruncation;
@@ -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;