@itwin/itwinui-react 2.0.0-dev.4 → 2.0.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 (56) hide show
  1. package/CHANGELOG.md +40 -906
  2. package/cjs/core/Avatar/Avatar.d.ts +1 -1
  3. package/cjs/core/AvatarGroup/AvatarGroup.d.ts +1 -1
  4. package/cjs/core/AvatarGroup/AvatarGroup.js +1 -1
  5. package/cjs/core/Carousel/CarouselSlider.js +2 -2
  6. package/cjs/core/ColorPicker/ColorBuilder.js +2 -7
  7. package/cjs/core/ColorPicker/ColorPalette.js +1 -1
  8. package/cjs/core/ColorPicker/ColorPicker.js +1 -3
  9. package/cjs/core/ComboBox/ComboBox.js +1 -1
  10. package/cjs/core/ComboBox/ComboBoxMenu.js +1 -1
  11. package/cjs/core/Dialog/DialogMain.js +1 -1
  12. package/cjs/core/Modal/ModalButtonBar.d.ts +1 -1
  13. package/cjs/core/Modal/ModalButtonBar.js +10 -1
  14. package/cjs/core/Modal/ModalContent.d.ts +1 -1
  15. package/cjs/core/Modal/ModalContent.js +10 -1
  16. package/cjs/core/Table/Table.js +1 -1
  17. package/cjs/core/Table/TablePaginator.d.ts +6 -0
  18. package/cjs/core/Table/TablePaginator.js +2 -1
  19. package/cjs/core/Table/hooks/useColumnDragAndDrop.js +3 -1
  20. package/cjs/core/Tabs/Tabs.js +3 -3
  21. package/cjs/core/utils/color/ColorValue.js +4 -2
  22. package/cjs/core/utils/components/Resizer.js +3 -2
  23. package/cjs/core/utils/components/VirtualScroll.js +7 -8
  24. package/cjs/core/utils/functions/styles.d.ts +1 -1
  25. package/cjs/core/utils/functions/styles.js +1 -1
  26. package/cjs/core/utils/hooks/useDragAndDrop.js +1 -1
  27. package/cjs/core/utils/hooks/useOverflow.js +4 -3
  28. package/cjs/core/utils/hooks/useTheme.js +2 -2
  29. package/esm/core/Avatar/Avatar.d.ts +1 -1
  30. package/esm/core/AvatarGroup/AvatarGroup.d.ts +1 -1
  31. package/esm/core/AvatarGroup/AvatarGroup.js +1 -1
  32. package/esm/core/Carousel/CarouselSlider.js +3 -3
  33. package/esm/core/ColorPicker/ColorBuilder.js +2 -7
  34. package/esm/core/ColorPicker/ColorPalette.js +1 -1
  35. package/esm/core/ColorPicker/ColorPicker.js +1 -3
  36. package/esm/core/ComboBox/ComboBox.js +2 -2
  37. package/esm/core/ComboBox/ComboBoxMenu.js +1 -1
  38. package/esm/core/Dialog/DialogMain.js +2 -2
  39. package/esm/core/Modal/ModalButtonBar.d.ts +1 -1
  40. package/esm/core/Modal/ModalButtonBar.js +6 -1
  41. package/esm/core/Modal/ModalContent.d.ts +1 -1
  42. package/esm/core/Modal/ModalContent.js +6 -1
  43. package/esm/core/Table/Table.js +2 -2
  44. package/esm/core/Table/TablePaginator.d.ts +6 -0
  45. package/esm/core/Table/TablePaginator.js +2 -1
  46. package/esm/core/Table/hooks/useColumnDragAndDrop.js +3 -1
  47. package/esm/core/Tabs/Tabs.js +4 -4
  48. package/esm/core/utils/color/ColorValue.js +4 -2
  49. package/esm/core/utils/components/Resizer.js +3 -2
  50. package/esm/core/utils/components/VirtualScroll.js +7 -8
  51. package/esm/core/utils/functions/styles.d.ts +1 -1
  52. package/esm/core/utils/functions/styles.js +1 -1
  53. package/esm/core/utils/hooks/useDragAndDrop.js +1 -1
  54. package/esm/core/utils/hooks/useOverflow.js +4 -3
  55. package/esm/core/utils/hooks/useTheme.js +2 -2
  56. package/package.json +4 -5
@@ -1,6 +1,11 @@
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';
1
6
  import { DialogContent } from '../Dialog/DialogContent';
