@itwin/itwinui-react 1.35.0 → 1.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/cjs/core/Alert/Alert.js +1 -1
  3. package/cjs/core/Badge/Badge.js +1 -1
  4. package/cjs/core/Breadcrumbs/Breadcrumbs.d.ts +2 -2
  5. package/cjs/core/Buttons/Button/Button.js +2 -2
  6. package/cjs/core/Buttons/IconButton/IconButton.js +2 -2
  7. package/cjs/core/Carousel/Carousel.js +1 -1
  8. package/cjs/core/Carousel/CarouselDotsList.js +1 -1
  9. package/cjs/core/Carousel/CarouselSlider.js +1 -1
  10. package/cjs/core/Checkbox/Checkbox.js +1 -1
  11. package/cjs/core/ColorPicker/ColorBuilder.js +3 -3
  12. package/cjs/core/ColorPicker/ColorInputPanel.js +1 -1
  13. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  14. package/cjs/core/ColorPicker/ColorSwatch.js +1 -1
  15. package/cjs/core/ComboBox/ComboBox.js +9 -6
  16. package/cjs/core/DatePicker/DatePicker.js +2 -2
  17. package/cjs/core/ExpandableBlock/ExpandableBlock.js +1 -1
  18. package/cjs/core/Footer/Footer.js +2 -2
  19. package/cjs/core/Header/HeaderBreadcrumbs.js +1 -1
  20. package/cjs/core/Header/HeaderButton.js +1 -0
  21. package/cjs/core/InformationPanel/InformationPanel.js +2 -2
  22. package/cjs/core/Input/Input.js +1 -1
  23. package/cjs/core/Menu/Menu.js +8 -3
  24. package/cjs/core/ProgressIndicators/ProgressLinear/ProgressLinear.d.ts +1 -1
  25. package/cjs/core/ProgressIndicators/ProgressLinear/ProgressLinear.js +2 -2
  26. package/cjs/core/ProgressIndicators/ProgressRadial/ProgressRadial.js +2 -2
  27. package/cjs/core/Radio/Radio.js +1 -1
  28. package/cjs/core/Select/Select.js +3 -3
  29. package/cjs/core/SkipToContentLink/SkipToContentLink.d.ts +33 -0
  30. package/cjs/core/SkipToContentLink/SkipToContentLink.js +50 -0
  31. package/cjs/core/SkipToContentLink/index.d.ts +4 -0
  32. package/cjs/core/SkipToContentLink/index.js +10 -0
  33. package/cjs/core/Slider/Slider.js +1 -1
  34. package/cjs/core/Slider/Thumb.js +1 -1
  35. package/cjs/core/Slider/Track.js +1 -1
  36. package/cjs/core/Surface/Surface.d.ts +32 -0
  37. package/cjs/core/Surface/Surface.js +70 -0
  38. package/cjs/core/Surface/index.d.ts +4 -0
  39. package/cjs/core/Surface/index.js +10 -0
  40. package/cjs/core/Table/Table.d.ts +7 -0
  41. package/cjs/core/Table/Table.js +44 -21
  42. package/cjs/core/Table/TableCell.js +3 -3
  43. package/cjs/core/Table/TablePaginator.js +6 -6
  44. package/cjs/core/Table/TableRowMemoized.js +13 -8
  45. package/cjs/core/Table/actionHandlers/index.d.ts +2 -1
  46. package/cjs/core/Table/actionHandlers/index.js +5 -1
  47. package/cjs/core/Table/cells/DefaultCell.d.ts +1 -1
  48. package/cjs/core/Table/cells/DefaultCell.js +5 -2
  49. package/cjs/core/Table/columns/actionColumn.d.ts +35 -0
  50. package/cjs/core/Table/columns/actionColumn.js +91 -0
  51. package/cjs/core/Table/columns/expanderColumn.d.ts +47 -0
  52. package/cjs/core/Table/columns/expanderColumn.js +81 -0
  53. package/cjs/core/Table/columns/index.d.ts +3 -0
  54. package/cjs/core/Table/columns/index.js +15 -0
  55. package/cjs/core/Table/columns/selectionColumn.d.ts +35 -0
  56. package/cjs/core/Table/columns/selectionColumn.js +67 -0
  57. package/cjs/core/Table/hooks/index.d.ts +2 -2
  58. package/cjs/core/Table/hooks/index.js +1 -3
  59. package/cjs/core/Table/hooks/useExpanderCell.d.ts +0 -1
  60. package/cjs/core/Table/hooks/useExpanderCell.js +25 -39
  61. package/cjs/core/Table/hooks/useResizeColumns.js +8 -2
  62. package/cjs/core/Table/hooks/useSelectionCell.d.ts +1 -2
  63. package/cjs/core/Table/hooks/useSelectionCell.js +8 -53
  64. package/cjs/core/Table/index.d.ts +1 -0
  65. package/cjs/core/Table/index.js +5 -1
  66. package/cjs/core/Table/utils.js +5 -5
  67. package/cjs/core/Tabs/Tabs.d.ts +1 -1
  68. package/cjs/core/Tabs/Tabs.js +7 -8
  69. package/cjs/core/Tag/Tag.js +6 -3
  70. package/cjs/core/Tag/TagContainer.js +1 -1
  71. package/cjs/core/Tile/Tile.d.ts +6 -2
  72. package/cjs/core/Tile/Tile.js +8 -3
  73. package/cjs/core/Toast/Toast.js +3 -3
  74. package/cjs/core/Toast/ToastWrapper.js +1 -1
  75. package/cjs/core/Tree/TreeNode.js +2 -2
  76. package/cjs/core/Typography/Anchor/Anchor.d.ts +1 -0
  77. package/cjs/core/Typography/Anchor/Anchor.js +1 -0
  78. package/cjs/core/Typography/Text/Text.js +1 -1
  79. package/cjs/core/UserIcon/UserIcon.js +2 -2
  80. package/cjs/core/UserIconGroup/UserIconGroup.js +3 -3
  81. package/cjs/core/Wizard/Step.js +1 -1
  82. package/cjs/core/Wizard/Wizard.js +1 -1
  83. package/cjs/core/index.d.ts +5 -1
  84. package/cjs/core/index.js +9 -2
  85. package/cjs/core/utils/color/ColorValue.js +11 -11
  86. package/cjs/core/utils/color/index.js +5 -1
  87. package/cjs/core/utils/components/FocusTrap.js +6 -8
  88. package/cjs/core/utils/components/InputContainer.js +1 -1
  89. package/cjs/core/utils/components/MiddleTextTruncation.js +1 -1
  90. package/cjs/core/utils/components/Popover.js +13 -1
  91. package/cjs/core/utils/components/VirtualScroll.js +1 -1
  92. package/cjs/core/utils/components/WithCSSTransition.js +5 -5
  93. package/cjs/core/utils/components/index.js +5 -1
  94. package/cjs/core/utils/functions/focusable.js +1 -1
  95. package/cjs/core/utils/functions/index.js +5 -1
  96. package/cjs/core/utils/hooks/index.js +5 -1
  97. package/cjs/core/utils/hooks/useOverflow.js +3 -3
  98. package/cjs/core/utils/hooks/useTheme.js +1 -1
  99. package/cjs/core/utils/index.js +5 -1
  100. package/cjs/index.js +5 -1
  101. package/cjs/types/react-table-config.d.ts +18 -0
  102. package/esm/core/Alert/Alert.js +1 -1
  103. package/esm/core/Badge/Badge.js +1 -1
  104. package/esm/core/Breadcrumbs/Breadcrumbs.d.ts +2 -2
  105. package/esm/core/Buttons/Button/Button.js +2 -2
  106. package/esm/core/Buttons/IconButton/IconButton.js +2 -2
  107. package/esm/core/Carousel/Carousel.js +1 -1
  108. package/esm/core/Carousel/CarouselDotsList.js +1 -1
  109. package/esm/core/Carousel/CarouselSlider.js +1 -1
  110. package/esm/core/Checkbox/Checkbox.js +1 -1
  111. package/esm/core/ColorPicker/ColorBuilder.js +3 -3
  112. package/esm/core/ColorPicker/ColorInputPanel.js +1 -1
  113. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  114. package/esm/core/ColorPicker/ColorSwatch.js +1 -1
  115. package/esm/core/ComboBox/ComboBox.js +9 -6
  116. package/esm/core/DatePicker/DatePicker.js +2 -2
  117. package/esm/core/ExpandableBlock/ExpandableBlock.js +1 -1
  118. package/esm/core/Footer/Footer.js +2 -2
  119. package/esm/core/Header/HeaderBreadcrumbs.js +1 -1
  120. package/esm/core/Header/HeaderButton.js +1 -0
  121. package/esm/core/InformationPanel/InformationPanel.js +2 -2
  122. package/esm/core/Input/Input.js +1 -1
  123. package/esm/core/Menu/Menu.js +8 -3
  124. package/esm/core/ProgressIndicators/ProgressLinear/ProgressLinear.d.ts +1 -1
  125. package/esm/core/ProgressIndicators/ProgressLinear/ProgressLinear.js +2 -2
  126. package/esm/core/ProgressIndicators/ProgressRadial/ProgressRadial.js +2 -2
  127. package/esm/core/Radio/Radio.js +1 -1
  128. package/esm/core/Select/Select.js +3 -3
  129. package/esm/core/SkipToContentLink/SkipToContentLink.d.ts +33 -0
  130. package/esm/core/SkipToContentLink/SkipToContentLink.js +44 -0
  131. package/esm/core/SkipToContentLink/index.d.ts +4 -0
  132. package/esm/core/SkipToContentLink/index.js +6 -0
  133. package/esm/core/Slider/Slider.js +1 -1
  134. package/esm/core/Slider/Thumb.js +1 -1
  135. package/esm/core/Slider/Track.js +1 -1
  136. package/esm/core/Surface/Surface.d.ts +32 -0
  137. package/esm/core/Surface/Surface.js +64 -0
  138. package/esm/core/Surface/index.d.ts +4 -0
  139. package/esm/core/Surface/index.js +6 -0
  140. package/esm/core/Table/Table.d.ts +7 -0
  141. package/esm/core/Table/Table.js +40 -17
  142. package/esm/core/Table/TableCell.js +2 -2
  143. package/esm/core/Table/TablePaginator.js +6 -6
  144. package/esm/core/Table/TableRowMemoized.js +13 -8
  145. package/esm/core/Table/actionHandlers/index.d.ts +2 -1
  146. package/esm/core/Table/actionHandlers/index.js +2 -1
  147. package/esm/core/Table/cells/DefaultCell.d.ts +1 -1
  148. package/esm/core/Table/cells/DefaultCell.js +5 -2
  149. package/esm/core/Table/columns/actionColumn.d.ts +35 -0
  150. package/esm/core/Table/columns/actionColumn.js +84 -0
  151. package/esm/core/Table/columns/expanderColumn.d.ts +47 -0
  152. package/esm/core/Table/columns/expanderColumn.js +74 -0
  153. package/esm/core/Table/columns/index.d.ts +3 -0
  154. package/esm/core/Table/columns/index.js +7 -0
  155. package/esm/core/Table/columns/selectionColumn.d.ts +35 -0
  156. package/esm/core/Table/columns/selectionColumn.js +60 -0
  157. package/esm/core/Table/hooks/index.d.ts +2 -2
  158. package/esm/core/Table/hooks/index.js +2 -2
  159. package/esm/core/Table/hooks/useExpanderCell.d.ts +0 -1
  160. package/esm/core/Table/hooks/useExpanderCell.js +24 -35
  161. package/esm/core/Table/hooks/useResizeColumns.js +8 -2
  162. package/esm/core/Table/hooks/useSelectionCell.d.ts +1 -2
  163. package/esm/core/Table/hooks/useSelectionCell.js +7 -49
  164. package/esm/core/Table/index.d.ts +1 -0
  165. package/esm/core/Table/index.js +1 -0
  166. package/esm/core/Table/utils.js +5 -5
  167. package/esm/core/Tabs/Tabs.d.ts +1 -1
  168. package/esm/core/Tabs/Tabs.js +7 -8
  169. package/esm/core/Tag/Tag.js +6 -3
  170. package/esm/core/Tag/TagContainer.js +1 -1
  171. package/esm/core/Tile/Tile.d.ts +6 -2
  172. package/esm/core/Tile/Tile.js +8 -3
  173. package/esm/core/Toast/Toast.js +3 -3
  174. package/esm/core/Toast/ToastWrapper.js +1 -1
  175. package/esm/core/Tree/TreeNode.js +2 -2
  176. package/esm/core/Typography/Anchor/Anchor.d.ts +1 -0
  177. package/esm/core/Typography/Anchor/Anchor.js +1 -0
  178. package/esm/core/Typography/Text/Text.js +1 -1
  179. package/esm/core/UserIcon/UserIcon.js +2 -2
  180. package/esm/core/UserIconGroup/UserIconGroup.js +3 -3
  181. package/esm/core/Wizard/Step.js +1 -1
  182. package/esm/core/Wizard/Wizard.js +1 -1
  183. package/esm/core/index.d.ts +5 -1
  184. package/esm/core/index.js +3 -1
  185. package/esm/core/utils/color/ColorValue.js +11 -11
  186. package/esm/core/utils/components/FocusTrap.js +6 -8
  187. package/esm/core/utils/components/InputContainer.js +1 -1
  188. package/esm/core/utils/components/MiddleTextTruncation.js +1 -1
  189. package/esm/core/utils/components/Popover.js +13 -1
  190. package/esm/core/utils/components/VirtualScroll.js +1 -1
  191. package/esm/core/utils/components/WithCSSTransition.js +5 -5
  192. package/esm/core/utils/functions/focusable.js +1 -1
  193. package/esm/core/utils/hooks/useOverflow.js +3 -3
  194. package/esm/core/utils/hooks/useTheme.js +1 -1
  195. package/esm/types/react-table-config.d.ts +18 -0
  196. package/package.json +21 -20
