@itwin/itwinui-react 3.0.0-dev.1 → 3.0.0-dev.2
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 +18 -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.js +3 -6
- package/cjs/core/FileUpload/FileUploadCard.js +9 -10
- 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 +11 -13
- package/cjs/core/Tile/Tile.js +2 -3
- package/cjs/core/TimePicker/TimePicker.js +13 -13
- package/cjs/core/Toast/Toast.js +2 -3
- package/cjs/core/Toast/Toaster.js +6 -11
- 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/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.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.js +5 -5
- 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.js +3 -6
- package/esm/core/FileUpload/FileUploadCard.js +9 -10
- 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 +12 -14
- package/esm/core/Tile/Tile.js +2 -3
- package/esm/core/TimePicker/TimePicker.js +13 -13
- package/esm/core/Toast/Toast.js +2 -3
- package/esm/core/Toast/Toaster.js +6 -11
- 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/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.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.js +5 -5
- 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 +18 -20
- package/cjs/core/utils/hooks/useIsThemeAlreadySet.d.ts +0 -7
- package/cjs/core/utils/hooks/useIsThemeAlreadySet.js +0 -54
- package/esm/core/utils/hooks/useIsThemeAlreadySet.d.ts +0 -7
- package/esm/core/utils/hooks/useIsThemeAlreadySet.js +0 -27
|
@@ -3,6 +3,7 @@
|
|
|
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 * as ReactDOM from 'react-dom';
|
|
6
7
|
import cx from 'classnames';
|
|
7
8
|
import { DialogTitleBar } from './DialogTitleBar.js';
|
|
8
9
|
import { DialogContent } from './DialogContent.js';
|
|
@@ -10,11 +11,18 @@ import { DialogBackdrop } from './DialogBackdrop.js';
|
|
|
10
11
|
import { DialogContext } from './DialogContext.js';
|
|
11
12
|
import { DialogButtonBar } from './DialogButtonBar.js';
|
|
12
13
|
import { DialogMain } from './DialogMain.js';
|
|
13
|
-
import { useMergedRefs, Box } from '../utils/index.js';
|
|
14
|
+
import { useMergedRefs, Box, useGlobals, getDocument, useIsClient, } from '../utils/index.js';
|
|
14
15
|
const DialogComponent = React.forwardRef((props, ref) => {
|
|
15
|
-
const { trapFocus = false, setFocus = false, preventDocumentScroll = false, isOpen = false, isDismissible = true, closeOnEsc = true, closeOnExternalClick = false, onClose, isDraggable = false, isResizable = false, relativeTo = 'viewport', placement, className, ...rest } = props;
|
|
16
|
+
const { trapFocus = false, setFocus = false, preventDocumentScroll = false, isOpen = false, isDismissible = true, closeOnEsc = true, closeOnExternalClick = false, onClose, isDraggable = false, isResizable = false, relativeTo = 'viewport', placement, className, portal = false, ...rest } = props;
|
|
16
17
|
const dialogRootRef = React.useRef(null);
|
|
17
|
-
const
|
|
18
|
+
const context = useGlobals();
|
|
19
|
+
const isClient = useIsClient();
|
|
20
|
+
const portalTo = typeof portal !== 'boolean'
|
|
21
|
+
? portal.to
|
|
22
|
+
: portal
|
|
23
|
+
? context?.portalContainerRef?.current ?? getDocument()?.body
|
|
24
|
+
: null;
|
|
25
|
+
const dialog = (React.createElement(Box, { className: cx('iui-dialog-wrapper', className), "data-iui-relative": relativeTo === 'container', ref: useMergedRefs(ref, dialogRootRef), ...rest }));
|
|
18
26
|
return (React.createElement(DialogContext.Provider, { value: {
|
|
19
27
|
isOpen,
|
|
20
28
|
onClose,
|
|
@@ -29,8 +37,7 @@ const DialogComponent = React.forwardRef((props, ref) => {
|
|
|
29
37
|
relativeTo,
|
|
30
38
|
dialogRootRef,
|
|
31
39
|
placement,
|
|
32
|
-
} },
|
|
33
|
-
React.createElement(Box, { className: cx('iui-dialog-wrapper', className), "data-iui-relative": relativeTo === 'container', ref: refs, ...rest })));
|
|
40
|
+
} }, portalTo && isClient ? ReactDOM.createPortal(dialog, portalTo) : dialog));
|
|
34
41
|
});
|
|
35
42
|
/**
|
|
36
43
|
* Dialog component.
|
|
@@ -27,7 +27,7 @@ export const DialogBackdrop = React.forwardRef((props, ref) => {
|
|
|
27
27
|
if (isDismissible && closeOnExternalClick && onClose) {
|
|
28
28
|
onClose(event);
|
|
29
29
|
}
|
|
30
|
-
onMouseDown
|
|
30
|
+
onMouseDown?.(event);
|
|
31
31
|
};
|
|
32
32
|
return (React.createElement(Backdrop, { isVisible: isVisible, className: cx({ 'iui-backdrop-fixed': relativeTo === 'viewport' }, className), ref: refs, onMouseDown: handleMouseDown, style: {
|
|
33
33
|
pointerEvents: 'auto',
|
|
@@ -61,6 +61,17 @@ export declare type DialogContextProps = {
|
|
|
61
61
|
* @default 'viewport'
|
|
62
62
|
*/
|
|
63
63
|
relativeTo?: 'container' | 'viewport';
|
|
64
|
+
/**
|
|
65
|
+
* If true, the dialog will be portaled into a <div> inside the nearest `ThemeProvider`.
|
|
66
|
+
* Recommended to set to true when for modal dialogs that use `relativeTo='viewport'`.
|
|
67
|
+
*
|
|
68
|
+
* Can be set to an object with a `to` property to portal into a specific element.
|
|
69
|
+
*
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
72
|
+
portal?: boolean | {
|
|
73
|
+
to: HTMLElement;
|
|
74
|
+
};
|
|
64
75
|
/**
|
|
65
76
|
* Dialog root ref. For internal use.
|
|
66
77
|
*/
|
|
@@ -45,8 +45,7 @@ export const DialogMain = React.forwardRef((props, ref) => {
|
|
|
45
45
|
}, [isOpen]);
|
|
46
46
|
// Prevents document from scrolling when the dialog is open.
|
|
47
47
|
React.useEffect(() => {
|
|
48
|
-
|
|
49
|
-
const ownerDocument = (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
48
|
+
const ownerDocument = dialogRef.current?.ownerDocument;
|
|
50
49
|
// If there is no `ownerDocument` or `preventDocumentScroll` is false or
|
|
51
50
|
// document body originally has `overflow: hidden` (possibly from other/parent dialog), then do nothing.
|
|
52
51
|
if (!ownerDocument ||
|
|
@@ -73,7 +72,7 @@ export const DialogMain = React.forwardRef((props, ref) => {
|
|
|
73
72
|
if (isDismissible && closeOnEsc && event.key === 'Escape' && onClose) {
|
|
74
73
|
onClose(event);
|
|
75
74
|
}
|
|
76
|
-
onKeyDown
|
|
75
|
+
onKeyDown?.(event);
|
|
77
76
|
};
|
|
78
77
|
const { onPointerDown, transform } = useDragAndDrop(dialogRef, dialogContext.dialogRootRef, isDraggable);
|
|
79
78
|
const handlePointerDown = React.useCallback((event) => {
|
|
@@ -83,23 +82,19 @@ export const DialogMain = React.forwardRef((props, ref) => {
|
|
|
83
82
|
}, [isDraggable, onPointerDown]);
|
|
84
83
|
// Prevents dialog from moving when window is being resized
|
|
85
84
|
useIsomorphicLayoutEffect(() => {
|
|
86
|
-
var _a;
|
|
87
85
|
if (!isDraggable || !isOpen) {
|
|
88
86
|
return;
|
|
89
87
|
}
|
|
90
|
-
const rect =
|
|
88
|
+
const rect = dialogRef.current?.getBoundingClientRect();
|
|
91
89
|
const [translateX, translateY] = getTranslateValues(dialogRef.current);
|
|
92
|
-
setStyle((oldStyle) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
transform: `translate(${translateX}px,${translateY}px)`,
|
|
101
|
-
});
|
|
102
|
-
});
|
|
90
|
+
setStyle((oldStyle) => ({
|
|
91
|
+
...oldStyle,
|
|
92
|
+
width: rect?.width,
|
|
93
|
+
height: rect?.height,
|
|
94
|
+
left: dialogRef.current?.offsetLeft,
|
|
95
|
+
top: dialogRef.current?.offsetTop,
|
|
96
|
+
transform: `translate(${translateX}px,${translateY}px)`,
|
|
97
|
+
}));
|
|
103
98
|
}, [isDraggable, isOpen]);
|
|
104
99
|
const setResizeStyle = React.useCallback((newStyle) => {
|
|
105
100
|
setStyle((oldStyle) => ({
|
|
@@ -131,15 +126,14 @@ export const DialogMain = React.forwardRef((props, ref) => {
|
|
|
131
126
|
}, timeout: { exit: 600 },
|
|
132
127
|
// Focuses dialog when opened
|
|
133
128
|
onEntered: () => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
setFocus &&
|
|
129
|
+
previousFocusedElement.current = dialogRef.current?.ownerDocument
|
|
130
|
+
.activeElement;
|
|
131
|
+
setFocus && dialogRef.current?.focus({ preventScroll: true });
|
|
137
132
|
},
|
|
138
133
|
// Brings back focus to the previously focused element when closed
|
|
139
134
|
onExit: () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
(_c = previousFocusedElement.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
135
|
+
if (dialogRef.current?.contains(dialogRef.current?.ownerDocument.activeElement)) {
|
|
136
|
+
previousFocusedElement.current?.focus();
|
|
143
137
|
}
|
|
144
138
|
}, unmountOnExit: true, nodeRef: dialogRef },
|
|
145
139
|
React.createElement(DialogDragContext.Provider, { value: { onPointerDown: handlePointerDown } },
|
|
@@ -26,29 +26,27 @@ import { Menu } from '../Menu/index.js';
|
|
|
26
26
|
*/
|
|
27
27
|
export const DropdownMenu = (props) => {
|
|
28
28
|
const { menuItems, children, className, style, role = 'menu', visible, placement = 'bottom-start', onShow, onHide, trigger, id, ...rest } = props;
|
|
29
|
-
const [isVisible, setIsVisible] = React.useState(visible
|
|
29
|
+
const [isVisible, setIsVisible] = React.useState(visible ?? false);
|
|
30
30
|
React.useEffect(() => {
|
|
31
|
-
setIsVisible(visible
|
|
31
|
+
setIsVisible(visible ?? false);
|
|
32
32
|
}, [visible]);
|
|
33
33
|
const open = React.useCallback(() => setIsVisible(true), []);
|
|
34
34
|
const close = React.useCallback(() => setIsVisible(false), []);
|
|
35
35
|
const targetRef = React.useRef(null);
|
|
36
36
|
const onShowHandler = React.useCallback((instance) => {
|
|
37
37
|
setIsVisible(true);
|
|
38
|
-
onShow
|
|
38
|
+
onShow?.(instance);
|
|
39
39
|
}, [onShow]);
|
|
40
40
|
const onHideHandler = React.useCallback((instance) => {
|
|
41
|
-
var _a;
|
|
42
41
|
setIsVisible(false);
|
|
43
|
-
|
|
44
|
-
onHide
|
|
42
|
+
targetRef.current?.focus();
|
|
43
|
+
onHide?.(instance);
|
|
45
44
|
}, [onHide]);
|
|
46
45
|
return (React.createElement(Popover, { content: React.createElement(Menu, { className: className, style: style, role: role, id: id }, React.useMemo(() => menuItems(close), [menuItems, close])), visible: trigger === undefined ? isVisible : undefined, onClickOutside: close, placement: placement, onShow: onShowHandler, onHide: onHideHandler, trigger: visible === undefined ? trigger : undefined, ...rest }, React.cloneElement(children, {
|
|
47
46
|
ref: mergeRefs(targetRef, props.children.ref),
|
|
48
47
|
onClick: (args) => {
|
|
49
|
-
var _a, _b;
|
|
50
48
|
trigger === undefined && (isVisible ? close() : open());
|
|
51
|
-
|
|
49
|
+
children.props.onClick?.(args);
|
|
52
50
|
},
|
|
53
51
|
})));
|
|
54
52
|
};
|
|
@@ -16,7 +16,7 @@ import { StatusIconMap, WithCSSTransition, SvgChevronRight, Icon, Box, } from '.
|
|
|
16
16
|
*/
|
|
17
17
|
export const ExpandableBlock = React.forwardRef((props, ref) => {
|
|
18
18
|
const { caption, children, className, title, onToggle, style, isExpanded = false, endIcon, status, size = 'default', styleType = 'default', disabled = false, ...rest } = props;
|
|
19
|
-
const icon = endIcon
|
|
19
|
+
const icon = endIcon ?? (status && StatusIconMap[status]());
|
|
20
20
|
const [expanded, setExpanded] = React.useState(isExpanded);
|
|
21
21
|
React.useEffect(() => {
|
|
22
22
|
setExpanded(isExpanded);
|
|
@@ -26,7 +26,7 @@ export const ExpandableBlock = React.forwardRef((props, ref) => {
|
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
setExpanded(!expanded);
|
|
29
|
-
onToggle
|
|
29
|
+
onToggle?.(!expanded);
|
|
30
30
|
};
|
|
31
31
|
const onKeyDown = (event) => {
|
|
32
32
|
if (event.altKey || disabled) {
|
|
@@ -18,7 +18,7 @@ const FileEmptyCardText = polymorphic.span('iui-file-card-empty-action');
|
|
|
18
18
|
// FileEmptyCard component
|
|
19
19
|
const FileEmptyCardComponent = React.forwardRef((props, ref) => {
|
|
20
20
|
const { children, className, ...rest } = props;
|
|
21
|
-
return (React.createElement(Box, { className: cx('iui-file-card-empty', className), ref: ref, ...rest }, children
|
|
21
|
+
return (React.createElement(Box, { className: cx('iui-file-card-empty', className), ref: ref, ...rest }, children ?? (React.createElement(React.Fragment, null,
|
|
22
22
|
React.createElement(FileEmptyCard.Icon, null),
|
|
23
23
|
React.createElement(FileEmptyCard.Text, null,
|
|
24
24
|
React.createElement(FileUploadCard.InputLabel, null, "Choose a file"),
|
|
@@ -22,31 +22,28 @@ export const FileUpload = React.forwardRef((props, ref) => {
|
|
|
22
22
|
e.stopPropagation();
|
|
23
23
|
};
|
|
24
24
|
const onDragEnterHandler = (e) => {
|
|
25
|
-
var _a, _b, _c;
|
|
26
25
|
e.preventDefault();
|
|
27
26
|
e.stopPropagation();
|
|
28
27
|
// only set active if a file is dragged over
|
|
29
|
-
if (!isDragActive &&
|
|
28
|
+
if (!isDragActive && e.dataTransfer?.items?.[0]?.kind === 'file') {
|
|
30
29
|
setIsDragActive(true);
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
32
|
const onDragLeaveHandler = (e) => {
|
|
34
|
-
var _a;
|
|
35
33
|
e.preventDefault();
|
|
36
34
|
e.stopPropagation();
|
|
37
35
|
// only set inactive if secondary target is outside the component
|
|
38
36
|
if (isDragActive &&
|
|
39
|
-
!
|
|
37
|
+
!fileUploadRef.current?.contains(e.relatedTarget)) {
|
|
40
38
|
setIsDragActive(false);
|
|
41
39
|
}
|
|
42
40
|
};
|
|
43
41
|
const onDropHandler = (e) => {
|
|
44
|
-
var _a;
|
|
45
42
|
e.preventDefault();
|
|
46
43
|
e.stopPropagation();
|
|
47
44
|
if (isDragActive) {
|
|
48
45
|
setIsDragActive(false);
|
|
49
|
-
onFileDropped(
|
|
46
|
+
onFileDropped(e.dataTransfer?.files);
|
|
50
47
|
}
|
|
51
48
|
};
|
|
52
49
|
return (React.createElement(Box, { className: cx('iui-file-upload', { 'iui-drag': isDragActive }, className), onDragEnter: onDragEnterHandler, onDragOver: onDragOverHandler, onDragLeave: onDragLeaveHandler, onDrop: onDropHandler, ref: refs, ...rest },
|
|
@@ -35,7 +35,7 @@ const FileUploadCardTitle = React.forwardRef((props, ref) => {
|
|
|
35
35
|
const { children, className, ...rest } = props;
|
|
36
36
|
const { files } = useSafeContext(FileUploadCardContext);
|
|
37
37
|
const title = files.length > 1 ? files.length + ' files selected' : files[0].name;
|
|
38
|
-
return (React.createElement(Box, { as: 'span', className: cx('iui-file-card-title', className), ref: ref, ...rest }, children
|
|
38
|
+
return (React.createElement(Box, { as: 'span', className: cx('iui-file-card-title', className), ref: ref, ...rest }, children ?? title));
|
|
39
39
|
});
|
|
40
40
|
FileUploadCardTitle.displayName = 'FileUploadCard.Title';
|
|
41
41
|
// ----------------------------------------------------------------------------
|
|
@@ -49,7 +49,7 @@ const FileUploadCardDescription = React.forwardRef((props, ref) => {
|
|
|
49
49
|
if (files.length > 2) {
|
|
50
50
|
description += ', and ' + (files.length - 2) + ' others';
|
|
51
51
|
}
|
|
52
|
-
return (React.createElement(Box, { as: 'span', className: cx('iui-file-card-description', className), ref: ref, ...rest }, children
|
|
52
|
+
return (React.createElement(Box, { as: 'span', className: cx('iui-file-card-description', className), ref: ref, ...rest }, children ?? description));
|
|
53
53
|
});
|
|
54
54
|
FileUploadCardDescription.displayName = 'FileUploadCard.Description';
|
|
55
55
|
// ----------------------------------------------------------------------------
|
|
@@ -70,8 +70,7 @@ const FileUploadCardInput = React.forwardRef((props, ref) => {
|
|
|
70
70
|
const { children, onChange, id, ...rest } = props;
|
|
71
71
|
const { files, onFilesChange, setInternalFiles, inputId, setInputId } = useSafeContext(FileUploadCardContext);
|
|
72
72
|
const setNativeFilesRef = React.useCallback((node) => {
|
|
73
|
-
|
|
74
|
-
if (!node || !((_a = getWindow()) === null || _a === void 0 ? void 0 : _a.DataTransfer)) {
|
|
73
|
+
if (!node || !getWindow()?.DataTransfer) {
|
|
75
74
|
return;
|
|
76
75
|
}
|
|
77
76
|
const dataTransfer = new DataTransfer();
|
|
@@ -88,19 +87,18 @@ const FileUploadCardInput = React.forwardRef((props, ref) => {
|
|
|
88
87
|
return (React.createElement(React.Fragment, null,
|
|
89
88
|
React.createElement(VisuallyHidden, { as: 'input', type: 'file', unhideOnFocus: false, onChange: mergeEventHandlers(onChange, (e) => {
|
|
90
89
|
const _files = Array.from(e.currentTarget.files || []);
|
|
91
|
-
onFilesChange
|
|
90
|
+
onFilesChange?.(_files);
|
|
92
91
|
setInternalFiles(_files);
|
|
93
|
-
}), ref: refs, id: id
|
|
92
|
+
}), ref: refs, id: id ?? inputId, ...rest }),
|
|
94
93
|
children));
|
|
95
94
|
});
|
|
96
95
|
FileUploadCardInput.displayName = 'FileUploadCard.Input';
|
|
97
96
|
const FileUploadCardComponent = React.forwardRef((props, ref) => {
|
|
98
|
-
var _a;
|
|
99
97
|
const { className, children, files: filesProp, onFilesChange, emptyCard = React.createElement(FileEmptyCard, null), input, ...rest } = props;
|
|
100
98
|
const [internalFiles, setInternalFiles] = React.useState();
|
|
101
99
|
const uid = useId();
|
|
102
100
|
const [inputId, setInputId] = React.useState(uid);
|
|
103
|
-
const files =
|
|
101
|
+
const files = filesProp ?? internalFiles ?? [];
|
|
104
102
|
return (React.createElement(FileUploadCardContext.Provider, { value: {
|
|
105
103
|
files,
|
|
106
104
|
onFilesChange,
|
|
@@ -108,13 +106,14 @@ const FileUploadCardComponent = React.forwardRef((props, ref) => {
|
|
|
108
106
|
inputId,
|
|
109
107
|
setInputId,
|
|
110
108
|
} },
|
|
111
|
-
|
|
109
|
+
files?.length ? (React.createElement(Box, { className: cx('iui-file-card', className), ref: ref, ...rest }, children ?? (React.createElement(React.Fragment, null,
|
|
112
110
|
React.createElement(FileUploadCard.Icon, null),
|
|
113
111
|
React.createElement(FileUploadCard.Info, null,
|
|
114
112
|
React.createElement(FileUploadCard.Title, null),
|
|
115
113
|
React.createElement(FileUploadCard.Description, null)),
|
|
116
114
|
React.createElement(FileUploadCard.Action, null,
|
|
117
|
-
React.createElement(FileUploadCard.InputLabel, null, "Replace")))))) : (emptyCard),
|
|
115
|
+
React.createElement(FileUploadCard.InputLabel, null, "Replace")))))) : (emptyCard),
|
|
116
|
+
input ?? React.createElement(FileUploadCard.Input, null)));
|
|
118
117
|
});
|
|
119
118
|
/**
|
|
120
119
|
* Default card to be used with the `FileUpload` wrapper component for single-file uploading.
|
|
@@ -40,10 +40,7 @@ export const InformationPanel = React.forwardRef((props, ref) => {
|
|
|
40
40
|
e.preventDefault();
|
|
41
41
|
e.stopPropagation();
|
|
42
42
|
infoPanelRef.current.ownerDocument.addEventListener('pointermove', onResize);
|
|
43
|
-
infoPanelRef.current.ownerDocument.addEventListener('pointerup', () => {
|
|
44
|
-
var _a;
|
|
45
|
-
return (_a = infoPanelRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.removeEventListener('pointermove', onResize);
|
|
46
|
-
}, { once: true });
|
|
43
|
+
infoPanelRef.current.ownerDocument.addEventListener('pointerup', () => infoPanelRef.current?.ownerDocument.removeEventListener('pointermove', onResize), { once: true });
|
|
47
44
|
};
|
|
48
45
|
const onResize = React.useCallback((e) => {
|
|
49
46
|
e.preventDefault();
|
|
@@ -16,7 +16,7 @@ import { StatusIconMap, InputContainer, useId } from '../utils/index.js';
|
|
|
16
16
|
export const LabeledInput = React.forwardRef((props, ref) => {
|
|
17
17
|
const uid = useId();
|
|
18
18
|
const { className, disabled = false, label, message, status, svgIcon, style, inputClassName, inputStyle, displayStyle = 'default', iconDisplayStyle = displayStyle === 'default' ? 'block' : 'inline', required = false, id = uid, ...rest } = props;
|
|
19
|
-
const icon = svgIcon
|
|
19
|
+
const icon = svgIcon ?? (status && StatusIconMap[status]());
|
|
20
20
|
return (React.createElement(InputContainer, { label: label, disabled: disabled, required: required, status: status, message: message, icon: icon, isLabelInline: displayStyle === 'inline', isIconInline: iconDisplayStyle === 'inline', className: className, style: style, inputId: id },
|
|
21
21
|
React.createElement(Input, { disabled: disabled, className: inputClassName, style: inputStyle, required: required, ref: ref, id: id, ...rest })));
|
|
22
22
|
});
|
|
@@ -29,7 +29,7 @@ import { Textarea } from '../Textarea/index.js';
|
|
|
29
29
|
export const LabeledTextarea = React.forwardRef((props, ref) => {
|
|
30
30
|
const uid = useId();
|
|
31
31
|
const { className, style, disabled = false, label, message, status, textareaClassName, textareaStyle, displayStyle = 'default', iconDisplayStyle = displayStyle === 'default' ? 'block' : 'inline', svgIcon, required = false, id = uid, ...textareaProps } = props;
|
|
32
|
-
const icon = svgIcon
|
|
32
|
+
const icon = svgIcon ?? (status && StatusIconMap[status]());
|
|
33
33
|
return (React.createElement(InputContainer, { label: label, disabled: disabled, required: required, status: status, message: message, icon: icon, isLabelInline: displayStyle === 'inline', isIconInline: iconDisplayStyle === 'inline', className: className, style: style, inputId: id },
|
|
34
34
|
React.createElement(Textarea, { disabled: disabled, className: textareaClassName, style: textareaStyle, required: required, id: id, ...textareaProps, ref: ref })));
|
|
35
35
|
});
|
package/esm/core/Menu/Menu.js
CHANGED
|
@@ -19,10 +19,9 @@ export const Menu = React.forwardRef((props, ref) => {
|
|
|
19
19
|
return focusableItems.filter((i) => !focusableItems.some((p) => p.contains(i.parentElement)));
|
|
20
20
|
}, []);
|
|
21
21
|
React.useEffect(() => {
|
|
22
|
-
var _a;
|
|
23
22
|
const items = getFocusableNodes();
|
|
24
23
|
if (focusedIndex != null) {
|
|
25
|
-
|
|
24
|
+
items?.[focusedIndex]?.focus();
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
const selectedIndex = items.findIndex((el) => el.getAttribute('aria-selected') === 'true');
|
|
@@ -35,10 +34,10 @@ export const Menu = React.forwardRef((props, ref) => {
|
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
const items = getFocusableNodes();
|
|
38
|
-
if (!
|
|
37
|
+
if (!items?.length) {
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
41
|
-
const currentIndex = focusedIndex
|
|
40
|
+
const currentIndex = focusedIndex ?? 0;
|
|
42
41
|
switch (event.key) {
|
|
43
42
|
case 'ArrowDown': {
|
|
44
43
|
setFocusedIndex(Math.min(currentIndex + 1, items.length - 1));
|
|
@@ -20,10 +20,9 @@ export const MenuItem = React.forwardRef((props, ref) => {
|
|
|
20
20
|
const { ref: parentMenuItemRef } = React.useContext(MenuItemContext);
|
|
21
21
|
const subMenuRef = React.useRef(null);
|
|
22
22
|
const [isSubmenuVisible, setIsSubmenuVisible] = React.useState(false);
|
|
23
|
-
const startIcon = startIconProp
|
|
24
|
-
const endIcon = endIconProp
|
|
23
|
+
const startIcon = startIconProp ?? icon;
|
|
24
|
+
const endIcon = endIconProp ?? badge;
|
|
25
25
|
const onKeyDown = (event) => {
|
|
26
|
-
var _a;
|
|
27
26
|
if (event.altKey) {
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
@@ -31,7 +30,7 @@ export const MenuItem = React.forwardRef((props, ref) => {
|
|
|
31
30
|
case 'Enter':
|
|
32
31
|
case ' ':
|
|
33
32
|
case 'Spacebar': {
|
|
34
|
-
!disabled &&
|
|
33
|
+
!disabled && onClick?.(value);
|
|
35
34
|
event.preventDefault();
|
|
36
35
|
break;
|
|
37
36
|
}
|
|
@@ -44,7 +43,7 @@ export const MenuItem = React.forwardRef((props, ref) => {
|
|
|
44
43
|
break;
|
|
45
44
|
}
|
|
46
45
|
case 'ArrowLeft': {
|
|
47
|
-
|
|
46
|
+
parentMenuItemRef?.current?.focus();
|
|
48
47
|
event.stopPropagation();
|
|
49
48
|
event.preventDefault();
|
|
50
49
|
break;
|
|
@@ -53,10 +52,9 @@ export const MenuItem = React.forwardRef((props, ref) => {
|
|
|
53
52
|
break;
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
|
-
const listItem = (React.createElement(ListItem, { actionable: true, size: size, active: isSelected, disabled: disabled, onClick: () => !disabled &&
|
|
57
|
-
var _a;
|
|
55
|
+
const listItem = (React.createElement(ListItem, { actionable: true, size: size, active: isSelected, disabled: disabled, onClick: () => !disabled && onClick?.(value), ref: refs, role: role, tabIndex: disabled || role === 'presentation' ? undefined : -1, "aria-selected": isSelected, "aria-haspopup": subMenuItems.length > 0, "aria-disabled": disabled, onKeyDown: onKeyDown, onMouseEnter: () => setIsSubmenuVisible(true), onMouseLeave: (e) => {
|
|
58
56
|
if (!(e.relatedTarget instanceof Node) ||
|
|
59
|
-
!
|
|
57
|
+
!subMenuRef.current?.contains(e.relatedTarget)) {
|
|
60
58
|
setIsSubmenuVisible(false);
|
|
61
59
|
}
|
|
62
60
|
}, ...rest },
|
|
@@ -69,10 +67,9 @@ export const MenuItem = React.forwardRef((props, ref) => {
|
|
|
69
67
|
endIcon && (React.createElement(ListItem.Icon, { as: 'span', "aria-hidden": true }, endIcon))));
|
|
70
68
|
return subMenuItems.length === 0 ? (listItem) : (React.createElement(MenuItemContext.Provider, { value: { ref: menuItemRef } },
|
|
71
69
|
React.createElement(Popover, { placement: 'right-start', visible: isSubmenuVisible, appendTo: 'parent', content: React.createElement("div", { onMouseLeave: () => setIsSubmenuVisible(false), onBlur: (e) => {
|
|
72
|
-
var _a, _b;
|
|
73
70
|
!!(e.relatedTarget instanceof Node) &&
|
|
74
|
-
!
|
|
75
|
-
!
|
|
71
|
+
!subMenuRef.current?.contains(e.relatedTarget) &&
|
|
72
|
+
!subMenuRef.current?.isEqualNode(e.relatedTarget) &&
|
|
76
73
|
setIsSubmenuVisible(false);
|
|
77
74
|
} },
|
|
78
75
|
React.createElement(Menu, { ref: subMenuRef }, subMenuItems)) }, listItem)));
|
|
@@ -30,16 +30,15 @@ declare type ModalProps = {
|
|
|
30
30
|
*/
|
|
31
31
|
onKeyDown?: React.KeyboardEventHandler;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* Document where the modal will be rendered.
|
|
39
|
-
* Can be specified to render in a different document (e.g. a popup window).
|
|
40
|
-
* @default document
|
|
33
|
+
* If true, the dialog will be portaled into a <div> inside the nearest `ThemeProvider`.
|
|
34
|
+
*
|
|
35
|
+
* Can be set to an object with a `to` property to portal into a specific element.
|
|
36
|
+
*
|
|
37
|
+
* @default true
|
|
41
38
|
*/
|
|
42
|
-
|
|
39
|
+
portal?: boolean | {
|
|
40
|
+
to: HTMLElement;
|
|
41
|
+
};
|
|
43
42
|
/**
|
|
44
43
|
* Content of the modal.
|
|
45
44
|
*/
|
package/esm/core/Modal/Modal.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
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 ReactDOM from 'react-dom';
|
|
7
|
-
import { getContainer, getDocument } from '../utils/index.js';
|
|
8
6
|
import { Dialog } from '../Dialog/index.js';
|
|
9
7
|
/**
|
|
10
8
|
* Modal component which can wrap any content.
|
|
@@ -28,16 +26,11 @@ import { Dialog } from '../Dialog/index.js';
|
|
|
28
26
|
* </Modal>
|
|
29
27
|
*/
|
|
30
28
|
export const Modal = React.forwardRef((props, forwardedRef) => {
|
|
31
|
-
const { isOpen = false, isDismissible = true, closeOnEsc = true, closeOnExternalClick = true, onClose, title, children,
|
|
32
|
-
|
|
33
|
-
React.useEffect(() => {
|
|
34
|
-
setContainer(getContainer(modalRootId, ownerDocument));
|
|
35
|
-
return () => setContainer(undefined);
|
|
36
|
-
}, [ownerDocument, modalRootId]);
|
|
37
|
-
return !!container ? (ReactDOM.createPortal(React.createElement(Dialog, { isOpen: isOpen, closeOnEsc: closeOnEsc, closeOnExternalClick: closeOnExternalClick, isDismissible: isDismissible, onClose: onClose, preventDocumentScroll: true, trapFocus: true, setFocus: true, ref: forwardedRef },
|
|
29
|
+
const { isOpen = false, isDismissible = true, closeOnEsc = true, closeOnExternalClick = true, onClose, title, children, portal = true, ...rest } = props;
|
|
30
|
+
return (React.createElement(Dialog, { isOpen: isOpen, closeOnEsc: closeOnEsc, closeOnExternalClick: closeOnExternalClick, isDismissible: isDismissible, onClose: onClose, preventDocumentScroll: true, trapFocus: true, setFocus: true, ref: forwardedRef, portal: portal },
|
|
38
31
|
React.createElement(Dialog.Backdrop, null),
|
|
39
32
|
React.createElement(Dialog.Main, { "aria-modal": true, ...rest },
|
|
40
33
|
React.createElement(Dialog.TitleBar, { titleText: title }),
|
|
41
|
-
children))
|
|
34
|
+
children)));
|
|
42
35
|
});
|
|
43
36
|
export default Modal;
|
|
@@ -14,16 +14,16 @@ const SearchBoxComponent = React.forwardRef((props, ref) => {
|
|
|
14
14
|
const inputRef = React.useRef(null);
|
|
15
15
|
const openButtonRef = React.useRef(null);
|
|
16
16
|
const [localExpanded, setLocalExpanded] = React.useState(isExpandedProp);
|
|
17
|
-
const isExpanded = isExpandedProp
|
|
17
|
+
const isExpanded = isExpandedProp ?? localExpanded;
|
|
18
18
|
const onCollapse = () => {
|
|
19
19
|
setLocalExpanded(false);
|
|
20
|
-
onCollapseProp
|
|
21
|
-
queueMicrotask(() =>
|
|
20
|
+
onCollapseProp?.();
|
|
21
|
+
queueMicrotask(() => openButtonRef.current?.focus({ preventScroll: true }));
|
|
22
22
|
};
|
|
23
23
|
const onExpand = () => {
|
|
24
24
|
setLocalExpanded(true);
|
|
25
|
-
onExpandProp
|
|
26
|
-
queueMicrotask(() =>
|
|
25
|
+
onExpandProp?.();
|
|
26
|
+
queueMicrotask(() => inputRef.current?.focus({ preventScroll: true }));
|
|
27
27
|
};
|
|
28
28
|
return (React.createElement(SearchBoxContext.Provider, { value: {
|
|
29
29
|
size,
|
|
@@ -37,7 +37,7 @@ const SearchBoxComponent = React.forwardRef((props, ref) => {
|
|
|
37
37
|
isExpanded,
|
|
38
38
|
expandable,
|
|
39
39
|
} },
|
|
40
|
-
React.createElement(InputFlexContainer, { ref: ref, className: cx('iui-searchbox', { 'iui-expandable-searchbox': expandable }, className), "data-iui-size": size, isDisabled: isDisabled, "data-iui-expanded": isExpanded, ...rest }, children
|
|
40
|
+
React.createElement(InputFlexContainer, { ref: ref, className: cx('iui-searchbox', { 'iui-expandable-searchbox': expandable }, className), "data-iui-size": size, isDisabled: isDisabled, "data-iui-expanded": isExpanded, ...rest }, children ?? (React.createElement(React.Fragment, null,
|
|
41
41
|
React.createElement(SearchBoxCollapsedState, null,
|
|
42
42
|
React.createElement(SearchBoxExpandButton, null)),
|
|
43
43
|
React.createElement(SearchBoxExpandedState, null,
|
|
@@ -51,7 +51,7 @@ const SearchBoxCollapsedState = ({ children, }) => {
|
|
|
51
51
|
if (!expandable || isExpanded) {
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
-
return React.createElement(React.Fragment, null, children
|
|
54
|
+
return React.createElement(React.Fragment, null, children ?? React.createElement(SearchBoxExpandButton, null));
|
|
55
55
|
};
|
|
56
56
|
SearchBoxCollapsedState.displayName = 'SearchBox.CollapsedState';
|
|
57
57
|
// ----------------------------------------------------------------------------
|
|
@@ -66,7 +66,7 @@ SearchBoxExpandedState.displayName = 'SearchBox.ExpandedState';
|
|
|
66
66
|
// ----------------------------------------------------------------------------
|
|
67
67
|
const SearchBoxIcon = React.forwardRef((props, ref) => {
|
|
68
68
|
const { className, children, ...rest } = props;
|
|
69
|
-
return (React.createElement(Icon, { "aria-hidden": true, className: cx('iui-search-icon', className), ref: ref, ...rest }, children
|
|
69
|
+
return (React.createElement(Icon, { "aria-hidden": true, className: cx('iui-search-icon', className), ref: ref, ...rest }, children ?? React.createElement(SvgSearch, null)));
|
|
70
70
|
});
|
|
71
71
|
SearchBoxIcon.displayName = 'SearchBox.Icon';
|
|
72
72
|
// ----------------------------------------------------------------------------
|
|
@@ -78,28 +78,28 @@ const SearchBoxInput = React.forwardRef((props, ref) => {
|
|
|
78
78
|
setInputId(idProp);
|
|
79
79
|
}
|
|
80
80
|
}, [idProp, inputId, setInputId]);
|
|
81
|
-
return (React.createElement(Box, { as: 'input', id: idProp
|
|
81
|
+
return (React.createElement(Box, { as: 'input', id: idProp ?? inputId, ref: useMergedRefs(ref, inputRef), role: 'searchbox', type: 'text', className: cx('iui-search-input', className), disabled: isDisabled, ...rest }));
|
|
82
82
|
});
|
|
83
83
|
SearchBoxInput.displayName = 'SearchBox.Input';
|
|
84
84
|
// ----------------------------------------------------------------------------
|
|
85
85
|
const SearchBoxButton = React.forwardRef((props, ref) => {
|
|
86
86
|
const { children, ...rest } = props;
|
|
87
87
|
const { size: sizeContext, isDisabled } = useSafeContext(SearchBoxContext);
|
|
88
|
-
return (React.createElement(IconButton, { styleType: 'borderless', size: sizeContext, ref: ref, disabled: isDisabled, ...rest }, children
|
|
88
|
+
return (React.createElement(IconButton, { styleType: 'borderless', size: sizeContext, ref: ref, disabled: isDisabled, ...rest }, children ?? React.createElement(SvgSearch, null)));
|
|
89
89
|
});
|
|
90
90
|
SearchBoxButton.displayName = 'SearchBox.Button';
|
|
91
91
|
// ----------------------------------------------------------------------------
|
|
92
92
|
const SearchBoxCollapseButton = React.forwardRef((props, ref) => {
|
|
93
93
|
const { children, onClick: onClickProp, ...rest } = props;
|
|
94
94
|
const { onCollapse, size: sizeContext, isDisabled, } = useSafeContext(SearchBoxContext);
|
|
95
|
-
return (React.createElement(SearchBoxButton, { ref: ref, "aria-label": 'Close searchbox', size: sizeContext, disabled: isDisabled, onClick: mergeEventHandlers(onClickProp, onCollapse), ...rest }, children
|
|
95
|
+
return (React.createElement(SearchBoxButton, { ref: ref, "aria-label": 'Close searchbox', size: sizeContext, disabled: isDisabled, onClick: mergeEventHandlers(onClickProp, onCollapse), ...rest }, children ?? React.createElement(SvgCloseSmall, null)));
|
|
96
96
|
});
|
|
97
97
|
SearchBoxCollapseButton.displayName = 'SearchBox.CollapseButton';
|
|
98
98
|
// ----------------------------------------------------------------------------
|
|
99
99
|
const SearchBoxExpandButton = React.forwardRef((props, ref) => {
|
|
100
100
|
const { children, className, onClick: onClickProp, ...rest } = props;
|
|
101
101
|
const { onExpand, size: sizeContext, isDisabled, openButtonRef, } = useSafeContext(SearchBoxContext);
|
|
102
|
-
return (React.createElement(SearchBoxButton, { ref: useMergedRefs(ref, openButtonRef), className: cx('iui-searchbox-open-button', className), "aria-label": 'Expand searchbox', size: sizeContext, disabled: isDisabled, onClick: mergeEventHandlers(onClickProp, onExpand), ...rest }, children
|
|
102
|
+
return (React.createElement(SearchBoxButton, { ref: useMergedRefs(ref, openButtonRef), className: cx('iui-searchbox-open-button', className), "aria-label": 'Expand searchbox', size: sizeContext, disabled: isDisabled, onClick: mergeEventHandlers(onClickProp, onExpand), ...rest }, children ?? React.createElement(SvgSearch, null)));
|
|
103
103
|
});
|
|
104
104
|
SearchBoxExpandButton.displayName = 'SearchBox.ExpandButton';
|
|
105
105
|
// ----------------------------------------------------------------------------
|