2
7
  /**
3
8
  * Container for content in `Modal`.
4
9
  */
5
- export const ModalContent = DialogContent;
10
+ export const ModalContent = (props) => (React.createElement(DialogContent, { ...props }));
6
11
  export default ModalContent;
@@ -6,7 +6,7 @@ import React from 'react';
6
6
  import cx from 'classnames';
7
7
  import { actions as TableActions, useFlexLayout, useFilters, useRowSelect, useSortBy, useTable, useExpanded, usePagination, useColumnOrder, useGlobalFilter, } from 'react-table';
8
8
  import { ProgressRadial } from '../ProgressIndicators';
9
- import { useTheme, useResizeObserver, SvgSortDown, SvgSortUp, } from '../utils';
9
+ import { useTheme, useResizeObserver, SvgSortDown, SvgSortUp, useIsomorphicLayoutEffect, } from '../utils';
10
10
  import '@itwin/itwinui-css/css/table.css';
11
11
  import { getCellStyle, getStickyStyle } from './utils';
12
12
  import { TableRowMemoized } from './TableRowMemoized';
@@ -285,7 +285,7 @@ export const Table = (props) => {
285
285
  }, [dispatch, state.columnResizing.columnWidths, flatHeaders, instance]);
286
286
  const [resizeRef] = useResizeObserver(onTableResize);
287
287
  // Flexbox handles columns resize so we take new column widths before browser repaints.
