@itwin/itwinui-react 3.15.5 → 3.16.0
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 +23 -0
- package/DEV-cjs/core/Breadcrumbs/Breadcrumbs.js +2 -2
- package/DEV-cjs/core/Checkbox/Checkbox.js +4 -6
- package/DEV-cjs/core/ComboBox/ComboBox.js +10 -6
- package/DEV-cjs/core/DatePicker/DatePicker.js +9 -1
- package/DEV-cjs/core/Dialog/Dialog.js +1 -1
- package/DEV-cjs/core/Panels/Panels.js +319 -0
- package/DEV-cjs/core/Panels/helpers.js +62 -0
- package/DEV-cjs/core/Radio/Radio.js +4 -6
- package/DEV-cjs/core/RadioTiles/RadioTileGroup.js +9 -2
- package/DEV-cjs/core/Select/SelectTag.js +9 -11
- package/DEV-cjs/core/Select/SelectTagContainer.js +2 -2
- package/DEV-cjs/core/Stepper/Stepper.js +1 -0
- package/DEV-cjs/core/Stepper/StepperStep.js +2 -1
- package/DEV-cjs/core/Table/Table.js +3 -4
- package/DEV-cjs/core/Table/TablePaginator.js +15 -3
- package/DEV-cjs/core/Table/actionHandlers/selectHandler.js +10 -7
- package/DEV-cjs/core/Table/columns/selectionColumn.js +6 -1
- package/DEV-cjs/core/Tree/Tree.js +1 -0
- package/DEV-cjs/index.js +4 -0
- package/DEV-cjs/styles.js +1 -1
- package/DEV-cjs/utils/components/MiddleTextTruncation.js +22 -4
- package/DEV-cjs/utils/components/OverflowContainer.js +170 -27
- package/DEV-cjs/utils/hooks/index.js +1 -1
- package/DEV-cjs/utils/hooks/useInstance.js +38 -0
- package/DEV-esm/core/Breadcrumbs/Breadcrumbs.js +2 -2
- package/DEV-esm/core/Checkbox/Checkbox.js +5 -10
- package/DEV-esm/core/ComboBox/ComboBox.js +10 -6
- package/DEV-esm/core/DatePicker/DatePicker.js +11 -1
- package/DEV-esm/core/Dialog/Dialog.js +1 -1
- package/DEV-esm/core/Panels/Panels.js +301 -0
- package/DEV-esm/core/Panels/helpers.js +42 -0
- package/DEV-esm/core/Radio/Radio.js +4 -9
- package/DEV-esm/core/RadioTiles/RadioTileGroup.js +8 -2
- package/DEV-esm/core/Select/SelectTag.js +9 -11
- package/DEV-esm/core/Select/SelectTagContainer.js +2 -2
- package/DEV-esm/core/Stepper/Stepper.js +1 -0
- package/DEV-esm/core/Stepper/StepperStep.js +2 -1
- package/DEV-esm/core/Table/Table.js +1 -5
- package/DEV-esm/core/Table/TablePaginator.js +16 -3
- package/DEV-esm/core/Table/actionHandlers/selectHandler.js +10 -7
- package/DEV-esm/core/Table/columns/selectionColumn.js +6 -1
- package/DEV-esm/core/Tree/Tree.js +1 -0
- package/DEV-esm/index.js +1 -0
- package/DEV-esm/styles.js +1 -1
- package/DEV-esm/utils/components/MiddleTextTruncation.js +22 -4
- package/DEV-esm/utils/components/OverflowContainer.js +143 -4
- package/DEV-esm/utils/hooks/index.js +1 -1
- package/DEV-esm/utils/hooks/useInstance.js +18 -0
- package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -2
- package/cjs/core/Checkbox/Checkbox.js +4 -6
- package/cjs/core/ComboBox/ComboBox.d.ts +13 -0
- package/cjs/core/ComboBox/ComboBox.js +10 -6
- package/cjs/core/DatePicker/DatePicker.d.ts +2 -2
- package/cjs/core/DatePicker/DatePicker.js +2 -1
- package/cjs/core/Dialog/Dialog.js +1 -1
- package/cjs/core/Dialog/DialogContext.d.ts +6 -2
- package/cjs/core/Panels/Panels.d.ts +174 -0
- package/cjs/core/Panels/Panels.js +312 -0
- package/cjs/core/Panels/helpers.d.ts +23 -0
- package/cjs/core/Panels/helpers.js +61 -0
- package/cjs/core/Radio/Radio.js +4 -6
- package/cjs/core/RadioTiles/RadioTileGroup.d.ts +3 -1
- package/cjs/core/RadioTiles/RadioTileGroup.js +9 -2
- package/cjs/core/Select/SelectTag.d.ts +3 -1
- package/cjs/core/Select/SelectTag.js +9 -11
- package/cjs/core/Select/SelectTagContainer.js +2 -2
- package/cjs/core/Stepper/Stepper.d.ts +4 -0
- package/cjs/core/Stepper/Stepper.js +1 -0
- package/cjs/core/Stepper/StepperStep.d.ts +4 -0
- package/cjs/core/Stepper/StepperStep.js +2 -1
- package/cjs/core/Table/Table.d.ts +1 -0
- package/cjs/core/Table/Table.js +3 -4
- package/cjs/core/Table/TablePaginator.js +15 -3
- package/cjs/core/Table/actionHandlers/selectHandler.js +10 -7
- package/cjs/core/Table/columns/selectionColumn.js +6 -1
- package/cjs/core/Tree/Tree.js +1 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +4 -0
- package/cjs/styles.js +1 -1
- package/cjs/utils/components/MiddleTextTruncation.d.ts +5 -7
- package/cjs/utils/components/MiddleTextTruncation.js +22 -4
- package/cjs/utils/components/OverflowContainer.d.ts +1 -0
- package/cjs/utils/components/OverflowContainer.js +170 -27
- package/cjs/utils/hooks/index.d.ts +1 -1
- package/cjs/utils/hooks/index.js +1 -1
- package/cjs/utils/hooks/useInstance.d.ts +22 -0
- package/cjs/utils/hooks/useInstance.js +38 -0
- package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -2
- package/esm/core/Checkbox/Checkbox.js +5 -10
- package/esm/core/ComboBox/ComboBox.d.ts +13 -0
- package/esm/core/ComboBox/ComboBox.js +10 -6
- package/esm/core/DatePicker/DatePicker.d.ts +2 -2
- package/esm/core/DatePicker/DatePicker.js +4 -1
- package/esm/core/Dialog/Dialog.js +1 -1
- package/esm/core/Dialog/DialogContext.d.ts +6 -2
- package/esm/core/Panels/Panels.d.ts +174 -0
- package/esm/core/Panels/Panels.js +294 -0
- package/esm/core/Panels/helpers.d.ts +23 -0
- package/esm/core/Panels/helpers.js +41 -0
- package/esm/core/Radio/Radio.js +4 -9
- package/esm/core/RadioTiles/RadioTileGroup.d.ts +3 -1
- package/esm/core/RadioTiles/RadioTileGroup.js +8 -2
- package/esm/core/Select/SelectTag.d.ts +3 -1
- package/esm/core/Select/SelectTag.js +9 -11
- package/esm/core/Select/SelectTagContainer.js +2 -2
- package/esm/core/Stepper/Stepper.d.ts +4 -0
- package/esm/core/Stepper/Stepper.js +1 -0
- package/esm/core/Stepper/StepperStep.d.ts +4 -0
- package/esm/core/Stepper/StepperStep.js +2 -1
- package/esm/core/Table/Table.d.ts +1 -0
- package/esm/core/Table/Table.js +1 -5
- package/esm/core/Table/TablePaginator.js +16 -3
- package/esm/core/Table/actionHandlers/selectHandler.js +10 -7
- package/esm/core/Table/columns/selectionColumn.js +6 -1
- package/esm/core/Tree/Tree.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/styles.js +1 -1
- package/esm/utils/components/MiddleTextTruncation.d.ts +5 -7
- package/esm/utils/components/MiddleTextTruncation.js +22 -4
- package/esm/utils/components/OverflowContainer.d.ts +1 -0
- package/esm/utils/components/OverflowContainer.js +143 -4
- package/esm/utils/hooks/index.d.ts +1 -1
- package/esm/utils/hooks/index.js +1 -1
- package/esm/utils/hooks/useInstance.d.ts +22 -0
- package/esm/utils/hooks/useInstance.js +18 -0
- package/package.json +2 -2
- package/styles.css +8 -8
- package/DEV-cjs/utils/hooks/useOverflow.js +0 -76
- package/DEV-esm/utils/hooks/useOverflow.js +0 -63
- package/cjs/utils/hooks/useOverflow.d.ts +0 -23
- package/cjs/utils/hooks/useOverflow.js +0 -76
- package/esm/utils/hooks/useOverflow.d.ts +0 -23
- package/esm/utils/hooks/useOverflow.js +0 -63
|
@@ -20,6 +20,7 @@ _export(exports, {
|
|
|
20
20
|
return onToggleHandler;
|
|
21
21
|
},
|
|
22
22
|
});
|
|
23
|
+
const _Table = require('../Table.js');
|
|
23
24
|
const onSelectHandler = (newState, instance, onSelect, isRowDisabled) => {
|
|
24
25
|
if (!instance?.rows.length) {
|
|
25
26
|
onSelect?.([], newState);
|
|
@@ -29,14 +30,16 @@ const onSelectHandler = (newState, instance, onSelect, isRowDisabled) => {
|
|
|
29
30
|
let handleRow = (row) => {
|
|
30
31
|
if (isRowDisabled?.(row.original)) return false;
|
|
31
32
|
let isAllSubSelected = true;
|
|
32
|
-
row.initialSubRows.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (row.initialSubRows[0]?.original[_Table.iuiId] === void 0)
|
|
34
|
+
row.initialSubRows.forEach((subRow) => {
|
|
35
|
+
let result = handleRow(subRow);
|
|
36
|
+
if (!result) isAllSubSelected = false;
|
|
37
|
+
});
|
|
36
38
|
if (
|
|
37
|
-
|
|
38
|
-
(!
|
|
39
|
-
|
|
39
|
+
newState.selectedRowIds[row.id] &&
|
|
40
|
+
(!instance.selectSubRows ||
|
|
41
|
+
!row.initialSubRows.length ||
|
|
42
|
+
isAllSubSelected)
|
|
40
43
|
)
|
|
41
44
|
newSelectedRowIds[row.id] = true;
|
|
42
45
|
return !!newSelectedRowIds[row.id];
|
|
@@ -21,6 +21,7 @@ const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildc
|
|
|
21
21
|
const _react = _interop_require_wildcard._(require('react'));
|
|
22
22
|
const _Checkbox = require('../../Checkbox/Checkbox.js');
|
|
23
23
|
const _index = require('../cells/index.js');
|
|
24
|
+
const _Table = require('../Table.js');
|
|
24
25
|
const SELECTION_CELL_ID = 'iui-table-checkbox-selector';
|
|
25
26
|
const SelectionColumn = (props = {}) => {
|
|
26
27
|
let { isDisabled, density } = props;
|
|
@@ -70,7 +71,11 @@ const SelectionColumn = (props = {}) => {
|
|
|
70
71
|
disabled: isDisabled?.(row.original),
|
|
71
72
|
onClick: (e) => e.stopPropagation(),
|
|
72
73
|
onChange: () => {
|
|
73
|
-
if (
|
|
74
|
+
if (
|
|
75
|
+
row.subRows.length > 0 &&
|
|
76
|
+
selectSubRows &&
|
|
77
|
+
void 0 === row.initialSubRows[0].original[_Table.iuiId]
|
|
78
|
+
)
|
|
74
79
|
row.toggleRowSelected(
|
|
75
80
|
!row.subRows.every(
|
|
76
81
|
(subRow) => subRow.isSelected || isDisabled?.(subRow.original),
|
package/cjs/core/Tree/Tree.js
CHANGED
package/cjs/index.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export { ModalContent } from './core/Modal/ModalContent.js';
|
|
|
62
62
|
export { ModalButtonBar } from './core/Modal/ModalButtonBar.js';
|
|
63
63
|
export { NotificationMarker } from './core/NotificationMarker/NotificationMarker.js';
|
|
64
64
|
export { Overlay } from './core/Overlay/Overlay.js';
|
|
65
|
+
export { Panels as unstable_Panels } from './core/Panels/Panels.js';
|
|
65
66
|
export { ProgressLinear } from './core/ProgressIndicators/ProgressLinear.js';
|
|
66
67
|
export { ProgressRadial } from './core/ProgressIndicators/ProgressRadial.js';
|
|
67
68
|
export { Radio } from './core/Radio/Radio.js';
|
package/cjs/index.js
CHANGED
|
@@ -371,6 +371,9 @@ _export(exports, {
|
|
|
371
371
|
tableFilters: function () {
|
|
372
372
|
return _index.tableFilters;
|
|
373
373
|
},
|
|
374
|
+
unstable_Panels: function () {
|
|
375
|
+
return _Panels.Panels;
|
|
376
|
+
},
|
|
374
377
|
useToaster: function () {
|
|
375
378
|
return _Toaster.useToaster;
|
|
376
379
|
},
|
|
@@ -437,6 +440,7 @@ const _ModalContent = require('./core/Modal/ModalContent.js');
|
|
|
437
440
|
const _ModalButtonBar = require('./core/Modal/ModalButtonBar.js');
|
|
438
441
|
const _NotificationMarker = require('./core/NotificationMarker/NotificationMarker.js');
|
|
439
442
|
const _Overlay = require('./core/Overlay/Overlay.js');
|
|
443
|
+
const _Panels = require('./core/Panels/Panels.js');
|
|
440
444
|
const _ProgressLinear = require('./core/ProgressIndicators/ProgressLinear.js');
|
|
441
445
|
const _ProgressRadial = require('./core/ProgressIndicators/ProgressRadial.js');
|
|
442
446
|
const _Radio = require('./core/Radio/Radio.js');
|
package/cjs/styles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { PolymorphicForwardRefComponent } from '../props.js';
|
|
3
|
+
type MiddleTextTruncationProps = {
|
|
4
4
|
/**
|
|
5
5
|
* Text to truncate.
|
|
6
6
|
*/
|
|
@@ -14,7 +14,7 @@ export type MiddleTextTruncationProps = {
|
|
|
14
14
|
* Custom renderer for the truncated text.
|
|
15
15
|
*/
|
|
16
16
|
textRenderer?: (truncatedText: string, originalText: string) => React.ReactNode;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
/**
|
|
19
19
|
* Truncates text with the ellipsis in the middle,
|
|
20
20
|
* leaving defined number of chars at the end.
|
|
@@ -31,7 +31,5 @@ export type MiddleTextTruncationProps = {
|
|
|
31
31
|
* )}
|
|
32
32
|
* />
|
|
33
33
|
*/
|
|
34
|
-
export declare const MiddleTextTruncation:
|
|
35
|
-
|
|
36
|
-
displayName: string;
|
|
37
|
-
};
|
|
34
|
+
export declare const MiddleTextTruncation: PolymorphicForwardRefComponent<"span", MiddleTextTruncationProps>;
|
|
35
|
+
export {};
|
|
@@ -11,9 +11,11 @@ Object.defineProperty(exports, 'MiddleTextTruncation', {
|
|
|
11
11
|
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
|
|
12
12
|
const _react = _interop_require_wildcard._(require('react'));
|
|
13
13
|
const _OverflowContainer = require('./OverflowContainer.js');
|
|
14
|
+
const _VisuallyHidden = require('../../core/VisuallyHidden/VisuallyHidden.js');
|
|
15
|
+
const _ShadowRoot = require('./ShadowRoot.js');
|
|
14
16
|
const ELLIPSIS_CHAR = '…';
|
|
15
|
-
const MiddleTextTruncation = (props) => {
|
|
16
|
-
let { text, style, ...rest } = props;
|
|
17
|
+
const MiddleTextTruncation = _react.forwardRef((props, forwardedRef) => {
|
|
18
|
+
let { text, endCharsCount, textRenderer, style, ...rest } = props;
|
|
17
19
|
return _react.createElement(
|
|
18
20
|
_OverflowContainer.OverflowContainer,
|
|
19
21
|
{
|
|
@@ -27,10 +29,26 @@ const MiddleTextTruncation = (props) => {
|
|
|
27
29
|
},
|
|
28
30
|
itemsCount: text.length,
|
|
29
31
|
...rest,
|
|
32
|
+
ref: forwardedRef,
|
|
30
33
|
},
|
|
31
|
-
_react.createElement(
|
|
34
|
+
_react.createElement(
|
|
35
|
+
_ShadowRoot.ShadowRoot,
|
|
36
|
+
null,
|
|
37
|
+
_react.createElement(_VisuallyHidden.VisuallyHidden, null, text),
|
|
38
|
+
_react.createElement('slot', {
|
|
39
|
+
'aria-hidden': true,
|
|
40
|
+
style: {
|
|
41
|
+
pointerEvents: 'none',
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
_react.createElement(MiddleTextTruncationContent, {
|
|
46
|
+
text: text,
|
|
47
|
+
endCharsCount: endCharsCount,
|
|
48
|
+
textRenderer: textRenderer,
|
|
49
|
+
}),
|
|
32
50
|
);
|
|
33
|
-
};
|
|
51
|
+
});
|
|
34
52
|
const MiddleTextTruncationContent = (props) => {
|
|
35
53
|
let { text, endCharsCount = 6, textRenderer } = props;
|
|
36
54
|
let { visibleCount } = _OverflowContainer.OverflowContainer.useContext();
|
|
@@ -12,48 +12,191 @@ const _interop_require_default = require('@swc/helpers/_/_interop_require_defaul
|
|
|
12
12
|
const _react = _interop_require_default._(require('react'));
|
|
13
13
|
const _useMergedRefs = require('../hooks/useMergedRefs.js');
|
|
14
14
|
const _Box = require('./Box.js');
|
|
15
|
-
const
|
|
15
|
+
const _useIsomorphicLayoutEffect = require('../hooks/useIsomorphicLayoutEffect.js');
|
|
16
16
|
const _useSafeContext = require('../hooks/useSafeContext.js');
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
let overflowContainerContextValue = _react.default.useMemo(
|
|
25
|
-
() => ({
|
|
26
|
-
visibleCount,
|
|
17
|
+
const _dev = require('../functions/dev.js');
|
|
18
|
+
const _useResizeObserver = require('../hooks/useResizeObserver.js');
|
|
19
|
+
const OverflowContainerMain = _react.default.forwardRef(
|
|
20
|
+
(props, forwardedRef) => {
|
|
21
|
+
let { itemsCount, children, overflowOrientation, ...rest } = props;
|
|
22
|
+
let [containerRef, visibleCount] = useOverflow(
|
|
27
23
|
itemsCount,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
overflowOrientation,
|
|
25
|
+
);
|
|
26
|
+
let overflowContainerContextValue = _react.default.useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
visibleCount,
|
|
29
|
+
itemsCount,
|
|
30
|
+
}),
|
|
31
|
+
[itemsCount, visibleCount],
|
|
32
|
+
);
|
|
33
|
+
return _react.default.createElement(
|
|
34
|
+
OverflowContainerContext.Provider,
|
|
38
35
|
{
|
|
39
|
-
|
|
40
|
-
...rest,
|
|
36
|
+
value: overflowContainerContextValue,
|
|
41
37
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
_react.default.createElement(
|
|
39
|
+
_Box.Box,
|
|
40
|
+
{
|
|
41
|
+
ref: (0, _useMergedRefs.useMergedRefs)(forwardedRef, containerRef),
|
|
42
|
+
...rest,
|
|
43
|
+
},
|
|
44
|
+
children,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
|
+
);
|
|
46
49
|
const OverflowContainerOverflowNode = (props) => {
|
|
47
50
|
let { children } = props;
|
|
48
51
|
let { visibleCount, itemsCount } = useOverflowContainerContext();
|
|
49
52
|
let isOverflowing = visibleCount < itemsCount;
|
|
50
53
|
return isOverflowing ? children : null;
|
|
51
54
|
};
|
|
55
|
+
const OverflowContainerComponent = _react.default.forwardRef(
|
|
56
|
+
(props, forwardedRef) => {
|
|
57
|
+
let { itemsCount, overflowOrientation = 'horizontal', ...rest } = props;
|
|
58
|
+
let [size, setSize] = _react.default.useState(null);
|
|
59
|
+
let [resizeRef] = (0, _useResizeObserver.useResizeObserver)(setSize);
|
|
60
|
+
let ref = (0, _useMergedRefs.useMergedRefs)(resizeRef, forwardedRef);
|
|
61
|
+
let key = `${itemsCount}${
|
|
62
|
+
'vertical' === overflowOrientation ? size?.height : size?.width
|
|
63
|
+
}`;
|
|
64
|
+
return _react.default.createElement(OverflowContainerMain, {
|
|
65
|
+
...rest,
|
|
66
|
+
key: key,
|
|
67
|
+
ref: ref,
|
|
68
|
+
itemsCount: itemsCount,
|
|
69
|
+
overflowOrientation: overflowOrientation,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
);
|
|
52
73
|
const OverflowContainer = Object.assign(OverflowContainerComponent, {
|
|
53
74
|
OverflowNode: OverflowContainerOverflowNode,
|
|
54
75
|
useContext: useOverflowContainerContext,
|
|
55
76
|
});
|
|
56
77
|
const OverflowContainerContext = _react.default.createContext(void 0);
|
|
78
|
+
const useOverflow = (itemsCount, orientation = 'horizontal') => {
|
|
79
|
+
let [guessState, dispatch] = _react.default.useReducer(
|
|
80
|
+
overflowGuessReducer,
|
|
81
|
+
{
|
|
82
|
+
itemsCount,
|
|
83
|
+
},
|
|
84
|
+
overflowGuessReducerInitialState,
|
|
85
|
+
);
|
|
86
|
+
let containerRef = _react.default.useRef(null);
|
|
87
|
+
let isGuessing = _react.default.useRef(false);
|
|
88
|
+
(0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
|
|
89
|
+
let { minGuess, maxGuess, isStabilized, visibleCount } = guessState;
|
|
90
|
+
if (isStabilized) return;
|
|
91
|
+
guessVisibleCount();
|
|
92
|
+
function guessVisibleCount() {
|
|
93
|
+
if (isStabilized || isGuessing.current || _dev.isUnitTest) return;
|
|
94
|
+
try {
|
|
95
|
+
isGuessing.current = true;
|
|
96
|
+
if (null == containerRef.current) return;
|
|
97
|
+
let dimension = 'horizontal' === orientation ? 'Width' : 'Height';
|
|
98
|
+
let availableSize = containerRef.current[`offset${dimension}`];
|
|
99
|
+
let requiredSize = containerRef.current[`scroll${dimension}`];
|
|
100
|
+
let isOverflowing = availableSize < requiredSize;
|
|
101
|
+
if (
|
|
102
|
+
0 === itemsCount ||
|
|
103
|
+
(1 === visibleCount && isOverflowing) ||
|
|
104
|
+
(visibleCount === itemsCount && !isOverflowing) ||
|
|
105
|
+
(maxGuess - minGuess === 1 && visibleCount === minGuess)
|
|
106
|
+
) {
|
|
107
|
+
dispatch({
|
|
108
|
+
type: 'stabilize',
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (maxGuess === visibleCount && !isOverflowing) {
|
|
113
|
+
dispatch({
|
|
114
|
+
type: 'shiftGuessRangeForward',
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
isOverflowing
|
|
119
|
+
? dispatch({
|
|
120
|
+
type: 'decreaseMaxGuess',
|
|
121
|
+
currentState: guessState,
|
|
122
|
+
})
|
|
123
|
+
: dispatch({
|
|
124
|
+
type: 'increaseMinGuess',
|
|
125
|
+
currentState: guessState,
|
|
126
|
+
});
|
|
127
|
+
} finally {
|
|
128
|
+
isGuessing.current = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}, [guessState, itemsCount, orientation]);
|
|
132
|
+
return [containerRef, guessState.visibleCount];
|
|
133
|
+
};
|
|
134
|
+
const STARTING_MAX_ITEMS_COUNT = 32;
|
|
135
|
+
const overflowGuessReducerInitialState = ({ itemsCount }) => {
|
|
136
|
+
let initialVisibleCount = Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT);
|
|
137
|
+
return _dev.isUnitTest
|
|
138
|
+
? {
|
|
139
|
+
isStabilized: true,
|
|
140
|
+
minGuess: null,
|
|
141
|
+
maxGuess: null,
|
|
142
|
+
itemsCount,
|
|
143
|
+
visibleCount: itemsCount,
|
|
144
|
+
}
|
|
145
|
+
: {
|
|
146
|
+
isStabilized: false,
|
|
147
|
+
minGuess: 0,
|
|
148
|
+
maxGuess: initialVisibleCount,
|
|
149
|
+
itemsCount,
|
|
150
|
+
visibleCount: initialVisibleCount,
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
const overflowGuessReducer = (state, action) => {
|
|
154
|
+
let getSafeVisibleCount = ({ visibleCount, itemsCount }) =>
|
|
155
|
+
Math.min(itemsCount, visibleCount);
|
|
156
|
+
switch (action.type) {
|
|
157
|
+
case 'decreaseMaxGuess':
|
|
158
|
+
case 'increaseMinGuess':
|
|
159
|
+
if (state.isStabilized) return state;
|
|
160
|
+
let newMinGuess = state.minGuess;
|
|
161
|
+
let newMaxGuess = state.maxGuess;
|
|
162
|
+
if ('decreaseMaxGuess' === action.type)
|
|
163
|
+
newMaxGuess = action.currentState.visibleCount;
|
|
164
|
+
else newMinGuess = action.currentState.visibleCount;
|
|
165
|
+
let newVisibleCount = Math.floor((newMinGuess + newMaxGuess) / 2);
|
|
166
|
+
return {
|
|
167
|
+
...state,
|
|
168
|
+
isStabilized: false,
|
|
169
|
+
minGuess: newMinGuess,
|
|
170
|
+
maxGuess: newMaxGuess,
|
|
171
|
+
visibleCount: getSafeVisibleCount({
|
|
172
|
+
visibleCount: newVisibleCount,
|
|
173
|
+
itemsCount: state.itemsCount,
|
|
174
|
+
}),
|
|
175
|
+
};
|
|
176
|
+
case 'shiftGuessRangeForward':
|
|
177
|
+
if (state.isStabilized) return state;
|
|
178
|
+
let doubleOfMaxGuess = 2 * state.maxGuess;
|
|
179
|
+
return {
|
|
180
|
+
...state,
|
|
181
|
+
isStabilized: false,
|
|
182
|
+
minGuess: state.maxGuess,
|
|
183
|
+
maxGuess: doubleOfMaxGuess,
|
|
184
|
+
visibleCount: getSafeVisibleCount({
|
|
185
|
+
visibleCount: doubleOfMaxGuess,
|
|
186
|
+
itemsCount: state.itemsCount,
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
case 'stabilize':
|
|
190
|
+
return {
|
|
191
|
+
...state,
|
|
192
|
+
isStabilized: true,
|
|
193
|
+
minGuess: null,
|
|
194
|
+
maxGuess: null,
|
|
195
|
+
};
|
|
196
|
+
default:
|
|
197
|
+
return state;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
57
200
|
function useOverflowContainerContext() {
|
|
58
201
|
let overflowContainerContext = (0, _useSafeContext.useSafeContext)(
|
|
59
202
|
OverflowContainerContext,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from './useEventListener.js';
|
|
2
2
|
export * from './useMergedRefs.js';
|
|
3
|
-
export * from './useOverflow.js';
|
|
4
3
|
export * from './useResizeObserver.js';
|
|
5
4
|
export * from './useContainerWidth.js';
|
|
6
5
|
export * from './useGlobals.js';
|
|
@@ -14,4 +13,5 @@ export * from './useId.js';
|
|
|
14
13
|
export * from './useControlledState.js';
|
|
15
14
|
export * from './useSyncExternalStore.js';
|
|
16
15
|
export * from './useVirtualScroll.js';
|
|
16
|
+
export * from './useInstance.js';
|
|
17
17
|
export * from './useWarningLogger.js';
|
package/cjs/utils/hooks/index.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
5
5
|
const _export_star = require('@swc/helpers/_/_export_star');
|
|
6
6
|
_export_star._(require('./useEventListener.js'), exports);
|
|
7
7
|
_export_star._(require('./useMergedRefs.js'), exports);
|
|
8
|
-
_export_star._(require('./useOverflow.js'), exports);
|
|
9
8
|
_export_star._(require('./useResizeObserver.js'), exports);
|
|
10
9
|
_export_star._(require('./useContainerWidth.js'), exports);
|
|
11
10
|
_export_star._(require('./useGlobals.js'), exports);
|
|
@@ -19,4 +18,5 @@ _export_star._(require('./useId.js'), exports);
|
|
|
19
18
|
_export_star._(require('./useControlledState.js'), exports);
|
|
20
19
|
_export_star._(require('./useSyncExternalStore.js'), exports);
|
|
21
20
|
_export_star._(require('./useVirtualScroll.js'), exports);
|
|
21
|
+
_export_star._(require('./useInstance.js'), exports);
|
|
22
22
|
_export_star._(require('./useWarningLogger.js'), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare class Instance {
|
|
2
|
+
}
|
|
3
|
+
export declare const useInstance: () => Instance;
|
|
4
|
+
/**
|
|
5
|
+
* Synchronizes the instance with the provided properties.
|
|
6
|
+
*
|
|
7
|
+
* @param instance Instance created by `useInstance`.
|
|
8
|
+
* @param properties Memoized object containing properties to be synchronized.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const instance = useInstance();
|
|
12
|
+
*
|
|
13
|
+
* const properties = React.useMemo(() => ({
|
|
14
|
+
* show: () => console.log('show'),
|
|
15
|
+
* }), []);
|
|
16
|
+
*
|
|
17
|
+
* useSynchronizeInstance(instance, properties);
|
|
18
|
+
*
|
|
19
|
+
* instance.show(); // logs 'show'
|
|
20
|
+
*/
|
|
21
|
+
export declare const useSynchronizeInstance: <T>(instance: T, properties: T) => T;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {
|
|
3
|
+
value: true,
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name],
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
useInstance: function () {
|
|
14
|
+
return useInstance;
|
|
15
|
+
},
|
|
16
|
+
useSynchronizeInstance: function () {
|
|
17
|
+
return useSynchronizeInstance;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
|
|
21
|
+
const _react = _interop_require_wildcard._(require('react'));
|
|
22
|
+
const _useSyncExternalStore = require('./useSyncExternalStore.js');
|
|
23
|
+
class Instance {}
|
|
24
|
+
const useInstance = () => _react.useMemo(() => new Instance(), []);
|
|
25
|
+
const useSynchronizeInstance = (instance, properties) => {
|
|
26
|
+
let synchronize = _react.useCallback(() => {
|
|
27
|
+
if (!(instance instanceof Instance)) return () => {};
|
|
28
|
+
Object.assign(instance, properties);
|
|
29
|
+
return () => {
|
|
30
|
+
for (let key in properties) delete instance[key];
|
|
31
|
+
};
|
|
32
|
+
}, [instance, properties]);
|
|
33
|
+
return (0, _useSyncExternalStore.useSyncExternalStore)(
|
|
34
|
+
synchronize,
|
|
35
|
+
() => instance,
|
|
36
|
+
() => instance,
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '../../utils/index.js';
|
|
9
9
|
import { Button } from '../Buttons/Button.js';
|
|
10
10
|
import { Anchor } from '../Typography/Anchor.js';
|
|
11
|
-
let BreadcrumbsComponent = React.forwardRef((props,
|
|
11
|
+
let BreadcrumbsComponent = React.forwardRef((props, forwardedRef) => {
|
|
12
12
|
let {
|
|
13
13
|
children: childrenProp,
|
|
14
14
|
currentIndex = React.Children.count(childrenProp) - 1,
|
|
@@ -26,7 +26,7 @@ let BreadcrumbsComponent = React.forwardRef((props, ref) => {
|
|
|
26
26
|
{
|
|
27
27
|
as: 'nav',
|
|
28
28
|
className: cx('iui-breadcrumbs', className),
|
|
29
|
-
ref:
|
|
29
|
+
ref: forwardedRef,
|
|
30
30
|
'aria-label': 'Breadcrumb',
|
|
31
31
|
...rest,
|
|
32
32
|
},
|
|
@@ -34,11 +34,11 @@ export const Checkbox = React.forwardRef((props, ref) => {
|
|
|
34
34
|
'iui-checkbox',
|
|
35
35
|
{
|
|
36
36
|
'iui-checkbox-visibility': 'eyeball' === variant,
|
|
37
|
-
'iui-loading': isLoading,
|
|
38
37
|
},
|
|
39
38
|
className,
|
|
40
39
|
),
|
|
41
40
|
style: style,
|
|
41
|
+
'data-iui-loading': isLoading ? 'true' : void 0,
|
|
42
42
|
disabled: disabled || isLoading,
|
|
43
43
|
type: 'checkbox',
|
|
44
44
|
ref: refs,
|
|
@@ -57,15 +57,10 @@ export const Checkbox = React.forwardRef((props, ref) => {
|
|
|
57
57
|
Box,
|
|
58
58
|
{
|
|
59
59
|
as: 'label',
|
|
60
|
-
className: cx(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[`iui-${status}`]: !!status,
|
|
65
|
-
'iui-loading': isLoading,
|
|
66
|
-
},
|
|
67
|
-
wrapperClassName,
|
|
68
|
-
),
|
|
60
|
+
className: cx('iui-checkbox-wrapper', wrapperClassName),
|
|
61
|
+
'data-iui-disabled': disabled ? 'true' : void 0,
|
|
62
|
+
'data-iui-status': status,
|
|
63
|
+
'data-iui-loading': isLoading ? 'true' : void 0,
|
|
69
64
|
...restWrapperProps,
|
|
70
65
|
},
|
|
71
66
|
checkbox,
|
|
@@ -33,11 +33,24 @@ export type ComboboxMultipleTypeProps<T> = {
|
|
|
33
33
|
* Callback fired when selected value changes.
|
|
34
34
|
*/
|
|
35
35
|
onChange?: (value: T) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Only applicable when `multiple` is enabled.
|
|
38
|
+
*
|
|
39
|
+
* If `true`, toggling an option will clear the filter.
|
|
40
|
+
* Useful when users would likely want to re-filter after toggling an option.
|
|
41
|
+
*
|
|
42
|
+
* If `false`, the filter will remain as-is after toggling an option.
|
|
43
|
+
* Useful when users would likely want to toggle multiple options from the _same_ filtered results.
|
|
44
|
+
*
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
clearFilterOnOptionToggle?: never;
|
|
36
48
|
} | {
|
|
37
49
|
multiple: true;
|
|
38
50
|
value?: T[] | null | undefined;
|
|
39
51
|
defaultValue?: T[] | null;
|
|
40
52
|
onChange?: (value: T[], event: MultipleOnChangeProps<T>) => void;
|
|
53
|
+
clearFilterOnOptionToggle?: boolean;
|
|
41
54
|
};
|
|
42
55
|
export type ComboBoxProps<T> = {
|
|
43
56
|
/**
|
|
@@ -47,6 +47,7 @@ export const ComboBox = React.forwardRef((props, forwardedRef) => {
|
|
|
47
47
|
onHide: onHideProp,
|
|
48
48
|
id = inputProps?.id ? `iui-${inputProps.id}-cb` : idPrefix,
|
|
49
49
|
defaultValue,
|
|
50
|
+
clearFilterOnOptionToggle = true,
|
|
50
51
|
...rest
|
|
51
52
|
} = props;
|
|
52
53
|
let inputRef = React.useRef(null);
|
|
@@ -200,7 +201,6 @@ export const ComboBox = React.forwardRef((props, forwardedRef) => {
|
|
|
200
201
|
preventScroll: true,
|
|
201
202
|
});
|
|
202
203
|
if (optionsRef.current[__originalIndex]?.disabled) return;
|
|
203
|
-
setIsInputDirty(false);
|
|
204
204
|
if (multiple) {
|
|
205
205
|
let actionType = isMenuItemSelected(__originalIndex)
|
|
206
206
|
? 'removed'
|
|
@@ -218,7 +218,10 @@ export const ComboBox = React.forwardRef((props, forwardedRef) => {
|
|
|
218
218
|
.filter(Boolean)
|
|
219
219
|
.join(', '),
|
|
220
220
|
);
|
|
221
|
-
|
|
221
|
+
if (clearFilterOnOptionToggle) {
|
|
222
|
+
setInputValue('');
|
|
223
|
+
setIsInputDirty(false);
|
|
224
|
+
}
|
|
222
225
|
} else {
|
|
223
226
|
setSelectedIndexes(__originalIndex);
|
|
224
227
|
hide();
|
|
@@ -226,13 +229,14 @@ export const ComboBox = React.forwardRef((props, forwardedRef) => {
|
|
|
226
229
|
}
|
|
227
230
|
},
|
|
228
231
|
[
|
|
229
|
-
|
|
230
|
-
isMenuItemSelected,
|
|
232
|
+
optionsRef,
|
|
231
233
|
multiple,
|
|
234
|
+
isMenuItemSelected,
|
|
235
|
+
selectedChangeHandler,
|
|
236
|
+
setSelectedIndexes,
|
|
232
237
|
onChangeHandler,
|
|
233
|
-
|
|
238
|
+
clearFilterOnOptionToggle,
|
|
234
239
|
hide,
|
|
235
|
-
setSelectedIndexes,
|
|
236
240
|
],
|
|
237
241
|
);
|
|
238
242
|
let getMenuItem = React.useCallback(
|
|
@@ -29,8 +29,8 @@ export type DateRangePickerProps = {
|
|
|
29
29
|
onChange?: (date: Date) => void;
|
|
30
30
|
} | {
|
|
31
31
|
enableRangeSelect: true;
|
|
32
|
-
startDate
|
|
33
|
-
endDate
|
|
32
|
+
startDate?: Date;
|
|
33
|
+
endDate?: Date;
|
|
34
34
|
onChange?: (startDate: Date, endDate: Date) => void;
|
|
35
35
|
};
|
|
36
36
|
type DatePickerProps = {
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
isBefore,
|
|
9
9
|
Box,
|
|
10
10
|
useId,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useWarningLogger,
|
|
11
13
|
} from '../../utils/index.js';
|
|
12
14
|
import { IconButton } from '../Buttons/IconButton.js';
|
|
13
15
|
import { TimePicker } from '../TimePicker/TimePicker.js';
|
|
@@ -135,6 +137,7 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
|
|
|
135
137
|
showDatesOutsideMonth = true,
|
|
136
138
|
...rest
|
|
137
139
|
} = props;
|
|
140
|
+
let logWarning = useWarningLogger();
|
|
138
141
|
let monthNames = localizedNames?.months ?? defaultMonths;
|
|
139
142
|
let shortDays = localizedNames?.shortDays ?? defaultShortDays;
|
|
140
143
|
let longDays = localizedNames?.days ?? defaultLongDays;
|
|
@@ -177,7 +180,7 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
|
|
|
177
180
|
);
|
|
178
181
|
}, [date, setMonthAndYear, startDate, endDate, enableRangeSelect]);
|
|
179
182
|
let popoverInitialFocusContext = React.useContext(PopoverInitialFocusContext);
|
|
180
|
-
|
|
183
|
+
useLayoutEffect(() => {
|
|
181
184
|
if (setFocus && popoverInitialFocusContext)
|
|
182
185
|
popoverInitialFocusContext.setInitialFocus(-1);
|
|
183
186
|
}, [popoverInitialFocusContext, setFocus]);
|
|
@@ -11,7 +11,7 @@ import { Transition } from 'react-transition-group';
|
|
|
11
11
|
let DialogComponent = React.forwardRef((props, ref) => {
|
|
12
12
|
let {
|
|
13
13
|
trapFocus = false,
|
|
14
|
-
setFocus =
|
|
14
|
+
setFocus = trapFocus,
|
|
15
15
|
preventDocumentScroll = false,
|
|
16
16
|
isOpen = false,
|
|
17
17
|
isDismissible = true,
|