@itwin/itwinui-react 1.41.0 → 1.43.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 (142) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/cjs/core/Backdrop/Backdrop.d.ts +10 -0
  3. package/cjs/core/Backdrop/Backdrop.js +41 -0
  4. package/cjs/core/Backdrop/index.d.ts +2 -0
  5. package/cjs/core/Backdrop/index.js +9 -0
  6. package/cjs/core/Breadcrumbs/Breadcrumbs.js +18 -18
  7. package/cjs/core/ButtonGroup/ButtonGroup.js +11 -4
  8. package/cjs/core/ComboBox/ComboBox.js +15 -14
  9. package/cjs/core/Dialog/Dialog.d.ts +41 -0
  10. package/cjs/core/Dialog/Dialog.js +59 -0
  11. package/cjs/core/Dialog/DialogBackdrop.d.ts +12 -0
  12. package/cjs/core/Dialog/DialogBackdrop.js +61 -0
  13. package/cjs/core/Dialog/DialogButtonBar.d.ts +18 -0
  14. package/cjs/core/Dialog/DialogButtonBar.js +50 -0
  15. package/cjs/core/Dialog/DialogContent.d.ts +17 -0
  16. package/cjs/core/Dialog/DialogContent.js +49 -0
  17. package/cjs/core/Dialog/DialogContext.d.ts +39 -0
  18. package/cjs/core/Dialog/DialogContext.js +16 -0
  19. package/cjs/core/Dialog/DialogMain.d.ts +36 -0
  20. package/cjs/core/Dialog/DialogMain.js +120 -0
  21. package/cjs/core/Dialog/DialogTitleBar.d.ts +34 -0
  22. package/cjs/core/Dialog/DialogTitleBar.js +69 -0
  23. package/cjs/core/Dialog/DialogTitleBarTitle.d.ts +15 -0
  24. package/cjs/core/Dialog/DialogTitleBarTitle.js +47 -0
  25. package/cjs/core/Dialog/index.d.ts +8 -0
  26. package/cjs/core/Dialog/index.js +10 -0
  27. package/cjs/core/Footer/Footer.d.ts +16 -2
  28. package/cjs/core/Footer/Footer.js +57 -45
  29. package/cjs/core/Footer/FooterItem.d.ts +8 -0
  30. package/cjs/core/Footer/FooterItem.js +46 -0
  31. package/cjs/core/Footer/FooterList.d.ts +8 -0
  32. package/cjs/core/Footer/FooterList.js +46 -0
  33. package/cjs/core/Footer/FooterSeparator.d.ts +8 -0
  34. package/cjs/core/Footer/FooterSeparator.js +46 -0
  35. package/cjs/core/Footer/index.d.ts +1 -1
  36. package/cjs/core/Footer/index.js +2 -1
  37. package/cjs/core/Modal/Modal.d.ts +4 -14
  38. package/cjs/core/Modal/Modal.js +9 -74
  39. package/cjs/core/Modal/ModalButtonBar.d.ts +1 -2
  40. package/cjs/core/Modal/ModalButtonBar.js +2 -39
  41. package/cjs/core/Modal/ModalContent.d.ts +1 -2
  42. package/cjs/core/Modal/ModalContent.js +2 -39
  43. package/cjs/core/Slider/Slider.d.ts +10 -0
  44. package/cjs/core/Slider/Slider.js +20 -14
  45. package/cjs/core/Slider/Thumb.d.ts +2 -1
  46. package/cjs/core/Slider/Thumb.js +5 -3
  47. package/cjs/core/Slider/Track.d.ts +2 -1
  48. package/cjs/core/Slider/Track.js +23 -4
  49. package/cjs/core/Table/Table.d.ts +24 -0
  50. package/cjs/core/Table/Table.js +12 -4
  51. package/cjs/core/Table/TableRowMemoized.d.ts +2 -0
  52. package/cjs/core/Table/TableRowMemoized.js +2 -2
  53. package/cjs/core/Table/columns/actionColumn.d.ts +8 -3
  54. package/cjs/core/Table/columns/actionColumn.js +33 -2
  55. package/cjs/core/Table/hooks/index.d.ts +1 -0
  56. package/cjs/core/Table/hooks/index.js +3 -1
  57. package/cjs/core/Table/hooks/useScrollToRow.d.ts +11 -0
  58. package/cjs/core/Table/hooks/useScrollToRow.js +49 -0
  59. package/cjs/core/Tree/Tree.d.ts +9 -0
  60. package/cjs/core/Tree/Tree.js +67 -19
  61. package/cjs/core/Tree/TreeContext.d.ts +4 -0
  62. package/cjs/core/Tree/TreeNode.js +8 -9
  63. package/cjs/core/Typography/Small/Small.js +1 -1
  64. package/cjs/core/index.d.ts +3 -1
  65. package/cjs/core/index.js +6 -3
  66. package/cjs/core/utils/components/FocusTrap.js +1 -1
  67. package/cjs/core/utils/components/MiddleTextTruncation.js +1 -1
  68. package/cjs/core/utils/hooks/index.d.ts +1 -0
  69. package/cjs/core/utils/hooks/index.js +1 -0
  70. package/cjs/core/utils/hooks/useLatestRef.d.ts +9 -0
  71. package/cjs/core/utils/hooks/useLatestRef.js +26 -0
  72. package/esm/core/Backdrop/Backdrop.d.ts +10 -0
  73. package/esm/core/Backdrop/Backdrop.js +35 -0
  74. package/esm/core/Backdrop/index.d.ts +2 -0
  75. package/esm/core/Backdrop/index.js +5 -0
  76. package/esm/core/Breadcrumbs/Breadcrumbs.js +18 -18
  77. package/esm/core/ButtonGroup/ButtonGroup.js +11 -4
  78. package/esm/core/ComboBox/ComboBox.js +16 -15
  79. package/esm/core/Dialog/Dialog.d.ts +41 -0
  80. package/esm/core/Dialog/Dialog.js +53 -0
  81. package/esm/core/Dialog/DialogBackdrop.d.ts +12 -0
  82. package/esm/core/Dialog/DialogBackdrop.js +55 -0
  83. package/esm/core/Dialog/DialogButtonBar.d.ts +18 -0
  84. package/esm/core/Dialog/DialogButtonBar.js +44 -0
  85. package/esm/core/Dialog/DialogContent.d.ts +17 -0
  86. package/esm/core/Dialog/DialogContent.js +43 -0
  87. package/esm/core/Dialog/DialogContext.d.ts +39 -0
  88. package/esm/core/Dialog/DialogContext.js +9 -0
  89. package/esm/core/Dialog/DialogMain.d.ts +36 -0
  90. package/esm/core/Dialog/DialogMain.js +114 -0
  91. package/esm/core/Dialog/DialogTitleBar.d.ts +34 -0
  92. package/esm/core/Dialog/DialogTitleBar.js +63 -0
  93. package/esm/core/Dialog/DialogTitleBarTitle.d.ts +15 -0
  94. package/esm/core/Dialog/DialogTitleBarTitle.js +41 -0
  95. package/esm/core/Dialog/index.d.ts +8 -0
  96. package/esm/core/Dialog/index.js +6 -0
  97. package/esm/core/Footer/Footer.d.ts +16 -2
  98. package/esm/core/Footer/Footer.js +56 -43
  99. package/esm/core/Footer/FooterItem.d.ts +8 -0
  100. package/esm/core/Footer/FooterItem.js +39 -0
  101. package/esm/core/Footer/FooterList.d.ts +8 -0
  102. package/esm/core/Footer/FooterList.js +39 -0
  103. package/esm/core/Footer/FooterSeparator.d.ts +8 -0
  104. package/esm/core/Footer/FooterSeparator.js +39 -0
  105. package/esm/core/Footer/index.d.ts +1 -1
  106. package/esm/core/Footer/index.js +1 -1
  107. package/esm/core/Modal/Modal.d.ts +4 -14
  108. package/esm/core/Modal/Modal.js +10 -75
  109. package/esm/core/Modal/ModalButtonBar.d.ts +1 -2
  110. package/esm/core/Modal/ModalButtonBar.js +2 -35
  111. package/esm/core/Modal/ModalContent.d.ts +1 -2
  112. package/esm/core/Modal/ModalContent.js +2 -35
  113. package/esm/core/Slider/Slider.d.ts +10 -0
  114. package/esm/core/Slider/Slider.js +20 -14
  115. package/esm/core/Slider/Thumb.d.ts +2 -1
  116. package/esm/core/Slider/Thumb.js +5 -3
  117. package/esm/core/Slider/Track.d.ts +2 -1
  118. package/esm/core/Slider/Track.js +23 -4
  119. package/esm/core/Table/Table.d.ts +24 -0
  120. package/esm/core/Table/Table.js +13 -5
  121. package/esm/core/Table/TableRowMemoized.d.ts +2 -0
  122. package/esm/core/Table/TableRowMemoized.js +2 -2
  123. package/esm/core/Table/columns/actionColumn.d.ts +8 -3
  124. package/esm/core/Table/columns/actionColumn.js +33 -2
  125. package/esm/core/Table/hooks/index.d.ts +1 -0
  126. package/esm/core/Table/hooks/index.js +1 -0
  127. package/esm/core/Table/hooks/useScrollToRow.d.ts +11 -0
  128. package/esm/core/Table/hooks/useScrollToRow.js +42 -0
  129. package/esm/core/Tree/Tree.d.ts +9 -0
  130. package/esm/core/Tree/Tree.js +68 -20
  131. package/esm/core/Tree/TreeContext.d.ts +4 -0
  132. package/esm/core/Tree/TreeNode.js +8 -9
  133. package/esm/core/Typography/Small/Small.js +1 -1
  134. package/esm/core/index.d.ts +3 -1
  135. package/esm/core/index.js +2 -1
  136. package/esm/core/utils/components/FocusTrap.js +1 -1
  137. package/esm/core/utils/components/MiddleTextTruncation.js +1 -1
  138. package/esm/core/utils/hooks/index.d.ts +1 -0
  139. package/esm/core/utils/hooks/index.js +1 -0
  140. package/esm/core/utils/hooks/useLatestRef.d.ts +9 -0
  141. package/esm/core/utils/hooks/useLatestRef.js +19 -0
  142. package/package.json +6 -5