288
- React.useLayoutEffect(() => {
288
+ useIsomorphicLayoutEffect(() => {
289
289
  if (state.isTableResizing) {
290
290
  const newColumnWidths = {};
291
291
  flatHeaders.forEach((column) => {
@@ -56,6 +56,12 @@ export declare type TablePaginatorProps = {
56
56
  * @default 'Rows per page'
57
57
  */
58
58
  rowsPerPageLabel?: string | null;
59
+ /**
60
+ * Function that returns a label shown in the bottom left to notify how many rows are selected.
61
+ * Only used if multi-selection mode is enabled.
62
+ * @default (totalSelectedRowsCount: number) => `${totalSelectedRowsCount} ${totalSelectedRowsCount === 1 ? 'row' : 'rows'} selected`;
63
+ */
64
+ rowsSelectedLabel?: (totalSelectedRowsCount: number) => string;
59
65
  };
60
66
  } & TablePaginatorRendererProps & Omit<CommonProps, 'title'>;
61
67
  /**
@@ -18,6 +18,7 @@ const defaultLocalization = {
18
18
  nextPage: 'Next page',
19
19
  goToPageLabel: (page) => `Go to page ${page}`,
20
20
  rowsPerPageLabel: 'Rows per page',
21
+ rowsSelectedLabel: (totalSelectedRowsCount) => `${totalSelectedRowsCount} ${totalSelectedRowsCount === 1 ? 'row' : 'rows'} selected`,
21
22
  };
22
23
  /**
23
24
  * Table paginator component. Recommended to pass to the `Table` as `paginatorRenderer` prop.
@@ -120,7 +121,7 @@ export const TablePaginator = (props) => {
120
121
  return null;
121
122
  }
122
123
  return (React.createElement("div", { className: cx('iui-table-paginator', className), ref: paginatorResizeRef, ...rest },
123
- React.createElement("div", { className: 'iui-left' }, totalSelectedRowsCount > 0 && (React.createElement("span", null, `${totalSelectedRowsCount} ${totalSelectedRowsCount === 1 ? 'row' : 'rows'} selected`))),
124
+ React.createElement("div", { className: 'iui-left' }, totalSelectedRowsCount > 0 && (React.createElement("span", null, localization.rowsSelectedLabel(totalSelectedRowsCount)))),
124
125
  showPagesList && (React.createElement("div", { className: 'iui-center', ref: overflowRef },
125
126
  React.createElement(IconButton, { styleType: 'borderless', disabled: currentPage === 0, onClick: () => onPageChange(currentPage - 1), size: buttonSize, "aria-label": localization.previousPage },
126
127
  React.createElement(SvgChevronLeft, null)),
@@ -39,7 +39,9 @@ const defaultGetDragAndDropProps = (isEnabled) => (props, { instance, header, })
39
39
  event.preventDefault();
40
40
  const headerIndex = instance.flatHeaders.indexOf(header);
41
41
  if (instance.state.columnReorderStartIndex !== headerIndex) {
42
- setOnDragColumnStyle(event, instance.state.columnReorderStartIndex > headerIndex ? 'left' : 'right');
42
+ setOnDragColumnStyle(event, instance.state.columnReorderStartIndex > headerIndex
43
+ ? 'left'
44
+ : 'right');
43
45
  }
44
46
  };
45
47
  const onDragLeave = (event) => {
@@ -4,7 +4,7 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import cx from 'classnames';
6
6
  import React from 'react';
7
- import { useTheme, useMergedRefs, getBoundedValue, useContainerWidth, } from '../utils';
7
+ import { useTheme, useMergedRefs, getBoundedValue, useContainerWidth, useIsomorphicLayoutEffect, } from '../utils';
8
8
  import '@itwin/itwinui-css/css/tabs.css';
9
9
  import { Tab } from './Tab';
10
10
  /**
@@ -43,14 +43,14 @@ export const Tabs = (props) => {
43
43
  const [currentActiveIndex, setCurrentActiveIndex] = React.useState(() => activeIndex != null
44
44
  ? getBoundedValue(activeIndex, 0, labels.length - 1)
45
45
  : 0);
46
- React.useLayoutEffect(() => {
46
+ useIsomorphicLayoutEffect(() => {
47
47
  if (activeIndex != null && currentActiveIndex !== activeIndex) {
48
48
  setCurrentActiveIndex(getBoundedValue(activeIndex, 0, labels.length - 1));
49
49
  }
50
50
  }, [activeIndex, currentActiveIndex, labels.length]);
51
51
  // CSS custom properties to place the active stripe
52
52
  const [stripeProperties, setStripeProperties] = React.useState({});
53
- React.useLayoutEffect(() => {
53
+ useIsomorphicLayoutEffect(() => {
54
54
  if (type !== 'default' && tablistRef.current != undefined) {
55
55
  const activeTab = tablistRef.current.children[currentActiveIndex];
56
56
  const activeTabRect = activeTab.getBoundingClientRect();
@@ -74,7 +74,7 @@ export const Tabs = (props) => {
74
74
  }
75
75
  }, [focusedIndex]);
76
76
  const [hasSublabel, setHasSublabel] = React.useState(false); // used for setting size
77
- React.useLayoutEffect(() => {
77
+ useIsomorphicLayoutEffect(() => {
78
78
  var _a;
79
79
  setHasSublabel(type !== 'pill' && // pill tabs should never have sublabels
80
80
  !!((_a = tablistRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.iui-tab-description')));
@@ -213,7 +213,8 @@ export class ColorValue {
213
213
  switch (name) {
214
214
  case 'rgb':
215
215
  case 'rgba':
216
- color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
216
+ color =
217
+ /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
217
218
  if (color) {
218
219
  // rgb(255,0,0) rgba(255,0,0,0.5)
219
220
  return [
@@ -226,7 +227,8 @@ export class ColorValue {
226
227
  break;
227
228
  case 'hsl':
228
229
  case 'hsla':
229
- color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
230
+ color =
231
+ /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
230
232
  if (color) {
231
233
  // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
232
234
  const h = parseFloat(color[1]);
@@ -26,7 +26,7 @@ export const Resizer = (props) => {
26
26
  const initialPointerX = event.clientX;
27
27
  const initialPointerY = event.clientY;
28
28
  const [initialTranslateX, initialTranslateY] = getTranslateValues(elementRef.current);
29
- const { width: initialWidth, height: initialHeight, } = elementRef.current.getBoundingClientRect();
29
+ const { width: initialWidth, height: initialHeight } = elementRef.current.getBoundingClientRect();
30
30
  let width = `${initialWidth}px`;
31
31
  let height = `${initialHeight}px`;
32
32
  let translateX = initialTranslateX;
@@ -126,7 +126,8 @@ export const Resizer = (props) => {
126
126
  elementRef.current.ownerDocument.addEventListener('pointerup', () => {
127
127
  document.removeEventListener('pointermove', onResizePointerMove);
128
128
  if (elementRef.current) {
129
- elementRef.current.ownerDocument.body.style.userSelect = originalUserSelect;
129
+ elementRef.current.ownerDocument.body.style.userSelect =
130
+ originalUserSelect;
130
131
  isResizing.current = false;
131
132
  onResizeEnd === null || onResizeEnd === void 0 ? void 0 : onResizeEnd({
132
133
  width,
@@ -3,8 +3,7 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import React from 'react';
6
- import { mergeRefs } from '../hooks';
7
- import { useResizeObserver } from '../hooks/useResizeObserver';
6
+ import { mergeRefs, useResizeObserver, useIsomorphicLayoutEffect, } from '../hooks';
8
7
  const getScrollableParent = (element, ownerDocument = document) => {
9
8
  if (!element || element === ownerDocument.body) {
10
9
  return ownerDocument.body;
@@ -146,18 +145,18 @@ export const useVirtualization = (props) => {
146
145
  const [resizeRef, resizeObserver] = useResizeObserver(onResize);
147
146
  // Find scrollable parent
148
147
  // Needed only on init
149
- React.useLayoutEffect(() => {
148
+ useIsomorphicLayoutEffect(() => {
150
149
  var _a;
151
150
  const scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
152
151
  scrollContainer.current = scrollableParent;
153
152
  resizeRef(scrollableParent);
154
153
  }, [resizeRef]);
155
154
  // Stop watching resize, when virtual scroll is unmounted
156
- React.useLayoutEffect(() => {
155
+ useIsomorphicLayoutEffect(() => {
157
156
  return () => resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
158
157
  }, [resizeObserver]);
159
158
  // Get child height when children available
160
- React.useLayoutEffect(() => updateChildHeight(), [updateChildHeight]);
159
+ useIsomorphicLayoutEffect(() => updateChildHeight(), [updateChildHeight]);
161
160
  const updateVirtualScroll = React.useCallback(() => {
162
161
  const scrollableContainer = getScrollableContainer();
163
162
  if (!scrollableContainer) {
@@ -191,7 +190,7 @@ export const useVirtualization = (props) => {
191
190
  : scrollContainer.current.removeEventListener('scroll', onScrollRef.current);
192
191
  }, []);
193
192
  // Add event listener to the scrollable container.
194
- React.useLayoutEffect(() => {
193
+ useIsomorphicLayoutEffect(() => {
195
194
  var _a, _b;
196
195
  removeScrollListener();
197
196
  onScrollRef.current = onScroll;
@@ -204,7 +203,7 @@ export const useVirtualization = (props) => {
204
203
  }
205
204
  return removeScrollListener;
206
205
  }, [onScroll, removeScrollListener]);
207
- React.useLayoutEffect(() => {
206
+ useIsomorphicLayoutEffect(() => {
208
207
  if (!isMounted) {
209
208
  return;
210
209
  }
@@ -256,7 +255,7 @@ export const useVirtualization = (props) => {
256
255
  }
257
256
  }
258
257
  }, [scrollToIndex, isMounted]);
259
- React.useLayoutEffect(() => {
258
+ useIsomorphicLayoutEffect(() => {
260
259
  if (!scrollContainerHeight) {
261
260
  return;
262
261
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Returns translate values as an array of a given element.
3
3
  * @param element HTML element you want to get translate value of
4
- * @returns Translate values in pixels in a array `[translateX, translateY]`
4
+ * @returns Translate values in pixels in an array `[translateX, translateY]`
5
5
  */
6
6
  export declare const getTranslateValues: (element: HTMLElement | null | undefined) => number[];
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Returns translate values as an array of a given element.
7
7
  * @param element HTML element you want to get translate value of
8
- * @returns Translate values in pixels in a array `[translateX, translateY]`
8
+ * @returns Translate values in pixels in an array `[translateX, translateY]`
9
9
  */
10
10
  export const getTranslateValues = (element) => {
11
11
  if (!element) {
@@ -35,7 +35,7 @@ export const useDragAndDrop = (elementRef, containerRef, enabled = true) => {
35
35
  if (!elementRef.current || !enabled) {
36
36
  return;
37
37
  }
38
- const { top, right, bottom, left, } = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
38
+ const { top, right, bottom, left } = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
39
39
  let [newTranslateX, newTranslateY] = getTranslateValues(elementRef.current);
40
40
  containerRectRef.current = getContainerRect(containerRef);
41
41
  if (bottom > containerRectRef.current.bottom) {
@@ -5,6 +5,7 @@
5
5
  import React from 'react';
6
6
  import { useMergedRefs } from './useMergedRefs';
7
7
  import { useResizeObserver } from './useResizeObserver';
8
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
8
9
  const STARTING_MAX_ITEMS_COUNT = 20;
9
10
  /**
10
11
  * Hook that observes the size of an element and returns the number of items
@@ -37,7 +38,7 @@ export const useOverflow = (items, disabled = false, orientation = 'horizontal')
37
38
  const updateContainerSize = React.useCallback(({ width, height }) => setContainerSize(orientation === 'horizontal' ? width : height), [orientation]);
38
39
  const [resizeRef, observer] = useResizeObserver(updateContainerSize);
39
40
  const resizeObserverRef = React.useRef(observer);
40
- React.useLayoutEffect(() => {
41
+ useIsomorphicLayoutEffect(() => {
41
42
  if (disabled) {
42
43
  setVisibleCount(items.length);
43
44
  }
@@ -47,7 +48,7 @@ export const useOverflow = (items, disabled = false, orientation = 'horizontal')
47
48
  }
48
49
  }, [containerSize, disabled, items]);
49
50
  const mergedRefs = useMergedRefs(containerRef, resizeRef);
50
- React.useLayoutEffect(() => {
51
+ useIsomorphicLayoutEffect(() => {
51
52
  var _a;
52
53
  if (!containerRef.current || disabled) {
53
54
  (_a = resizeObserverRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -75,7 +76,7 @@ export const useOverflow = (items, disabled = false, orientation = 'horizontal')
75
76
  }
76
77
  needsFullRerender.current = false;
77
78
  }, [containerSize, visibleCount, disabled, items.length, orientation]);
78
- React.useLayoutEffect(() => {
79
+ useIsomorphicLayoutEffect(() => {
79
80
  previousContainerSize.current = containerSize;
80
81
  }, [containerSize]);
81
82
  return [mergedRefs, visibleCount];
@@ -22,8 +22,8 @@ export const useTheme = (theme, themeOptions) => {
22
22
  const themeContext = React.useContext(ThemeContext);
23
23
  const ownerDocument = (_a = themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.ownerDocument) !== null && _a !== void 0 ? _a : getDocument();
24
24
  useIsomorphicLayoutEffect(() => {
25
- // exit early if theme was already set by provider
26
- if (themeContext || !ownerDocument) {
25
+ // exit early if theme was already set by provider or is present on <body>
26
+ if (themeContext || !ownerDocument || ownerDocument.body.dataset.iuiTheme) {
27
27
  return;
28
28
  }
29
29
  ownerDocument.body.classList.toggle('iui-root', true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "2.0.0-dev.4",
3
+ "version": "2.0.1",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "main": "cjs/index.js",
@@ -46,8 +46,8 @@
46
46
  "ux"
47
47
  ],
48
48
  "scripts": {
49
- "build": "yarn clean:build && yarn copy-files && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
50
- "build:watch": "yarn clean:build && yarn copy-files && concurrently \"tsc -p tsconfig.cjs.json --watch\" \"tsc -p tsconfig.esm.json --watch\"",
49
+ "build": "yarn clean:build && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
50
+ "build:watch": "yarn clean:build && concurrently \"tsc -p tsconfig.cjs.json --watch\" \"tsc -p tsconfig.esm.json --watch\"",
51
51
  "clean:build": "yarn clean:coverage && rimraf esm && rimraf cjs",
52
52
  "clean:coverage": "rimraf coverage",
53
53
  "clean": "rimraf .turbo && yarn clean:coverage && yarn clean:build && rimraf node_modules",
@@ -56,12 +56,11 @@
56
56
  "format": "prettier --config .prettierrc **/*.{tsx,ts,js} --ignore-path .gitignore --write",
57
57
  "lint": "eslint \"**/*.{js,ts,tsx}\" --max-warnings=0",
58
58
  "lint:fix": "yarn lint --fix && node ../configs/copyrightLinter.js --fix \"*/**/*.{js,ts,tsx}\"",
59
- "copy-files": "cpy \"../../{README,LICENSE}.md\" .",
60
59
  "dev": "yarn build:watch",
61
60
  "createComponent": "node ../../scripts/createComponent.js"
62
61
  },
63
62
  "dependencies": {
64
- "@itwin/itwinui-css": "^1.0.0",
63
+ "@itwin/itwinui-css": "^1.1.0",
65
64
  "@itwin/itwinui-illustrations-react": "^2.0.0",
66
65
  "@itwin/itwinui-variables": "^1.0.0",
67
66
  "@tippyjs/react": "^4.2.6",