@itwin/itwinui-react 3.0.0-dev.7 → 3.0.0-dev.9
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 +68 -0
- package/cjs/core/Alert/Alert.d.ts +20 -9
- package/cjs/core/Alert/Alert.js +48 -10
- package/cjs/core/ButtonGroup/ButtonGroup.js +41 -36
- package/cjs/core/Buttons/DropdownButton/DropdownButton.js +7 -19
- package/cjs/core/Buttons/IconButton/IconButton.js +27 -44
- package/cjs/core/Buttons/SplitButton/SplitButton.d.ts +4 -4
- package/cjs/core/Buttons/SplitButton/SplitButton.js +54 -29
- package/cjs/core/ColorPicker/ColorInputPanel.js +172 -231
- package/cjs/core/ComboBox/ComboBox.d.ts +2 -2
- package/cjs/core/ComboBox/ComboBox.js +33 -25
- package/cjs/core/ComboBox/ComboBoxEndIcon.js +3 -22
- package/cjs/core/ComboBox/ComboBoxInput.js +29 -21
- package/cjs/core/ComboBox/ComboBoxMenu.d.ts +2 -2
- package/cjs/core/ComboBox/ComboBoxMenu.js +73 -93
- package/cjs/core/ComboBox/ComboBoxMenuItem.d.ts +1 -1
- package/cjs/core/ComboBox/ComboBoxMenuItem.js +8 -6
- package/cjs/core/ComboBox/helpers.d.ts +5 -3
- package/cjs/core/DatePicker/DatePicker.d.ts +30 -8
- package/cjs/core/DatePicker/DatePicker.js +40 -5
- package/cjs/core/Dialog/Dialog.js +10 -16
- package/cjs/core/Dialog/DialogContext.d.ts +3 -4
- package/cjs/core/DropdownMenu/DropdownMenu.d.ts +6 -5
- package/cjs/core/DropdownMenu/DropdownMenu.js +59 -55
- package/cjs/core/ExpandableBlock/ExpandableBlock.d.ts +20 -14
- package/cjs/core/ExpandableBlock/ExpandableBlock.js +38 -15
- package/cjs/core/Header/HeaderDropdownButton.js +1 -2
- package/cjs/core/Header/HeaderSplitButton.js +2 -2
- package/cjs/core/Input/Input.d.ts +4 -0
- package/cjs/core/Input/Input.js +2 -1
- package/cjs/core/InputGrid/InputGrid.d.ts +25 -0
- package/cjs/core/InputGrid/InputGrid.js +39 -0
- package/cjs/core/InputGrid/index.d.ts +3 -0
- package/cjs/core/InputGrid/index.js +15 -0
- package/cjs/core/InputGroup/InputGroup.d.ts +13 -0
- package/cjs/core/InputGroup/InputGroup.js +35 -9
- package/cjs/core/InputWithDecorations/InputWithDecorations.d.ts +39 -0
- package/cjs/core/InputWithDecorations/InputWithDecorations.js +81 -0
- package/cjs/core/InputWithDecorations/index.d.ts +3 -0
- package/cjs/core/InputWithDecorations/index.js +15 -0
- package/cjs/core/Label/Label.d.ts +5 -0
- package/cjs/core/Label/Label.js +2 -0
- package/cjs/core/LabeledInput/LabeledInput.d.ts +22 -16
- package/cjs/core/LabeledInput/LabeledInput.js +52 -29
- package/cjs/core/LabeledSelect/LabeledSelect.d.ts +17 -7
- package/cjs/core/LabeledSelect/LabeledSelect.js +36 -17
- package/cjs/core/LabeledTextarea/LabeledTextarea.d.ts +15 -5
- package/cjs/core/LabeledTextarea/LabeledTextarea.js +12 -45
- package/cjs/core/Menu/Menu.d.ts +1 -1
- package/cjs/core/Menu/Menu.js +2 -2
- package/cjs/core/Menu/MenuDivider.d.ts +2 -1
- package/cjs/core/Menu/MenuDivider.js +1 -1
- package/cjs/core/Menu/MenuItem.d.ts +1 -1
- package/cjs/core/Menu/MenuItem.js +78 -55
- package/cjs/core/Menu/MenuItemSkeleton.d.ts +1 -1
- package/cjs/core/Menu/MenuItemSkeleton.js +0 -1
- package/cjs/core/SearchBox/SearchBox.js +1 -1
- package/cjs/core/Select/Select.d.ts +9 -5
- package/cjs/core/Select/Select.js +81 -99
- package/cjs/core/SideNavigation/SideNavigation.js +2 -0
- package/cjs/core/Slider/Thumb.js +1 -0
- package/cjs/core/StatusMessage/StatusMessage.d.ts +12 -2
- package/cjs/core/StatusMessage/StatusMessage.js +23 -9
- package/cjs/core/Table/SubRowExpander.js +2 -0
- package/cjs/core/Table/columns/actionColumn.js +3 -7
- package/cjs/core/Table/filters/DateRangeFilter/DatePickerInput.d.ts +6 -1
- package/cjs/core/Table/filters/DateRangeFilter/DatePickerInput.js +56 -33
- package/cjs/core/Table/filters/DateRangeFilter/DateRangeFilter.d.ts +2 -0
- package/cjs/core/Table/filters/DateRangeFilter/DateRangeFilter.js +2 -0
- package/cjs/core/Table/filters/FilterToggle.js +3 -2
- package/cjs/core/Textarea/Textarea.d.ts +7 -1
- package/cjs/core/Textarea/Textarea.js +6 -11
- package/cjs/core/ThemeProvider/ThemeProvider.js +1 -1
- package/cjs/core/Tile/Tile.d.ts +139 -15
- package/cjs/core/Tile/Tile.js +128 -38
- package/cjs/core/Toast/Toast.d.ts +12 -4
- package/cjs/core/Toast/Toast.js +20 -4
- package/cjs/core/Tooltip/Tooltip.d.ts +35 -28
- package/cjs/core/Tooltip/Tooltip.js +116 -117
- package/cjs/core/TransferList/TransferList.js +4 -12
- package/cjs/core/index.d.ts +3 -1
- package/cjs/core/index.js +28 -5
- package/cjs/core/utils/components/Icon.d.ts +5 -0
- package/cjs/core/utils/components/Icon.js +8 -1
- package/cjs/core/utils/components/InputContainer.d.ts +4 -5
- package/cjs/core/utils/components/InputContainer.js +21 -37
- package/cjs/core/utils/components/InputFlexContainer.d.ts +1 -0
- package/cjs/core/utils/components/InputFlexContainer.js +3 -1
- package/cjs/core/utils/components/Popover.d.ts +113 -27
- package/cjs/core/utils/components/Popover.js +156 -118
- package/cjs/core/utils/components/Portal.d.ts +27 -0
- package/cjs/core/utils/components/Portal.js +43 -0
- package/cjs/core/utils/components/index.d.ts +1 -0
- package/cjs/core/utils/components/index.js +1 -0
- package/cjs/core/utils/functions/index.d.ts +1 -0
- package/cjs/core/utils/functions/index.js +1 -0
- package/cjs/core/utils/functions/react.d.ts +8 -0
- package/cjs/core/utils/functions/react.js +40 -0
- package/cjs/core/utils/hooks/index.d.ts +1 -1
- package/cjs/core/utils/hooks/index.js +1 -1
- package/cjs/core/utils/hooks/useControlledState.d.ts +13 -0
- package/cjs/core/utils/hooks/useControlledState.js +39 -0
- package/cjs/styles.js +10 -31
- package/esm/core/Alert/Alert.d.ts +20 -9
- package/esm/core/Alert/Alert.js +49 -10
- package/esm/core/ButtonGroup/ButtonGroup.js +41 -36
- package/esm/core/Buttons/DropdownButton/DropdownButton.js +8 -24
- package/esm/core/Buttons/IconButton/IconButton.js +25 -40
- package/esm/core/Buttons/SplitButton/SplitButton.d.ts +4 -4
- package/esm/core/Buttons/SplitButton/SplitButton.js +61 -28
- package/esm/core/ColorPicker/ColorInputPanel.js +173 -232
- package/esm/core/ComboBox/ComboBox.d.ts +2 -2
- package/esm/core/ComboBox/ComboBox.js +34 -25
- package/esm/core/ComboBox/ComboBoxEndIcon.js +4 -25
- package/esm/core/ComboBox/ComboBoxInput.js +22 -21
- package/esm/core/ComboBox/ComboBoxMenu.d.ts +2 -2
- package/esm/core/ComboBox/ComboBoxMenu.js +67 -87
- package/esm/core/ComboBox/ComboBoxMenuItem.d.ts +1 -1
- package/esm/core/ComboBox/ComboBoxMenuItem.js +9 -7
- package/esm/core/ComboBox/helpers.d.ts +5 -3
- package/esm/core/DatePicker/DatePicker.d.ts +30 -8
- package/esm/core/DatePicker/DatePicker.js +25 -5
- package/esm/core/Dialog/Dialog.js +11 -23
- package/esm/core/Dialog/DialogContext.d.ts +3 -4
- package/esm/core/DropdownMenu/DropdownMenu.d.ts +6 -5
- package/esm/core/DropdownMenu/DropdownMenu.js +64 -56
- package/esm/core/ExpandableBlock/ExpandableBlock.d.ts +20 -14
- package/esm/core/ExpandableBlock/ExpandableBlock.js +39 -17
- package/esm/core/Header/HeaderDropdownButton.js +1 -2
- package/esm/core/Header/HeaderSplitButton.js +2 -2
- package/esm/core/Input/Input.d.ts +4 -0
- package/esm/core/Input/Input.js +2 -1
- package/esm/core/InputGrid/InputGrid.d.ts +25 -0
- package/esm/core/InputGrid/InputGrid.js +35 -0
- package/esm/core/InputGrid/index.d.ts +3 -0
- package/esm/core/InputGrid/index.js +6 -0
- package/esm/core/InputGroup/InputGroup.d.ts +13 -0
- package/esm/core/InputGroup/InputGroup.js +34 -10
- package/esm/core/InputWithDecorations/InputWithDecorations.d.ts +39 -0
- package/esm/core/InputWithDecorations/InputWithDecorations.js +80 -0
- package/esm/core/InputWithDecorations/index.d.ts +3 -0
- package/esm/core/InputWithDecorations/index.js +6 -0
- package/esm/core/Label/Label.d.ts +5 -0
- package/esm/core/Label/Label.js +2 -0
- package/esm/core/LabeledInput/LabeledInput.d.ts +22 -16
- package/esm/core/LabeledInput/LabeledInput.js +53 -29
- package/esm/core/LabeledSelect/LabeledSelect.d.ts +17 -7
- package/esm/core/LabeledSelect/LabeledSelect.js +37 -18
- package/esm/core/LabeledTextarea/LabeledTextarea.d.ts +15 -5
- package/esm/core/LabeledTextarea/LabeledTextarea.js +14 -45
- package/esm/core/Menu/Menu.d.ts +1 -1
- package/esm/core/Menu/Menu.js +8 -3
- package/esm/core/Menu/MenuDivider.d.ts +2 -1
- package/esm/core/Menu/MenuDivider.js +1 -1
- package/esm/core/Menu/MenuItem.d.ts +1 -1
- package/esm/core/Menu/MenuItem.js +85 -52
- package/esm/core/Menu/MenuItemSkeleton.d.ts +1 -1
- package/esm/core/Menu/MenuItemSkeleton.js +0 -1
- package/esm/core/SearchBox/SearchBox.js +1 -1
- package/esm/core/Select/Select.d.ts +9 -5
- package/esm/core/Select/Select.js +81 -96
- package/esm/core/SideNavigation/SideNavigation.js +2 -0
- package/esm/core/Slider/Thumb.js +1 -0
- package/esm/core/StatusMessage/StatusMessage.d.ts +12 -2
- package/esm/core/StatusMessage/StatusMessage.js +23 -16
- package/esm/core/Table/SubRowExpander.js +2 -0
- package/esm/core/Table/columns/actionColumn.js +3 -7
- package/esm/core/Table/filters/DateRangeFilter/DatePickerInput.d.ts +6 -1
- package/esm/core/Table/filters/DateRangeFilter/DatePickerInput.js +56 -33
- package/esm/core/Table/filters/DateRangeFilter/DateRangeFilter.d.ts +2 -0
- package/esm/core/Table/filters/DateRangeFilter/DateRangeFilter.js +2 -0
- package/esm/core/Table/filters/FilterToggle.js +3 -2
- package/esm/core/Textarea/Textarea.d.ts +7 -1
- package/esm/core/Textarea/Textarea.js +6 -11
- package/esm/core/ThemeProvider/ThemeProvider.js +4 -3
- package/esm/core/Tile/Tile.d.ts +139 -15
- package/esm/core/Tile/Tile.js +128 -38
- package/esm/core/Toast/Toast.d.ts +12 -4
- package/esm/core/Toast/Toast.js +21 -4
- package/esm/core/Tooltip/Tooltip.d.ts +35 -28
- package/esm/core/Tooltip/Tooltip.js +119 -116
- package/esm/core/TransferList/TransferList.js +4 -9
- package/esm/core/index.d.ts +3 -1
- package/esm/core/index.js +3 -0
- package/esm/core/utils/components/Icon.d.ts +5 -0
- package/esm/core/utils/components/Icon.js +8 -1
- package/esm/core/utils/components/InputContainer.d.ts +4 -5
- package/esm/core/utils/components/InputContainer.js +21 -32
- package/esm/core/utils/components/InputFlexContainer.d.ts +1 -0
- package/esm/core/utils/components/InputFlexContainer.js +3 -1
- package/esm/core/utils/components/Popover.d.ts +113 -27
- package/esm/core/utils/components/Popover.js +175 -118
- package/esm/core/utils/components/Portal.d.ts +27 -0
- package/esm/core/utils/components/Portal.js +36 -0
- package/esm/core/utils/components/index.d.ts +1 -0
- package/esm/core/utils/components/index.js +1 -0
- package/esm/core/utils/functions/index.d.ts +1 -0
- package/esm/core/utils/functions/index.js +1 -0
- package/esm/core/utils/functions/react.d.ts +8 -0
- package/esm/core/utils/functions/react.js +35 -0
- package/esm/core/utils/hooks/index.d.ts +1 -1
- package/esm/core/utils/hooks/index.js +1 -1
- package/esm/core/utils/hooks/useControlledState.d.ts +13 -0
- package/esm/core/utils/hooks/useControlledState.js +34 -0
- package/esm/styles.js +10 -31
- package/package.json +3 -5
- package/styles.css +23 -20
- package/cjs/core/ComboBox/ComboBoxDropdown.d.ts +0 -7
- package/cjs/core/ComboBox/ComboBoxDropdown.js +0 -48
- package/cjs/core/utils/hooks/useUncontrolledState.d.ts +0 -6
- package/cjs/core/utils/hooks/useUncontrolledState.js +0 -18
- package/esm/core/ComboBox/ComboBoxDropdown.d.ts +0 -7
- package/esm/core/ComboBox/ComboBoxDropdown.js +0 -42
- package/esm/core/utils/hooks/useUncontrolledState.d.ts +0 -6
- package/esm/core/utils/hooks/useUncontrolledState.js +0 -13
|
@@ -3,126 +3,183 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
6
|
+
import {
|
|
7
|
+
useFloating,
|
|
8
|
+
useClick,
|
|
9
|
+
useDismiss,
|
|
10
|
+
useInteractions,
|
|
11
|
+
size,
|
|
12
|
+
autoUpdate,
|
|
13
|
+
offset,
|
|
14
|
+
flip,
|
|
15
|
+
shift,
|
|
16
|
+
autoPlacement,
|
|
17
|
+
inline,
|
|
18
|
+
hide,
|
|
19
|
+
FloatingFocusManager,
|
|
20
|
+
useHover,
|
|
21
|
+
useFocus,
|
|
22
|
+
safePolygon,
|
|
23
|
+
useRole,
|
|
24
|
+
} from '@floating-ui/react';
|
|
25
|
+
import {
|
|
26
|
+
Box,
|
|
27
|
+
cloneElementWithRef,
|
|
28
|
+
useControlledState,
|
|
29
|
+
useMergedRefs,
|
|
30
|
+
} from '../index.js';
|
|
31
|
+
import { Portal } from './Portal.js';
|
|
32
|
+
import { Surface } from '../../Surface/index.js';
|
|
33
|
+
import { ThemeProvider } from '../../ThemeProvider/index.js';
|
|
34
|
+
// ----------------------------------------------------------------------------
|
|
35
|
+
export const usePopover = (options) => {
|
|
36
|
+
const {
|
|
37
|
+
placement = 'bottom-start',
|
|
38
|
+
visible,
|
|
39
|
+
onVisibleChange,
|
|
40
|
+
closeOnOutsideClick,
|
|
41
|
+
autoUpdateOptions,
|
|
42
|
+
middleware = { flip: true, shift: true },
|
|
43
|
+
matchWidth,
|
|
44
|
+
trigger = { click: true, hover: false, focus: false },
|
|
45
|
+
role,
|
|
46
|
+
} = options;
|
|
47
|
+
const [open, onOpenChange] = useControlledState(
|
|
48
|
+
false,
|
|
49
|
+
visible,
|
|
50
|
+
onVisibleChange,
|
|
51
|
+
);
|
|
52
|
+
const floating = useFloating({
|
|
53
|
+
placement,
|
|
54
|
+
open,
|
|
55
|
+
onOpenChange,
|
|
56
|
+
whileElementsMounted: (...args) => autoUpdate(...args, autoUpdateOptions),
|
|
57
|
+
middleware: [
|
|
58
|
+
middleware.offset !== undefined && offset(middleware.offset),
|
|
59
|
+
middleware.flip && flip(),
|
|
60
|
+
middleware.shift && shift(),
|
|
61
|
+
matchWidth &&
|
|
62
|
+
size({
|
|
63
|
+
apply: ({ rects }) => {
|
|
64
|
+
setReferenceWidth(rects.reference.width);
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
middleware.autoPlacement && autoPlacement(),
|
|
68
|
+
middleware.inline && inline(),
|
|
69
|
+
middleware.hide && hide(),
|
|
70
|
+
].filter(Boolean),
|
|
71
|
+
});
|
|
72
|
+
const interactions = useInteractions([
|
|
73
|
+
useClick(floating.context, { enabled: !!trigger.click }),
|
|
74
|
+
useDismiss(floating.context, { outsidePress: closeOnOutsideClick }),
|
|
75
|
+
useHover(floating.context, {
|
|
76
|
+
enabled: !!trigger.hover,
|
|
77
|
+
delay: 100,
|
|
78
|
+
handleClose: safePolygon({ buffer: 1 }),
|
|
34
79
|
}),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
plugins: [
|
|
54
|
-
lazyLoad,
|
|
55
|
-
removeTabIndex,
|
|
56
|
-
hideOnEscOrTab,
|
|
57
|
-
...(props.plugins || []),
|
|
58
|
-
],
|
|
59
|
-
popperOptions: {
|
|
60
|
-
strategy: 'fixed',
|
|
61
|
-
...props.popperOptions,
|
|
62
|
-
modifiers: [
|
|
63
|
-
{ name: 'flip' },
|
|
64
|
-
{
|
|
65
|
-
name: 'preventOverflow',
|
|
66
|
-
options: { padding: 0 },
|
|
80
|
+
useFocus(floating.context, { enabled: !!trigger.focus }),
|
|
81
|
+
useRole(floating.context, { role: 'dialog', enabled: !!role }),
|
|
82
|
+
]);
|
|
83
|
+
const [referenceWidth, setReferenceWidth] = React.useState();
|
|
84
|
+
const getFloatingProps = React.useCallback(
|
|
85
|
+
(userProps) =>
|
|
86
|
+
interactions.getFloatingProps({
|
|
87
|
+
...userProps,
|
|
88
|
+
style: {
|
|
89
|
+
...floating.floatingStyles,
|
|
90
|
+
zIndex: 9999,
|
|
91
|
+
...(matchWidth && referenceWidth
|
|
92
|
+
? {
|
|
93
|
+
minInlineSize: `${referenceWidth}px`,
|
|
94
|
+
maxInlineSize: `min(${referenceWidth * 2}px, 90vw)`,
|
|
95
|
+
}
|
|
96
|
+
: {}),
|
|
97
|
+
...userProps?.style,
|
|
67
98
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
e.stopPropagation();
|
|
83
|
-
props.content.props.onClick?.(e);
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
: props.content;
|
|
87
|
-
computedProps.content = mounted ? clonedContent : '';
|
|
88
|
-
}
|
|
89
|
-
return React.createElement(Tippy, { ...computedProps, ref: refs });
|
|
90
|
-
});
|
|
99
|
+
}),
|
|
100
|
+
[floating.floatingStyles, interactions, matchWidth, referenceWidth],
|
|
101
|
+
);
|
|
102
|
+
return React.useMemo(
|
|
103
|
+
() => ({
|
|
104
|
+
open,
|
|
105
|
+
onOpenChange,
|
|
106
|
+
...interactions,
|
|
107
|
+
getFloatingProps,
|
|
108
|
+
...floating,
|
|
109
|
+
}),
|
|
110
|
+
[open, onOpenChange, interactions, getFloatingProps, floating],
|
|
111
|
+
);
|
|
112
|
+
};
|
|
91
113
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
114
|
+
* A utility component to help with positioning of floating content.
|
|
115
|
+
* Built on top of [`floating-ui`](https://floating-ui.com/)
|
|
94
116
|
*/
|
|
95
|
-
export const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
export const Popover = React.forwardRef((props, forwardedRef) => {
|
|
118
|
+
const {
|
|
119
|
+
portal = true,
|
|
120
|
+
//
|
|
121
|
+
// popover options
|
|
122
|
+
visible,
|
|
123
|
+
placement,
|
|
124
|
+
onVisibleChange,
|
|
125
|
+
closeOnOutsideClick,
|
|
126
|
+
matchWidth,
|
|
127
|
+
//
|
|
128
|
+
// dom props
|
|
129
|
+
children,
|
|
130
|
+
content,
|
|
131
|
+
applyBackground,
|
|
132
|
+
...rest
|
|
133
|
+
} = props;
|
|
134
|
+
const popover = usePopover({
|
|
135
|
+
visible,
|
|
136
|
+
placement,
|
|
137
|
+
onVisibleChange,
|
|
138
|
+
closeOnOutsideClick,
|
|
139
|
+
matchWidth,
|
|
140
|
+
role: 'dialog',
|
|
141
|
+
});
|
|
142
|
+
const [popoverElement, setPopoverElement] = React.useState();
|
|
143
|
+
const popoverRef = useMergedRefs(
|
|
144
|
+
popover.refs.setFloating,
|
|
145
|
+
forwardedRef,
|
|
146
|
+
setPopoverElement,
|
|
147
|
+
);
|
|
148
|
+
return React.createElement(
|
|
149
|
+
React.Fragment,
|
|
150
|
+
null,
|
|
151
|
+
cloneElementWithRef(children, (children) => ({
|
|
152
|
+
...popover.getReferenceProps(children.props),
|
|
153
|
+
ref: popover.refs.setReference,
|
|
154
|
+
})),
|
|
155
|
+
popover.open
|
|
156
|
+
? React.createElement(
|
|
157
|
+
Portal,
|
|
158
|
+
{ portal: portal },
|
|
159
|
+
React.createElement(
|
|
160
|
+
ThemeProvider,
|
|
161
|
+
{ portalContainer: popoverElement },
|
|
162
|
+
React.createElement(
|
|
163
|
+
FloatingFocusManager,
|
|
164
|
+
{
|
|
165
|
+
context: popover.context,
|
|
166
|
+
modal: false,
|
|
167
|
+
initialFocus: -1,
|
|
168
|
+
returnFocus: true,
|
|
169
|
+
},
|
|
170
|
+
React.createElement(
|
|
171
|
+
Box,
|
|
172
|
+
{
|
|
173
|
+
as: applyBackground ? Surface : 'div',
|
|
174
|
+
...popover.getFloatingProps(rest),
|
|
175
|
+
ref: popoverRef,
|
|
176
|
+
},
|
|
177
|
+
content,
|
|
178
|
+
),
|
|
179
|
+
),
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
: null,
|
|
183
|
+
);
|
|
184
|
+
});
|
|
128
185
|
export default Popover;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type PortalProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Where should the element be portaled to?
|
|
5
|
+
*
|
|
6
|
+
* If true, it will portal into nearest ThemeContext.portalContainer.
|
|
7
|
+
*
|
|
8
|
+
* If false, it will not be portaled.
|
|
9
|
+
*
|
|
10
|
+
* Otherwise, it will portal to the element passed to `to`.
|
|
11
|
+
*
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
portal?: boolean | {
|
|
15
|
+
to: HTMLElement | (() => HTMLElement);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Helper component that portals children according to the following conditions:
|
|
20
|
+
* - renders null on server
|
|
21
|
+
* - if `portal` is set to true, renders into nearest ThemeContext.portalContainer
|
|
22
|
+
* - if `portal` is set to false, renders as-is without portal
|
|
23
|
+
* - otherwise renders into `portal.to` (can be an element or a function)
|
|
24
|
+
*
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
export declare const Portal: (props: React.PropsWithChildren<PortalProps>) => React.ReactNode;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 * as React from 'react';
|
|
6
|
+
import * as ReactDOM from 'react-dom';
|
|
7
|
+
import { ThemeContext } from '../../ThemeProvider/ThemeContext.js';
|
|
8
|
+
import { getDocument } from '../functions/dom.js';
|
|
9
|
+
import { useIsClient } from '../hooks/useIsClient.js';
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Helper component that portals children according to the following conditions:
|
|
13
|
+
* - renders null on server
|
|
14
|
+
* - if `portal` is set to true, renders into nearest ThemeContext.portalContainer
|
|
15
|
+
* - if `portal` is set to false, renders as-is without portal
|
|
16
|
+
* - otherwise renders into `portal.to` (can be an element or a function)
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
export const Portal = (props) => {
|
|
21
|
+
const { portal = true, children } = props;
|
|
22
|
+
const isClient = useIsClient();
|
|
23
|
+
const portalTo = usePortalTo(portal);
|
|
24
|
+
if (!isClient) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return portalTo ? ReactDOM.createPortal(children, portalTo) : children;
|
|
28
|
+
};
|
|
29
|
+
// ----------------------------------------------------------------------------
|
|
30
|
+
const usePortalTo = (portal) => {
|
|
31
|
+
const themeInfo = React.useContext(ThemeContext);
|
|
32
|
+
if (typeof portal === 'boolean') {
|
|
33
|
+
return portal ? themeInfo?.portalContainer ?? getDocument()?.body : null;
|
|
34
|
+
}
|
|
35
|
+
return typeof portal.to === 'function' ? portal.to() : portal.to;
|
|
36
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper over `cloneElement` that automatically checks for `isValidElement`
|
|
4
|
+
* and automatically merges `children.ref` with the ref passed in props.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare const cloneElementWithRef: (children: React.ReactNode, getProps: (children: JSX.Element) => Record<string, unknown>) => string | number | true | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 * as React from 'react';
|
|
6
|
+
import { mergeRefs } from '../hooks/useMergedRefs.js';
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper over `cloneElement` that automatically checks for `isValidElement`
|
|
9
|
+
* and automatically merges `children.ref` with the ref passed in props.
|
|
10
|
+
*
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
export const cloneElementWithRef = (children, getProps) => {
|
|
14
|
+
if (!children) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (!React.isValidElement(children)) {
|
|
18
|
+
return children;
|
|
19
|
+
}
|
|
20
|
+
const props = getProps(children);
|
|
21
|
+
const ref = mergeRefs(
|
|
22
|
+
...[
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
'ref' in children ? children.ref : null,
|
|
25
|
+
'ref' in props ? props.ref : null,
|
|
26
|
+
].filter(Boolean),
|
|
27
|
+
);
|
|
28
|
+
return React.cloneElement(children, {
|
|
29
|
+
...props,
|
|
30
|
+
// we already checked ref above and handled null, so ts-ignore is ok
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
ref,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper over `useState` that always gives preference to the
|
|
4
|
+
* controlled state (which often comes from a prop).
|
|
5
|
+
*
|
|
6
|
+
* This is helpful when a component needs to support both uncontrolled
|
|
7
|
+
* and controlled states. If controlled value/setter is not passed,
|
|
8
|
+
* then it will work just like a regular `useState`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const [state, setState] = useControlledState(null, props.value, props.onChange);
|
|
12
|
+
*/
|
|
13
|
+
export declare const useControlledState: <T>(initialValue: T, controlledState: T, setControlledState?: React.Dispatch<React.SetStateAction<T>> | undefined) => readonly [T, React.Dispatch<React.SetStateAction<T>>];
|
|
@@ -0,0 +1,34 @@
|
|
|
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 * as React from 'react';
|
|
6
|
+
/**
|
|
7
|
+
* Wrapper over `useState` that always gives preference to the
|
|
8
|
+
* controlled state (which often comes from a prop).
|
|
9
|
+
*
|
|
10
|
+
* This is helpful when a component needs to support both uncontrolled
|
|
11
|
+
* and controlled states. If controlled value/setter is not passed,
|
|
12
|
+
* then it will work just like a regular `useState`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const [state, setState] = useControlledState(null, props.value, props.onChange);
|
|
16
|
+
*/
|
|
17
|
+
export const useControlledState = (
|
|
18
|
+
initialValue,
|
|
19
|
+
controlledState,
|
|
20
|
+
setControlledState,
|
|
21
|
+
) => {
|
|
22
|
+
const [uncontrolledState, setUncontrolledState] =
|
|
23
|
+
React.useState(initialValue);
|
|
24
|
+
const state =
|
|
25
|
+
controlledState !== undefined ? controlledState : uncontrolledState;
|
|
26
|
+
const setState = React.useCallback(
|
|
27
|
+
(value) => {
|
|
28
|
+
setUncontrolledState(value);
|
|
29
|
+
setControlledState?.(value);
|
|
30
|
+
},
|
|
31
|
+
[setControlledState, setUncontrolledState],
|
|
32
|
+
);
|
|
33
|
+
return [state, setState];
|
|
34
|
+
};
|
package/esm/styles.js
CHANGED
|
@@ -33,8 +33,9 @@ const styles = {
|
|
|
33
33
|
'iui-button-dropdown': '_iui3-button-dropdown',
|
|
34
34
|
'iui-button-split': '_iui3-button-split',
|
|
35
35
|
'iui-button-group': '_iui3-button-group',
|
|
36
|
-
'iui-input-container': '_iui3-input-container',
|
|
36
|
+
'iui-input-flex-container': '_iui3-input-flex-container',
|
|
37
37
|
'iui-input': '_iui3-input',
|
|
38
|
+
'iui-input-grid': '_iui3-input-grid',
|
|
38
39
|
'iui-disabled': '_iui3-disabled',
|
|
39
40
|
'iui-button-group-vertical': '_iui3-button-group-vertical',
|
|
40
41
|
'iui-button-group-overflow-x': '_iui3-button-group-overflow-x',
|
|
@@ -177,36 +178,18 @@ const styles = {
|
|
|
177
178
|
'iui-information-body-content': '_iui3-information-body-content',
|
|
178
179
|
'iui-input-label': '_iui3-input-label',
|
|
179
180
|
'iui-inline': '_iui3-inline',
|
|
180
|
-
'iui-required': '_iui3-required',
|
|
181
181
|
'iui-input-with-icon': '_iui3-input-with-icon',
|
|
182
182
|
'iui-select-tag-container': '_iui3-select-tag-container',
|
|
183
183
|
'iui-end-icon': '_iui3-end-icon',
|
|
184
|
-
'iui-actionable': '_iui3-actionable',
|
|
185
184
|
'iui-open': '_iui3-open',
|
|
186
|
-
'iui-
|
|
187
|
-
'iui-with-message': '_iui3-with-message',
|
|
188
|
-
'iui-input-icon': '_iui3-input-icon',
|
|
185
|
+
'iui-required': '_iui3-required',
|
|
189
186
|
'iui-input-group': '_iui3-input-group',
|
|
187
|
+
'iui-status-message': '_iui3-status-message',
|
|
188
|
+
'iui-select-button': '_iui3-select-button',
|
|
189
|
+
'iui-input-group-wrapper': '_iui3-input-group-wrapper',
|
|
190
190
|
'iui-toggle-switch-wrapper': '_iui3-toggle-switch-wrapper',
|
|
191
191
|
'iui-radio-wrapper': '_iui3-radio-wrapper',
|
|
192
|
-
'iui-inline-label': '_iui3-inline-label',
|
|
193
|
-
'iui-label': '_iui3-label',
|
|
194
|
-
'iui-message': '_iui3-message',
|
|
195
|
-
'iui-select-button': '_iui3-select-button',
|
|
196
|
-
'iui-input-flex-container': '_iui3-input-flex-container',
|
|
197
192
|
'iui-keyboard': '_iui3-keyboard',
|
|
198
|
-
'iui-location-marker': '_iui3-location-marker',
|
|
199
|
-
'iui-location-marker-default': '_iui3-location-marker-default',
|
|
200
|
-
'iui-location-marker-default-pin': '_iui3-location-marker-default-pin',
|
|
201
|
-
'iui-location-marker-default-pin-dot':
|
|
202
|
-
'_iui3-location-marker-default-pin-dot',
|
|
203
|
-
'iui-location-marker-data-rich': '_iui3-location-marker-data-rich',
|
|
204
|
-
'iui-location-marker-data-rich-body': '_iui3-location-marker-data-rich-body',
|
|
205
|
-
'iui-location-marker-data-rich-icon': '_iui3-location-marker-data-rich-icon',
|
|
206
|
-
'iui-location-marker-data-rich-icon-monochrome':
|
|
207
|
-
'_iui3-location-marker-data-rich-icon-monochrome',
|
|
208
|
-
'iui-location-marker-me': '_iui3-location-marker-me',
|
|
209
|
-
'iui-location-marker-me-dot': '_iui3-location-marker-me-dot',
|
|
210
193
|
'iui-list': '_iui3-list',
|
|
211
194
|
'iui-menu': '_iui3-menu',
|
|
212
195
|
'iui-header-menu-icon': '_iui3-header-menu-icon',
|
|
@@ -235,10 +218,10 @@ const styles = {
|
|
|
235
218
|
'iui-overlay-exiting': '_iui3-overlay-exiting',
|
|
236
219
|
closeAnimation,
|
|
237
220
|
'iui-progress-indicator-radial': '_iui3-progress-indicator-radial',
|
|
238
|
-
'iui-
|
|
221
|
+
'iui-ugj3ux4': '_iui3-ugj3ux4',
|
|
239
222
|
'iui-progress-indicator-linear-label':
|
|
240
223
|
'_iui3-progress-indicator-linear-label',
|
|
241
|
-
'iui-
|
|
224
|
+
'iui-ugj3uxq': '_iui3-ugj3uxq',
|
|
242
225
|
'iui-radio': '_iui3-radio',
|
|
243
226
|
'iui-radio-tile': '_iui3-radio-tile',
|
|
244
227
|
'iui-radio-tile-icon': '_iui3-radio-tile-icon',
|
|
@@ -305,6 +288,7 @@ const styles = {
|
|
|
305
288
|
'iui-table-body': '_iui3-table-body',
|
|
306
289
|
'iui-table-header-wrapper': '_iui3-table-header-wrapper',
|
|
307
290
|
'iui-slot': '_iui3-slot',
|
|
291
|
+
'iui-actionable': '_iui3-actionable',
|
|
308
292
|
'iui-table-filter-button': '_iui3-table-filter-button',
|
|
309
293
|
'iui-table-resizer': '_iui3-table-resizer',
|
|
310
294
|
'iui-table-resizer-bar': '_iui3-table-resizer-bar',
|
|
@@ -401,6 +385,7 @@ const styles = {
|
|
|
401
385
|
'iui-placement-bottom-start': '_iui3-placement-bottom-start',
|
|
402
386
|
'iui-placement-bottom-end': '_iui3-placement-bottom-end',
|
|
403
387
|
'iui-status-area': '_iui3-status-area',
|
|
388
|
+
'iui-message': '_iui3-message',
|
|
404
389
|
'iui-toast-anchor': '_iui3-toast-anchor',
|
|
405
390
|
'iui-informational': '_iui3-informational',
|
|
406
391
|
'iui-label-on-left': '_iui3-label-on-left',
|
|
@@ -408,11 +393,8 @@ const styles = {
|
|
|
408
393
|
'iui-toggle-switch-icon': '_iui3-toggle-switch-icon',
|
|
409
394
|
'iui-toggle-switch': '_iui3-toggle-switch',
|
|
410
395
|
'iui-toggle-switch-label': '_iui3-toggle-switch-label',
|
|
411
|
-
'iui-tooltip-container': '_iui3-tooltip-container',
|
|
412
396
|
'iui-tooltip': '_iui3-tooltip',
|
|
413
|
-
'iui-tooltip-visible': '_iui3-tooltip-visible',
|
|
414
397
|
'iui-transfer-list-wrapper': '_iui3-transfer-list-wrapper',
|
|
415
|
-
'iui-transfer-list-listbox-label': '_iui3-transfer-list-listbox-label',
|
|
416
398
|
'iui-transfer-list-listbox-wrapper': '_iui3-transfer-list-listbox-wrapper',
|
|
417
399
|
'iui-transfer-list-listbox': '_iui3-transfer-list-listbox',
|
|
418
400
|
'iui-transfer-list-toolbar': '_iui3-transfer-list-toolbar',
|
|
@@ -434,9 +416,6 @@ const styles = {
|
|
|
434
416
|
'iui-svg-icon': '_iui3-svg-icon',
|
|
435
417
|
'iui-notification-marker': '_iui3-notification-marker',
|
|
436
418
|
pulse,
|
|
437
|
-
'iui-popover': '_iui3-popover',
|
|
438
|
-
'tippy-box': '_iui3-tippy-box',
|
|
439
|
-
'tippy-content': '_iui3-tippy-content',
|
|
440
419
|
'iui-divider': '_iui3-divider',
|
|
441
420
|
'iui-flex': '_iui3-flex',
|
|
442
421
|
'iui-flex-spacer': '_iui3-flex-spacer',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/itwinui-react",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.9",
|
|
4
4
|
"author": "Bentley Systems",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -73,17 +73,15 @@
|
|
|
73
73
|
"dev:styles": "yarn build:styles --watch"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@floating-ui/react": "^0.
|
|
77
|
-
"@tippyjs/react": "^4.2.6",
|
|
76
|
+
"@floating-ui/react": "^0.25.3",
|
|
78
77
|
"@types/react-table": "^7.0.18",
|
|
79
78
|
"classnames": "^2.2.6",
|
|
80
79
|
"react-table": "^7.1.0",
|
|
81
80
|
"react-transition-group": "^4.4.2",
|
|
82
|
-
"tippy.js": "^6.3.7",
|
|
83
81
|
"tslib": "^2.6.0"
|
|
84
82
|
},
|
|
85
83
|
"devDependencies": {
|
|
86
|
-
"@itwin/itwinui-css": "^2.0.0-dev.
|
|
84
|
+
"@itwin/itwinui-css": "^2.0.0-dev.8",
|
|
87
85
|
"@itwin/itwinui-illustrations-react": "^2.1.0",
|
|
88
86
|
"@itwin/itwinui-variables": "3.0.0-dev.1",
|
|
89
87
|
"@swc/cli": "^0.1.62",
|