@@ -0,0 +1,4 @@
1
+ export { Surface } from './Surface';
2
+ export type { SurfaceProps } from './Surface';
3
+ declare const _default: "./Surface";
4
+ export default _default;
@@ -0,0 +1,6 @@
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
+ export { Surface } from './Surface';
6
+ export default './Surface';
@@ -3,6 +3,7 @@ import { CellProps, TableOptions, Row, TableState } from 'react-table';
3
3
  import { CommonProps } from '../utils';
4
4
  import '@itwin/itwinui-css/css/table.css';
5
5
  import { TableFilterValue } from './filters';
6
+ export declare const tableResizeStartAction = "tableResizeStart";
6
7
  export declare type TablePaginatorRendererProps = {
7
8
  /**
8
9
  * The zero-based index of the current page.
@@ -63,6 +64,12 @@ export declare type TableProps<T extends Record<string, unknown> = Record<string
63
64
  * Handler for when a row is clicked. Must be memoized.
64
65
  */
65
66
  onRowClick?: (event: React.MouseEvent, row: Row<T>) => void;
67
+ /**
68
+ * Modify the selection mode of the table.
69
+ * The column with checkboxes will not be present with 'single' selection mode.
70
+ * @default 'multi'
71
+ */
72
+ selectionMode?: 'multi' | 'single';
66
73
  /**
67
74
  * Flag whether table columns can be sortable.
68
75
  * @default false
@@ -37,12 +37,11 @@ import { TableRowMemoized } from './TableRowMemoized';
37
37
  import { FilterToggle } from './filters';
38
38
  import { customFilterFunctions } from './filters/customFilterFunctions';
39
39
  import { useExpanderCell, useSelectionCell, useSubRowFiltering, useSubRowSelection, useResizeColumns, useColumnDragAndDrop, } from './hooks';
40
- import { onExpandHandler, onFilterHandler, onSelectHandler, } from './actionHandlers';
41
- import { onSingleSelectHandler } from './actionHandlers/selectHandler';
42
- import { onTableResizeEnd, onTableResizeStart, } from './actionHandlers/resizeHandler';
40
+ import { onExpandHandler, onFilterHandler, onSelectHandler, onSingleSelectHandler, onTableResizeEnd, onTableResizeStart, } from './actionHandlers';
43
41
  import VirtualScroll from '../utils/components/VirtualScroll';
42
+ import { SELECTION_CELL_ID } from './columns';
44
43
  var singleRowSelectedAction = 'singleRowSelected';
45
- var tableResizeStartAction = 'tableResizeStart';
44
+ export var tableResizeStartAction = 'tableResizeStart';
46
45
  var tableResizeEndAction = 'tableResizeEnd';
47
46
  /**
48
47
  * Table based on [react-table](https://react-table.tanstack.com/docs/api/overview).
@@ -88,9 +87,10 @@ var tableResizeEndAction = 'tableResizeEnd';
88
87
  */
89
88
  export var Table = function (props) {
90
89
  var _a;
91
- var data = props.data, columns = props.columns, _b = props.isLoading, isLoading = _b === void 0 ? false : _b, emptyTableContent = props.emptyTableContent, className = props.className, style = props.style, id = props.id, _c = props.isSelectable, isSelectable = _c === void 0 ? false : _c, onSelect = props.onSelect, onRowClick = props.onRowClick, _d = props.isSortable, isSortable = _d === void 0 ? false : _d, onSort = props.onSort, stateReducer = props.stateReducer, onBottomReached = props.onBottomReached, onRowInViewport = props.onRowInViewport, _e = props.intersectionMargin, intersectionMargin = _e === void 0 ? 300 : _e, subComponent = props.subComponent, onExpand = props.onExpand, onFilter = props.onFilter, emptyFilteredTableContent = props.emptyFilteredTableContent, filterFunctions = props.filterTypes, expanderCell = props.expanderCell, isRowDisabled = props.isRowDisabled, rowProps = props.rowProps, _f = props.density, density = _f === void 0 ? 'default' : _f, _g = props.selectSubRows, selectSubRows = _g === void 0 ? true : _g, getSubRows = props.getSubRows, _h = props.selectRowOnClick, selectRowOnClick = _h === void 0 ? true : _h, paginatorRenderer = props.paginatorRenderer, _j = props.pageSize, pageSize = _j === void 0 ? 25 : _j, _k = props.isResizable, isResizable = _k === void 0 ? false : _k, _l = props.styleType, styleType = _l === void 0 ? 'default' : _l, _m = props.enableVirtualization, enableVirtualization = _m === void 0 ? false : _m, _o = props.enableColumnReordering, enableColumnReordering = _o === void 0 ? false : _o, rest = __rest(props, ["data", "columns", "isLoading", "emptyTableContent", "className", "style", "id", "isSelectable", "onSelect", "onRowClick", "isSortable", "onSort", "stateReducer", "onBottomReached", "onRowInViewport", "intersectionMargin", "subComponent", "onExpand", "onFilter", "emptyFilteredTableContent", "filterTypes", "expanderCell", "isRowDisabled", "rowProps", "density", "selectSubRows", "getSubRows", "selectRowOnClick", "paginatorRenderer", "pageSize", "isResizable", "styleType", "enableVirtualization", "enableColumnReordering"]);
90
+ var _b;
91
+ var data = props.data, columns = props.columns, _c = props.isLoading, isLoading = _c === void 0 ? false : _c, emptyTableContent = props.emptyTableContent, className = props.className, style = props.style, id = props.id, _d = props.isSelectable, isSelectable = _d === void 0 ? false : _d, onSelect = props.onSelect, onRowClick = props.onRowClick, _e = props.selectionMode, selectionMode = _e === void 0 ? 'multi' : _e, _f = props.isSortable, isSortable = _f === void 0 ? false : _f, onSort = props.onSort, stateReducer = props.stateReducer, onBottomReached = props.onBottomReached, onRowInViewport = props.onRowInViewport, _g = props.intersectionMargin, intersectionMargin = _g === void 0 ? 300 : _g, subComponent = props.subComponent, onExpand = props.onExpand, onFilter = props.onFilter, emptyFilteredTableContent = props.emptyFilteredTableContent, filterFunctions = props.filterTypes, expanderCell = props.expanderCell, isRowDisabled = props.isRowDisabled, rowProps = props.rowProps, _h = props.density, density = _h === void 0 ? 'default' : _h, _j = props.selectSubRows, selectSubRows = _j === void 0 ? true : _j, getSubRows = props.getSubRows, _k = props.selectRowOnClick, selectRowOnClick = _k === void 0 ? true : _k, paginatorRenderer = props.paginatorRenderer, _l = props.pageSize, pageSize = _l === void 0 ? 25 : _l, _m = props.isResizable, isResizable = _m === void 0 ? false : _m, _o = props.styleType, styleType = _o === void 0 ? 'default' : _o, _p = props.enableVirtualization, enableVirtualization = _p === void 0 ? false : _p, _q = props.enableColumnReordering, enableColumnReordering = _q === void 0 ? false : _q, rest = __rest(props, ["data", "columns", "isLoading", "emptyTableContent", "className", "style", "id", "isSelectable", "onSelect", "onRowClick", "selectionMode", "isSortable", "onSort", "stateReducer", "onBottomReached", "onRowInViewport", "intersectionMargin", "subComponent", "onExpand", "onFilter", "emptyFilteredTableContent", "filterTypes", "expanderCell", "isRowDisabled", "rowProps", "density", "selectSubRows", "getSubRows", "selectRowOnClick", "paginatorRenderer", "pageSize", "isResizable", "styleType", "enableVirtualization", "enableColumnReordering"]);
92
92
  useTheme();
93
- var _p = React.useState(), ownerDocument = _p[0], setOwnerDocument = _p[1];
93
+ var _r = React.useState(), ownerDocument = _r[0], setOwnerDocument = _r[1];
94
94
  var defaultColumn = React.useMemo(function () { return ({
95
95
  maxWidth: 0,
96
96
  minWidth: 0,
@@ -103,6 +103,7 @@ export var Table = function (props) {
103
103
  onBottomReachedRef.current = onBottomReached;
104
104
  onRowInViewportRef.current = onRowInViewport;
105
105
  }, [onBottomReached, onRowInViewport]);
106
+ var hasManualSelectionColumn = (_b = columns[0]) === null || _b === void 0 ? void 0 : _b.columns.some(function (column) { return column.id === SELECTION_CELL_ID; });
106
107
  var tableStateReducer = React.useCallback(function (newState, action, previousState, instance) {
107
108
  switch (action.type) {
108
109
  case TableActions.toggleSortBy:
@@ -116,13 +117,17 @@ export var Table = function (props) {
116
117
  onExpandHandler(newState, instance, onExpand);
117
118
  break;
118
119
  case singleRowSelectedAction: {
119
- newState = onSingleSelectHandler(newState, action, instance, onSelect, isRowDisabled);
120
+ newState = onSingleSelectHandler(newState, action, instance, onSelect,
121
+ // If it has manual selection column, then we can't check whether row is disabled
122
+ hasManualSelectionColumn ? undefined : isRowDisabled);
120
123
  break;
121
124
  }
122
125
  case TableActions.toggleRowSelected:
123
126
  case TableActions.toggleAllRowsSelected:
124
127
  case TableActions.toggleAllPageRowsSelected: {
125
- onSelectHandler(newState, instance, onSelect, isRowDisabled);
128
+ onSelectHandler(newState, instance, onSelect,
129
+ // If it has manual selection column, then we can't check whether row is disabled
130
+ hasManualSelectionColumn ? undefined : isRowDisabled);
126
131
  break;
127
132
  }
128
133
  case tableResizeStartAction: {
@@ -139,14 +144,22 @@ export var Table = function (props) {
139
144
  return stateReducer
140
145
  ? stateReducer(newState, action, previousState, instance)
141
146
  : newState;
142
- }, [isRowDisabled, onExpand, onFilter, onSelect, onSort, stateReducer]);
147
+ }, [
148
+ hasManualSelectionColumn,
149
+ isRowDisabled,
150
+ onExpand,
151
+ onFilter,
152
+ onSelect,
153
+ onSort,
154
+ stateReducer,
155
+ ]);
143
156
  var filterTypes = React.useMemo(function () { return (__assign(__assign({}, customFilterFunctions), filterFunctions)); }, [filterFunctions]);
144
157
  var hasAnySubRows = React.useMemo(function () {
145
158
  return data.some(function (item, index) {
146
159
  return getSubRows ? getSubRows(item, index) : item.subRows;
147
160
  });
148
161
  }, [data, getSubRows]);
149
- var instance = useTable(__assign(__assign({ manualPagination: !paginatorRenderer, paginateExpandedRows: false }, props), { columns: columns, defaultColumn: defaultColumn, disableSortBy: !isSortable, stateReducer: tableStateReducer, filterTypes: filterTypes, selectSubRows: selectSubRows, data: data, getSubRows: getSubRows, initialState: __assign({ pageSize: pageSize }, props.initialState) }), useFlexLayout, useResizeColumns(ownerDocument), useFilters, useSubRowFiltering(hasAnySubRows), useSortBy, useExpanded, usePagination, useRowSelect, useSubRowSelection, useExpanderCell(subComponent, expanderCell, isRowDisabled), useSelectionCell(isSelectable, isRowDisabled), useColumnOrder, useColumnDragAndDrop(enableColumnReordering));
162
+ var instance = useTable(__assign(__assign({ manualPagination: !paginatorRenderer, paginateExpandedRows: false }, props), { columns: columns, defaultColumn: defaultColumn, disableSortBy: !isSortable, stateReducer: tableStateReducer, filterTypes: filterTypes, selectSubRows: selectSubRows, data: data, getSubRows: getSubRows, initialState: __assign({ pageSize: pageSize }, props.initialState) }), useFlexLayout, useResizeColumns(ownerDocument), useFilters, useSubRowFiltering(hasAnySubRows), useSortBy, useExpanded, usePagination, useRowSelect, useSubRowSelection, useExpanderCell(subComponent, expanderCell, isRowDisabled), useSelectionCell(isSelectable, selectionMode, isRowDisabled), useColumnOrder, useColumnDragAndDrop(enableColumnReordering));
150
163
  var getTableProps = instance.getTableProps, rows = instance.rows, headerGroups = instance.headerGroups, getTableBodyProps = instance.getTableBodyProps, prepareRow = instance.prepareRow, state = instance.state, allColumns = instance.allColumns, filteredFlatRows = instance.filteredFlatRows, dispatch = instance.dispatch, page = instance.page, gotoPage = instance.gotoPage, setPageSize = instance.setPageSize, flatHeaders = instance.flatHeaders;
151
164
  var ariaDataAttributes = Object.entries(rest).reduce(function (result, _a) {
152
165
  var key = _a[0], value = _a[1];
@@ -158,8 +171,14 @@ export var Table = function (props) {
158
171
  var areFiltersSet = allColumns.some(function (column) { return !!column.filterValue; });
159
172
  var onRowClickHandler = React.useCallback(function (event, row) {
160
173
  var isDisabled = isRowDisabled === null || isRowDisabled === void 0 ? void 0 : isRowDisabled(row.original);
161
- if (isSelectable && !isDisabled && selectRowOnClick) {
162
- if (!row.isSelected && !event.ctrlKey) {
174
+ if (!isDisabled) {
175
+ onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(event, row);
176
+ }
177
+ if (isSelectable &&
178
+ !isDisabled &&
179
+ selectRowOnClick &&
180
+ !event.isDefaultPrevented()) {
181
+ if (!row.isSelected && (selectionMode === 'single' || !event.ctrlKey)) {
163
182
  dispatch({
164
183
  type: singleRowSelectedAction,
165
184
  id: row.id,
@@ -169,10 +188,14 @@ export var Table = function (props) {
169
188
  row.toggleRowSelected(!row.isSelected);
170
189
  }
171
190
  }
172
- if (!isDisabled) {
173
- onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(event, row);
174
- }
175
- }, [isRowDisabled, isSelectable, selectRowOnClick, dispatch, onRowClick]);
191
+ }, [
192
+ isRowDisabled,
193
+ isSelectable,
194
+ selectRowOnClick,
195
+ selectionMode,
196
+ dispatch,
197
+ onRowClick,
198
+ ]);
176
199
  React.useEffect(function () {
177
200
  setPageSize(pageSize);
178
201
  }, [pageSize, setPageSize]);
@@ -253,7 +276,7 @@ export var Table = function (props) {
253
276
  resizeRef(element);
254
277
  }
255
278
  }, id: id }, getTableProps({
256
- className: cx('iui-table', (_a = {}, _a["iui-" + density] = density !== 'default', _a), className),
279
+ className: cx('iui-table', (_a = {}, _a["iui-".concat(density)] = density !== 'default', _a), className),
257
280
  style: style,
258
281
  }), ariaDataAttributes),
259
282
  React.createElement("div", { className: 'iui-table-header', ref: headerRef }, headerGroups.slice(1).map(function (headerGroup) {
@@ -17,7 +17,7 @@ import React from 'react';
17
17
  import cx from 'classnames';
18
18
  import { getCellStyle } from './utils';
19
19
  import { SubRowExpander } from './SubRowExpander';
20
- import { SELECTION_CELL_ID } from './hooks';
20
+ import { SELECTION_CELL_ID } from './columns';
21
21
  import { DefaultCell } from './cells';
22
22
  export var TableCell = function (props) {
23
23
  var cell = props.cell, cellIndex = props.cellIndex, isDisabled = props.isDisabled, tableHasSubRows = props.tableHasSubRows, tableInstance = props.tableInstance, expanderCell = props.expanderCell;
@@ -46,6 +46,6 @@ export var TableCell = function (props) {
46
46
  cellProps: cellProps,
47
47
  children: cellContent,
48
48
  };
49
- return (React.createElement(React.Fragment, null, cell.column.cellRenderer ? (cell.column.cellRenderer(cellRendererProps)) : (React.createElement(DefaultCell, __assign({}, cellRendererProps)))));
49
+ return (React.createElement(React.Fragment, null, cell.column.cellRenderer ? (cell.column.cellRenderer(__assign(__assign({}, cellRendererProps), { isDisabled: function () { return isDisabled; } }))) : (React.createElement(DefaultCell, __assign({}, cellRendererProps, { isDisabled: function () { return isDisabled; } })))));
50
50
  };
51
51
  export default TableCell;
@@ -34,15 +34,15 @@ import { ProgressRadial } from '../ProgressIndicators';
34
34
  import { MenuItem } from '../Menu';
35
35
  import { getBoundedValue, useTheme, useOverflow, useContainerWidth, } from '../utils';
36
36
  var defaultLocalization = {
37
- pageSizeLabel: function (size) { return size + " per page"; },
37
+ pageSizeLabel: function (size) { return "".concat(size, " per page"); },
38
38
  rangeLabel: function (startIndex, endIndex, totalRows, isLoading) {
39
39
  return isLoading
40
- ? startIndex + "-" + endIndex + "\u2026"
41
- : startIndex + "-" + endIndex + " of " + totalRows;
40
+ ? "".concat(startIndex, "-").concat(endIndex, "\u2026")
41
+ : "".concat(startIndex, "-").concat(endIndex, " of ").concat(totalRows);
42
42
  },
43
43
  previousPage: 'Previous page',
44
44
  nextPage: 'Next page',
45
- goToPageLabel: function (page) { return "Go to page " + page; },
45
+ goToPageLabel: function (page) { return "Go to page ".concat(page); },
46
46
  rowsPerPageLabel: 'Rows per page',
47
47
  };
48
48
  /**
@@ -66,12 +66,12 @@ export var TablePaginator = function (props) {
66
66
  var needFocus = React.useRef(false);
67
67
  var isMounted = React.useRef(false);
68
68
  React.useEffect(function () {
69
- var _a, _b, _c;
69
+ var _a, _b;
70
70
  // Checking `isMounted.current` prevents from focusing on initial load.
71
71
  // Checking `needFocus.current` prevents from focusing page when clicked on previous/next page.
72
72
  if (isMounted.current && needFocus.current) {
73
73
  var buttonToFocus = Array.from((_b = (_a = pageListRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.iui-paginator-page-button')) !== null && _b !== void 0 ? _b : []).find(function (el) { var _a; return ((_a = el.textContent) === null || _a === void 0 ? void 0 : _a.trim()) === (focusedIndex + 1).toString(); });
74
- (_c = buttonToFocus) === null || _c === void 0 ? void 0 : _c.focus();
74
+ buttonToFocus === null || buttonToFocus === void 0 ? void 0 : buttonToFocus.focus();
75
75
  needFocus.current = false;
76
76
  }
77
77
  isMounted.current = true;
@@ -31,7 +31,7 @@ export var TableRow = function (props) {
31
31
  isLast && ((_b = onBottomReached.current) === null || _b === void 0 ? void 0 : _b.call(onBottomReached));
32
32
  }, [isLast, onBottomReached, onRowInViewport, row.original]);
33
33
  var rowRef = useIntersection(onIntersect, {
34
- rootMargin: intersectionMargin + "px",
34
+ rootMargin: "".concat(intersectionMargin, "px"),
35
35
  });
36
36
  var userRowProps = rowProps === null || rowProps === void 0 ? void 0 : rowProps(row);
37
37
  var mergedProps = __assign(__assign(__assign({}, row.getRowProps({ style: { flex: "0 0 auto", minWidth: '100%' } })), userRowProps), {
@@ -51,7 +51,9 @@ export var TableRow = function (props) {
51
51
  return (React.createElement(TableCell, { key: cell.getCellProps().key, cell: cell, cellIndex: index, isDisabled: isDisabled, tableHasSubRows: tableHasSubRows, tableInstance: tableInstance, expanderCell: expanderCell }));
52
52
  })),
53
53
  subComponent && (React.createElement(WithCSSTransition, { in: row.isExpanded },
54
- React.createElement("div", { className: 'iui-row iui-expanded-content' }, subComponent(row))))));
54
+ React.createElement("div", { className: cx('iui-row', 'iui-expanded-content', {
55
+ 'iui-disabled': isDisabled,
56
+ }) }, subComponent(row))))));
55
57
  };
56
58
  var hasAnySelectedSubRow = function (row, selectedRowIds) {
57
59
  if (selectedRowIds === null || selectedRowIds === void 0 ? void 0 : selectedRowIds[row.id]) {
@@ -62,14 +64,17 @@ var hasAnySelectedSubRow = function (row, selectedRowIds) {
62
64
  });
63
65
  };
64
66
  export var TableRowMemoized = React.memo(TableRow, function (prevProp, nextProp) {
65
- var _a, _b, _c, _d;
67
+ var _a, _b, _c, _d, _e, _f, _g;
66
68
  return prevProp.isLast === nextProp.isLast &&
69
+ ((_a = prevProp.state.hiddenColumns) === null || _a === void 0 ? void 0 : _a.length) ===
70
+ ((_b = nextProp.state.hiddenColumns) === null || _b === void 0 ? void 0 : _b.length) &&
71
+ !!((_c = prevProp.state.hiddenColumns) === null || _c === void 0 ? void 0 : _c.every(function (column, index) { var _a; return ((_a = nextProp.state.hiddenColumns) === null || _a === void 0 ? void 0 : _a[index]) === column; })) &&
67
72
  prevProp.onRowInViewport === nextProp.onRowInViewport &&
68
73
  prevProp.onBottomReached === nextProp.onBottomReached &&
69
74
  prevProp.onClick === nextProp.onClick &&
70
75
  prevProp.row.original === nextProp.row.original &&
71
- ((_a = prevProp.state.selectedRowIds) === null || _a === void 0 ? void 0 : _a[prevProp.row.id]) ===
72
- ((_b = nextProp.state.selectedRowIds) === null || _b === void 0 ? void 0 : _b[nextProp.row.id]) &&
76
+ ((_d = prevProp.state.selectedRowIds) === null || _d === void 0 ? void 0 : _d[prevProp.row.id]) ===
77
+ ((_e = nextProp.state.selectedRowIds) === null || _e === void 0 ? void 0 : _e[nextProp.row.id]) &&
73
78
  // Check if sub-rows selection has changed and whether to show indeterminate state or not
74
79
  prevProp.row.subRows.some(function (subRow) {
75
80
  return hasAnySelectedSubRow(subRow, prevProp.state.selectedRowIds);
@@ -77,8 +82,8 @@ export var TableRowMemoized = React.memo(TableRow, function (prevProp, nextProp)
77
82
  nextProp.row.subRows.some(function (subRow) {
78
83
  return hasAnySelectedSubRow(subRow, nextProp.state.selectedRowIds);
79
84
  }) &&
80
- ((_c = prevProp.state.expanded) === null || _c === void 0 ? void 0 : _c[prevProp.row.id]) ===
81
- ((_d = nextProp.state.expanded) === null || _d === void 0 ? void 0 : _d[nextProp.row.id]) &&
85
+ ((_f = prevProp.state.expanded) === null || _f === void 0 ? void 0 : _f[prevProp.row.id]) ===
86
+ ((_g = nextProp.state.expanded) === null || _g === void 0 ? void 0 : _g[nextProp.row.id]) &&
82
87
  prevProp.subComponent === nextProp.subComponent &&
83
88
  prevProp.row.cells.every(function (cell, index) { return nextProp.row.cells[index].column === cell.column; }) &&
84
89
  prevProp.isDisabled === nextProp.isDisabled &&
@@ -87,5 +92,5 @@ export var TableRowMemoized = React.memo(TableRow, function (prevProp, nextProp)
87
92
  prevProp.tableHasSubRows === nextProp.tableHasSubRows &&
88
93
  prevProp.state.columnOrder === nextProp.state.columnOrder &&
89
94
  !nextProp.state.columnResizing.isResizingColumn &&
90
- !nextProp.state.isTableResizing;
95
+ prevProp.state.isTableResizing === nextProp.state.isTableResizing;
91
96
  });
@@ -1,3 +1,4 @@
1
1
  export { onExpandHandler } from './expandHandler';
2
2
  export { onFilterHandler } from './filterHandler';
3
- export { onSelectHandler } from './selectHandler';
3
+ export { onSelectHandler, onSingleSelectHandler } from './selectHandler';
4
+ export { onTableResizeStart, onTableResizeEnd } from './resizeHandler';
@@ -4,4 +4,5 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  export { onExpandHandler } from './expandHandler';
6
6
  export { onFilterHandler } from './filterHandler';
7
- export { onSelectHandler } from './selectHandler';
7
+ export { onSelectHandler, onSingleSelectHandler } from './selectHandler';
8
+ export { onTableResizeStart, onTableResizeEnd } from './resizeHandler';
@@ -12,5 +12,5 @@ export declare type DefaultCellProps<T extends Record<string, unknown>> = CellRe
12
12
  * cellRenderer: (props) => <DefaultCell {...props} />,
13
13
  * }
14
14
  */
15
- export declare const DefaultCell: <T extends Record<string, unknown>>(props: CellRendererProps<T>) => JSX.Element;
15
+ export declare const DefaultCell: <T extends Record<string, unknown>>(props: DefaultCellProps<T>) => JSX.Element;
16
16
  export default DefaultCell;
@@ -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 cx from 'classnames';
28
29
  /**
29
30
  * Default cell.
30
31
  * It should be passed to `cellRenderer`.
@@ -39,7 +40,9 @@ import React from 'react';
39
40
  export var DefaultCell = function (props) {
40
41
  // Omitting `cellProps`
41
42
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
- var cellElementProps = props.cellElementProps, children = props.children, cellProps = props.cellProps, rest = __rest(props, ["cellElementProps", "children", "cellProps"]);
43
- return (React.createElement("div", __assign({}, cellElementProps, rest), children));
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
47
  };
45
48
  export default DefaultCell;
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import { HeaderProps } from 'react-table';
3
+ /**
4
+ * Action column that adds column manager to the Table header.
5
+ * It is recommended to add this column to the end of the Table
6
+ * and to override its `Cell` prop with your row actions menu.
7
+ * @example
8
+ * {
9
+ * ...ActionColumn({ columnManager: true }),
10
+ * Cell: () => (
11
+ * <DropdownMenu menuItems={menuItems}>
12
+ * <IconButton
13
+ * styleType='borderless'
14
+ * onClick={(e) => e.stopPropagation()}
15
+ * >
16
+ * <SvgMore />
17
+ * </IconButton>
18
+ * </DropdownMenu>
19
+ * ),
20
+ * },
21
+ */
22
+ export declare const ActionColumn: <T extends Record<string, unknown>>({ columnManager, }?: {
23
+ columnManager?: boolean | undefined;
24
+ }) => {
25
+ id: string;
26
+ disableResizing: boolean;
27
+ disableGroupBy: boolean;
28
+ minWidth: number;
29
+ width: number;
30
+ maxWidth: number;
31
+ columnClassName: string;
32
+ cellClassName: string;
33
+ disableReordering: boolean;
34
+ Header: ({ allColumns, dispatch, state }: HeaderProps<T>) => JSX.Element | null;
35
+ };
@@ -0,0 +1,84 @@
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 { Checkbox } from '../../Checkbox';
7
+ import SvgColumnManager from '@itwin/itwinui-icons-react/cjs/icons/ColumnManager';
8
+ import { DropdownMenu } from '../../DropdownMenu';
9
+ import { IconButton } from '../../Buttons/IconButton';
10
+ import { MenuItem } from '../../Menu';
11
+ import { tableResizeStartAction } from '../Table';
12
+ import { SELECTION_CELL_ID } from './selectionColumn';
13
+ import { EXPANDER_CELL_ID } from './expanderColumn';
14
+ var ACTION_CELL_ID = 'iui-table-action';
15
+ /**
16
+ * Action column that adds column manager to the Table header.
17
+ * It is recommended to add this column to the end of the Table
18
+ * and to override its `Cell` prop with your row actions menu.
19
+ * @example
20
+ * {
21
+ * ...ActionColumn({ columnManager: true }),
22
+ * Cell: () => (
23
+ * <DropdownMenu menuItems={menuItems}>
24
+ * <IconButton
25
+ * styleType='borderless'
26
+ * onClick={(e) => e.stopPropagation()}
27
+ * >
28
+ * <SvgMore />
29
+ * </IconButton>
30
+ * </DropdownMenu>
31
+ * ),
32
+ * },
33
+ */
34
+ export var ActionColumn = function (_a) {
35
+ var _b = _a === void 0 ? {} : _a, _c = _b.columnManager, columnManager = _c === void 0 ? false : _c;
36
+ return {
37
+ id: ACTION_CELL_ID,
38
+ disableResizing: true,
39
+ disableGroupBy: true,
40
+ minWidth: 48,
41
+ width: 48,
42
+ maxWidth: 48,
43
+ columnClassName: 'iui-slot',
44
+ cellClassName: 'iui-slot',
45
+ disableReordering: true,
46
+ Header: function (_a) {
47
+ var allColumns = _a.allColumns, dispatch = _a.dispatch, state = _a.state;
48
+ var _b = React.useState(false), isOpen = _b[0], setIsOpen = _b[1];
49
+ if (!columnManager) {
50
+ return null;
51
+ }
52
+ var defaultColumnIds = [
53
+ SELECTION_CELL_ID,
54
+ EXPANDER_CELL_ID,
55
+ ACTION_CELL_ID,
56
+ ];
57
+ var headerCheckBoxes = function () {
58
+ return allColumns
59
+ //Filters out any default columns made such as selection and expansion
60
+ .filter(function (_a) {
61
+ var id = _a.id;
62
+ return !defaultColumnIds.includes(id);
63
+ })
64
+ .map(function (column) {
65
+ var checked = column.getToggleHiddenProps().checked;
66
+ var onClick = function () {
67
+ column.toggleHidden(checked);
68
+ // If no column was resized then leave table resize handling to the flexbox
69
+ if (Object.keys(state.columnResizing.columnWidths).length === 0) {
70
+ return;
71
+ }
72
+ // Triggers an update to resize the widths of all visible columns
73
+ dispatch({ type: tableResizeStartAction });
74
+ };
75
+ return (React.createElement(MenuItem, { key: column.id, icon: React.createElement(Checkbox, { checked: checked, disabled: column.disableToggleVisibility, onClick: function (e) { return e.stopPropagation(); }, onChange: onClick, "aria-labelledby": "iui-column-".concat(column.id) }), onClick: onClick, disabled: column.disableToggleVisibility },
76
+ React.createElement("div", { id: "iui-column-".concat(column.id) }, column.render('Header'))));
77
+ });
78
+ };
79
+ return (React.createElement(DropdownMenu, { menuItems: headerCheckBoxes, onHide: function () { return setIsOpen(false); }, onShow: function () { return setIsOpen(true); } },
80
+ React.createElement(IconButton, { styleType: 'borderless', isActive: isOpen },
81
+ React.createElement(SvgColumnManager, null))));
82
+ },
83
+ };
84
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { CellProps, CellRendererProps, Row } from 'react-table';
3
+ export declare const EXPANDER_CELL_ID = "iui-table-expander";
4
+ /**
5
+ * Expander column that adds sub-content expander column to the Table.
6
+ * It is recommended to use it as the first column or after selection column.
7
+ * @example
8
+ * const subComponent = useCallback(
9
+ * (row: Row) => (
10
+ * <div style={{ padding: 16 }}>
11
+ * <Leading>Extra information</Leading>
12
+ * <pre>
13
+ * <code>{JSON.stringify({ values: row.values }, null, 2)}</code>
14
+ * </pre>
15
+ * </div>
16
+ * ),
17
+ * [],
18
+ * );
19
+ * const isExpanderDisabled = useCallback((rowData) => {
20
+ * return rowData.name === 'Name2';
21
+ * }, []);
22
+ * const columns = useMemo(() => [
23
+ * Header: 'Table',
24
+ * columns: [
25
+ * ExpanderColumn({ subComponent, isDisabled: isExpanderDisabled }),
26
+ * // Rest of your columns
27
+ * ],
28
+ * ], [isExpanderDisabled, subComponent]);
29
+ */
30
+ export declare const ExpanderColumn: <T extends Record<string, unknown>>(props?: {
31
+ /** Function that returns expanded content. If row doesn't have it, then should return `false`/`null`. */
32
+ subComponent?: ((row: Row<T>) => React.ReactNode) | undefined;
33
+ /** Function that returns whether expander is disabled */
34
+ isDisabled?: ((rowData: T) => boolean) | undefined;
35
+ }) => {
36
+ id: string;
37
+ disableResizing: boolean;
38
+ disableGroupBy: boolean;
39
+ disableReordering: boolean;
40
+ minWidth: number;
41
+ width: number;
42
+ maxWidth: number;
43
+ columnClassName: string;
44
+ cellClassName: string;
45
+ Cell: (props: CellProps<T, any>) => JSX.Element | null;
46
+ cellRenderer: (props: CellRendererProps<T>) => JSX.Element;
47
+ };
@@ -0,0 +1,74 @@
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
+ /*---------------------------------------------------------------------------------------------
13
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
14
+ * See LICENSE.md in the project root for license terms and full copyright notice.
15
+ *--------------------------------------------------------------------------------------------*/
16
+ import React from 'react';
17
+ import SvgChevronRight from '@itwin/itwinui-icons-react/cjs/icons/ChevronRight';
18
+ import { IconButton } from '../../Buttons';
19
+ import { DefaultCell } from '../cells';
20
+ export var EXPANDER_CELL_ID = 'iui-table-expander';
21
+ /**
22
+ * Expander column that adds sub-content expander column to the Table.
23
+ * It is recommended to use it as the first column or after selection column.
24
+ * @example
25
+ * const subComponent = useCallback(
26
+ * (row: Row) => (
27
+ * <div style={{ padding: 16 }}>
28
+ * <Leading>Extra information</Leading>
29
+ * <pre>
30
+ * <code>{JSON.stringify({ values: row.values }, null, 2)}</code>
31
+ * </pre>
32
+ * </div>
33
+ * ),
34
+ * [],
35
+ * );
36
+ * const isExpanderDisabled = useCallback((rowData) => {
37
+ * return rowData.name === 'Name2';
38
+ * }, []);
39
+ * const columns = useMemo(() => [
40
+ * Header: 'Table',
41
+ * columns: [
42
+ * ExpanderColumn({ subComponent, isDisabled: isExpanderDisabled }),
43
+ * // Rest of your columns
44
+ * ],
45
+ * ], [isExpanderDisabled, subComponent]);
46
+ */
47
+ export var ExpanderColumn = function (props) {
48
+ if (props === void 0) { props = {}; }
49
+ var subComponent = props.subComponent, isDisabled = props.isDisabled;
50
+ return {
51
+ id: EXPANDER_CELL_ID,
52
+ disableResizing: true,
53
+ disableGroupBy: true,
54
+ disableReordering: true,
55
+ minWidth: 48,
56
+ width: 48,
57
+ maxWidth: 48,
58
+ columnClassName: 'iui-slot',
59
+ cellClassName: 'iui-slot',
60
+ Cell: function (props) {
61
+ var row = props.row;
62
+ if (!(subComponent === null || subComponent === void 0 ? void 0 : subComponent(row))) {
63
+ return null;
64
+ }
65
+ else {
66
+ return (React.createElement(IconButton, { className: 'iui-row-expander', styleType: 'borderless', size: 'small', onClick: function (e) {
67
+ e.stopPropagation();
68
+ row.toggleRowExpanded();
69
+ }, disabled: isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(props.row.original) }, React.createElement(SvgChevronRight, null)));
70
+ }
71
+ },
72
+ cellRenderer: function (props) { return (React.createElement(DefaultCell, __assign({}, props, { isDisabled: function (rowData) { return !!(isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(rowData)); } }))); },
73
+ };
74
+ };
@@ -0,0 +1,3 @@
1
+ export { ActionColumn } from './actionColumn';
2
+ export { SELECTION_CELL_ID, SelectionColumn } from './selectionColumn';
3
+ export { EXPANDER_CELL_ID, ExpanderColumn } from './expanderColumn';
@@ -0,0 +1,7 @@
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
+ export { ActionColumn } from './actionColumn';
6
+ export { SELECTION_CELL_ID, SelectionColumn } from './selectionColumn';
7
+ export { EXPANDER_CELL_ID, ExpanderColumn } from './expanderColumn';
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import { CellProps, CellRendererProps, HeaderProps } from 'react-table';
3
+ export declare const SELECTION_CELL_ID = "iui-table-checkbox-selector";
4
+ /**
5
+ * Selection column that adds selection checkbox column to the Table.
6
+ * It is recommended to use it as the first column.
7
+ * @example
8
+ * const isCheckboxDisabled = useCallback((rowData) => {
9
+ * return rowData.name === 'Name1';
10
+ * }, []);
11
+ * const columns = useMemo(() => [
12
+ * Header: 'Table',
13
+ * columns: [
14
+ * SelectionColumn({ isDisabled: isCheckboxDisabled }),
15
+ * // Rest of your columns
16
+ * ],
17
+ * ], [isCheckboxDisabled]);
18
+ */
19
+ export declare const SelectionColumn: <T extends Record<string, unknown>>(props?: {
20
+ /** Function that returns whether row checkbox should be disabled. */
21
+ isDisabled?: ((rowData: T) => boolean) | undefined;
22
+ }) => {
23
+ id: string;
24
+ disableResizing: boolean;
25
+ disableGroupBy: boolean;
26
+ disableReordering: boolean;
27
+ minWidth: number;
28
+ width: number;
29
+ maxWidth: number;
30
+ columnClassName: string;
31
+ cellClassName: string;
32
+ Header: ({ getToggleAllRowsSelectedProps, rows, initialRows, state, }: HeaderProps<T>) => JSX.Element;
33
+ Cell: ({ row }: CellProps<T, any>) => JSX.Element;
34
+ cellRenderer: (props: CellRendererProps<T>) => JSX.Element;
35
+ };