@itwin/itwinui-react 1.24.0 → 1.27.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 (130) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/cjs/core/Buttons/Button/Button.d.ts +1 -1
  3. package/cjs/core/Buttons/Button/Button.js +4 -5
  4. package/cjs/core/Buttons/IconButton/IconButton.js +2 -3
  5. package/cjs/core/Checkbox/Checkbox.d.ts +11 -0
  6. package/cjs/core/Checkbox/Checkbox.js +14 -4
  7. package/cjs/core/ColorPicker/ColorBuilder.js +1 -1
  8. package/cjs/core/ColorPicker/ColorInputPanel.js +43 -21
  9. package/cjs/core/ColorPicker/ColorPalette.js +1 -1
  10. package/cjs/core/ColorPicker/ColorPicker.js +2 -2
  11. package/cjs/core/ColorPicker/ColorPickerContext.d.ts +2 -2
  12. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  13. package/cjs/core/ColorPicker/ColorSwatch.js +10 -6
  14. package/cjs/core/ComboBox/ComboBox.d.ts +2 -2
  15. package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
  16. package/cjs/core/ErrorPage/ErrorPage.d.ts +2 -1
  17. package/cjs/core/ErrorPage/ErrorPage.js +3 -2
  18. package/cjs/core/InformationPanel/InformationPanel.d.ts +4 -1
  19. package/cjs/core/InformationPanel/InformationPanel.js +4 -1
  20. package/cjs/core/InformationPanel/InformationPanelContent.d.ts +42 -0
  21. package/cjs/core/InformationPanel/InformationPanelContent.js +66 -0
  22. package/cjs/core/InformationPanel/index.d.ts +2 -0
  23. package/cjs/core/InformationPanel/index.js +3 -1
  24. package/cjs/core/Label/Label.d.ts +31 -0
  25. package/cjs/core/Label/Label.js +53 -0
  26. package/cjs/core/Label/index.d.ts +4 -0
  27. package/cjs/core/Label/index.js +10 -0
  28. package/cjs/core/LabeledInput/LabeledInput.d.ts +2 -2
  29. package/cjs/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
  30. package/cjs/core/Menu/MenuItem.d.ts +1 -1
  31. package/cjs/core/Modal/ModalButtonBar.d.ts +2 -1
  32. package/cjs/core/Modal/ModalButtonBar.js +3 -2
  33. package/cjs/core/Table/Table.d.ts +8 -0
  34. package/cjs/core/Table/Table.js +71 -10
  35. package/cjs/core/Table/TableCell.js +1 -1
  36. package/cjs/core/Table/TablePaginator.d.ts +7 -7
  37. package/cjs/core/Table/TablePaginator.js +20 -10
  38. package/cjs/core/Table/TableRowMemoized.d.ts +21 -0
  39. package/cjs/core/Table/TableRowMemoized.js +6 -3
  40. package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +51 -0
  41. package/cjs/core/Table/actionHandlers/resizeHandler.js +22 -0
  42. package/cjs/core/Table/actionHandlers/selectHandler.d.ts +10 -7
  43. package/cjs/core/Table/hooks/index.d.ts +1 -0
  44. package/cjs/core/Table/hooks/index.js +3 -1
  45. package/cjs/core/Table/hooks/useResizeColumns.d.ts +5 -0
  46. package/cjs/core/Table/hooks/useResizeColumns.js +271 -0
  47. package/cjs/core/Table/utils.d.ts +1 -1
  48. package/cjs/core/Table/utils.js +8 -2
  49. package/cjs/core/Tabs/Tabs.d.ts +4 -0
  50. package/cjs/core/Tabs/Tabs.js +23 -29
  51. package/cjs/core/index.d.ts +6 -4
  52. package/cjs/core/index.js +6 -2
  53. package/cjs/core/utils/color/ColorValue.d.ts +1 -0
  54. package/cjs/core/utils/color/ColorValue.js +96 -84
  55. package/cjs/core/utils/components/MiddleTextTruncation.d.ts +21 -0
  56. package/cjs/core/utils/components/MiddleTextTruncation.js +56 -0
  57. package/cjs/core/utils/components/index.d.ts +1 -0
  58. package/cjs/core/utils/components/index.js +1 -0
  59. package/cjs/core/utils/hooks/index.d.ts +1 -0
  60. package/cjs/core/utils/hooks/index.js +1 -0
  61. package/cjs/core/utils/hooks/useContainerWidth.d.ts +17 -0
  62. package/cjs/core/utils/hooks/useContainerWidth.js +50 -0
  63. package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
  64. package/cjs/core/utils/hooks/useOverflow.js +30 -17
  65. package/cjs/types/react-table-config.d.ts +16 -3
  66. package/esm/core/Buttons/Button/Button.d.ts +1 -1
  67. package/esm/core/Buttons/Button/Button.js +4 -5
  68. package/esm/core/Buttons/IconButton/IconButton.js +2 -3
  69. package/esm/core/Checkbox/Checkbox.d.ts +11 -0
  70. package/esm/core/Checkbox/Checkbox.js +14 -4
  71. package/esm/core/ColorPicker/ColorBuilder.js +1 -1
  72. package/esm/core/ColorPicker/ColorInputPanel.js +43 -21
  73. package/esm/core/ColorPicker/ColorPalette.js +1 -1
  74. package/esm/core/ColorPicker/ColorPicker.js +2 -2
  75. package/esm/core/ColorPicker/ColorPickerContext.d.ts +2 -2
  76. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  77. package/esm/core/ColorPicker/ColorSwatch.js +10 -6
  78. package/esm/core/ComboBox/ComboBox.d.ts +2 -2
  79. package/esm/core/DatePicker/DatePicker.d.ts +1 -1
  80. package/esm/core/ErrorPage/ErrorPage.d.ts +2 -1
  81. package/esm/core/ErrorPage/ErrorPage.js +3 -2
  82. package/esm/core/InformationPanel/InformationPanel.d.ts +4 -1
  83. package/esm/core/InformationPanel/InformationPanel.js +4 -1
  84. package/esm/core/InformationPanel/InformationPanelContent.d.ts +42 -0
  85. package/esm/core/InformationPanel/InformationPanelContent.js +59 -0
  86. package/esm/core/InformationPanel/index.d.ts +2 -0
  87. package/esm/core/InformationPanel/index.js +1 -0
  88. package/esm/core/Label/Label.d.ts +31 -0
  89. package/esm/core/Label/Label.js +46 -0
  90. package/esm/core/Label/index.d.ts +4 -0
  91. package/esm/core/Label/index.js +6 -0
  92. package/esm/core/LabeledInput/LabeledInput.d.ts +2 -2
  93. package/esm/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
  94. package/esm/core/Menu/MenuItem.d.ts +1 -1
  95. package/esm/core/Modal/ModalButtonBar.d.ts +2 -1
  96. package/esm/core/Modal/ModalButtonBar.js +3 -2
  97. package/esm/core/Table/Table.d.ts +8 -0
  98. package/esm/core/Table/Table.js +73 -12
  99. package/esm/core/Table/TableCell.js +1 -1
  100. package/esm/core/Table/TablePaginator.d.ts +7 -7
  101. package/esm/core/Table/TablePaginator.js +21 -11
  102. package/esm/core/Table/TableRowMemoized.d.ts +21 -0
  103. package/esm/core/Table/TableRowMemoized.js +4 -2
  104. package/esm/core/Table/actionHandlers/resizeHandler.d.ts +51 -0
  105. package/esm/core/Table/actionHandlers/resizeHandler.js +17 -0
  106. package/esm/core/Table/actionHandlers/selectHandler.d.ts +10 -7
  107. package/esm/core/Table/hooks/index.d.ts +1 -0
  108. package/esm/core/Table/hooks/index.js +1 -0
  109. package/esm/core/Table/hooks/useResizeColumns.d.ts +5 -0
  110. package/esm/core/Table/hooks/useResizeColumns.js +267 -0
  111. package/esm/core/Table/utils.d.ts +1 -1
  112. package/esm/core/Table/utils.js +8 -2
  113. package/esm/core/Tabs/Tabs.d.ts +4 -0
  114. package/esm/core/Tabs/Tabs.js +24 -30
  115. package/esm/core/index.d.ts +6 -4
  116. package/esm/core/index.js +3 -2
  117. package/esm/core/utils/color/ColorValue.d.ts +1 -0
  118. package/esm/core/utils/color/ColorValue.js +96 -84
  119. package/esm/core/utils/components/MiddleTextTruncation.d.ts +21 -0
  120. package/esm/core/utils/components/MiddleTextTruncation.js +49 -0
  121. package/esm/core/utils/components/index.d.ts +1 -0
  122. package/esm/core/utils/components/index.js +1 -0
  123. package/esm/core/utils/hooks/index.d.ts +1 -0
  124. package/esm/core/utils/hooks/index.js +1 -0
  125. package/esm/core/utils/hooks/useContainerWidth.d.ts +17 -0
  126. package/esm/core/utils/hooks/useContainerWidth.js +43 -0
  127. package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
  128. package/esm/core/utils/hooks/useOverflow.js +30 -17
  129. package/esm/types/react-table-config.d.ts +16 -3
  130. package/package.json +13 -5