@@ -0,0 +1,35 @@
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 __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { useTheme } from '../utils';
30
+ import '@itwin/itwinui-css/css/backdrop.css';
31
+ export var Backdrop = React.forwardRef(function (props, ref) {
32
+ var _a = props.isVisible, isVisible = _a === void 0 ? true : _a, className = props.className, rest = __rest(props, ["isVisible", "className"]);
33
+ useTheme();
34
+ return (React.createElement("div", __assign({ className: cx('iui-backdrop', { 'iui-backdrop-visible': isVisible }, className), ref: ref }, rest)));
35
+ });
@@ -0,0 +1,2 @@
1
+ export { Backdrop } from './Backdrop';
2
+ export type { BackdropProps } from './Backdrop';
@@ -0,0 +1,5 @@
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 { Backdrop } from './Backdrop';
@@ -56,28 +56,15 @@ export var Breadcrumbs = React.forwardRef(function (props, ref) {
56
56
  useTheme();
57
57
  var _b = useOverflow(items), overflowRef = _b[0], visibleCount = _b[1];
58
58
  var refs = useMergedRefs(overflowRef, ref);
59
- var Separator = function () { return (React.createElement("li", { className: 'iui-breadcrumbs-separator', "aria-hidden": true }, separator !== null && separator !== void 0 ? separator : React.createElement(SvgChevronRight, null))); };
60
- var ListItem = function (_a) {
61
- var _b;
62
- var index = _a.index;
63
- var item = items[index];
64
- return (React.createElement("li", { className: 'iui-breadcrumbs-item iui-breadcrumbs-item-overrides' }, React.isValidElement(item)
65
- ? React.cloneElement(item, {
66
- 'aria-current': ((_b = item.props['aria-current']) !== null && _b !== void 0 ? _b : currentIndex === index)
67
- ? 'location'
68
- : undefined,
69
- })
70
- : item));
71
- };
72
59
  return (React.createElement("nav", __assign({ className: cx('iui-breadcrumbs', className), ref: refs, "aria-label": 'Breadcrumb' }, rest),
73
60
  React.createElement("ol", { className: 'iui-breadcrumbs-list' },
74
61
  visibleCount > 1 && (React.createElement(React.Fragment, null,
75
- React.createElement(ListItem, { index: 0 }),
76
- React.createElement(Separator, null))),
62
+ React.createElement(ListItem, { item: items[0], isActive: currentIndex === 0 }),
63
+ React.createElement(Separator, { separator: separator }))),
77
64
  items.length - visibleCount > 0 && (React.createElement(React.Fragment, null,
78
65
  React.createElement("li", { className: 'iui-breadcrumbs-item iui-breadcrumbs-item-overrides' },
79
66
  React.createElement("span", { className: 'iui-breadcrumbs-text' }, "\u2026")),
80
- React.createElement(Separator, null))),
67
+ React.createElement(Separator, { separator: separator }))),
81
68
  items
82
69
  .slice(visibleCount > 1
83
70
  ? items.length - visibleCount + 1
@@ -87,8 +74,21 @@ export var Breadcrumbs = React.forwardRef(function (props, ref) {
87
74
  ? 1 + (items.length - visibleCount) + _index
88
75
  : items.length - 1;
89
76
  return (React.createElement(React.Fragment, { key: index },
90
- React.createElement(ListItem, { index: index }),
91
- index < items.length - 1 && React.createElement(Separator, null)));
77
+ React.createElement(ListItem, { item: items[index], isActive: currentIndex === index }),
78
+ index < items.length - 1 && (React.createElement(Separator, { separator: separator }))));
92
79
  }))));
