@itwin/itwinui-react 3.0.0-dev.1 → 3.0.0-dev.3
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.
- package/CHANGELOG.md +25 -0
- package/cjs/core/Alert/Alert.d.ts +47 -28
- package/cjs/core/Alert/Alert.js +73 -21
- package/cjs/core/Avatar/Avatar.js +1 -1
- package/cjs/core/AvatarGroup/AvatarGroup.js +1 -1
- package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
- package/cjs/core/ButtonGroup/ButtonGroup.js +1 -4
- package/cjs/core/Buttons/DropdownButton/DropdownButton.js +3 -5
- package/cjs/core/Carousel/Carousel.d.ts +2 -2
- package/cjs/core/Carousel/Carousel.js +3 -5
- package/cjs/core/Carousel/CarouselDotsList.js +8 -10
- package/cjs/core/Carousel/CarouselNavigation.d.ts +2 -2
- package/cjs/core/Carousel/CarouselNavigation.js +3 -5
- package/cjs/core/Carousel/CarouselSlider.js +10 -15
- package/cjs/core/ColorPicker/ColorBuilder.js +7 -10
- package/cjs/core/ColorPicker/ColorInputPanel.js +12 -15
- package/cjs/core/ColorPicker/ColorPalette.js +4 -6
- package/cjs/core/ColorPicker/ColorPicker.js +3 -3
- package/cjs/core/ComboBox/ComboBox.js +25 -32
- package/cjs/core/ComboBox/ComboBoxDropdown.js +1 -2
- package/cjs/core/ComboBox/ComboBoxEndIcon.js +1 -1
- package/cjs/core/ComboBox/ComboBoxInput.js +21 -20
- package/cjs/core/ComboBox/ComboBoxMenu.js +3 -4
- package/cjs/core/ComboBox/ComboBoxMenuItem.js +2 -2
- package/cjs/core/ComboBox/helpers.js +4 -5
- package/cjs/core/DatePicker/DatePicker.js +32 -32
- package/cjs/core/Dialog/Dialog.js +11 -4
- package/cjs/core/Dialog/DialogBackdrop.js +1 -1
- package/cjs/core/Dialog/DialogContext.d.ts +11 -0
- package/cjs/core/Dialog/DialogMain.js +16 -22
- package/cjs/core/DropdownMenu/DropdownMenu.js +6 -8
- package/cjs/core/ExpandableBlock/ExpandableBlock.js +2 -2
- package/cjs/core/FileUpload/FileEmptyCard.js +1 -1
- package/cjs/core/FileUpload/FileUpload.d.ts +3 -4
- package/cjs/core/FileUpload/FileUpload.js +5 -8
- package/cjs/core/FileUpload/FileUploadCard.js +9 -10
- package/cjs/core/FileUpload/FileUploadTemplate.d.ts +1 -0
- package/cjs/core/FileUpload/FileUploadTemplate.js +1 -0
- package/cjs/core/InformationPanel/InformationPanel.js +1 -4
- package/cjs/core/LabeledInput/LabeledInput.js +1 -1
- package/cjs/core/LabeledTextarea/LabeledTextarea.js +1 -1
- package/cjs/core/Menu/Menu.js +3 -4
- package/cjs/core/Menu/MenuItem.js +8 -11
- package/cjs/core/Modal/Modal.d.ts +8 -9
- package/cjs/core/Modal/Modal.js +7 -17
- package/cjs/core/SearchBox/SearchBox.js +12 -12
- package/cjs/core/Select/Select.js +12 -17
- package/cjs/core/SideNavigation/SideNavigation.js +2 -2
- package/cjs/core/Slider/Slider.js +16 -19
- package/cjs/core/Slider/Thumb.js +1 -1
- package/cjs/core/StatusMessage/StatusMessage.js +1 -1
- package/cjs/core/Stepper/Stepper.js +1 -1
- package/cjs/core/Stepper/StepperStep.js +1 -1
- package/cjs/core/Table/Table.js +15 -15
- package/cjs/core/Table/TablePaginator.js +2 -3
- package/cjs/core/Table/TableRowMemoized.js +38 -45
- package/cjs/core/Table/actionHandlers/expandHandler.js +3 -3
- package/cjs/core/Table/actionHandlers/filterHandler.js +4 -5
- package/cjs/core/Table/actionHandlers/selectHandler.js +6 -6
- package/cjs/core/Table/cells/DefaultCell.js +1 -1
- package/cjs/core/Table/cells/EditableCell.js +6 -12
- package/cjs/core/Table/columns/actionColumn.js +3 -6
- package/cjs/core/Table/columns/expanderColumn.js +3 -3
- package/cjs/core/Table/columns/selectionColumn.js +4 -4
- package/cjs/core/Table/filters/DateRangeFilter/DatePickerInput.js +2 -4
- package/cjs/core/Table/filters/DateRangeFilter/DateRangeFilter.js +2 -3
- package/cjs/core/Table/filters/NumberRangeFilter/NumberRangeFilter.js +2 -3
- package/cjs/core/Table/filters/TextFilter/TextFilter.js +1 -2
- package/cjs/core/Table/hooks/useResizeColumns.js +16 -22
- package/cjs/core/Table/hooks/useScrollToRow.js +1 -2
- package/cjs/core/Table/hooks/useStickyColumns.js +3 -5
- package/cjs/core/Table/hooks/useSubRowFiltering.js +2 -4
- package/cjs/core/Tabs/Tabs.js +13 -16
- package/cjs/core/ThemeProvider/ThemeContext.d.ts +1 -1
- package/cjs/core/ThemeProvider/ThemeProvider.d.ts +2 -3
- package/cjs/core/ThemeProvider/ThemeProvider.js +14 -13
- package/cjs/core/Tile/Tile.js +2 -3
- package/cjs/core/TimePicker/TimePicker.js +13 -13
- package/cjs/core/Toast/Toast.d.ts +5 -10
- package/cjs/core/Toast/Toast.js +17 -16
- package/cjs/core/Toast/Toaster.d.ts +24 -26
- package/cjs/core/Toast/Toaster.js +91 -121
- package/cjs/core/Toast/index.d.ts +1 -4
- package/cjs/core/Toast/index.js +3 -6
- package/cjs/core/TransferList/TransferList.js +3 -4
- package/cjs/core/Tree/Tree.js +9 -13
- package/cjs/core/Tree/TreeNode.js +9 -10
- package/cjs/core/index.d.ts +1 -2
- package/cjs/core/index.js +2 -5
- package/cjs/core/utils/color/ColorValue.js +9 -15
- package/cjs/core/utils/components/AutoclearingHiddenLiveRegion.js +2 -3
- package/cjs/core/utils/components/FocusTrap.js +4 -4
- package/cjs/core/utils/components/MiddleTextTruncation.js +1 -2
- package/cjs/core/utils/components/Popover.d.ts +1 -1
- package/cjs/core/utils/components/Popover.js +5 -8
- package/cjs/core/utils/components/Resizer.js +7 -6
- package/cjs/core/utils/components/VirtualScroll.js +14 -21
- package/cjs/core/utils/functions/dom.d.ts +0 -8
- package/cjs/core/utils/functions/dom.js +3 -26
- package/cjs/core/utils/functions/polymorphic.d.ts +1 -1
- package/cjs/core/utils/functions/polymorphic.js +1 -1
- package/cjs/core/utils/functions/supports.js +1 -1
- package/cjs/core/utils/hooks/index.d.ts +0 -1
- package/cjs/core/utils/hooks/index.js +0 -1
- package/cjs/core/utils/hooks/useContainerWidth.js +1 -1
- package/cjs/core/utils/hooks/useDragAndDrop.js +8 -10
- package/cjs/core/utils/hooks/useEventListener.js +1 -1
- package/cjs/core/utils/hooks/useGlobals.d.ts +9 -2
- package/cjs/core/utils/hooks/useGlobals.js +6 -4
- package/cjs/core/utils/hooks/useId.js +1 -2
- package/cjs/core/utils/hooks/useIntersection.js +2 -3
- package/cjs/core/utils/hooks/useMediaQuery.js +6 -8
- package/cjs/core/utils/hooks/useOverflow.js +1 -2
- package/cjs/core/utils/hooks/useResizeObserver.js +3 -4
- package/cjs/styles.js +1 -4
- package/esm/core/Alert/Alert.d.ts +47 -28
- package/esm/core/Alert/Alert.js +74 -22
- package/esm/core/Avatar/Avatar.js +1 -1
- package/esm/core/AvatarGroup/AvatarGroup.js +1 -1
- package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
- package/esm/core/ButtonGroup/ButtonGroup.js +1 -4
- package/esm/core/Buttons/DropdownButton/DropdownButton.js +3 -5
- package/esm/core/Carousel/Carousel.d.ts +2 -2
- package/esm/core/Carousel/Carousel.js +3 -5
- package/esm/core/Carousel/CarouselDotsList.js +8 -10
- package/esm/core/Carousel/CarouselNavigation.d.ts +2 -2
- package/esm/core/Carousel/CarouselNavigation.js +3 -5
- package/esm/core/Carousel/CarouselSlider.js +10 -15
- package/esm/core/ColorPicker/ColorBuilder.js +7 -10
- package/esm/core/ColorPicker/ColorInputPanel.js +12 -15
- package/esm/core/ColorPicker/ColorPalette.js +4 -6
- package/esm/core/ColorPicker/ColorPicker.js +3 -3
- package/esm/core/ComboBox/ComboBox.js +25 -32
- package/esm/core/ComboBox/ComboBoxDropdown.js +1 -2
- package/esm/core/ComboBox/ComboBoxEndIcon.js +1 -1
- package/esm/core/ComboBox/ComboBoxInput.js +21 -20
- package/esm/core/ComboBox/ComboBoxMenu.js +3 -4
- package/esm/core/ComboBox/ComboBoxMenuItem.js +2 -2
- package/esm/core/ComboBox/helpers.js +4 -5
- package/esm/core/DatePicker/DatePicker.js +32 -32
- package/esm/core/Dialog/Dialog.js +12 -5
- package/esm/core/Dialog/DialogBackdrop.js +1 -1
- package/esm/core/Dialog/DialogContext.d.ts +11 -0
- package/esm/core/Dialog/DialogMain.js +16 -22
- package/esm/core/DropdownMenu/DropdownMenu.js +6 -8
- package/esm/core/ExpandableBlock/ExpandableBlock.js +2 -2
- package/esm/core/FileUpload/FileEmptyCard.js +1 -1
- package/esm/core/FileUpload/FileUpload.d.ts +3 -4
- package/esm/core/FileUpload/FileUpload.js +5 -8
- package/esm/core/FileUpload/FileUploadCard.js +9 -10
- package/esm/core/FileUpload/FileUploadTemplate.d.ts +1 -0
- package/esm/core/FileUpload/FileUploadTemplate.js +1 -0
- package/esm/core/InformationPanel/InformationPanel.js +1 -4
- package/esm/core/LabeledInput/LabeledInput.js +1 -1
- package/esm/core/LabeledTextarea/LabeledTextarea.js +1 -1
- package/esm/core/Menu/Menu.js +3 -4
- package/esm/core/Menu/MenuItem.js +8 -11
- package/esm/core/Modal/Modal.d.ts +8 -9
- package/esm/core/Modal/Modal.js +3 -10
- package/esm/core/SearchBox/SearchBox.js +12 -12
- package/esm/core/Select/Select.js +12 -17
- package/esm/core/SideNavigation/SideNavigation.js +2 -2
- package/esm/core/Slider/Slider.js +16 -19
- package/esm/core/Slider/Thumb.js +1 -1
- package/esm/core/StatusMessage/StatusMessage.js +1 -1
- package/esm/core/Stepper/Stepper.js +1 -1
- package/esm/core/Stepper/StepperStep.js +1 -1
- package/esm/core/Table/Table.js +15 -15
- package/esm/core/Table/TablePaginator.js +2 -3
- package/esm/core/Table/TableRowMemoized.js +38 -45
- package/esm/core/Table/actionHandlers/expandHandler.js +3 -3
- package/esm/core/Table/actionHandlers/filterHandler.js +4 -5
- package/esm/core/Table/actionHandlers/selectHandler.js +6 -6
- package/esm/core/Table/cells/DefaultCell.js +1 -1
- package/esm/core/Table/cells/EditableCell.js +6 -12
- package/esm/core/Table/columns/actionColumn.js +3 -6
- package/esm/core/Table/columns/expanderColumn.js +3 -3
- package/esm/core/Table/columns/selectionColumn.js +4 -4
- package/esm/core/Table/filters/DateRangeFilter/DatePickerInput.js +2 -4
- package/esm/core/Table/filters/DateRangeFilter/DateRangeFilter.js +2 -3
- package/esm/core/Table/filters/NumberRangeFilter/NumberRangeFilter.js +2 -3
- package/esm/core/Table/filters/TextFilter/TextFilter.js +1 -2
- package/esm/core/Table/hooks/useResizeColumns.js +16 -22
- package/esm/core/Table/hooks/useScrollToRow.js +1 -2
- package/esm/core/Table/hooks/useStickyColumns.js +3 -5
- package/esm/core/Table/hooks/useSubRowFiltering.js +2 -4
- package/esm/core/Tabs/Tabs.js +13 -16
- package/esm/core/ThemeProvider/ThemeContext.d.ts +1 -1
- package/esm/core/ThemeProvider/ThemeProvider.d.ts +2 -3
- package/esm/core/ThemeProvider/ThemeProvider.js +15 -14
- package/esm/core/Tile/Tile.js +2 -3
- package/esm/core/TimePicker/TimePicker.js +13 -13
- package/esm/core/Toast/Toast.d.ts +5 -10
- package/esm/core/Toast/Toast.js +18 -17
- package/esm/core/Toast/Toaster.d.ts +24 -26
- package/esm/core/Toast/Toaster.js +85 -121
- package/esm/core/Toast/index.d.ts +1 -4
- package/esm/core/Toast/index.js +1 -3
- package/esm/core/TransferList/TransferList.js +3 -4
- package/esm/core/Tree/Tree.js +9 -13
- package/esm/core/Tree/TreeNode.js +9 -10
- package/esm/core/index.d.ts +1 -2
- package/esm/core/index.js +1 -1
- package/esm/core/utils/color/ColorValue.js +9 -15
- package/esm/core/utils/components/AutoclearingHiddenLiveRegion.js +2 -3
- package/esm/core/utils/components/FocusTrap.js +4 -4
- package/esm/core/utils/components/MiddleTextTruncation.js +1 -2
- package/esm/core/utils/components/Popover.d.ts +1 -1
- package/esm/core/utils/components/Popover.js +5 -8
- package/esm/core/utils/components/Resizer.js +7 -6
- package/esm/core/utils/components/VirtualScroll.js +14 -21
- package/esm/core/utils/functions/dom.d.ts +0 -8
- package/esm/core/utils/functions/dom.js +2 -21
- package/esm/core/utils/functions/polymorphic.d.ts +1 -1
- package/esm/core/utils/functions/polymorphic.js +1 -1
- package/esm/core/utils/functions/supports.js +1 -1
- package/esm/core/utils/hooks/index.d.ts +0 -1
- package/esm/core/utils/hooks/index.js +0 -1
- package/esm/core/utils/hooks/useContainerWidth.js +1 -1
- package/esm/core/utils/hooks/useDragAndDrop.js +8 -10
- package/esm/core/utils/hooks/useEventListener.js +1 -1
- package/esm/core/utils/hooks/useGlobals.d.ts +9 -2
- package/esm/core/utils/hooks/useGlobals.js +6 -4
- package/esm/core/utils/hooks/useId.js +1 -2
- package/esm/core/utils/hooks/useIntersection.js +2 -3
- package/esm/core/utils/hooks/useMediaQuery.js +6 -8
- package/esm/core/utils/hooks/useOverflow.js +1 -2
- package/esm/core/utils/hooks/useResizeObserver.js +3 -4
- package/esm/styles.js +1 -4
- package/package.json +2 -2
- package/styles.css +19 -20
- package/cjs/core/Toast/ToastWrapper.d.ts +0 -10
- package/cjs/core/Toast/ToastWrapper.js +0 -49
- package/cjs/core/utils/hooks/useIsThemeAlreadySet.d.ts +0 -7
- package/cjs/core/utils/hooks/useIsThemeAlreadySet.js +0 -54
- package/esm/core/Toast/ToastWrapper.d.ts +0 -10
- package/esm/core/Toast/ToastWrapper.js +0 -20
- package/esm/core/utils/hooks/useIsThemeAlreadySet.d.ts +0 -7
- package/esm/core/utils/hooks/useIsThemeAlreadySet.js +0 -27
|
@@ -3,130 +3,94 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
import cx from 'classnames';
|
|
7
|
+
import { Box, useSafeContext } from '../utils/index.js';
|
|
8
|
+
import { Toast } from './Toast.js';
|
|
9
|
+
// ----------------------------------------------------------------------------
|
|
10
|
+
export const useToaster = () => {
|
|
11
|
+
const dispatch = useSafeContext(ToasterDispatchContext);
|
|
12
|
+
const showToast = React.useCallback((category) => (content, options) => {
|
|
13
|
+
const id = nextId();
|
|
14
|
+
dispatch({
|
|
15
|
+
type: 'add',
|
|
16
|
+
toast: { ...options, id, content, category },
|
|
17
|
+
});
|
|
18
|
+
return { close: () => dispatch({ type: 'remove', id }) };
|
|
19
|
+
}, [dispatch]);
|
|
20
|
+
return {
|
|
21
|
+
positive: showToast('positive'),
|
|
22
|
+
informational: showToast('informational'),
|
|
23
|
+
negative: showToast('negative'),
|
|
24
|
+
warning: showToast('warning'),
|
|
25
|
+
closeAll: () => {
|
|
26
|
+
dispatch({ type: 'close-all' });
|
|
27
|
+
},
|
|
28
|
+
setSettings: (settings) => {
|
|
29
|
+
dispatch({ type: 'settings', settings });
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
// ----------------------------------------------------------------------------
|
|
34
|
+
export const Toaster = () => {
|
|
35
|
+
const { toasts, settings } = useSafeContext(ToasterStateContext);
|
|
36
|
+
return (React.createElement(Box, { className: cx(`iui-toast-wrapper`, `iui-placement-${settings.placement}`) }, toasts.map((toastProps) => {
|
|
37
|
+
return React.createElement(Toast, { key: toastProps.id, ...toastProps });
|
|
38
|
+
})));
|
|
39
|
+
};
|
|
40
|
+
// ----------------------------------------------------------------------------
|
|
41
|
+
export const ToastProvider = ({ children }) => {
|
|
42
|
+
const [toasterState, dispatch] = React.useReducer(toastReducer, {
|
|
43
|
+
toasts: [],
|
|
44
|
+
settings: {
|
|
45
|
+
order: 'auto',
|
|
16
46
|
placement: 'top',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return (React.createElement(ToasterDispatchContext.Provider, { value: dispatch },
|
|
50
|
+
React.createElement(ToasterStateContext.Provider, { value: toasterState }, children)));
|
|
51
|
+
};
|
|
52
|
+
const toastReducer = (state, action) => {
|
|
53
|
+
if (action.type === 'add') {
|
|
54
|
+
let order = state.settings.order;
|
|
55
|
+
if (order === 'auto') {
|
|
56
|
+
order = state.settings.placement.startsWith('top')
|
|
57
|
+
? 'descending'
|
|
58
|
+
: 'ascending';
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...state,
|
|
62
|
+
toasts: [
|
|
63
|
+
...(order === 'ascending' ? state.toasts : []),
|
|
64
|
+
action.toast,
|
|
65
|
+
...(order === 'descending' ? state.toasts : []),
|
|
66
|
+
],
|
|
17
67
|
};
|
|
18
|
-
this.toastsRef = React.createRef();
|
|
19
|
-
this.isInitialized = false;
|
|
20
|
-
// Create container on demand.
|
|
21
|
-
// Cannot do it in constructor, because SSG/SSR apps would fail.
|
|
22
|
-
this.asyncInit = async () => {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
if (this.isInitialized) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const container = (_a = getContainer(TOASTS_CONTAINER_ID)) !== null && _a !== void 0 ? _a : (_b = getDocument()) === null || _b === void 0 ? void 0 : _b.body;
|
|
28
|
-
if (!container) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
this.isInitialized = true;
|
|
32
|
-
const toastWrapper = React.createElement(ToastWrapper, { ref: this.toastsRef });
|
|
33
|
-
const _ReactDOM = ReactDOM; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
34
|
-
// v18 mode
|
|
35
|
-
if (_ReactDOM.createRoot) {
|
|
36
|
-
const _ReactDOMInternals = _ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
37
|
-
// suppress warning about importing createRoot from react-dom/client
|
|
38
|
-
if (_ReactDOMInternals) {
|
|
39
|
-
_ReactDOMInternals.usingClientEntryPoint = true;
|
|
40
|
-
}
|
|
41
|
-
const root = _ReactDOM.createRoot(container);
|
|
42
|
-
root.render(toastWrapper);
|
|
43
|
-
// revert suppression, not to influence users app
|
|
44
|
-
if (_ReactDOMInternals) {
|
|
45
|
-
_ReactDOMInternals.usingClientEntryPoint = false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
// v17 and before
|
|
50
|
-
ReactDOM.render(toastWrapper, container);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Set global Toaster settings for toasts order and placement.
|
|
56
|
-
* Settings will be applied to new toasts on the page.
|
|
57
|
-
*/
|
|
58
|
-
setSettings(newSettings) {
|
|
59
|
-
var _a, _b, _c;
|
|
60
|
-
(_a = newSettings.placement) !== null && _a !== void 0 ? _a : (newSettings.placement = this.settings.placement);
|
|
61
|
-
(_b = newSettings.order) !== null && _b !== void 0 ? _b : (newSettings.order = ((_c = newSettings.placement) === null || _c === void 0 ? void 0 : _c.startsWith('bottom'))
|
|
62
|
-
? 'ascending'
|
|
63
|
-
: 'descending');
|
|
64
|
-
this.settings = newSettings;
|
|
65
|
-
this.asyncInit().then(() => {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
(_a = this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setPlacement((_b = this.settings.placement) !== null && _b !== void 0 ? _b : 'top');
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
positive(content, options) {
|
|
71
|
-
return this.createToast(content, 'positive', options);
|
|
72
|
-
}
|
|
73
|
-
informational(content, options) {
|
|
74
|
-
return this.createToast(content, 'informational', options);
|
|
75
|
-
}
|
|
76
|
-
negative(content, options) {
|
|
77
|
-
return this.createToast(content, 'negative', options);
|
|
78
|
-
}
|
|
79
|
-
warning(content, options) {
|
|
80
|
-
return this.createToast(content, 'warning', options);
|
|
81
68
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
...options,
|
|
89
|
-
content,
|
|
90
|
-
category,
|
|
91
|
-
onRemove: () => {
|
|
92
|
-
var _a;
|
|
93
|
-
this.removeToast(currentId);
|
|
94
|
-
(_a = options === null || options === void 0 ? void 0 : options.onRemove) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
95
|
-
},
|
|
96
|
-
id: currentId,
|
|
97
|
-
isVisible: true,
|
|
98
|
-
},
|
|
99
|
-
...(this.settings.order === 'descending' ? this.toasts : []),
|
|
100
|
-
];
|
|
101
|
-
this.updateView();
|
|
102
|
-
return { close: () => this.closeToast(currentId) };
|
|
103
|
-
}
|
|
104
|
-
removeToast(id) {
|
|
105
|
-
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
106
|
-
this.updateView();
|
|
107
|
-
}
|
|
108
|
-
updateView() {
|
|
109
|
-
this.asyncInit().then(() => {
|
|
110
|
-
var _a;
|
|
111
|
-
(_a = this.toastsRef.current) === null || _a === void 0 ? void 0 : _a.setToasts(this.toasts);
|
|
112
|
-
});
|
|
69
|
+
if (action.type === 'remove') {
|
|
70
|
+
return {
|
|
71
|
+
...state,
|
|
72
|
+
toasts: state.toasts.filter((toast) => toast.id !== action.id),
|
|
73
|
+
};
|
|
113
74
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
this.updateView();
|
|
75
|
+
if (action.type === 'close-all') {
|
|
76
|
+
return {
|
|
77
|
+
...state,
|
|
78
|
+
toasts: state.toasts.map((toast) => ({ ...toast, isVisible: false })),
|
|
79
|
+
};
|
|
122
80
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
...toast,
|
|
127
|
-
isVisible: false,
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
this.updateView();
|
|
81
|
+
if (action.type === 'settings') {
|
|
82
|
+
return { ...state, settings: { ...state.settings, ...action.settings } };
|
|
131
83
|
}
|
|
132
|
-
|
|
84
|
+
return state;
|
|
85
|
+
};
|
|
86
|
+
// ----------------------------------------------------------------------------
|
|
87
|
+
export const ToasterStateContext = React.createContext(undefined);
|
|
88
|
+
ToasterStateContext.displayName = 'ToasterStateContext';
|
|
89
|
+
// ----------------------------------------------------------------------------
|
|
90
|
+
const ToasterDispatchContext = React.createContext(undefined);
|
|
91
|
+
ToasterDispatchContext.displayName = 'ToasterDispatchContext';
|
|
92
|
+
// ----------------------------------------------------------------------------
|
|
93
|
+
const nextId = (() => {
|
|
94
|
+
let count = 0;
|
|
95
|
+
return () => ++count;
|
|
96
|
+
})();
|
package/esm/core/Toast/index.js
CHANGED
|
@@ -2,6 +2,4 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
|
|
6
|
-
const toaster = new Toaster();
|
|
7
|
-
export default toaster;
|
|
5
|
+
export { useToaster } from './Toaster.js';
|
|
@@ -30,10 +30,9 @@ const TransferListListbox = React.forwardRef((props, ref) => {
|
|
|
30
30
|
return focusableItems.filter((i) => !focusableItems.some((p) => p.contains(i.parentElement)));
|
|
31
31
|
}, []);
|
|
32
32
|
React.useEffect(() => {
|
|
33
|
-
var _a;
|
|
34
33
|
const items = getFocusableNodes();
|
|
35
34
|
if (focusedIndex != null) {
|
|
36
|
-
|
|
35
|
+
items?.[focusedIndex]?.focus();
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
}, [focusedIndex, getFocusableNodes]);
|
|
@@ -42,10 +41,10 @@ const TransferListListbox = React.forwardRef((props, ref) => {
|
|
|
42
41
|
return;
|
|
43
42
|
}
|
|
44
43
|
const items = getFocusableNodes();
|
|
45
|
-
if (!
|
|
44
|
+
if (!items?.length) {
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
48
|
-
const currentIndex = focusedIndex
|
|
47
|
+
const currentIndex = focusedIndex ?? 0;
|
|
49
48
|
switch (event.key) {
|
|
50
49
|
case 'ArrowDown': {
|
|
51
50
|
setFocusedIndex(Math.min(currentIndex + 1, items.length - 1));
|
package/esm/core/Tree/Tree.js
CHANGED
|
@@ -73,10 +73,10 @@ export const Tree = (props) => {
|
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
const items = getFocusableNodes();
|
|
76
|
-
if (!
|
|
76
|
+
if (!items?.length) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
const activeIndex = items.findIndex((el) =>
|
|
79
|
+
const activeIndex = items.findIndex((el) => el.contains(treeRef.current?.ownerDocument.activeElement));
|
|
80
80
|
const currentIndex = activeIndex > -1 ? activeIndex : 0;
|
|
81
81
|
switch (event.key) {
|
|
82
82
|
case 'ArrowUp': {
|
|
@@ -126,20 +126,18 @@ export const Tree = (props) => {
|
|
|
126
126
|
return [flatList, firstLevelNodes];
|
|
127
127
|
}, [data, getNode]);
|
|
128
128
|
const itemRenderer = React.useCallback((index) => {
|
|
129
|
-
var _a, _b, _c, _d;
|
|
130
129
|
const node = flatNodesList[index];
|
|
131
130
|
return (React.createElement(TreeContext.Provider, { key: node.nodeProps.nodeId, value: {
|
|
132
131
|
nodeDepth: node.depth,
|
|
133
132
|
subNodeIds: node.subNodeIds,
|
|
134
133
|
groupSize: node.depth === 0
|
|
135
134
|
? firstLevelNodesList.length
|
|
136
|
-
:
|
|
135
|
+
: node.parentNode?.subNodeIds?.length ?? 0,
|
|
137
136
|
indexInGroup: node.indexInGroup,
|
|
138
|
-
parentNodeId:
|
|
137
|
+
parentNodeId: node.parentNode?.nodeProps.nodeId,
|
|
139
138
|
scrollToParent: node.parentNode
|
|
140
139
|
? () => {
|
|
141
|
-
|
|
142
|
-
const parentNodeId = (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.nodeProps.nodeId;
|
|
140
|
+
const parentNodeId = node.parentNode?.nodeProps.nodeId;
|
|
143
141
|
const parentNodeIndex = flatNodesList.findIndex((n) => n.nodeProps.nodeId === parentNodeId);
|
|
144
142
|
setScrollToIndex(parentNodeIndex);
|
|
145
143
|
}
|
|
@@ -153,11 +151,10 @@ export const Tree = (props) => {
|
|
|
153
151
|
}, [flatNodesList]);
|
|
154
152
|
React.useEffect(() => {
|
|
155
153
|
setTimeout(() => {
|
|
156
|
-
var _a;
|
|
157
154
|
if (scrollToIndex !== undefined) {
|
|
158
155
|
const nodeId = flatNodesListRef.current[scrollToIndex].nodeProps.nodeId;
|
|
159
|
-
const nodeElement =
|
|
160
|
-
nodeElement
|
|
156
|
+
const nodeElement = treeRef.current?.ownerDocument.querySelector(`#${nodeId}`);
|
|
157
|
+
nodeElement?.focus();
|
|
161
158
|
// Need to reset that if navigating with mouse and keyboard,
|
|
162
159
|
// e.g. pressing arrow left to go to parent node and then with mouse
|
|
163
160
|
// clicking some other child node and then pressing arrow left
|
|
@@ -166,13 +163,12 @@ export const Tree = (props) => {
|
|
|
166
163
|
});
|
|
167
164
|
}, [scrollToIndex]);
|
|
168
165
|
const handleFocus = (event) => {
|
|
169
|
-
|
|
170
|
-
if ((_a = treeRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.relatedTarget)) {
|
|
166
|
+
if (treeRef.current?.contains(event.relatedTarget)) {
|
|
171
167
|
return;
|
|
172
168
|
}
|
|
173
169
|
const items = getFocusableNodes();
|
|
174
170
|
if (items.length > 0) {
|
|
175
|
-
|
|
171
|
+
items[focusedIndex.current]?.focus();
|
|
176
172
|
}
|
|
177
173
|
};
|
|
178
174
|
return (React.createElement(React.Fragment, null, enableVirtualization ? (React.createElement(VirtualizedTree, { flatNodesList: flatNodesList, itemRenderer: itemRenderer, scrollToIndex: scrollToIndex, onFocus: handleFocus, onKeyDown: handleKeyDown, ref: treeRef, className: className, style: style, ...rest })) : (React.createElement(TreeElement, { onKeyDown: handleKeyDown, onFocus: handleFocus, className: className, style: style, ref: treeRef, ...rest }, flatNodesList.map((_, i) => itemRenderer(i))))));
|
|
@@ -32,11 +32,10 @@ export const TreeNode = (props) => {
|
|
|
32
32
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
33
33
|
const nodeRef = React.useRef(null);
|
|
34
34
|
const onKeyDown = (event) => {
|
|
35
|
-
var _a, _b, _c, _d, _e, _f;
|
|
36
35
|
if (event.altKey) {
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
|
-
const isNodeFocused = nodeRef.current ===
|
|
38
|
+
const isNodeFocused = nodeRef.current === nodeRef.current?.ownerDocument.activeElement;
|
|
40
39
|
switch (event.key) {
|
|
41
40
|
case 'ArrowLeft': {
|
|
42
41
|
event.preventDefault();
|
|
@@ -46,19 +45,19 @@ export const TreeNode = (props) => {
|
|
|
46
45
|
break;
|
|
47
46
|
}
|
|
48
47
|
if (parentNodeId) {
|
|
49
|
-
scrollToParent
|
|
48
|
+
scrollToParent?.();
|
|
50
49
|
break;
|
|
51
50
|
}
|
|
52
51
|
// If it is top level node (doesn't have parent node), then do nothing.
|
|
53
52
|
break;
|
|
54
53
|
}
|
|
55
54
|
const focusableElements = getFocusableElements(nodeRef.current);
|
|
56
|
-
const currentIndex = focusableElements.indexOf(
|
|
55
|
+
const currentIndex = focusableElements.indexOf(nodeRef.current?.ownerDocument.activeElement);
|
|
57
56
|
if (currentIndex === 0) {
|
|
58
|
-
|
|
57
|
+
nodeRef.current?.focus();
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
|
-
|
|
60
|
+
focusableElements[currentIndex - 1]?.focus();
|
|
62
61
|
}
|
|
63
62
|
break;
|
|
64
63
|
}
|
|
@@ -70,10 +69,10 @@ export const TreeNode = (props) => {
|
|
|
70
69
|
onExpanded(nodeId, true);
|
|
71
70
|
break;
|
|
72
71
|
}
|
|
73
|
-
|
|
72
|
+
focusableElements[0]?.focus();
|
|
74
73
|
break;
|
|
75
74
|
}
|
|
76
|
-
const currentIndex = focusableElements.indexOf(
|
|
75
|
+
const currentIndex = focusableElements.indexOf(nodeRef.current?.ownerDocument.activeElement);
|
|
77
76
|
if (currentIndex < focusableElements.length - 1) {
|
|
78
77
|
focusableElements[currentIndex + 1].focus();
|
|
79
78
|
break;
|
|
@@ -89,7 +88,7 @@ export const TreeNode = (props) => {
|
|
|
89
88
|
}
|
|
90
89
|
event.preventDefault();
|
|
91
90
|
if (!isDisabled) {
|
|
92
|
-
onSelected
|
|
91
|
+
onSelected?.(nodeId, !isSelected);
|
|
93
92
|
}
|
|
94
93
|
break;
|
|
95
94
|
}
|
|
@@ -111,7 +110,7 @@ export const TreeNode = (props) => {
|
|
|
111
110
|
React.createElement(Box, { className: cx('iui-tree-node', {
|
|
112
111
|
'iui-active': isSelected,
|
|
113
112
|
'iui-disabled': isDisabled,
|
|
114
|
-
}), style: { '--level': nodeDepth }, onClick: () => !isDisabled &&
|
|
113
|
+
}), style: { '--level': nodeDepth }, onClick: () => !isDisabled && onSelected?.(nodeId, !isSelected) },
|
|
115
114
|
checkbox && (React.createElement(Box, { className: 'iui-tree-node-checkbox' }, React.isValidElement(checkbox)
|
|
116
115
|
? React.cloneElement(checkbox, {
|
|
117
116
|
tabIndex: isFocused ? 0 : -1,
|
package/esm/core/index.d.ts
CHANGED
|
@@ -51,8 +51,7 @@ export { Textarea } from './Textarea/index.js';
|
|
|
51
51
|
export { Tile } from './Tile/index.js';
|
|
52
52
|
export { TimePicker } from './TimePicker/index.js';
|
|
53
53
|
export type { MeridiemType } from './TimePicker/index.js';
|
|
54
|
-
export {
|
|
55
|
-
export type { ToastOptions } from './Toast/index.js';
|
|
54
|
+
export { useToaster } from './Toast/index.js';
|
|
56
55
|
export { ThemeProvider } from './ThemeProvider/index.js';
|
|
57
56
|
export type { ThemeType } from './ThemeProvider/index.js';
|
|
58
57
|
export { ToggleSwitch } from './ToggleSwitch/index.js';
|
package/esm/core/index.js
CHANGED
|
@@ -50,7 +50,7 @@ export { Tag, TagContainer } from './Tag/index.js';
|
|
|
50
50
|
export { Textarea } from './Textarea/index.js';
|
|
51
51
|
export { Tile } from './Tile/index.js';
|
|
52
52
|
export { TimePicker } from './TimePicker/index.js';
|
|
53
|
-
export {
|
|
53
|
+
export { useToaster } from './Toast/index.js';
|
|
54
54
|
export { ThemeProvider } from './ThemeProvider/index.js';
|
|
55
55
|
export { ToggleSwitch } from './ToggleSwitch/index.js';
|
|
56
56
|
export { Tooltip } from './Tooltip/index.js';
|
|
@@ -110,27 +110,24 @@ export class ColorValue {
|
|
|
110
110
|
* This allows component builders to know if they received bad input from user.
|
|
111
111
|
*/
|
|
112
112
|
static fromString(val, defaultColorIfNotParsed) {
|
|
113
|
-
const [tbgr, hue] = this.computeTbgrFromString(val, defaultColorIfNotParsed
|
|
113
|
+
const [tbgr, hue] = this.computeTbgrFromString(val, defaultColorIfNotParsed?.toTbgr());
|
|
114
114
|
return new ColorValue(tbgr, hue);
|
|
115
115
|
}
|
|
116
116
|
/** Create a ColorValue from hue, saturation, lightness values. */
|
|
117
117
|
static fromHSL(hsl) {
|
|
118
|
-
|
|
119
|
-
const alpha = (_a = hsl.a) !== null && _a !== void 0 ? _a : 1;
|
|
118
|
+
const alpha = hsl.a ?? 1;
|
|
120
119
|
return new ColorValue(this.computeTbgrFromHSL(hsl.h / 360, hsl.s / 100, hsl.l / 100, Math.round((1 - alpha) * 255)), hsl.h);
|
|
121
120
|
}
|
|
122
121
|
/** Create a ColorValue from an RgbColor */
|
|
123
122
|
static fromRGB(rgb) {
|
|
124
|
-
|
|
125
|
-
const alpha = (_a = rgb.a) !== null && _a !== void 0 ? _a : 1;
|
|
123
|
+
const alpha = rgb.a ?? 1;
|
|
126
124
|
return ColorValue.fromRgbt(rgb.r, rgb.g, rgb.b, Math.round((1 - alpha) * 255));
|
|
127
125
|
}
|
|
128
126
|
/**
|
|
129
127
|
* Create a ColorValue from an HsvColor
|
|
130
128
|
*/
|
|
131
129
|
static fromHSV(hsv) {
|
|
132
|
-
|
|
133
|
-
const alpha = (_a = hsv.a) !== null && _a !== void 0 ? _a : 1;
|
|
130
|
+
const alpha = hsv.a ?? 1;
|
|
134
131
|
const transparency = Math.round((1 - alpha) * 255);
|
|
135
132
|
// Check for simple case first.
|
|
136
133
|
if (!hsv.s || hsv.h === -1) {
|
|
@@ -481,33 +478,30 @@ export class ColorValue {
|
|
|
481
478
|
}
|
|
482
479
|
/** 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. */
|
|
483
480
|
toRgbString(includeAlpha) {
|
|
484
|
-
var _a;
|
|
485
481
|
const rgb = this.toRgbColor();
|
|
486
482
|
const rgbString = `${rgb.r}, ${rgb.g}, ${rgb.b}`;
|
|
487
483
|
if (includeAlpha) {
|
|
488
|
-
const alpha =
|
|
484
|
+
const alpha = rgb.a ?? 1;
|
|
489
485
|
return `rgba(${rgbString}, ${ColorValue.getFormattedColorNumber(alpha, 2)})`;
|
|
490
486
|
}
|
|
491
487
|
return `rgb(${rgbString})`;
|
|
492
488
|
}
|
|
493
489
|
/** 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%). */
|
|
494
490
|
toHslString(includeAlpha) {
|
|
495
|
-
var _a, _b;
|
|
496
491
|
const hsl = this.toHslColor();
|
|
497
|
-
const hslString = `${ColorValue.getFormattedColorNumber(
|
|
492
|
+
const hslString = `${ColorValue.getFormattedColorNumber(this._hue ?? hsl.h)}, ${ColorValue.getFormattedColorNumber(hsl.s)}%, ${ColorValue.getFormattedColorNumber(hsl.l)}%`;
|
|
498
493
|
if (includeAlpha) {
|
|
499
|
-
const alpha =
|
|
494
|
+
const alpha = hsl.a ?? 1;
|
|
500
495
|
return `hsla(${hslString}, ${ColorValue.getFormattedColorNumber(alpha, 2)})`;
|
|
501
496
|
}
|
|
502
497
|
return `hsl(${hslString})`;
|
|
503
498
|
}
|
|
504
499
|
/** Convert this ColorValue to a string in the form "hsv(h,s,v) or hsva(h,s,v,a)" - i.e hsv(120,50%,50%). */
|
|
505
500
|
toHsvString(includeAlpha) {
|
|
506
|
-
var _a, _b;
|
|
507
501
|
const hsv = this.toHsvColor();
|
|
508
|
-
const hsvString = `${
|
|
502
|
+
const hsvString = `${this._hue ?? hsv.h}, ${hsv.s}%, ${hsv.v}%`;
|
|
509
503
|
if (includeAlpha) {
|
|
510
|
-
const alpha =
|
|
504
|
+
const alpha = hsv.a ?? 1;
|
|
511
505
|
return `hsva(${hsvString}, ${ColorValue.getFormattedColorNumber(alpha, 2)})`;
|
|
512
506
|
}
|
|
513
507
|
return `hsv(${hsvString})`;
|
|
@@ -16,10 +16,9 @@ import { getWindow } from '../functions/index.js';
|
|
|
16
16
|
export const AutoclearingHiddenLiveRegion = ({ text = '' }) => {
|
|
17
17
|
const [maybeText, setMaybeText] = React.useState(text);
|
|
18
18
|
React.useEffect(() => {
|
|
19
|
-
var _a;
|
|
20
19
|
setMaybeText(text);
|
|
21
|
-
const timeout =
|
|
22
|
-
return () =>
|
|
20
|
+
const timeout = getWindow()?.setTimeout(() => setMaybeText(''), 5000);
|
|
21
|
+
return () => void getWindow()?.clearTimeout(timeout);
|
|
23
22
|
}, [text]);
|
|
24
23
|
return (React.createElement(VisuallyHidden, { as: 'div', "aria-live": 'polite', "aria-atomic": 'true' }, maybeText));
|
|
25
24
|
};
|
|
@@ -21,19 +21,19 @@ export const FocusTrap = (props) => {
|
|
|
21
21
|
const onFirstFocus = (event) => {
|
|
22
22
|
const [firstElement, lastElement] = getFirstLastFocusables();
|
|
23
23
|
if (event.relatedTarget === firstElement) {
|
|
24
|
-
lastElement
|
|
24
|
+
lastElement?.focus();
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
firstElement
|
|
27
|
+
firstElement?.focus();
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
const onLastFocus = (event) => {
|
|
31
31
|
const [firstElement, lastElement] = getFirstLastFocusables();
|
|
32
32
|
if (event.relatedTarget === lastElement) {
|
|
33
|
-
firstElement
|
|
33
|
+
firstElement?.focus();
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
lastElement
|
|
36
|
+
lastElement?.focus();
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
return (React.createElement(React.Fragment, null,
|
|
@@ -22,7 +22,6 @@ const ELLIPSIS_CHAR = '…';
|
|
|
22
22
|
* />
|
|
23
23
|
*/
|
|
24
24
|
export const MiddleTextTruncation = (props) => {
|
|
25
|
-
var _a;
|
|
26
25
|
const { text, endCharsCount = 6, textRenderer, style, ...rest } = props;
|
|
27
26
|
const [ref, visibleCount] = useOverflow(text);
|
|
28
27
|
const truncatedText = React.useMemo(() => {
|
|
@@ -39,6 +38,6 @@ export const MiddleTextTruncation = (props) => {
|
|
|
39
38
|
flexGrow: 1,
|
|
40
39
|
whiteSpace: 'nowrap',
|
|
41
40
|
...style,
|
|
42
|
-
}, ref: ref, ...rest },
|
|
41
|
+
}, ref: ref, ...rest }, textRenderer?.(truncatedText, text) ?? truncatedText));
|
|
43
42
|
};
|
|
44
43
|
export default MiddleTextTruncation;
|
|
@@ -25,7 +25,7 @@ export declare type PopoverProps = {
|
|
|
25
25
|
* with pre-configured props and plugins (e.g. lazy mounting, focus, etc).
|
|
26
26
|
* @private
|
|
27
27
|
*/
|
|
28
|
-
export declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverProps, "disabled" | "className" | "role" | "offset" | "children" | "content" | "plugins" | "
|
|
28
|
+
export declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverProps, "disabled" | "className" | "role" | "offset" | "children" | "content" | "plugins" | "placement" | "trigger" | "visible" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "theme" | "zIndex" | "singleton" | "reference"> & React.RefAttributes<unknown>>;
|
|
29
29
|
/**
|
|
30
30
|
* Plugin to hide Popover when either Esc key is pressed,
|
|
31
31
|
* or when the content inside is not tabbable and Tab key is pressed.
|
|
@@ -13,7 +13,6 @@ import { ThemeContext } from '../../ThemeProvider/ThemeContext.js';
|
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
15
|
export const Popover = React.forwardRef((props, ref) => {
|
|
16
|
-
var _a;
|
|
17
16
|
const [mounted, setMounted] = React.useState(false);
|
|
18
17
|
const themeInfo = React.useContext(ThemeContext);
|
|
19
18
|
const isDomAvailable = useIsClient();
|
|
@@ -30,15 +29,14 @@ export const Popover = React.forwardRef((props, ref) => {
|
|
|
30
29
|
const removeTabIndex = {
|
|
31
30
|
fn: () => ({
|
|
32
31
|
onCreate: (instance) => {
|
|
33
|
-
|
|
34
|
-
(_a = instance.popper.firstElementChild) === null || _a === void 0 ? void 0 : _a.removeAttribute('tabindex');
|
|
32
|
+
instance.popper.firstElementChild?.removeAttribute('tabindex');
|
|
35
33
|
},
|
|
36
34
|
}),
|
|
37
35
|
};
|
|
38
36
|
const computedProps = {
|
|
39
37
|
allowHTML: true,
|
|
40
38
|
animation: false,
|
|
41
|
-
appendTo: (el) =>
|
|
39
|
+
appendTo: (el) => themeInfo?.portalContainerRef?.current || el.ownerDocument.body,
|
|
42
40
|
arrow: false,
|
|
43
41
|
duration: 0,
|
|
44
42
|
interactive: true,
|
|
@@ -63,7 +61,7 @@ export const Popover = React.forwardRef((props, ref) => {
|
|
|
63
61
|
modifiers: [
|
|
64
62
|
{ name: 'flip' },
|
|
65
63
|
{ name: 'preventOverflow', options: { padding: 0 } },
|
|
66
|
-
...(
|
|
64
|
+
...(props.popperOptions?.modifiers || []),
|
|
67
65
|
],
|
|
68
66
|
},
|
|
69
67
|
};
|
|
@@ -78,9 +76,8 @@ export const Popover = React.forwardRef((props, ref) => {
|
|
|
78
76
|
const clonedContent = React.isValidElement(props.content)
|
|
79
77
|
? React.cloneElement(props.content, {
|
|
80
78
|
onClick: (e) => {
|
|
81
|
-
var _a, _b;
|
|
82
79
|
e.stopPropagation();
|
|
83
|
-
|
|
80
|
+
props.content.props.onClick?.(e);
|
|
84
81
|
},
|
|
85
82
|
})
|
|
86
83
|
: props.content;
|
|
@@ -97,7 +94,7 @@ export const hideOnEscOrTab = {
|
|
|
97
94
|
/** @returns true if none of the children are tabbable */
|
|
98
95
|
const shouldHideOnTab = () => {
|
|
99
96
|
const descendents = Array.from(instance.popper.querySelectorAll('*'));
|
|
100
|
-
return !descendents.some((el) =>
|
|
97
|
+
return !descendents.some((el) => el?.tabIndex >= 0);
|
|
101
98
|
};
|
|
102
99
|
const onKeyDown = (event) => {
|
|
103
100
|
if (event.altKey) {
|
|
@@ -38,17 +38,18 @@ export const Resizer = (props) => {
|
|
|
38
38
|
const originalUserSelect = ownerDocument.body.style.userSelect;
|
|
39
39
|
ownerDocument.body.style.userSelect = 'none';
|
|
40
40
|
const onResizePointerMove = (event) => {
|
|
41
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
42
41
|
if (!elementRef.current) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
if (!isResizing.current) {
|
|
46
45
|
isResizing.current = true;
|
|
47
|
-
onResizeStart
|
|
46
|
+
onResizeStart?.();
|
|
48
47
|
}
|
|
49
|
-
const containerRect =
|
|
50
|
-
const clientX = getBoundedValue(event.clientX,
|
|
51
|
-
const clientY = getBoundedValue(event.clientY,
|
|
48
|
+
const containerRect = containerRef?.current?.getBoundingClientRect();
|
|
49
|
+
const clientX = getBoundedValue(event.clientX, containerRect?.left ?? 0, containerRect?.right ?? ownerDocument.documentElement.clientWidth ?? 0);
|
|
50
|
+
const clientY = getBoundedValue(event.clientY, containerRect?.top ?? 0, containerRect?.bottom ??
|
|
51
|
+
ownerDocument.documentElement.clientHeight ??
|
|
52
|
+
0);
|
|
52
53
|
const diffX = initialPointerX - clientX;
|
|
53
54
|
const diffY = initialPointerY - clientY;
|
|
54
55
|
switch (resizer) {
|
|
@@ -129,7 +130,7 @@ export const Resizer = (props) => {
|
|
|
129
130
|
if (elementRef.current) {
|
|
130
131
|
ownerDocument.body.style.userSelect = originalUserSelect;
|
|
131
132
|
isResizing.current = false;
|
|
132
|
-
onResizeEnd
|
|
133
|
+
onResizeEnd?.({
|
|
133
134
|
width,
|
|
134
135
|
height,
|
|
135
136
|
transform: `translate(${translateX}px, ${translateY}px)`,
|