@@ -0,0 +1,267 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { actions, makePropGetter, useGetLatest, } from 'react-table';
22
+ export var useResizeColumns = function (ownerDocument) { return function (hooks) {
23
+ hooks.getResizerProps = [defaultGetResizerProps(ownerDocument)];
24
+ hooks.stateReducers.push(reducer);
25
+ hooks.useInstanceBeforeDimensions.push(useInstanceBeforeDimensions);
26
+ }; };
27
+ var isTouchEvent = function (event) {
28
+ return event.type === 'touchstart';
29
+ };
30
+ var defaultGetResizerProps = function (ownerDocument) { return function (props, _a) {
31
+ var instance = _a.instance, header = _a.header, nextHeader = _a.nextHeader;
32
+ if (!ownerDocument) {
33
+ return props;
34
+ }
35
+ var dispatch = instance.dispatch, flatHeaders = instance.flatHeaders;
36
+ var onResizeStart = function (e, header) {
37
+ // lets not respond to multiple touches (e.g. 2 or 3 fingers)
38
+ if (isTouchEvent(e) && e.touches && e.touches.length > 1) {
39
+ return;
40
+ }
41
+ // Setting `width` here because it might take several rerenders until actual column width is set.
42
+ flatHeaders.forEach(function (h) {
43
+ if (!h.width) {
44
+ h.width = h.resizeWidth;
45
+ }
46
+ });
47
+ var headerIdWidths = getLeafHeaders(header).map(function (d) { return [d.id, d.width]; });
48
+ var nextHeaderIdWidths = nextHeader
49
+ ? getLeafHeaders(nextHeader).map(function (d) { return [d.id, d.width]; })
50
+ : [];
51
+ var clientX = isTouchEvent(e)
52
+ ? Math.round(e.touches[0].clientX)
53
+ : e.clientX;
54
+ var dispatchMove = function (clientXPos) {
55
+ return dispatch({ type: actions.columnResizing, clientX: clientXPos });
56
+ };
57
+ var dispatchEnd = function () {
58
+ return dispatch({
59
+ type: actions.columnDoneResizing,
60
+ });
61
+ };
62
+ var handlersAndEvents = {
63
+ mouse: {
64
+ moveEvent: 'mousemove',
65
+ moveHandler: function (e) { return dispatchMove(e.clientX); },
66
+ upEvent: 'mouseup',
67
+ upHandler: function () {
68
+ ownerDocument.removeEventListener('mousemove', handlersAndEvents.mouse.moveHandler);
69
+ ownerDocument.removeEventListener('mouseup', handlersAndEvents.mouse.upHandler);
70
+ dispatchEnd();
71
+ },
72
+ },
73
+ touch: {
74
+ moveEvent: 'touchmove',
75
+ moveHandler: function (e) {
76
+ if (e.cancelable) {
77
+ e.preventDefault();
78
+ e.stopPropagation();
79
+ }
80
+ dispatchMove(e.touches[0].clientX);
81
+ },
82
+ upEvent: 'touchend',
83
+ upHandler: function () {
84
+ ownerDocument.removeEventListener(handlersAndEvents.touch.moveEvent, handlersAndEvents.touch.moveHandler);
85
+ ownerDocument.removeEventListener(handlersAndEvents.touch.upEvent, handlersAndEvents.touch.moveHandler);
86
+ dispatchEnd();
87
+ },
88
+ },
89
+ };
90
+ var events = isTouchEvent(e)
91
+ ? handlersAndEvents.touch
92
+ : handlersAndEvents.mouse;
93
+ var passiveIfSupported = passiveEventSupported()
94
+ ? { passive: false }
95
+ : false;
96
+ ownerDocument.addEventListener(events.moveEvent, events.moveHandler, passiveIfSupported);
97
+ ownerDocument.addEventListener(events.upEvent, events.upHandler, passiveIfSupported);
98
+ dispatch({
99
+ type: actions.columnStartResizing,
100
+ columnId: header.id,
101
+ columnWidth: header.width,
102
+ nextColumnWidth: nextHeader === null || nextHeader === void 0 ? void 0 : nextHeader.width,
103
+ headerIdWidths: headerIdWidths,
104
+ nextHeaderIdWidths: nextHeaderIdWidths,
105
+ clientX: clientX,
106
+ });
107
+ };
108
+ return [
109
+ props,
110
+ {
111
+ onMouseDown: function (e) {
112
+ e.persist();
113
+ e.stopPropagation();
114
+ onResizeStart(e, header);
115
+ },
116
+ onTouchStart: function (e) {
117
+ e.persist();
118
+ e.stopPropagation();
119
+ onResizeStart(e, header);
120
+ },
121
+ style: {
122
+ cursor: 'col-resize',
123
+ },
124
+ draggable: false,
125
+ role: 'separator',
126
+ },
127
+ ];
128
+ }; };
129
+ useResizeColumns.pluginName = 'useResizeColumns';
130
+ var reducer = function (newState, action, previousState, instance) {
131
+ if (action.type === actions.init) {
132
+ return __assign(__assign({}, newState), { columnResizing: {
133
+ columnWidths: {},
134
+ } });
135
+ }
136
+ if (action.type === actions.resetResize) {
137
+ return __assign(__assign({}, newState), { columnResizing: {
138
+ columnWidths: {},
139
+ } });
140
+ }
141
+ if (action.type === actions.columnStartResizing) {
142
+ var clientX = action.clientX, columnId = action.columnId, columnWidth = action.columnWidth, nextColumnWidth = action.nextColumnWidth, headerIdWidths = action.headerIdWidths, nextHeaderIdWidths = action.nextHeaderIdWidths;
143
+ return __assign(__assign({}, newState), { columnResizing: __assign(__assign({}, newState.columnResizing), { startX: clientX, columnWidth: columnWidth, nextColumnWidth: nextColumnWidth, headerIdWidths: headerIdWidths, nextHeaderIdWidths: nextHeaderIdWidths, isResizingColumn: columnId }) });
144
+ }
145
+ if (action.type === actions.columnResizing) {
146
+ var clientX = action.clientX;
147
+ var _a = newState.columnResizing, _b = _a.startX, startX = _b === void 0 ? 0 : _b, _c = _a.columnWidth, columnWidth = _c === void 0 ? 1 : _c, _d = _a.nextColumnWidth, nextColumnWidth = _d === void 0 ? 1 : _d, _e = _a.headerIdWidths, headerIdWidths = _e === void 0 ? [] : _e, _f = _a.nextHeaderIdWidths, nextHeaderIdWidths = _f === void 0 ? [] : _f;
148
+ var deltaX = clientX - startX;
149
+ var newColumnWidths = getColumnWidths(headerIdWidths, deltaX / columnWidth);
150
+ var newNextColumnWidths = getColumnWidths(nextHeaderIdWidths, -deltaX / nextColumnWidth);
151
+ if (!isNewColumnWidthsValid(newColumnWidths, instance === null || instance === void 0 ? void 0 : instance.flatHeaders) ||
152
+ !isNewColumnWidthsValid(newNextColumnWidths, instance === null || instance === void 0 ? void 0 : instance.flatHeaders)) {
153
+ return newState;
154
+ }
155
+ return __assign(__assign({}, newState), { columnResizing: __assign(__assign({}, newState.columnResizing), { columnWidths: __assign(__assign(__assign({}, newState.columnResizing.columnWidths), newColumnWidths), newNextColumnWidths) }) });
156
+ }
157
+ if (action.type === actions.columnDoneResizing) {
158
+ return __assign(__assign({}, newState), { columnResizing: __assign(__assign({}, newState.columnResizing), { startX: undefined, isResizingColumn: undefined }) });
159
+ }
160
+ return newState;
161
+ };
162
+ var getColumnWidths = function (headerIdWidths, deltaPercentage) {
163
+ var columnWidths = {};
164
+ headerIdWidths.forEach(function (_a) {
165
+ var headerId = _a[0], headerWidth = _a[1];
166
+ columnWidths[headerId] = Math.max(headerWidth + headerWidth * deltaPercentage, 0);
167
+ });
168
+ return columnWidths;
169
+ };
170
+ var isNewColumnWidthsValid = function (columnWidths, headers) {
171
+ // Prevents from going outside the column bounds
172
+ if (Object.values(columnWidths).some(function (width) { return width <= 1; })) {
173
+ return false;
174
+ }
175
+ var _loop_1 = function (headerId, width) {
176
+ var header = headers === null || headers === void 0 ? void 0 : headers.find(function (h) { return h.id === headerId; });
177
+ if (!header) {
178
+ return "continue";
179
+ }
180
+ var minWidth = header.minWidth || 0;
181
+ var maxWidth = header.maxWidth || Infinity;
182
+ if (width < minWidth || width > maxWidth) {
183
+ return { value: false };
184
+ }
185
+ };
186
+ for (var _i = 0, _a = Object.entries(columnWidths); _i < _a.length; _i++) {
187
+ var _b = _a[_i], headerId = _b[0], width = _b[1];
188
+ var state_1 = _loop_1(headerId, width);
189
+ if (typeof state_1 === "object")
190
+ return state_1.value;
191
+ }
192
+ return true;
193
+ };
194
+ var useInstanceBeforeDimensions = function (instance) {
195
+ var flatHeaders = instance.flatHeaders, getHooks = instance.getHooks, columnResizing = instance.state.columnResizing;
196
+ var getInstance = useGetLatest(instance);
197
+ flatHeaders.forEach(function (header, index) {
198
+ var _a;
199
+ var resizeWidth = columnResizing.columnWidths[header.id];
200
+ header.width = resizeWidth || header.width || header.originalWidth;
201
+ header.isResizing = columnResizing.isResizingColumn === header.id;
202
+ var headerToResize = header.disableResizing
203
+ ? getPreviousResizableHeader(header, instance)
204
+ : header;
205
+ var nextResizableHeader = getNextResizableHeader(header, instance);
206
+ header.canResize =
207
+ header.disableResizing != null ? !header.disableResizing : true;
208
+ // Show resizer when header is resizable or when next header is resizable
209
+ // and there is resizable columns on the left side of the resizer.
210
+ header.isResizerVisible =
211
+ (header.canResize && !!nextResizableHeader) ||
212
+ (headerToResize && !!((_a = instance.flatHeaders[index + 1]) === null || _a === void 0 ? void 0 : _a.canResize));
213
+ header.getResizerProps = makePropGetter(getHooks().getResizerProps, {
214
+ instance: getInstance(),
215
+ header: headerToResize,
216
+ nextHeader: nextResizableHeader,
217
+ });
218
+ });
219
+ };
220
+ var getPreviousResizableHeader = function (headerColumn, instance) {
221
+ var _a;
222
+ var headersList = ((_a = headerColumn.parent) === null || _a === void 0 ? void 0 : _a.columns) || instance.flatHeaders;
223
+ var headerIndex = headersList.findIndex(function (h) { return h.id === headerColumn.id; });
224
+ return __spreadArray([], headersList, true).slice(0, headerIndex)
225
+ .reverse()
226
+ .find(function (h) { return !h.disableResizing; });
227
+ };
228
+ var getNextResizableHeader = function (headerColumn, instance) {
229
+ var _a;
230
+ var headersList = ((_a = headerColumn.parent) === null || _a === void 0 ? void 0 : _a.columns) || instance.flatHeaders;
231
+ var headerIndex = headersList.findIndex(function (h) { return h.id === headerColumn.id; });
232
+ return __spreadArray([], headersList, true).slice(headerIndex + 1)
233
+ .find(function (h) { return !h.disableResizing; });
234
+ };
235
+ function getLeafHeaders(header) {
236
+ var leafHeaders = [];
237
+ var recurseHeader = function (header) {
238
+ if (header.columns && header.columns.length) {
239
+ header.columns.map(recurseHeader);
240
+ }
241
+ leafHeaders.push(header);
242
+ };
243
+ recurseHeader(header);
244
+ return leafHeaders;
245
+ }
246
+ // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#safely_detecting_option_support
247
+ var passiveSupported = null;
248
+ var passiveEventSupported = function () {
249
+ // memoize support to avoid adding multiple test events
250
+ if (passiveSupported != null) {
251
+ return passiveSupported;
252
+ }
253
+ try {
254
+ var options = {
255
+ once: true,
256
+ get passive() {
257
+ passiveSupported = true;
258
+ return false;
259
+ },
260
+ };
261
+ window.addEventListener('test', function () { }, options);
262
+ }
263
+ catch (_a) {
264
+ passiveSupported = false;
265
+ }
266
+ return passiveSupported;
267
+ };
@@ -1,2 +1,2 @@
1
1
  import { ColumnInstance } from 'react-table';