93
80
  });
81
+ var ListItem = function (_a) {
82
+ var _b;
83
+ var item = _a.item, isActive = _a.isActive;
84
+ return (React.createElement("li", { className: 'iui-breadcrumbs-item iui-breadcrumbs-item-overrides' }, React.isValidElement(item)
85
+ ? React.cloneElement(item, {
86
+ 'aria-current': ((_b = item.props['aria-current']) !== null && _b !== void 0 ? _b : isActive) ? 'location' : undefined,
87
+ })
88
+ : item));
89
+ };
90
+ var Separator = function (_a) {
91
+ var separator = _a.separator;
92
+ return (React.createElement("li", { className: 'iui-breadcrumbs-separator', "aria-hidden": true }, separator !== null && separator !== void 0 ? separator : React.createElement(SvgChevronRight, null)));
93
+ };
94
94
  export default Breadcrumbs;
@@ -66,9 +66,16 @@ export var ButtonGroup = React.forwardRef(function (props, ref) {
66
66
  'iui-button-group': orientation === 'horizontal',
67
67
  'iui-button-group-vertical': orientation === 'vertical',
68
68
  'iui-button-group-overflow-x': !!overflowButton && orientation === 'horizontal',
69
- }, className), "aria-orientation": orientation, ref: refs }, rest), !!overflowButton && visibleCount < items.length ? (React.createElement(React.Fragment, null,
70
- overflowButton && overflowPlacement === 'start' && (React.createElement("div", null, overflowButton(visibleCount))),
71
- items.slice(0, visibleCount - 1),
72
- overflowButton && overflowPlacement === 'end' && (React.createElement("div", null, overflowButton(visibleCount))))) : (items)));
69
+ }, className), "aria-orientation": orientation, ref: refs }, rest),
70
+ React.createElement(React.Fragment, null,
71
+ visibleCount < items.length &&
72
+ overflowButton &&
73
+ overflowPlacement === 'start' && (React.createElement("div", null, overflowButton(visibleCount))),
74
+ visibleCount < items.length
75
+ ? items.slice(0, visibleCount - 1)
76
+ : items,
77
+ visibleCount < items.length &&
78
+ overflowButton &&
79
+ overflowPlacement === 'end' && (React.createElement("div", null, overflowButton(visibleCount))))));
73
80
  });
