@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
|
@@ -27,40 +27,34 @@ export const EditableCell = (props) => {
|
|
|
27
27
|
const [key, setKey] = React.useState(getRandomValue(10));
|
|
28
28
|
const [isDirty, setIsDirty] = React.useState(false);
|
|
29
29
|
return (React.createElement(Box, { ...cellElementProps, contentEditable: true, suppressContentEditableWarning: true, key: key, ...rest, onInput: (e) => {
|
|
30
|
-
var _a;
|
|
31
30
|
setValue(sanitizeString(e.target.innerText));
|
|
32
31
|
setIsDirty(true);
|
|
33
|
-
|
|
32
|
+
props.onInput?.(e);
|
|
34
33
|
}, onBlur: (e) => {
|
|
35
|
-
var _a;
|
|
36
34
|
if (isDirty) {
|
|
37
35
|
onCellEdit(cellProps.column.id, value, cellProps.row.original);
|
|
38
36
|
}
|
|
39
|
-
|
|
37
|
+
props.onBlur?.(e);
|
|
40
38
|
// Prevents error when text is cleared.
|
|
41
39
|
// New key makes React to reattach with the DOM so it won't complain about deleted text node.
|
|
42
40
|
setKey(getRandomValue(10));
|
|
43
41
|
}, onKeyDown: (e) => {
|
|
44
|
-
var _a;
|
|
45
42
|
// Prevents from adding HTML elements (div, br) inside a cell on Enter press
|
|
46
43
|
if (e.key === 'Enter') {
|
|
47
44
|
e.preventDefault();
|
|
48
45
|
}
|
|
49
|
-
|
|
46
|
+
props.onKeyDown?.(e);
|
|
50
47
|
}, onPaste: (e) => {
|
|
51
|
-
var _a;
|
|
52
48
|
e.preventDefault();
|
|
53
49
|
document.execCommand('inserttext', false, sanitizeString(e.clipboardData.getData('text/plain')));
|
|
54
|
-
|
|
50
|
+
props.onPaste?.(e);
|
|
55
51
|
}, onDrop: (e) => {
|
|
56
|
-
var _a;
|
|
57
52
|
// Prevents from drag'n'dropping into a cell because it will add unwanted HTML elements
|
|
58
53
|
e.preventDefault();
|
|
59
|
-
|
|
54
|
+
props.onDrop?.(e);
|
|
60
55
|
}, onClick: (e) => {
|
|
61
|
-
var _a;
|
|
62
56
|
e.stopPropagation();
|
|
63
|
-
|
|
57
|
+
props.onClick?.(e);
|
|
64
58
|
} }, children));
|
|
65
59
|
};
|
|
66
60
|
export default EditableCell;
|
|
@@ -71,8 +71,7 @@ export const ActionColumn = ({ columnManager = false, } = {}) => {
|
|
|
71
71
|
// and table is scrolled to the very left which means our visibility dropdown menu is not visible.
|
|
72
72
|
// So for better UX we need to scroll to that dropdown menu.
|
|
73
73
|
queueMicrotask(() => {
|
|
74
|
-
|
|
75
|
-
(_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
|
|
74
|
+
buttonRef.current?.scrollIntoView();
|
|
76
75
|
});
|
|
77
76
|
};
|
|
78
77
|
return (React.createElement(MenuItem, { key: column.id, startIcon: React.createElement(Checkbox, { checked: checked, disabled: column.disableToggleVisibility, onClick: (e) => e.stopPropagation(), onChange: onClick, "aria-labelledby": `iui-column-${column.id}` }), onClick: onClick, disabled: column.disableToggleVisibility },
|
|
@@ -82,13 +81,11 @@ export const ActionColumn = ({ columnManager = false, } = {}) => {
|
|
|
82
81
|
? columnManager.dropdownMenuProps
|
|
83
82
|
: {};
|
|
84
83
|
return (React.createElement(DropdownMenu, { ...dropdownMenuProps, menuItems: headerCheckBoxes, onHide: (i) => {
|
|
85
|
-
var _a;
|
|
86
84
|
setIsOpen(false);
|
|
87
|
-
|
|
85
|
+
dropdownMenuProps.onHide?.(i);
|
|
88
86
|
}, onShow: (i) => {
|
|
89
|
-
var _a;
|
|
90
87
|
setIsOpen(true);
|
|
91
|
-
|
|
88
|
+
dropdownMenuProps.onShow?.(i);
|
|
92
89
|
}, className: cx('iui-scroll', dropdownMenuProps.className) },
|
|
93
90
|
React.createElement(IconButton, { styleType: 'borderless', isActive: isOpen, ref: buttonRef },
|
|
94
91
|
React.createElement(SvgColumnManager, null))));
|
|
@@ -44,16 +44,16 @@ export const ExpanderColumn = (props = {}) => {
|
|
|
44
44
|
cellClassName: 'iui-slot',
|
|
45
45
|
Cell: (props) => {
|
|
46
46
|
const { row } = props;
|
|
47
|
-
if (!
|
|
47
|
+
if (!subComponent?.(row)) {
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
return (React.createElement(IconButton, { className: 'iui-table-row-expander', styleType: 'borderless', size: 'small', onClick: (e) => {
|
|
52
52
|
e.stopPropagation();
|
|
53
53
|
row.toggleRowExpanded();
|
|
54
|
-
}, disabled: isDisabled
|
|
54
|
+
}, disabled: isDisabled?.(props.row.original) }, React.createElement(SvgChevronRight, null)));
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
cellRenderer: (props) => (React.createElement(DefaultCell, { ...props, isDisabled: (rowData) => !!
|
|
57
|
+
cellRenderer: (props) => (React.createElement(DefaultCell, { ...props, isDisabled: (rowData) => !!isDisabled?.(rowData) })),
|
|
58
58
|
};
|
|
59
59
|
};
|
|
@@ -32,14 +32,14 @@ export const SelectionColumn = (props = {}) => {
|
|
|
32
32
|
columnClassName: 'iui-slot',
|
|
33
33
|
cellClassName: 'iui-slot',
|
|
34
34
|
Header: ({ getToggleAllRowsSelectedProps, toggleAllRowsSelected, rows, initialRows, state, }) => {
|
|
35
|
-
const disabled = rows.every((row) => isDisabled
|
|
36
|
-
const checked = initialRows.every((row) => state.selectedRowIds[row.id] ||
|
|
35
|
+
const disabled = rows.every((row) => isDisabled?.(row.original));
|
|
36
|
+
const checked = initialRows.every((row) => state.selectedRowIds[row.id] || isDisabled?.(row.original));
|
|
37
37
|
const indeterminate = !checked && Object.keys(state.selectedRowIds).length > 0;
|
|
38
38
|
return (React.createElement(Checkbox, { ...getToggleAllRowsSelectedProps(), style: {}, title: '' // Removes default title that comes from react-table
|
|
39
39
|
, checked: checked && !disabled, indeterminate: indeterminate, disabled: disabled, onChange: () => toggleAllRowsSelected(!rows.some((row) => row.isSelected)) }));
|
|
40
40
|
},
|
|
41
41
|
Cell: ({ row }) => (React.createElement(Checkbox, { ...row.getToggleRowSelectedProps(), style: {}, title: '' // Removes default title that comes from react-table
|
|
42
|
-
, disabled: isDisabled
|
|
43
|
-
cellRenderer: (props) => (React.createElement(DefaultCell, { ...props, isDisabled: (rowData) => !!
|
|
42
|
+
, disabled: isDisabled?.(row.original), onClick: (e) => e.stopPropagation() })),
|
|
43
|
+
cellRenderer: (props) => (React.createElement(DefaultCell, { ...props, isDisabled: (rowData) => !!isDisabled?.(rowData) })),
|
|
44
44
|
};
|
|
45
45
|
};
|
|
@@ -27,10 +27,9 @@ const DatePickerInput = (props) => {
|
|
|
27
27
|
const [isVisible, setIsVisible] = React.useState(false);
|
|
28
28
|
const close = React.useCallback(() => setIsVisible(false), []);
|
|
29
29
|
const onDateSelected = React.useCallback((date) => {
|
|
30
|
-
var _a;
|
|
31
30
|
onChange(date);
|
|
32
31
|
close();
|
|
33
|
-
|
|
32
|
+
buttonRef.current?.focus();
|
|
34
33
|
}, [close, onChange]);
|
|
35
34
|
const onInputChange = React.useCallback((event) => {
|
|
36
35
|
const value = event.target.value;
|
|
@@ -44,8 +43,7 @@ const DatePickerInput = (props) => {
|
|
|
44
43
|
}
|
|
45
44
|
}, [onChange, parseInput]);
|
|
46
45
|
return (React.createElement(Popover, { content: React.createElement(DatePicker, { date: date, onChange: onDateSelected, setFocus: true, isDateDisabled: isDateDisabled }), placement: 'bottom', visible: isVisible, onClickOutside: (_, e) => {
|
|
47
|
-
|
|
48
|
-
if (!((_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
46
|
+
if (!buttonRef.current?.contains(e.target)) {
|
|
49
47
|
close();
|
|
50
48
|
}
|
|
51
49
|
}, appendTo: 'parent' },
|
|
@@ -27,11 +27,10 @@ const defaultParseInput = (text) => {
|
|
|
27
27
|
return new Date('');
|
|
28
28
|
};
|
|
29
29
|
export const DateRangeFilter = (props) => {
|
|
30
|
-
var _a, _b, _c, _d;
|
|
31
30
|
const { column, translatedLabels, setFilter, clearFilter, formatDate = defaultFormatDate, parseInput = defaultParseInput, placeholder = 'MMM dd, yyyy', } = props;
|
|
32
31
|
useGlobals();
|
|
33
32
|
const translatedStrings = { ...defaultStrings, ...translatedLabels };
|
|
34
|
-
const [from, setFrom] = React.useState(
|
|
33
|
+
const [from, setFrom] = React.useState(column.filterValue?.[0] ? new Date(column.filterValue?.[0]) : undefined);
|
|
35
34
|
const onFromChange = React.useCallback((date) => {
|
|
36
35
|
setFrom((prevDate) => {
|
|
37
36
|
if (prevDate || !date) {
|
|
@@ -40,7 +39,7 @@ export const DateRangeFilter = (props) => {
|
|
|
40
39
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
|
|
41
40
|
});
|
|
42
41
|
}, []);
|
|
43
|
-
const [to, setTo] = React.useState(
|
|
42
|
+
const [to, setTo] = React.useState(column.filterValue?.[1] ? new Date(column.filterValue?.[1]) : undefined);
|
|
44
43
|
const onToChange = React.useCallback((date) => {
|
|
45
44
|
setTo((prevDate) => {
|
|
46
45
|
if (prevDate || !date) {
|
|
@@ -12,12 +12,11 @@ const defaultStrings = {
|
|
|
12
12
|
to: 'To',
|
|
13
13
|
};
|
|
14
14
|
export const NumberRangeFilter = (props) => {
|
|
15
|
-
var _a, _b, _c, _d;
|
|
16
15
|
const { column, translatedLabels, setFilter, clearFilter } = props;
|
|
17
16
|
useGlobals();
|
|
18
17
|
const translatedStrings = { ...defaultStrings, ...translatedLabels };
|
|
19
|
-
const [from, setFrom] = React.useState(
|
|
20
|
-
const [to, setTo] = React.useState(
|
|
18
|
+
const [from, setFrom] = React.useState(column.filterValue?.[0] ?? '');
|
|
19
|
+
const [to, setTo] = React.useState(column.filterValue?.[1] ?? '');
|
|
21
20
|
const parseInputValue = (value) => {
|
|
22
21
|
return !value || isNaN(Number(value)) ? undefined : Number(value);
|
|
23
22
|
};
|
|
@@ -8,10 +8,9 @@ import { Input } from '../../../Input/index.js';
|
|
|
8
8
|
import { FilterButtonBar } from '../FilterButtonBar.js';
|
|
9
9
|
import { BaseFilter } from '../BaseFilter.js';
|
|
10
10
|
export const TextFilter = (props) => {
|
|
11
|
-
var _a;
|
|
12
11
|
const { column, translatedLabels, setFilter, clearFilter } = props;
|
|
13
12
|
useGlobals();
|
|
14
|
-
const [text, setText] = React.useState(
|
|
13
|
+
const [text, setText] = React.useState(column.filterValue ?? '');
|
|
15
14
|
const onKeyDown = (event) => {
|
|
16
15
|
if (event.altKey) {
|
|
17
16
|
return;
|
|
@@ -10,7 +10,6 @@ const isTouchEvent = (event) => {
|
|
|
10
10
|
const defaultGetResizerProps = (ownerDocument) => (props, { instance, header, nextHeader, }) => {
|
|
11
11
|
const { dispatch } = instance;
|
|
12
12
|
const onResizeStart = (e, header) => {
|
|
13
|
-
var _a, _b, _c;
|
|
14
13
|
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
15
14
|
if (isTouchEvent(e) && e.touches && e.touches.length > 1) {
|
|
16
15
|
return;
|
|
@@ -35,10 +34,9 @@ const defaultGetResizerProps = (ownerDocument) => (props, { instance, header, ne
|
|
|
35
34
|
moveHandler: (e) => dispatchMove(e.clientX),
|
|
36
35
|
upEvent: 'mouseup',
|
|
37
36
|
upHandler: () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
(_c = ownerDocument.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('mouseleave', handlersAndEvents.mouse.upHandler);
|
|
37
|
+
ownerDocument.current?.removeEventListener('mousemove', handlersAndEvents.mouse.moveHandler);
|
|
38
|
+
ownerDocument.current?.removeEventListener('mouseup', handlersAndEvents.mouse.upHandler);
|
|
39
|
+
ownerDocument.current?.removeEventListener('mouseleave', handlersAndEvents.mouse.upHandler);
|
|
42
40
|
dispatchEnd();
|
|
43
41
|
},
|
|
44
42
|
},
|
|
@@ -53,9 +51,8 @@ const defaultGetResizerProps = (ownerDocument) => (props, { instance, header, ne
|
|
|
53
51
|
},
|
|
54
52
|
upEvent: 'touchend',
|
|
55
53
|
upHandler: () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(_b = ownerDocument.current) === null || _b === void 0 ? void 0 : _b.removeEventListener(handlersAndEvents.touch.upEvent, handlersAndEvents.touch.moveHandler);
|
|
54
|
+
ownerDocument.current?.removeEventListener(handlersAndEvents.touch.moveEvent, handlersAndEvents.touch.moveHandler);
|
|
55
|
+
ownerDocument.current?.removeEventListener(handlersAndEvents.touch.upEvent, handlersAndEvents.touch.moveHandler);
|
|
59
56
|
dispatchEnd();
|
|
60
57
|
},
|
|
61
58
|
},
|
|
@@ -66,10 +63,10 @@ const defaultGetResizerProps = (ownerDocument) => (props, { instance, header, ne
|
|
|
66
63
|
const passiveIfSupported = passiveEventSupported()
|
|
67
64
|
? { passive: false }
|
|
68
65
|
: false;
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
ownerDocument.current?.addEventListener(events.moveEvent, events.moveHandler, passiveIfSupported);
|
|
67
|
+
ownerDocument.current?.addEventListener(events.upEvent, events.upHandler, passiveIfSupported);
|
|
71
68
|
if (!isTouchEvent(e)) {
|
|
72
|
-
|
|
69
|
+
ownerDocument.current?.addEventListener('mouseleave', handlersAndEvents.mouse.upHandler, passiveIfSupported);
|
|
73
70
|
}
|
|
74
71
|
dispatch({
|
|
75
72
|
type: actions.columnStartResizing,
|
|
@@ -153,8 +150,8 @@ const reducer = (newState, action, previousState, instance) => {
|
|
|
153
150
|
const newColumnWidths = getColumnWidths(headerIdWidths, deltaX / columnWidth);
|
|
154
151
|
const isTableWidthDecreasing = calculateTableWidth(newColumnWidths, instance.flatHeaders) <
|
|
155
152
|
instance.tableWidth;
|
|
156
|
-
const newNextColumnWidths =
|
|
157
|
-
(
|
|
153
|
+
const newNextColumnWidths = instance?.columnResizeMode === 'fit' ||
|
|
154
|
+
(instance?.columnResizeMode === 'expand' && isTableWidthDecreasing)
|
|
158
155
|
? getColumnWidths(nextHeaderIdWidths, -deltaX / nextColumnWidth)
|
|
159
156
|
: {};
|
|
160
157
|
if (!isNewColumnWidthsValid(newColumnWidths, instance.flatHeaders) ||
|
|
@@ -164,7 +161,7 @@ const reducer = (newState, action, previousState, instance) => {
|
|
|
164
161
|
}
|
|
165
162
|
// Setting `width` here because it might take several rerenders until actual column width is set.
|
|
166
163
|
// Also setting after the actual resize happened.
|
|
167
|
-
instance
|
|
164
|
+
instance?.flatHeaders.forEach((h) => {
|
|
168
165
|
if (!h.width) {
|
|
169
166
|
h.width = h.resizeWidth;
|
|
170
167
|
}
|
|
@@ -206,7 +203,7 @@ const isNewColumnWidthsValid = (columnWidths, headers) => {
|
|
|
206
203
|
return false;
|
|
207
204
|
}
|
|
208
205
|
for (const [headerId, width] of Object.entries(columnWidths)) {
|
|
209
|
-
const header = headers
|
|
206
|
+
const header = headers?.find((h) => h.id === headerId);
|
|
210
207
|
if (!header) {
|
|
211
208
|
continue;
|
|
212
209
|
}
|
|
@@ -238,7 +235,6 @@ const useInstanceBeforeDimensions = (instance) => {
|
|
|
238
235
|
const { flatHeaders, getHooks, state: { columnResizing }, columnResizeMode, } = instance;
|
|
239
236
|
const getInstance = useGetLatest(instance);
|
|
240
237
|
flatHeaders.forEach((header, index) => {
|
|
241
|
-
var _a;
|
|
242
238
|
const resizeWidth = columnResizing.columnWidths[header.id];
|
|
243
239
|
header.width = resizeWidth || header.width || header.originalWidth;
|
|
244
240
|
header.isResizing = columnResizing.isResizingColumn === header.id;
|
|
@@ -258,7 +254,7 @@ const useInstanceBeforeDimensions = (instance) => {
|
|
|
258
254
|
if (columnResizeMode === 'fit') {
|
|
259
255
|
header.isResizerVisible =
|
|
260
256
|
(header.canResize && !!nextResizableHeader) ||
|
|
261
|
-
(headerToResize && !!
|
|
257
|
+
(headerToResize && !!instance.flatHeaders[index + 1]?.canResize);
|
|
262
258
|
// When resize mode is `expand` show resizer on the current resizable column.
|
|
263
259
|
}
|
|
264
260
|
else {
|
|
@@ -272,8 +268,7 @@ const useInstanceBeforeDimensions = (instance) => {
|
|
|
272
268
|
});
|
|
273
269
|
};
|
|
274
270
|
const getPreviousResizableHeader = (headerColumn, instance) => {
|
|
275
|
-
|
|
276
|
-
const headersList = (((_a = headerColumn.parent) === null || _a === void 0 ? void 0 : _a.columns) || instance.flatHeaders).filter(({ isVisible }) => isVisible);
|
|
271
|
+
const headersList = (headerColumn.parent?.columns || instance.flatHeaders).filter(({ isVisible }) => isVisible);
|
|
277
272
|
const headerIndex = headersList.findIndex((h) => h.id === headerColumn.id);
|
|
278
273
|
return [...headersList]
|
|
279
274
|
.slice(0, headerIndex)
|
|
@@ -281,8 +276,7 @@ const getPreviousResizableHeader = (headerColumn, instance) => {
|
|
|
281
276
|
.find((h) => !h.disableResizing);
|
|
282
277
|
};
|
|
283
278
|
const getNextResizableHeader = (headerColumn, instance) => {
|
|
284
|
-
|
|
285
|
-
const headersList = (((_a = headerColumn.parent) === null || _a === void 0 ? void 0 : _a.columns) || instance.flatHeaders).filter(({ isVisible }) => isVisible);
|
|
279
|
+
const headersList = (headerColumn.parent?.columns || instance.flatHeaders).filter(({ isVisible }) => isVisible);
|
|
286
280
|
const headerIndex = headersList.findIndex((h) => h.id === headerColumn.id);
|
|
287
281
|
return [...headersList]
|
|
288
282
|
.slice(headerIndex + 1)
|
|
@@ -331,7 +325,7 @@ const passiveEventSupported = () => {
|
|
|
331
325
|
};
|
|
332
326
|
window.addEventListener('test', () => { }, options);
|
|
333
327
|
}
|
|
334
|
-
catch
|
|
328
|
+
catch {
|
|
335
329
|
passiveSupported = false;
|
|
336
330
|
}
|
|
337
331
|
return passiveSupported;
|
|
@@ -23,14 +23,13 @@ export function useScrollToRow({ data, enableVirtualization, page, paginatorRend
|
|
|
23
23
|
// For non-virtualized tables, we need to add a ref to each row
|
|
24
24
|
// and scroll to the element
|
|
25
25
|
React.useEffect(() => {
|
|
26
|
-
var _a;
|
|
27
26
|
if (enableVirtualization ||
|
|
28
27
|
scrollToIndex === undefined ||
|
|
29
28
|
scrollToIndex === null ||
|
|
30
29
|
scrollToIndex < 0) {
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
rowRefs.current[pageRef.current[scrollToIndex].id]?.scrollIntoView();
|
|
34
33
|
}, [enableVirtualization, scrollToIndex]);
|
|
35
34
|
const tableRowRef = React.useCallback((row) => {
|
|
36
35
|
return (element) => {
|
|
@@ -10,7 +10,6 @@ export const useStickyColumns = (hooks) => {
|
|
|
10
10
|
hooks.useInstance.push(useInstance);
|
|
11
11
|
};
|
|
12
12
|
const reducer = (newState, action) => {
|
|
13
|
-
var _a, _b;
|
|
14
13
|
if (action.type === actions.init) {
|
|
15
14
|
return {
|
|
16
15
|
...newState,
|
|
@@ -18,7 +17,7 @@ const reducer = (newState, action) => {
|
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
if (action.type === actions.setScrolledLeft &&
|
|
21
|
-
|
|
20
|
+
newState.sticky?.isScrolledToLeft !== action.value // Prevents unnecessary re-render
|
|
22
21
|
) {
|
|
23
22
|
return {
|
|
24
23
|
...newState,
|
|
@@ -29,7 +28,7 @@ const reducer = (newState, action) => {
|
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
30
|
if (action.type === actions.setScrolledRight &&
|
|
32
|
-
|
|
31
|
+
newState.sticky?.isScrolledToRight !== action.value // Prevents unnecessary re-render
|
|
33
32
|
) {
|
|
34
33
|
return {
|
|
35
34
|
...newState,
|
|
@@ -45,9 +44,8 @@ const useInstance = (instance) => {
|
|
|
45
44
|
const { flatHeaders } = instance;
|
|
46
45
|
// Edge case. Saving original sticky state in case sticky columns are reordered.
|
|
47
46
|
flatHeaders.forEach((header) => {
|
|
48
|
-
var _a;
|
|
49
47
|
if (!header.originalSticky) {
|
|
50
|
-
header.originalSticky =
|
|
48
|
+
header.originalSticky = header.sticky ?? 'none';
|
|
51
49
|
}
|
|
52
50
|
header.sticky =
|
|
53
51
|
header.originalSticky === 'none' ? undefined : header.originalSticky;
|
|
@@ -27,15 +27,13 @@ const useInstance = (hasAnySubRows, instance) => {
|
|
|
27
27
|
// Restore original sub-rows
|
|
28
28
|
const setSubRows = (rows) => {
|
|
29
29
|
rows.forEach((row) => {
|
|
30
|
-
|
|
31
|
-
row.subRows = (_a = row.initialSubRows) !== null && _a !== void 0 ? _a : [];
|
|
30
|
+
row.subRows = row.initialSubRows ?? [];
|
|
32
31
|
setSubRows(row.subRows);
|
|
33
32
|
});
|
|
34
33
|
};
|
|
35
34
|
setSubRows(instance.initialRows);
|
|
36
35
|
let currentlyFilteredRows = [...instance.initialRows];
|
|
37
36
|
instance.state.filters.forEach(({ id: columnId, value: filterValue }) => {
|
|
38
|
-
var _a;
|
|
39
37
|
const column = instance.allColumns.find((c) => c.id === columnId);
|
|
40
38
|
if (!column) {
|
|
41
39
|
return;
|
|
@@ -46,7 +44,7 @@ const useInstance = (hasAnySubRows, instance) => {
|
|
|
46
44
|
};
|
|
47
45
|
const filterFn = typeof column.filter === 'function'
|
|
48
46
|
? column.filter
|
|
49
|
-
: filterTypes[
|
|
47
|
+
: filterTypes[column.filter ?? 'text'];
|
|
50
48
|
currentlyFilteredRows = currentlyFilteredRows.filter((row) => handleRowFiltering(row, filterFn, columnId, filterValue));
|
|
51
49
|
});
|
|
52
50
|
const filteredRows = [];
|
package/esm/core/Tabs/Tabs.js
CHANGED
|
@@ -86,22 +86,20 @@ export const Tabs = (props) => {
|
|
|
86
86
|
React.useEffect(() => {
|
|
87
87
|
if (tablistRef.current && focusedIndex !== undefined) {
|
|
88
88
|
const tab = tablistRef.current.querySelectorAll(`.${styles['iui-tab']}`)[focusedIndex];
|
|
89
|
-
tab
|
|
89
|
+
tab?.focus();
|
|
90
90
|
}
|
|
91
91
|
}, [focusedIndex]);
|
|
92
92
|
const [hasSublabel, setHasSublabel] = React.useState(false); // used for setting size
|
|
93
93
|
useIsomorphicLayoutEffect(() => {
|
|
94
|
-
var _a;
|
|
95
94
|
setHasSublabel(type !== 'pill' && // pill tabs should never have sublabels
|
|
96
|
-
!!
|
|
95
|
+
!!tablistRef.current?.querySelector(`.${styles['iui-tab-description']}`));
|
|
97
96
|
}, [type]);
|
|
98
97
|
const enableHorizontalScroll = React.useCallback((e) => {
|
|
99
|
-
var _a;
|
|
100
98
|
const ownerDoc = tablistRef.current;
|
|
101
99
|
if (ownerDoc === null) {
|
|
102
100
|
return;
|
|
103
101
|
}
|
|
104
|
-
let scrollLeft =
|
|
102
|
+
let scrollLeft = ownerDoc?.scrollLeft ?? 0;
|
|
105
103
|
if (e.deltaY > 0 || e.deltaX > 0) {
|
|
106
104
|
scrollLeft += 25;
|
|
107
105
|
}
|
|
@@ -116,12 +114,12 @@ export const Tabs = (props) => {
|
|
|
116
114
|
if (ownerDoc === null) {
|
|
117
115
|
return;
|
|
118
116
|
}
|
|
119
|
-
if (!
|
|
117
|
+
if (!overflowOptions?.useOverflow || orientation === 'vertical') {
|
|
120
118
|
ownerDoc.removeEventListener('wheel', enableHorizontalScroll);
|
|
121
119
|
return;
|
|
122
120
|
}
|
|
123
121
|
ownerDoc.addEventListener('wheel', enableHorizontalScroll);
|
|
124
|
-
}, [overflowOptions
|
|
122
|
+
}, [overflowOptions?.useOverflow, orientation, enableHorizontalScroll]);
|
|
125
123
|
const isTabHidden = (activeTab, isVertical) => {
|
|
126
124
|
const ownerDoc = tablistRef.current;
|
|
127
125
|
if (ownerDoc === null) {
|
|
@@ -201,7 +199,7 @@ export const Tabs = (props) => {
|
|
|
201
199
|
setTimeout(() => {
|
|
202
200
|
const ownerDoc = tablistRef.current;
|
|
203
201
|
if (ownerDoc !== null &&
|
|
204
|
-
|
|
202
|
+
overflowOptions?.useOverflow &&
|
|
205
203
|
currentActiveIndex !== undefined) {
|
|
206
204
|
const activeTab = ownerDoc.querySelectorAll(`.${styles['iui-tab']}`)[currentActiveIndex];
|
|
207
205
|
const isVertical = orientation === 'vertical';
|
|
@@ -212,7 +210,7 @@ export const Tabs = (props) => {
|
|
|
212
210
|
}
|
|
213
211
|
}, 50);
|
|
214
212
|
}, [
|
|
215
|
-
overflowOptions
|
|
213
|
+
overflowOptions?.useOverflow,
|
|
216
214
|
currentActiveIndex,
|
|
217
215
|
focusedIndex,
|
|
218
216
|
orientation,
|
|
@@ -248,19 +246,19 @@ export const Tabs = (props) => {
|
|
|
248
246
|
}, [orientation, setScrollingPlacement]);
|
|
249
247
|
// apply correct mask when tabs list is resized
|
|
250
248
|
const [resizeRef] = useResizeObserver(determineScrollingPlacement);
|
|
251
|
-
resizeRef(tablistRef
|
|
249
|
+
resizeRef(tablistRef?.current);
|
|
252
250
|
// check if overflow tabs are scrolled to far edges
|
|
253
251
|
React.useEffect(() => {
|
|
254
252
|
const ownerDoc = tablistRef.current;
|
|
255
253
|
if (ownerDoc === null) {
|
|
256
254
|
return;
|
|
257
255
|
}
|
|
258
|
-
if (!
|
|
256
|
+
if (!overflowOptions?.useOverflow) {
|
|
259
257
|
ownerDoc.removeEventListener('scroll', determineScrollingPlacement);
|
|
260
258
|
return;
|
|
261
259
|
}
|
|
262
260
|
ownerDoc.addEventListener('scroll', determineScrollingPlacement);
|
|
263
|
-
}, [overflowOptions
|
|
261
|
+
}, [overflowOptions?.useOverflow, determineScrollingPlacement]);
|
|
264
262
|
const onTabClick = React.useCallback((index) => {
|
|
265
263
|
if (onTabSelected) {
|
|
266
264
|
onTabSelected(index);
|
|
@@ -276,7 +274,7 @@ export const Tabs = (props) => {
|
|
|
276
274
|
const tab = labels[index];
|
|
277
275
|
return React.isValidElement(tab) && tab.props.disabled;
|
|
278
276
|
};
|
|
279
|
-
let newIndex = focusedIndex
|
|
277
|
+
let newIndex = focusedIndex ?? currentActiveIndex;
|
|
280
278
|
/** focus next tab if delta is +1, previous tab if -1 */
|
|
281
279
|
const focusTab = (delta = +1) => {
|
|
282
280
|
do {
|
|
@@ -339,9 +337,8 @@ export const Tabs = (props) => {
|
|
|
339
337
|
'aria-selected': index === currentActiveIndex,
|
|
340
338
|
tabIndex: index === currentActiveIndex ? 0 : -1,
|
|
341
339
|
onClick: (args) => {
|
|
342
|
-
var _a, _b;
|
|
343
340
|
onClick();
|
|
344
|
-
|
|
341
|
+
label.props.onClick?.(args);
|
|
345
342
|
},
|
|
346
343
|
}))));
|
|
347
344
|
}, [currentActiveIndex, onTabClick]);
|
|
@@ -351,7 +348,7 @@ export const Tabs = (props) => {
|
|
|
351
348
|
'iui-animated': type !== 'default' && isClient,
|
|
352
349
|
'iui-not-animated': type !== 'default' && !isClient,
|
|
353
350
|
'iui-large': hasSublabel,
|
|
354
|
-
}, tabsClassName), "data-iui-overflow": overflowOptions
|
|
351
|
+
}, tabsClassName), "data-iui-overflow": overflowOptions?.useOverflow, "data-iui-scroll-placement": scrollingPlacement, role: 'tablist', ref: refs, onKeyDown: onKeyDown, ...rest }, labels.map((label, index) => createTab(label, index))),
|
|
355
352
|
actions && (React.createElement(Box, { className: 'iui-tabs-actions-wrapper' },
|
|
356
353
|
React.createElement(Box, { className: 'iui-tabs-actions' }, actions))),
|
|
357
354
|
children && (React.createElement(Box, { className: cx('iui-tabs-content', contentClassName), role: 'tabpanel' }, children))));
|
|
@@ -3,5 +3,5 @@ import type { ThemeOptions, ThemeType } from './ThemeProvider.js';
|
|
|
3
3
|
export declare const ThemeContext: React.Context<{
|
|
4
4
|
theme?: ThemeType | undefined;
|
|
5
5
|
themeOptions?: ThemeOptions | undefined;
|
|
6
|
-
|
|
6
|
+
portalContainerRef?: React.RefObject<HTMLElement> | undefined;
|
|
7
7
|
} | undefined>;
|
|
@@ -37,10 +37,9 @@ declare type RootProps = {
|
|
|
37
37
|
applyBackground?: boolean;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
* This will be used to determine if applyBackground will default to false.
|
|
40
|
+
* This will be used to determine if background will be applied.
|
|
42
41
|
*/
|
|
43
|
-
|
|
42
|
+
shouldApplyBackground?: boolean;
|
|
44
43
|
};
|
|
45
44
|
declare type ThemeProviderOwnProps = Pick<RootProps, 'theme'> & {
|
|
46
45
|
themeOptions?: RootProps['themeOptions'];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import cx from 'classnames';
|
|
7
|
-
import { useMediaQuery, useMergedRefs,
|
|
7
|
+
import { useMediaQuery, useMergedRefs, Box } from '../utils/index.js';
|
|
8
8
|
import { ThemeContext } from './ThemeContext.js';
|
|
9
9
|
/**
|
|
10
10
|
* This component provides global styles and applies theme to the entire tree
|
|
@@ -33,28 +33,26 @@ import { ThemeContext } from './ThemeContext.js';
|
|
|
33
33
|
* </ThemeProvider>
|
|
34
34
|
*/
|
|
35
35
|
export const ThemeProvider = React.forwardRef((props, ref) => {
|
|
36
|
-
var _a;
|
|
37
36
|
const { theme: themeProp, children, themeOptions, ...rest } = props;
|
|
38
|
-
const
|
|
39
|
-
const mergedRefs = useMergedRefs(rootRef, ref);
|
|
37
|
+
const portalContainerRef = React.useRef(null);
|
|
40
38
|
const parentContext = React.useContext(ThemeContext);
|
|
41
|
-
const theme = themeProp === 'inherit' ?
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const theme = themeProp === 'inherit' ? parentContext?.theme ?? 'light' : themeProp;
|
|
40
|
+
const shouldApplyBackground = themeOptions?.applyBackground ??
|
|
41
|
+
(themeProp === 'inherit' ? false : !parentContext);
|
|
42
|
+
const contextValue = React.useMemo(() => ({ theme, themeOptions, portalContainerRef }), [theme, themeOptions]);
|
|
43
|
+
return (React.createElement(ThemeContext.Provider, { value: contextValue },
|
|
44
|
+
React.createElement(Root, { theme: theme, shouldApplyBackground: shouldApplyBackground, themeOptions: themeOptions, ref: ref, ...rest },
|
|
45
|
+
children,
|
|
46
|
+
React.createElement("div", { ref: portalContainerRef }))));
|
|
46
47
|
});
|
|
47
48
|
export default ThemeProvider;
|
|
48
49
|
const Root = React.forwardRef((props, forwardedRef) => {
|
|
49
|
-
|
|
50
|
-
const { theme, children, themeOptions, className, isInheritingTheme, ...rest } = props;
|
|
50
|
+
const { theme, children, themeOptions, shouldApplyBackground, className, ...rest } = props;
|
|
51
51
|
const ref = React.useRef(null);
|
|
52
52
|
const mergedRefs = useMergedRefs(ref, forwardedRef);
|
|
53
53
|
const prefersDark = useMediaQuery('(prefers-color-scheme: dark)');
|
|
54
54
|
const prefersHighContrast = useMediaQuery('(prefers-contrast: more)');
|
|
55
55
|
const shouldApplyDark = theme === 'dark' || (theme === 'os' && prefersDark);
|
|
56
|
-
const shouldApplyHC =
|
|
57
|
-
const isThemeAlreadySet = useIsThemeAlreadySet((_b = ref.current) === null || _b === void 0 ? void 0 : _b.ownerDocument);
|
|
58
|
-
const shouldApplyBackground = (_c = themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.applyBackground) !== null && _c !== void 0 ? _c : (isInheritingTheme ? false : !isThemeAlreadySet.current);
|
|
56
|
+
const shouldApplyHC = themeOptions?.highContrast ?? prefersHighContrast;
|
|
59
57
|
return (React.createElement(Box, { className: cx('iui-root', { 'iui-root-background': shouldApplyBackground }, className), "data-iui-theme": shouldApplyDark ? 'dark' : 'light', "data-iui-contrast": shouldApplyHC ? 'high' : 'default', ref: mergedRefs, ...rest }, children));
|
|
60
58
|
});
|
package/esm/core/Tile/Tile.js
CHANGED
|
@@ -49,7 +49,7 @@ export const Tile = Object.assign(React.forwardRef((props, forwardedRef) => {
|
|
|
49
49
|
const showMenu = React.useCallback(() => setIsMenuVisible(true), []);
|
|
50
50
|
const hideMenu = React.useCallback(() => setIsMenuVisible(false), []);
|
|
51
51
|
const [localActionable, setLocalActionable] = React.useState(isActionableProp);
|
|
52
|
-
const isActionable = isActionableProp
|
|
52
|
+
const isActionable = isActionableProp ?? localActionable;
|
|
53
53
|
const tileName = (React.createElement(Box, { className: 'iui-tile-name' },
|
|
54
54
|
React.createElement(TitleIcon, { isLoading: isLoading, isSelected: isSelected, isNew: isNew, status: status }),
|
|
55
55
|
React.createElement(Box, { as: 'span', className: 'iui-tile-name-label' }, isActionable && onClick ? (React.createElement(LinkAction, { as: 'button', onClick: !isDisabled ? onClick : undefined, "aria-disabled": isDisabled }, name)) : (name))));
|
|
@@ -84,9 +84,8 @@ export const Tile = Object.assign(React.forwardRef((props, forwardedRef) => {
|
|
|
84
84
|
metadata != undefined && (React.createElement(Box, { className: 'iui-tile-metadata' }, metadata)),
|
|
85
85
|
moreOptions && (React.createElement(DropdownMenu, { onShow: showMenu, onHide: hideMenu, menuItems: (close) => moreOptions.map((option) => React.cloneElement(option, {
|
|
86
86
|
onClick: (value) => {
|
|
87
|
-
var _a, _b;
|
|
88
87
|
close();
|
|
89
|
-
|
|
88
|
+
option.props.onClick?.(value);
|
|
90
89
|
},
|
|
91
90
|
})) },
|
|
92
91
|
React.createElement(Box, { className: cx('iui-tile-more-options', {
|