2
- export declare const getCellStyle: <T extends Record<string, unknown>>(column: ColumnInstance<T>) => React.CSSProperties | undefined;
2
+ export declare const getCellStyle: <T extends Record<string, unknown>>(column: ColumnInstance<T>, isTableResizing: boolean) => React.CSSProperties | undefined;
@@ -1,10 +1,16 @@
1
- export var getCellStyle = function (column) {
1
+ export var getCellStyle = function (column, isTableResizing) {
2
2
  var style = {};
3
3
  style.flex = "1 1 145px";
4
4
  if (column.width) {
5
5
  var width = typeof column.width === 'string' ? column.width : column.width + "px";
6
6
  style.width = width;
7
- style.flex = "0 0 " + width;
7
+ // This allows flexbox to handle the width of the column on table resize
8
+ if (isTableResizing && column.canResize) {
9
+ style.flex = Number(column.width) + " 1 " + width;
10
+ }
11
+ else {
12
+ style.flex = "0 0 " + width;
13
+ }
8
14
  }
9
15
  if (column.maxWidth) {
10
16
  style.maxWidth = column.maxWidth + "px";
@@ -43,6 +43,10 @@ export declare type TabsProps = {
43
43
  * Custom CSS class name for tab panel.
44
44
  */
45
45
  contentClassName?: string;
46
+ /**
47
+ * Custom CSS class name for the tabs wrapper.
48
+ */
49
+ wrapperClassName?: string;
46
50
  /**
47
51
  * Content inside the tab panel.
48
52
  */
@@ -26,7 +26,7 @@ var __rest = (this && this.__rest) || function (s, e) {
26
26
  *--------------------------------------------------------------------------------------------*/
27
27
  import cx from 'classnames';
28
28
  import React from 'react';
29
- import { useTheme, useResizeObserver, useMergedRefs, getBoundedValue, } from '../utils';
29
+ import { useTheme, useMergedRefs, getBoundedValue, getWindow, useContainerWidth, } from '../utils';
30
30
  import '@itwin/itwinui-css/css/tabs.css';
31
31
  import { Tab } from './Tab';
32
32
  /**
@@ -54,45 +54,38 @@ import { Tab } from './Tab';
54
54
  * <Tabs labels={tabsWithIcons} type='pill' />
55
55
  */
56
56
  export var Tabs = function (props) {
57
- var labels = props.labels, activeIndex = props.activeIndex, onTabSelected = props.onTabSelected, _a = props.focusActivationMode, focusActivationMode = _a === void 0 ? 'auto' : _a, _b = props.type, type = _b === void 0 ? 'default' : _b, _c = props.color, color = _c === void 0 ? 'blue' : _c, _d = props.orientation, orientation = _d === void 0 ? 'horizontal' : _d, tabsClassName = props.tabsClassName, contentClassName = props.contentClassName, children = props.children, rest = __rest(props, ["labels", "activeIndex", "onTabSelected", "focusActivationMode", "type", "color", "orientation", "tabsClassName", "contentClassName", "children"]);
57
+ var _a, _b, _c;
58
+ var labels = props.labels, activeIndex = props.activeIndex, onTabSelected = props.onTabSelected, _d = props.focusActivationMode, focusActivationMode = _d === void 0 ? 'auto' : _d, _e = props.type, type = _e === void 0 ? 'default' : _e, _f = props.color, color = _f === void 0 ? 'blue' : _f, _g = props.orientation, orientation = _g === void 0 ? 'horizontal' : _g, tabsClassName = props.tabsClassName, contentClassName = props.contentClassName, wrapperClassName = props.wrapperClassName, children = props.children, rest = __rest(props, ["labels", "activeIndex", "onTabSelected", "focusActivationMode", "type", "color", "orientation", "tabsClassName", "contentClassName", "wrapperClassName", "children"]);
58
59
  useTheme();
59
60
  var tablistRef = React.useRef(null);
60
- var _e = React.useState(function () { var _a; return (_a = tablistRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width; }), tabsWidth = _e[0], setTabsWidth = _e[1];
61
- var updateTabsWidth = React.useCallback(function (_a) {
62
- var width = _a.width;
63
- return setTabsWidth(width);
64
- }, []);
65
- var tablistSizeRef = useResizeObserver(updateTabsWidth)[0];
61
+ var _h = useContainerWidth(type !== 'default'), tablistSizeRef = _h[0], tabsWidth = _h[1];
66
62
  var refs = useMergedRefs(tablistRef, tablistSizeRef);
67
- var _f = React.useState(function () {
63
+ var _j = React.useState(function () {
68
64
  return activeIndex != null
69
65
  ? getBoundedValue(activeIndex, 0, labels.length - 1)
70
66
  : 0;
71
- }), currentActiveIndex = _f[0], setCurrentActiveIndex = _f[1];
67
+ }), currentActiveIndex = _j[0], setCurrentActiveIndex = _j[1];
72
68
  React.useLayoutEffect(function () {
73
69
  if (activeIndex != null && currentActiveIndex !== activeIndex) {
74
70
  setCurrentActiveIndex(getBoundedValue(activeIndex, 0, labels.length - 1));
75
71
  }
76
72
  }, [activeIndex, currentActiveIndex, labels.length]);
77
- var _g = React.useState({}), stripeStyle = _g[0], setStripeStyle = _g[1];
73
+ // CSS custom properties to place the active stripe
74
+ var _k = React.useState({}), stripeProperties = _k[0], setStripeProperties = _k[1];
78
75
  React.useLayoutEffect(function () {
79
- var _a;
80
- if (type !== 'default') {
81
- var activeTab = (_a = tablistRef.current) === null || _a === void 0 ? void 0 : _a.children[currentActiveIndex];
82
- var activeTabRect = activeTab === null || activeTab === void 0 ? void 0 : activeTab.getBoundingClientRect();
83
- setStripeStyle({
84
- width: orientation === 'horizontal' ? activeTabRect === null || activeTabRect === void 0 ? void 0 : activeTabRect.width : undefined,
85
- height: orientation === 'vertical' ? activeTabRect === null || activeTabRect === void 0 ? void 0 : activeTabRect.height : undefined,
86
- left: orientation === 'horizontal'
87
- ? activeTab === null || activeTab === void 0 ? void 0 : activeTab.offsetLeft
88
- : (activeTabRect === null || activeTabRect === void 0 ? void 0 : activeTabRect.width) - 2,
89
- top: orientation === 'horizontal'
90
- ? (activeTabRect === null || activeTabRect === void 0 ? void 0 : activeTabRect.height) - 2
91
- : activeTab === null || activeTab === void 0 ? void 0 : activeTab.offsetTop,
92
- });
76
+ if (type !== 'default' && tablistRef.current != undefined) {
77
+ var activeTab = tablistRef.current.children[currentActiveIndex];
78
+ var activeTabRect = activeTab.getBoundingClientRect();
79
+ setStripeProperties(__assign(__assign({}, (orientation === 'horizontal' && {
80
+ '--stripe-width': activeTabRect.width + "px",
81
+ '--stripe-left': activeTab.offsetLeft + "px",
82
+ })), (orientation === 'vertical' && {
83
+ '--stripe-height': activeTabRect.height + "px",
84
+ '--stripe-top': activeTab.offsetTop + "px",
85
+ })));
93
86
  }
94
87
  }, [currentActiveIndex, type, orientation, tabsWidth]);
95
- var _h = React.useState(), focusedIndex = _h[0], setFocusedIndex = _h[1];
88
+ var _l = React.useState(), focusedIndex = _l[0], setFocusedIndex = _l[1];
96
89
  React.useEffect(function () {
97
90
  var _a;
98
91
  if (tablistRef.current && focusedIndex !== undefined) {
@@ -100,7 +93,7 @@ export var Tabs = function (props) {
100
93
  (_a = tab) === null || _a === void 0 ? void 0 : _a.focus();
101
94
  }
102
95
  }, [focusedIndex]);
103
- var _j = React.useState(false), hasSublabel = _j[0], setHasSublabel = _j[1]; // used for setting size
96
+ var _m = React.useState(false), hasSublabel = _m[0], setHasSublabel = _m[1]; // used for setting size
104
97
  React.useLayoutEffect(function () {
105
98
  var _a;
106
99
  setHasSublabel(type !== 'pill' && // pill tabs should never have sublabels
@@ -173,10 +166,12 @@ export var Tabs = function (props) {
173
166
  break;
174
167
  }
175
168
  };
176
- return (React.createElement("div", { className: cx('iui-tabs-wrapper', "iui-" + orientation) },
169
+ var isIE = !((_c = (_b = (_a = getWindow()) === null || _a === void 0 ? void 0 : _a.CSS) === null || _b === void 0 ? void 0 : _b.supports) === null || _c === void 0 ? void 0 : _c.call(_b, '--stripe-width', '100px'));
170
+ return (React.createElement("div", { className: cx('iui-tabs-wrapper', "iui-" + orientation, wrapperClassName), style: stripeProperties },
177
171
  React.createElement("ul", __assign({ className: cx('iui-tabs', "iui-" + type, {
178
172
  'iui-green': color === 'green',
179
- 'iui-animated': type !== 'default',
173
+ 'iui-animated': type !== 'default' && !isIE,
174
+ 'iui-not-animated': isIE,
180
175
  'iui-large': hasSublabel,
181
176
  }, tabsClassName), role: 'tablist', ref: refs, onKeyDown: onKeyDown }, rest), labels.map(function (label, index) {
182
177
  var onClick = function () {
@@ -198,7 +193,6 @@ export var Tabs = function (props) {
198
193
  },
199
194
  }))));
200
195
  })),
201
- type !== 'default' && (React.createElement("div", { className: 'iui-tab-stripe', style: stripeStyle })),
202
196
  children && (React.createElement("div", { className: cx('iui-tabs-content', contentClassName), role: 'tabpanel' }, children))));
203
197
  };
204
198
  /**
@@ -32,10 +32,12 @@ export { Header, HeaderBreadcrumbs, HeaderButton, HeaderLogo } from './Header';
32
32
  export type { HeaderProps, HeaderBreadcrumbsProps, HeaderButtonProps, HeaderLogoProps, } from './Header';
33
33
  export { VerticalTabs, Tab, HorizontalTabs, HorizontalTab } from './Tabs';
34
34
  export type { VerticalTabsProps, TabProps, HorizontalTabsProps, HorizontalTabProps, } from './Tabs';
35
- export { InformationPanel, InformationPanelWrapper, InformationPanelHeader, InformationPanelBody, } from './InformationPanel';
36
- export type { InformationPanelProps, InformationPanelWrapperProps, InformationPanelHeaderProps, InformationPanelBodyProps, } from './InformationPanel';
35
+ export { InformationPanel, InformationPanelWrapper, InformationPanelHeader, InformationPanelBody, InformationPanelContent, } from './InformationPanel';
36
+ export type { InformationPanelProps, InformationPanelWrapperProps, InformationPanelHeaderProps, InformationPanelBodyProps, InformationPanelContentProps, } from './InformationPanel';
37
37
  export { Input } from './Input';
38
38
  export type { InputProps } from './Input';
39
+ export { Label } from './Label';
40
+ export type { LabelProps } from './Label';
39
41
  export { LabeledInput } from './LabeledInput';
40
42
  export type { LabeledInputProps } from './LabeledInput';
41
43
  export { InputGroup } from './InputGroup';
@@ -86,5 +88,5 @@ export { UserIconGroup } from './UserIconGroup';
86
88
  export type { UserIconGroupProps } from './UserIconGroup';
87
89
  export { Wizard } from './Wizard';
88
90
  export type { WizardProps, StepProperties, WizardType, WizardLocalization, } from './Wizard';
89
- export { getUserColor, useTheme, ColorValue } from './utils';
90
- export type { ThemeType } from './utils';
91
+ export { getUserColor, useTheme, ColorValue, MiddleTextTruncation, } from './utils';
92
+ export type { ThemeType, MiddleTextTruncationProps } from './utils';
package/esm/core/index.js CHANGED
@@ -19,8 +19,9 @@ export { FileUpload, FileUploadTemplate } from './FileUpload';
19
19
  export { Footer } from './Footer';
20
20
  export { Header, HeaderBreadcrumbs, HeaderButton, HeaderLogo } from './Header';
21
21
  export { VerticalTabs, Tab, HorizontalTabs, HorizontalTab } from './Tabs';
22
- export { InformationPanel, InformationPanelWrapper, InformationPanelHeader, InformationPanelBody, } from './InformationPanel';
22
+ export { InformationPanel, InformationPanelWrapper, InformationPanelHeader, InformationPanelBody, InformationPanelContent, } from './InformationPanel';
23
23
  export { Input } from './Input';
24
+ export { Label } from './Label';
24
25
  export { LabeledInput } from './LabeledInput';
25
26
  export { InputGroup } from './InputGroup';
26
27
  export { LabeledSelect } from './LabeledSelect';
@@ -46,4 +47,4 @@ export { Body, Headline, Leading, Small, Subheading, Title, Blockquote, Code, Kb
46
47
  export { UserIcon } from './UserIcon';
47
48
  export { UserIconGroup } from './UserIconGroup';
48
49
  export { Wizard } from './Wizard';
49
- export { getUserColor, useTheme, ColorValue } from './utils';
50
+ export { getUserColor, useTheme, ColorValue, MiddleTextTruncation, } from './utils';
@@ -170,6 +170,7 @@ export declare class ColorValue {
170
170
  private static toHsv;
171
171
  /** True if the value of this ColorValue is the same as another ColorValue. */
172
172
  equals(other: ColorValue): boolean;
173
+ static getFormattedColorNumber(value: number, precision?: number): string;
173
174
  /** Convert the 0xTTBBGGRR color to a string of the form "rgba(r,g,b,a)" where the color components are specified in decimal and the alpha component is a fraction. */
174
175
  toRgbString(includeAlpha?: boolean): string;
175
176
  /** Convert this ColorValue to a string in the form "hsl(h,s,l) or hsla(h,s,l,a)" - i.e hsl(120,50%,50%). */