74
81
  export default ButtonGroup;
@@ -28,7 +28,7 @@ import React from 'react';
28
28
  import cx from 'classnames';
29
29
  import { MenuExtraContent } from '../Menu';
30
30
  import { Text } from '../Typography';
31
- import { useTheme, getRandomValue, mergeRefs, } from '../utils';
31
+ import { useTheme, getRandomValue, mergeRefs, useLatestRef, } from '../utils';
32
32
  import 'tippy.js/animations/shift-away.css';
33
33
  import { ComboBoxActionContext, comboBoxReducer, ComboBoxRefsContext, ComboBoxStateContext, } from './helpers';
34
34
  import { ComboBoxDropdown } from './ComboBoxDropdown';
@@ -69,11 +69,9 @@ export var ComboBox = function (props) {
69
69
  var menuRef = React.useRef(null);
70
70
  var toggleButtonRef = React.useRef(null);
71
71
  var mounted = React.useRef(false);
72
- // Latest value of the onChange prop
73
- var onChangeProp = React.useRef(onChange);
74
- React.useEffect(function () {
75
- onChangeProp.current = onChange;
76
- }, [onChange]);
72
+ var valuePropRef = useLatestRef(valueProp);
73
+ var onChangeProp = useLatestRef(onChange);
74
+ var optionsRef = useLatestRef(options);
77
75
  // Record to store all extra information (e.g. original indexes), where the key is the id of the option
78
76
  var optionsExtraInfoRef = React.useRef({});
79
77
  // Clear the extra info when the options change so that it can be reinitialized below
@@ -93,7 +91,7 @@ export var ComboBox = function (props) {
93
91
  var _e = React.useReducer(comboBoxReducer, {
94
92
  isOpen: false,
95
93
  selectedIndex: valueProp
96
- ? options.findIndex(function (option) { return option.value === valueProp; })
94
+ ? optionsRef.current.findIndex(function (option) { return option.value === valueProp; })
97
95
  : -1,
98
96
  focusedIndex: -1,
99
97
  }), _f = _e[0], isOpen = _f.isOpen, selectedIndex = _f.selectedIndex, focusedIndex = _f.focusedIndex, dispatch = _e[1];
@@ -102,7 +100,7 @@ export var ComboBox = function (props) {
102
100
  // When the dropdown opens
103
101
  if (isOpen) {
104
102
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); // Focus the input
105
- setFilteredOptions(options); // Reset the filtered list
103
+ setFilteredOptions(optionsRef.current); // Reset the filtered list
106
104
  dispatch(['focus']);
107
105
  }
108
106
  // When the dropdown closes
@@ -111,10 +109,10 @@ export var ComboBox = function (props) {
111
109
  dispatch(['focus']);
112
110
  // Reset the input value
113
111
  setInputValue(selectedIndex != undefined && selectedIndex >= 0
114
- ? (_b = options[selectedIndex]) === null || _b === void 0 ? void 0 : _b.label
112
+ ? (_b = optionsRef.current[selectedIndex]) === null || _b === void 0 ? void 0 : _b.label
115
113
  : '');
116
114
  }
117
- }, [isOpen, options, selectedIndex]);
115
+ }, [isOpen, optionsRef, selectedIndex]);
118
116
  // Set min-width of menu to be same as input
119
117
  var _g = React.useState(0), minWidth = _g[0], setMinWidth = _g[1];
120
118
  React.useEffect(function () {
@@ -145,14 +143,14 @@ export var ComboBox = function (props) {
145
143
  var value = event.currentTarget.value;
146
144
  setInputValue(value);
147
145
  dispatch(['open']); // reopen when typing
148
- setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, value)) !== null && _a !== void 0 ? _a : options.filter(function (option) {
146
+ setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(optionsRef.current, value)) !== null && _a !== void 0 ? _a : optionsRef.current.filter(function (option) {
149
147
  return option.label.toLowerCase().includes(value.toLowerCase());
150
148
  }));
151
149
  if (focusedIndex != -1) {
152
150
  dispatch(['focus', -1]);
153
151
  }
154
152
  (_b = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _b === void 0 ? void 0 : _b.call(inputProps, event);
155
- }, [filterFunction, focusedIndex, inputProps, options]);
153
+ }, [filterFunction, focusedIndex, inputProps, optionsRef]);
156
154
  // When the value prop changes, update the selectedIndex
157
155
  React.useEffect(function () {
158
156
  dispatch([
@@ -168,9 +166,12 @@ export var ComboBox = function (props) {
168
166
  mounted.current = true;
169
167
  return;
170
168
  }
171
- var value = (_a = options[selectedIndex]) === null || _a === void 0 ? void 0 : _a.value;
172
- (_b = onChangeProp.current) === null || _b === void 0 ? void 0 : _b.call(onChangeProp, value);
173
- }, [options, selectedIndex]);
169
+ var currentValue = (_a = optionsRef.current[selectedIndex]) === null || _a === void 0 ? void 0 : _a.value;
170
+ if (currentValue === valuePropRef.current || selectedIndex === -1) {
171
+ return;
172
+ }
173
+ (_b = onChangeProp.current) === null || _b === void 0 ? void 0 : _b.call(onChangeProp, currentValue);
174
+ }, [onChangeProp, optionsRef, selectedIndex, valuePropRef]);
174
175
  var getMenuItem = React.useCallback(function (option, filteredIndex) {
175
176
  var optionId = getOptionId(option, id);
176
177
  var __originalIndex = optionsExtraInfoRef.current[optionId].__originalIndex;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import '@itwin/itwinui-css/css/dialog.css';
3
+ import { DialogContextProps } from './DialogContext';
4
+ export declare type DialogProps = {
5
+ /**
6
+ * Dialog content.
7
+ */
8
+ children: React.ReactNode;
9
+ } & DialogContextProps;
10
+ /**
11
+ * Dialog component.
12
+ * @example
13
+ * <Dialog
14
+ * isOpen={isOpen}
15
+ * onClose={() => setIsOpen(false)}
16
+ * trapFocus
17
+ * preventDocumentScroll
18
+ * >
19
+ * <Dialog.Backdrop />
20
+ * <Dialog.Main aria-modal>
21
+ * <Dialog.TitleBar>My dialog title</Dialog.TitleBar>
22
+ * <Dialog.Content>
23
+ * Here is my dialog content
24
+ * </Dialog.Content>
25
+ * <Dialog.ButtonBar>
26
+ * <Button styleType='high-visibility'>Confirm</Button>
27
+ * <Button>Close</Button>
28
+ * </Dialog.ButtonBar>
29
+ * </Dialog.Main>
30
+ * </Dialog>
31
+ */
32
+ export declare const Dialog: ((props: DialogProps) => JSX.Element) & {
33
+ Backdrop: React.ForwardRefExoticComponent<Pick<import("./DialogBackdrop").DialogBackdropProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isVisible" | "isDismissible" | "closeOnExternalClick"> & React.RefAttributes<HTMLDivElement>>;
34
+ Main: React.ForwardRefExoticComponent<Pick<import("./DialogMain").DialogMainProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "styleType" | "isOpen" | "isDismissible" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll"> & React.RefAttributes<HTMLDivElement>>;
35
+ TitleBar: React.ForwardRefExoticComponent<Pick<import("./DialogTitleBar").DialogTitleBarProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isDismissible" | "titleText"> & React.RefAttributes<HTMLDivElement>> & {
36
+ Title: React.ForwardRefExoticComponent<Pick<import("./DialogTitleBarTitle").DialogTitleBarTitleProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
37
+ };
38
+ Content: React.ForwardRefExoticComponent<Pick<import("./DialogContent").DialogContentProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
39
+ ButtonBar: React.ForwardRefExoticComponent<Pick<import("./DialogButtonBar").DialogButtonBarProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
40
+ };
41
+ export default Dialog;
@@ -0,0 +1,53 @@
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 '@itwin/itwinui-css/css/dialog.css';
7
+ import { DialogTitleBar } from './DialogTitleBar';
8
+ import { DialogContent } from './DialogContent';
9
+ import { DialogBackdrop } from './DialogBackdrop';
10
+ import { DialogContext } from './DialogContext';
11
+ import { DialogButtonBar } from './DialogButtonBar';
12
+ import DialogMain from './DialogMain';
13
+ /**
14
+ * Dialog component.
15
+ * @example
16
+ * <Dialog
17
+ * isOpen={isOpen}
18
+ * onClose={() => setIsOpen(false)}
19
+ * trapFocus
20
+ * preventDocumentScroll
21
+ * >
22
+ * <Dialog.Backdrop />
23
+ * <Dialog.Main aria-modal>
24
+ * <Dialog.TitleBar>My dialog title</Dialog.TitleBar>
25
+ * <Dialog.Content>
26
+ * Here is my dialog content
27
+ * </Dialog.Content>
28
+ * <Dialog.ButtonBar>
29
+ * <Button styleType='high-visibility'>Confirm</Button>
30
+ * <Button>Close</Button>
31
+ * </Dialog.ButtonBar>
32
+ * </Dialog.Main>
33
+ * </Dialog>
34
+ */
35
+ export var Dialog = Object.assign(function (props) {
36
+ var children = props.children, _a = props.trapFocus, trapFocus = _a === void 0 ? false : _a, _b = props.preventDocumentScroll, preventDocumentScroll = _b === void 0 ? false : _b, _c = props.isOpen, isOpen = _c === void 0 ? false : _c, _d = props.isDismissible, isDismissible = _d === void 0 ? true : _d, _e = props.closeOnEsc, closeOnEsc = _e === void 0 ? true : _e, _f = props.closeOnExternalClick, closeOnExternalClick = _f === void 0 ? false : _f, onClose = props.onClose;
37
+ return (React.createElement(DialogContext.Provider, { value: {
38
+ isOpen: isOpen,
39
+ onClose: onClose,
40
+ closeOnEsc: closeOnEsc,
41
+ closeOnExternalClick: closeOnExternalClick,
42
+ isDismissible: isDismissible,
43
+ preventDocumentScroll: preventDocumentScroll,
44
+ trapFocus: trapFocus,
45
+ } }, children));
46
+ }, {
47
+ Backdrop: DialogBackdrop,
48
+ Main: DialogMain,
49
+ TitleBar: DialogTitleBar,
50
+ Content: DialogContent,
51
+ ButtonBar: DialogButtonBar,
52
+ });
53
+ export default Dialog;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { BackdropProps } from '../Backdrop';
3
+ import { DialogContextProps } from './DialogContext';
4
+ export declare type DialogBackdropProps = BackdropProps & Pick<DialogContextProps, 'onClose' | 'isDismissible' | 'closeOnExternalClick'>;
5
+ /**
6
+ * Backdrop component for dialog. Recommended to be used with `Dialog`
7
+ * then its visibility is being controlled by dialog's `isOpen` prop.
8
+ * @example
9
+ * <Dialog.Backdrop />
10
+ */
11
+ export declare const DialogBackdrop: React.ForwardRefExoticComponent<Pick<DialogBackdropProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isVisible" | "isDismissible" | "closeOnExternalClick"> & React.RefAttributes<HTMLDivElement>>;
12
+ export default DialogBackdrop;
@@ -0,0 +1,55 @@
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 __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import { Backdrop } from '../Backdrop';
29
+ import { useMergedRefs } from '../utils';
30
+ import { useDialogContext } from './DialogContext';
31
+ /**
32
+ * Backdrop component for dialog. Recommended to be used with `Dialog`
33
+ * then its visibility is being controlled by dialog's `isOpen` prop.
34
+ * @example
35
+ * <Dialog.Backdrop />
36
+ */
37
+ export var DialogBackdrop = React.forwardRef(function (props, ref) {
38
+ var dialogContext = useDialogContext();
39
+ var _a = props.isVisible, isVisible = _a === void 0 ? dialogContext.isOpen : _a, _b = props.isDismissible, isDismissible = _b === void 0 ? dialogContext.isDismissible : _b, _c = props.onClose, onClose = _c === void 0 ? dialogContext.onClose : _c, _d = props.closeOnExternalClick, closeOnExternalClick = _d === void 0 ? dialogContext.closeOnExternalClick : _d, onMouseDown = props.onMouseDown, rest = __rest(props, ["isVisible", "isDismissible", "onClose", "closeOnExternalClick", "onMouseDown"]);
40
+ var backdropRef = React.useRef(null);
41
+ var refs = useMergedRefs(backdropRef, ref);
42
+ var handleMouseDown = function (event) {
43
+ // Prevents React from resetting its properties
44
+ event.persist();
45
+ if (event.target !== backdropRef.current) {
46
+ return;
47
+ }
48
+ if (isDismissible && closeOnExternalClick && onClose) {
49
+ onClose(event);
50
+ }
51
+ onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
52
+ };
53
+ return (React.createElement(Backdrop, __assign({ isVisible: isVisible, ref: refs, onMouseDown: handleMouseDown }, rest)));
54
+ });
55
+ export default DialogBackdrop;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import '@itwin/itwinui-css/css/dialog.css';
3
+ export declare type DialogButtonBarProps = {
4
+ /**
5
+ * Buttons in the dialog bar.
6
+ */
7
+ children: React.ReactNode;
8
+ } & React.ComponentPropsWithRef<'div'>;
9
+ /**
10
+ * Container for Buttons in `Dialog`. Recommended to be used as a child of `Dialog`.
11
+ * @example
12
+ * <Dialog.ButtonBar>
13
+ * <Button styleType='high-visibility'>Confirm</Button>
14
+ * <Button>Close</Button>
15
+ * </Dialog.ButtonBar>
16
+ */
17
+ export declare const DialogButtonBar: React.ForwardRefExoticComponent<Pick<DialogButtonBarProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
18
+ export default DialogButtonBar;
@@ -0,0 +1,44 @@
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 __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { useTheme } from '../utils';
30
+ import '@itwin/itwinui-css/css/dialog.css';
31
+ /**
32
+ * Container for Buttons in `Dialog`. Recommended to be used as a child of `Dialog`.
33
+ * @example
34
+ * <Dialog.ButtonBar>
35
+ * <Button styleType='high-visibility'>Confirm</Button>
36
+ * <Button>Close</Button>
37
+ * </Dialog.ButtonBar>
38
+ */
39
+ export var DialogButtonBar = React.forwardRef(function (props, ref) {
40
+ var children = props.children, className = props.className, rest = __rest(props, ["children", "className"]);
41
+ useTheme();
42
+ return (React.createElement("div", __assign({ className: cx('iui-dialog-button-bar', className), ref: ref }, rest), children));
43
+ });
44
+ export default DialogButtonBar;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import '@itwin/itwinui-css/css/dialog.css';
3
+ export declare type DialogContentProps = {
4
+ /**
5
+ * Main content in the `Dialog`.
6
+ */
7
+ children: React.ReactNode;
8
+ } & React.ComponentPropsWithRef<'div'>;
9
+ /**
10
+ * Container for content in `Dialog`. Recommended to be used as a child of `Dialog`.
11
+ * @example
12
+ * <Dialog.Content>
13
+ * My dialog content
14
+ * </Dialog.Content>
15
+ */
16
+ export declare const DialogContent: React.ForwardRefExoticComponent<Pick<DialogContentProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
17
+ export default DialogContent;
@@ -0,0 +1,43 @@
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 __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /*---------------------------------------------------------------------------------------------
24
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
25
+ * See LICENSE.md in the project root for license terms and full copyright notice.
26
+ *--------------------------------------------------------------------------------------------*/
27
+ import React from 'react';
28
+ import cx from 'classnames';
29
+ import { useTheme } from '../utils';
30
+ import '@itwin/itwinui-css/css/dialog.css';
31
+ /**
32
+ * Container for content in `Dialog`. Recommended to be used as a child of `Dialog`.
33
+ * @example
34
+ * <Dialog.Content>
35
+ * My dialog content
36
+ * </Dialog.Content>
37
+ */
38
+ export var DialogContent = React.forwardRef(function (props, ref) {
39
+ var children = props.children, className = props.className, rest = __rest(props, ["children", "className"]);
40
+ useTheme();
41
+ return (React.createElement("div", __assign({ className: cx('iui-dialog-content', className), ref: ref }, rest), children));
42
+ });
43
+ export default DialogContent;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ export declare type DialogContextProps = {
3
+ /**
4
+ * Flag whether dialog should be shown.
5
+ * @default false
6
+ */
7
+ isOpen?: boolean;
8
+ /**
9
+ * Handler that is called when dialog is closed.
10
+ */
11
+ onClose?: (event?: React.SyntheticEvent) => void;
12
+ /**
13
+ * Flag whether dialog is dismissible. If false, you can't close it.
14
+ * @default true
15
+ */
16
+ isDismissible?: boolean;
17
+ /**
18
+ * Flag whether dialog should be closed on backdrop press.
19
+ * @default false
20
+ */
21
+ closeOnExternalClick?: boolean;
22
+ /**
23
+ * Flag whether dialog should be closed on Escape key press.
24
+ * @default true
25
+ */
26
+ closeOnEsc?: boolean;
27
+ /**
28
+ * Traps the focus inside the dialog. This is useful when the dialog is modal.
29
+ * @default false
30
+ */
31
+ trapFocus?: boolean;
32
+ /**
33
+ * Prevents body from being scrollable. This is useful when the dialog is modal.
34
+ * @default false
35
+ */
36
+ preventDocumentScroll?: boolean;
37
+ };
38
+ export declare const DialogContext: React.Context<DialogContextProps | undefined>;
39
+ export declare const useDialogContext: () => DialogContextProps;
@@ -0,0 +1,9 @@
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
+ export var DialogContext = React.createContext(undefined);
7
+ export var useDialogContext = function () {
8
+ return React.useContext(DialogContext) || {};
9
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import '@itwin/itwinui-css/css/dialog.css';
3
+ import { DialogContextProps } from './DialogContext';
4
+ export declare type DialogMainProps = {
5
+ /**
6
+ * Type of the dialog.
7
+ * @default 'default'
8
+ */
9
+ styleType?: 'default' | 'fullPage';
10
+ /**
11
+ * Content of the dialog.
12
+ */
13
+ children: React.ReactNode;
14
+ } & Omit<DialogContextProps, 'closeOnExternalClick'> & React.ComponentPropsWithRef<'div'>;
15
+ /**
16
+ * Dialog component which can wrap any content.
17
+ * @example
18
+ * <Dialog.Main>
19
+ * <Dialog.TitleBar>
20
+ * My dialog title
21
+ * </Dialog.TitleBar>
22
+ * <Dialog.Content>
23
+ * Here is my dialog content
24
+ * </Dialog.Content>
25
+ * <Dialog.ButtonBar>
26
+ * <Button styleType='high-visibility'>
27
+ * Primary button
28
+ * </Button>
29
+ * <Button>
30
+ * Secondary button
31
+ * </Button>
32
+ * </Dialog.ButtonBar>
33
+ * </Dialog.Main>
34
+ */
35
+ export declare const DialogMain: React.ForwardRefExoticComponent<Pick<DialogMainProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "styleType" | "isOpen" | "isDismissible" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll"> & React.RefAttributes<HTMLDivElement>>;
36
+ export default DialogMain;