@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.
Files changed (135) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/DEV-cjs/core/Breadcrumbs/Breadcrumbs.js +2 -2
  3. package/DEV-cjs/core/Checkbox/Checkbox.js +4 -6
  4. package/DEV-cjs/core/ComboBox/ComboBox.js +10 -6
  5. package/DEV-cjs/core/DatePicker/DatePicker.js +9 -1
  6. package/DEV-cjs/core/Dialog/Dialog.js +1 -1
  7. package/DEV-cjs/core/Panels/Panels.js +319 -0
  8. package/DEV-cjs/core/Panels/helpers.js +62 -0
  9. package/DEV-cjs/core/Radio/Radio.js +4 -6
  10. package/DEV-cjs/core/RadioTiles/RadioTileGroup.js +9 -2
  11. package/DEV-cjs/core/Select/SelectTag.js +9 -11
  12. package/DEV-cjs/core/Select/SelectTagContainer.js +2 -2
  13. package/DEV-cjs/core/Stepper/Stepper.js +1 -0
  14. package/DEV-cjs/core/Stepper/StepperStep.js +2 -1
  15. package/DEV-cjs/core/Table/Table.js +3 -4
  16. package/DEV-cjs/core/Table/TablePaginator.js +15 -3
  17. package/DEV-cjs/core/Table/actionHandlers/selectHandler.js +10 -7
  18. package/DEV-cjs/core/Table/columns/selectionColumn.js +6 -1
  19. package/DEV-cjs/core/Tree/Tree.js +1 -0
  20. package/DEV-cjs/index.js +4 -0
  21. package/DEV-cjs/styles.js +1 -1
  22. package/DEV-cjs/utils/components/MiddleTextTruncation.js +22 -4
  23. package/DEV-cjs/utils/components/OverflowContainer.js +170 -27
  24. package/DEV-cjs/utils/hooks/index.js +1 -1
  25. package/DEV-cjs/utils/hooks/useInstance.js +38 -0
  26. package/DEV-esm/core/Breadcrumbs/Breadcrumbs.js +2 -2
  27. package/DEV-esm/core/Checkbox/Checkbox.js +5 -10
  28. package/DEV-esm/core/ComboBox/ComboBox.js +10 -6
  29. package/DEV-esm/core/DatePicker/DatePicker.js +11 -1
  30. package/DEV-esm/core/Dialog/Dialog.js +1 -1
  31. package/DEV-esm/core/Panels/Panels.js +301 -0
  32. package/DEV-esm/core/Panels/helpers.js +42 -0
  33. package/DEV-esm/core/Radio/Radio.js +4 -9
  34. package/DEV-esm/core/RadioTiles/RadioTileGroup.js +8 -2
  35. package/DEV-esm/core/Select/SelectTag.js +9 -11
  36. package/DEV-esm/core/Select/SelectTagContainer.js +2 -2
  37. package/DEV-esm/core/Stepper/Stepper.js +1 -0
  38. package/DEV-esm/core/Stepper/StepperStep.js +2 -1
  39. package/DEV-esm/core/Table/Table.js +1 -5
  40. package/DEV-esm/core/Table/TablePaginator.js +16 -3
  41. package/DEV-esm/core/Table/actionHandlers/selectHandler.js +10 -7
  42. package/DEV-esm/core/Table/columns/selectionColumn.js +6 -1
  43. package/DEV-esm/core/Tree/Tree.js +1 -0
  44. package/DEV-esm/index.js +1 -0
  45. package/DEV-esm/styles.js +1 -1
  46. package/DEV-esm/utils/components/MiddleTextTruncation.js +22 -4
  47. package/DEV-esm/utils/components/OverflowContainer.js +143 -4
  48. package/DEV-esm/utils/hooks/index.js +1 -1
  49. package/DEV-esm/utils/hooks/useInstance.js +18 -0
  50. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -2
  51. package/cjs/core/Checkbox/Checkbox.js +4 -6
  52. package/cjs/core/ComboBox/ComboBox.d.ts +13 -0
  53. package/cjs/core/ComboBox/ComboBox.js +10 -6
  54. package/cjs/core/DatePicker/DatePicker.d.ts +2 -2
  55. package/cjs/core/DatePicker/DatePicker.js +2 -1
  56. package/cjs/core/Dialog/Dialog.js +1 -1
  57. package/cjs/core/Dialog/DialogContext.d.ts +6 -2
  58. package/cjs/core/Panels/Panels.d.ts +174 -0
  59. package/cjs/core/Panels/Panels.js +312 -0
  60. package/cjs/core/Panels/helpers.d.ts +23 -0
  61. package/cjs/core/Panels/helpers.js +61 -0
  62. package/cjs/core/Radio/Radio.js +4 -6
  63. package/cjs/core/RadioTiles/RadioTileGroup.d.ts +3 -1
  64. package/cjs/core/RadioTiles/RadioTileGroup.js +9 -2
  65. package/cjs/core/Select/SelectTag.d.ts +3 -1
  66. package/cjs/core/Select/SelectTag.js +9 -11
  67. package/cjs/core/Select/SelectTagContainer.js +2 -2
  68. package/cjs/core/Stepper/Stepper.d.ts +4 -0
  69. package/cjs/core/Stepper/Stepper.js +1 -0
  70. package/cjs/core/Stepper/StepperStep.d.ts +4 -0
  71. package/cjs/core/Stepper/StepperStep.js +2 -1
  72. package/cjs/core/Table/Table.d.ts +1 -0
  73. package/cjs/core/Table/Table.js +3 -4
  74. package/cjs/core/Table/TablePaginator.js +15 -3
  75. package/cjs/core/Table/actionHandlers/selectHandler.js +10 -7
  76. package/cjs/core/Table/columns/selectionColumn.js +6 -1
  77. package/cjs/core/Tree/Tree.js +1 -0
  78. package/cjs/index.d.ts +1 -0
  79. package/cjs/index.js +4 -0
  80. package/cjs/styles.js +1 -1
  81. package/cjs/utils/components/MiddleTextTruncation.d.ts +5 -7
  82. package/cjs/utils/components/MiddleTextTruncation.js +22 -4
  83. package/cjs/utils/components/OverflowContainer.d.ts +1 -0
  84. package/cjs/utils/components/OverflowContainer.js +170 -27
  85. package/cjs/utils/hooks/index.d.ts +1 -1
  86. package/cjs/utils/hooks/index.js +1 -1
  87. package/cjs/utils/hooks/useInstance.d.ts +22 -0
  88. package/cjs/utils/hooks/useInstance.js +38 -0
  89. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -2
  90. package/esm/core/Checkbox/Checkbox.js +5 -10
  91. package/esm/core/ComboBox/ComboBox.d.ts +13 -0
  92. package/esm/core/ComboBox/ComboBox.js +10 -6
  93. package/esm/core/DatePicker/DatePicker.d.ts +2 -2
  94. package/esm/core/DatePicker/DatePicker.js +4 -1
  95. package/esm/core/Dialog/Dialog.js +1 -1
  96. package/esm/core/Dialog/DialogContext.d.ts +6 -2
  97. package/esm/core/Panels/Panels.d.ts +174 -0
  98. package/esm/core/Panels/Panels.js +294 -0
  99. package/esm/core/Panels/helpers.d.ts +23 -0
  100. package/esm/core/Panels/helpers.js +41 -0
  101. package/esm/core/Radio/Radio.js +4 -9
  102. package/esm/core/RadioTiles/RadioTileGroup.d.ts +3 -1
  103. package/esm/core/RadioTiles/RadioTileGroup.js +8 -2
  104. package/esm/core/Select/SelectTag.d.ts +3 -1
  105. package/esm/core/Select/SelectTag.js +9 -11
  106. package/esm/core/Select/SelectTagContainer.js +2 -2
  107. package/esm/core/Stepper/Stepper.d.ts +4 -0
  108. package/esm/core/Stepper/Stepper.js +1 -0
  109. package/esm/core/Stepper/StepperStep.d.ts +4 -0
  110. package/esm/core/Stepper/StepperStep.js +2 -1
  111. package/esm/core/Table/Table.d.ts +1 -0
  112. package/esm/core/Table/Table.js +1 -5
  113. package/esm/core/Table/TablePaginator.js +16 -3
  114. package/esm/core/Table/actionHandlers/selectHandler.js +10 -7
  115. package/esm/core/Table/columns/selectionColumn.js +6 -1
  116. package/esm/core/Tree/Tree.js +1 -0
  117. package/esm/index.d.ts +1 -0
  118. package/esm/index.js +1 -0
  119. package/esm/styles.js +1 -1
  120. package/esm/utils/components/MiddleTextTruncation.d.ts +5 -7
  121. package/esm/utils/components/MiddleTextTruncation.js +22 -4
  122. package/esm/utils/components/OverflowContainer.d.ts +1 -0
  123. package/esm/utils/components/OverflowContainer.js +143 -4
  124. package/esm/utils/hooks/index.d.ts +1 -1
  125. package/esm/utils/hooks/index.js +1 -1
  126. package/esm/utils/hooks/useInstance.d.ts +22 -0
  127. package/esm/utils/hooks/useInstance.js +18 -0
  128. package/package.json +2 -2
  129. package/styles.css +8 -8
  130. package/DEV-cjs/utils/hooks/useOverflow.js +0 -76
  131. package/DEV-esm/utils/hooks/useOverflow.js +0 -63
  132. package/cjs/utils/hooks/useOverflow.d.ts +0 -23
  133. package/cjs/utils/hooks/useOverflow.js +0 -76
  134. package/esm/utils/hooks/useOverflow.d.ts +0 -23
  135. package/esm/utils/hooks/useOverflow.js +0 -63
@@ -1,13 +1,14 @@
1
1
  import React from 'react';
2
2
  import { useMergedRefs } from '../hooks/useMergedRefs.js';
3
3
  import { Box } from './Box.js';
4
- import { useOverflow } from '../hooks/useOverflow.js';
4
+ import { useLayoutEffect } from '../hooks/useIsomorphicLayoutEffect.js';
5
5
  import { useSafeContext } from '../hooks/useSafeContext.js';
6
- let OverflowContainerComponent = React.forwardRef((props, ref) => {
6
+ import { isUnitTest } from '../functions/dev.js';
7
+ import { useResizeObserver } from '../hooks/useResizeObserver.js';
8
+ let OverflowContainerMain = React.forwardRef((props, forwardedRef) => {
7
9
  let { itemsCount, children, overflowOrientation, ...rest } = props;
8
10
  let [containerRef, visibleCount] = useOverflow(
9
11
  itemsCount,
10
- false,
11
12
  overflowOrientation,
12
13
  );
13
14
  let overflowContainerContextValue = React.useMemo(
@@ -25,7 +26,7 @@ let OverflowContainerComponent = React.forwardRef((props, ref) => {
25
26
  React.createElement(
26
27
  Box,
27
28
  {
28
- ref: useMergedRefs(ref, containerRef),
29
+ ref: useMergedRefs(forwardedRef, containerRef),
29
30
  ...rest,
30
31
  },
31
32
  children,
@@ -38,12 +39,150 @@ let OverflowContainerOverflowNode = (props) => {
38
39
  let isOverflowing = visibleCount < itemsCount;
39
40
  return isOverflowing ? children : null;
40
41
  };
42
+ let OverflowContainerComponent = React.forwardRef((props, forwardedRef) => {
43
+ let { itemsCount, overflowOrientation = 'horizontal', ...rest } = props;
44
+ let [size, setSize] = React.useState(null);
45
+ let [resizeRef] = useResizeObserver(setSize);
46
+ let ref = useMergedRefs(resizeRef, forwardedRef);
47
+ let key = `${itemsCount}${
48
+ 'vertical' === overflowOrientation ? size?.height : size?.width
49
+ }`;
50
+ return React.createElement(OverflowContainerMain, {
51
+ ...rest,
52
+ key: key,
53
+ ref: ref,
54
+ itemsCount: itemsCount,
55
+ overflowOrientation: overflowOrientation,
56
+ });
57
+ });
41
58
  export const OverflowContainer = Object.assign(OverflowContainerComponent, {
42
59
  OverflowNode: OverflowContainerOverflowNode,
43
60
  useContext: useOverflowContainerContext,
44
61
  });
45
62
  let OverflowContainerContext = React.createContext(void 0);
46
63
  OverflowContainerContext.displayName = 'OverflowContainerContext';
64
+ let useOverflow = (itemsCount, orientation = 'horizontal') => {
65
+ let [guessState, dispatch] = React.useReducer(
66
+ overflowGuessReducer,
67
+ {
68
+ itemsCount,
69
+ },
70
+ overflowGuessReducerInitialState,
71
+ );
72
+ let containerRef = React.useRef(null);
73
+ let isGuessing = React.useRef(false);
74
+ useLayoutEffect(() => {
75
+ let { minGuess, maxGuess, isStabilized, visibleCount } = guessState;
76
+ if (isStabilized) return;
77
+ guessVisibleCount();
78
+ function guessVisibleCount() {
79
+ if (isStabilized || isGuessing.current || isUnitTest) return;
80
+ try {
81
+ isGuessing.current = true;
82
+ if (null == containerRef.current) return;
83
+ let dimension = 'horizontal' === orientation ? 'Width' : 'Height';
84
+ let availableSize = containerRef.current[`offset${dimension}`];
85
+ let requiredSize = containerRef.current[`scroll${dimension}`];
86
+ let isOverflowing = availableSize < requiredSize;
87
+ if (
88
+ 0 === itemsCount ||
89
+ (1 === visibleCount && isOverflowing) ||
90
+ (visibleCount === itemsCount && !isOverflowing) ||
91
+ (maxGuess - minGuess === 1 && visibleCount === minGuess)
92
+ ) {
93
+ dispatch({
94
+ type: 'stabilize',
95
+ });
96
+ return;
97
+ }
98
+ if (maxGuess === visibleCount && !isOverflowing) {
99
+ dispatch({
100
+ type: 'shiftGuessRangeForward',
101
+ });
102
+ return;
103
+ }
104
+ isOverflowing
105
+ ? dispatch({
106
+ type: 'decreaseMaxGuess',
107
+ currentState: guessState,
108
+ })
109
+ : dispatch({
110
+ type: 'increaseMinGuess',
111
+ currentState: guessState,
112
+ });
113
+ } finally {
114
+ isGuessing.current = false;
115
+ }
116
+ }
117
+ }, [guessState, itemsCount, orientation]);
118
+ return [containerRef, guessState.visibleCount];
119
+ };
120
+ let STARTING_MAX_ITEMS_COUNT = 32;
121
+ let overflowGuessReducerInitialState = ({ itemsCount }) => {
122
+ let initialVisibleCount = Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT);
123
+ return isUnitTest
124
+ ? {
125
+ isStabilized: true,
126
+ minGuess: null,
127
+ maxGuess: null,
128
+ itemsCount,
129
+ visibleCount: itemsCount,
130
+ }
131
+ : {
132
+ isStabilized: false,
133
+ minGuess: 0,
134
+ maxGuess: initialVisibleCount,
135
+ itemsCount,
136
+ visibleCount: initialVisibleCount,
137
+ };
138
+ };
139
+ let overflowGuessReducer = (state, action) => {
140
+ let getSafeVisibleCount = ({ visibleCount, itemsCount }) =>
141
+ Math.min(itemsCount, visibleCount);
142
+ switch (action.type) {
143
+ case 'decreaseMaxGuess':
144
+ case 'increaseMinGuess':
145
+ if (state.isStabilized) return state;
146
+ let newMinGuess = state.minGuess;
147
+ let newMaxGuess = state.maxGuess;
148
+ if ('decreaseMaxGuess' === action.type)
149
+ newMaxGuess = action.currentState.visibleCount;
150
+ else newMinGuess = action.currentState.visibleCount;
151
+ let newVisibleCount = Math.floor((newMinGuess + newMaxGuess) / 2);
152
+ return {
153
+ ...state,
154
+ isStabilized: false,
155
+ minGuess: newMinGuess,
156
+ maxGuess: newMaxGuess,
157
+ visibleCount: getSafeVisibleCount({
158
+ visibleCount: newVisibleCount,
159
+ itemsCount: state.itemsCount,
160
+ }),
161
+ };
162
+ case 'shiftGuessRangeForward':
163
+ if (state.isStabilized) return state;
164
+ let doubleOfMaxGuess = 2 * state.maxGuess;
165
+ return {
166
+ ...state,
167
+ isStabilized: false,
168
+ minGuess: state.maxGuess,
169
+ maxGuess: doubleOfMaxGuess,
170
+ visibleCount: getSafeVisibleCount({
171
+ visibleCount: doubleOfMaxGuess,
172
+ itemsCount: state.itemsCount,
173
+ }),
174
+ };
175
+ case 'stabilize':
176
+ return {
177
+ ...state,
178
+ isStabilized: true,
179
+ minGuess: null,
180
+ maxGuess: null,
181
+ };
182
+ default:
183
+ return state;
184
+ }
185
+ };
47
186
  function useOverflowContainerContext() {
48
187
  let overflowContainerContext = useSafeContext(OverflowContainerContext);
49
188
  return 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';
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { useSyncExternalStore } from './useSyncExternalStore.js';
3
+ class Instance {}
4
+ export const useInstance = () => React.useMemo(() => new Instance(), []);
5
+ export const useSynchronizeInstance = (instance, properties) => {
6
+ let synchronize = React.useCallback(() => {
7
+ if (!(instance instanceof Instance)) return () => {};
8
+ Object.assign(instance, properties);
9
+ return () => {
10
+ for (let key in properties) delete instance[key];
11
+ };
12
+ }, [instance, properties]);
13
+ return useSyncExternalStore(
14
+ synchronize,
15
+ () => instance,
16
+ () => instance,
17
+ );
18
+ };
@@ -15,7 +15,7 @@ const _classnames = _interop_require_default._(require('classnames'));
15
15
  const _index = require('../../utils/index.js');
16
16
  const _Button = require('../Buttons/Button.js');
17
17
  const _Anchor = require('../Typography/Anchor.js');
18
- const BreadcrumbsComponent = _react.forwardRef((props, ref) => {
18
+ const BreadcrumbsComponent = _react.forwardRef((props, forwardedRef) => {
19
19
  let {
20
20
  children: childrenProp,
21
21
  currentIndex = _react.Children.count(childrenProp) - 1,
@@ -33,7 +33,7 @@ const BreadcrumbsComponent = _react.forwardRef((props, ref) => {
33
33
  {
34
34
  as: 'nav',
35
35
  className: (0, _classnames.default)('iui-breadcrumbs', className),
36
- ref: ref,
36
+ ref: forwardedRef,
37
37
  'aria-label': 'Breadcrumb',
38
38
  ...rest,
39
39
  },
@@ -46,11 +46,11 @@ const Checkbox = _react.forwardRef((props, ref) => {
46
46
  'iui-checkbox',
47
47
  {
48
48
  'iui-checkbox-visibility': 'eyeball' === variant,
49
- 'iui-loading': isLoading,
50
49
  },
51
50
  className,
52
51
  ),
53
52
  style: style,
53
+ 'data-iui-loading': isLoading ? 'true' : void 0,
54
54
  disabled: disabled || isLoading,
55
55
  type: 'checkbox',
56
56
  ref: refs,
@@ -71,13 +71,11 @@ const Checkbox = _react.forwardRef((props, ref) => {
71
71
  as: 'label',
72
72
  className: (0, _classnames.default)(
73
73
  'iui-checkbox-wrapper',
74
- {
75
- 'iui-disabled': disabled,
76
- [`iui-${status}`]: !!status,
77
- 'iui-loading': isLoading,
78
- },
79
74
  wrapperClassName,
80
75
  ),
76
+ 'data-iui-disabled': disabled ? 'true' : void 0,
77
+ 'data-iui-status': status,
78
+ 'data-iui-loading': isLoading ? 'true' : void 0,
81
79
  ...restWrapperProps,
82
80
  },
83
81
  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
  /**
@@ -51,6 +51,7 @@ const ComboBox = _react.forwardRef((props, forwardedRef) => {
51
51
  onHide: onHideProp,
52
52
  id = inputProps?.id ? `iui-${inputProps.id}-cb` : idPrefix,
53
53
  defaultValue,
54
+ clearFilterOnOptionToggle = true,
54
55
  ...rest
55
56
  } = props;
56
57
  let inputRef = _react.useRef(null);
@@ -204,7 +205,6 @@ const ComboBox = _react.forwardRef((props, forwardedRef) => {
204
205
  preventScroll: true,
205
206
  });
206
207
  if (optionsRef.current[__originalIndex]?.disabled) return;
207
- setIsInputDirty(false);
208
208
  if (multiple) {
209
209
  let actionType = isMenuItemSelected(__originalIndex)
210
210
  ? 'removed'
@@ -222,7 +222,10 @@ const ComboBox = _react.forwardRef((props, forwardedRef) => {
222
222
  .filter(Boolean)
223
223
  .join(', '),
224
224
  );
225
- setInputValue('');
225
+ if (clearFilterOnOptionToggle) {
226
+ setInputValue('');
227
+ setIsInputDirty(false);
228
+ }
226
229
  } else {
227
230
  setSelectedIndexes(__originalIndex);
228
231
  hide();
@@ -230,13 +233,14 @@ const ComboBox = _react.forwardRef((props, forwardedRef) => {
230
233
  }
231
234
  },
232
235
  [
233
- selectedChangeHandler,
234
- isMenuItemSelected,
236
+ optionsRef,
235
237
  multiple,
238
+ isMenuItemSelected,
239
+ selectedChangeHandler,
240
+ setSelectedIndexes,
236
241
  onChangeHandler,
237
- optionsRef,
242
+ clearFilterOnOptionToggle,
238
243
  hide,
239
- setSelectedIndexes,
240
244
  ],
241
245
  );
242
246
  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: Date;
33
- endDate: Date;
32
+ startDate?: Date;
33
+ endDate?: Date;
34
34
  onChange?: (startDate: Date, endDate: Date) => void;
35
35
  };
36
36
  type DatePickerProps = {
@@ -148,6 +148,7 @@ const DatePicker = _react.forwardRef((props, forwardedRef) => {
148
148
  showDatesOutsideMonth = true,
149
149
  ...rest
150
150
  } = props;
151
+ let logWarning = (0, _index.useWarningLogger)();
151
152
  let monthNames = localizedNames?.months ?? defaultMonths;
152
153
  let shortDays = localizedNames?.shortDays ?? defaultShortDays;
153
154
  let longDays = localizedNames?.days ?? defaultLongDays;
@@ -192,7 +193,7 @@ const DatePicker = _react.forwardRef((props, forwardedRef) => {
192
193
  let popoverInitialFocusContext = _react.useContext(
193
194
  _Popover.PopoverInitialFocusContext,
194
195
  );
195
- _react.useLayoutEffect(() => {
196
+ (0, _index.useLayoutEffect)(() => {
196
197
  if (setFocus && popoverInitialFocusContext)
197
198
  popoverInitialFocusContext.setInitialFocus(-1);
198
199
  }, [popoverInitialFocusContext, setFocus]);
@@ -23,7 +23,7 @@ const _reacttransitiongroup = require('react-transition-group');
23
23
  const DialogComponent = _react.forwardRef((props, ref) => {
24
24
  let {
25
25
  trapFocus = false,
26
- setFocus = false,
26
+ setFocus = trapFocus,
27
27
  preventDocumentScroll = false,
28
28
  isOpen = false,
29
29
  isDismissible = true,
@@ -30,13 +30,17 @@ export type DialogContextProps = {
30
30
  */
31
31
  closeOnEsc?: boolean;
32
32
  /**
33
- * Traps the focus inside the dialog. This is useful when the dialog is modal.
33
+ * Prevents focus from leaving the dialog. This is useful when the dialog is modal.
34
+ *
35
+ * Setting this prop to `true` will also set `setFocus` to `true`.
36
+ *
34
37
  * @default false
35
38
  */
36
39
  trapFocus?: boolean;
37
40
  /**
38
41
  * If true, focuses the dialog.
39
- * @default false
42
+ *
43
+ * Defaults to `true` if `trapFocus` is set to `true`, otherwise defaults to `false`.
40
44
  */
41
45
  setFocus?: boolean;
42
46
  /**
@@ -0,0 +1,174 @@
1
+ import * as React from 'react';
2
+ import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
3
+ import { Text } from '../Typography/Text.js';
4
+ import type { FocusEntry, PanelsInstance, TriggerMapEntry } from './helpers.js';
5
+ type PanelsWrapperProps = {
6
+ /**
7
+ * Function that gets called when the active panel is changed.
8
+ */
9
+ onActiveIdChange?: (newActiveId: string) => void;
10
+ children: React.ReactNode;
11
+ /**
12
+ * Pass an instance created by `useInstance` to control the panels imperatively.
13
+ *
14
+ * @example
15
+ * const panels = Panels.useInstance();
16
+ * <Panels instance={panels} />
17
+ */
18
+ instance?: PanelsInstance;
19
+ };
20
+ export declare const PanelsWrapper: PolymorphicForwardRefComponent<"div", PanelsWrapperProps>;
21
+ export declare const PanelsWrapperContext: React.Context<{
22
+ activePanelId: string | undefined;
23
+ setActivePanelId: React.Dispatch<React.SetStateAction<string>>;
24
+ /**
25
+ * Simpler alternative to a full history stack.
26
+ *
27
+ * ```
28
+ * Record<
29
+ * string, // Id of a panel
30
+ * {
31
+ * triggerId: string, // Id of the trigger element that points to this panel
32
+ * panelId: string, // Id of the panel element in which the trigger is present
33
+ * }
34
+ * >
35
+ * ```
36
+ */
37
+ triggers: Record<string, TriggerMapEntry>;
38
+ setTriggers: React.Dispatch<React.SetStateAction<Record<string, TriggerMapEntry>>>;
39
+ changeActivePanel: (newActiveId: string) => void;
40
+ shouldFocus: FocusEntry;
41
+ setShouldFocus: React.Dispatch<React.SetStateAction<FocusEntry>>;
42
+ panels: React.MutableRefObject<Set<string>>;
43
+ } | undefined>;
44
+ type PanelProps = {
45
+ id: string;
46
+ };
47
+ type PanelTriggerProps = {
48
+ for: string;
49
+ children: React.ReactElement;
50
+ };
51
+ type PanelHeaderProps = {
52
+ titleProps?: React.ComponentProps<typeof Text>;
53
+ };
54
+ export declare const Panels: {
55
+ /**
56
+ * Component that manages the logic for layered panels.
57
+ * It can be used anywhere to create layers. E.g. `Menu`, `InformationPanel`, `Popover`, etc.
58
+ *
59
+ * Requirements:
60
+ * - The initial displayed Panel should be the first `Panel` in the `Panels.Wrapper`.
61
+ * - A panel can have only one trigger pointing to it. i.e. out of all the triggers across all panels,
62
+ * only one can point to a particular panel.
63
+ * - The `Panels.Panel`s within the wrapper should be in the order of the navigation. E.g.:
64
+ * ```jsx
65
+ * <Panels.Wrapper>
66
+ * <Panels.Panel id={root} /> // Must come before moreDetails since it contains the trigger to moreDetails
67
+ * <Panels.Panel id={moreDetails}> // Must come after root since it is navigated to from root
68
+ * </Panels.Wrapper>
69
+ * ```
70
+ *
71
+ * @example
72
+ * <Panels.Wrapper as={Surface}>
73
+ * <Panels.Panel
74
+ * id={panelIdRoot}
75
+ * as={Surface}
76
+ * border={false}
77
+ * elevation={0}
78
+ * >
79
+ * <Surface.Header as={Panels.Header}>Root</Surface.Header>
80
+ * <Surface.Body as={List}>
81
+ * <ListItem>
82
+ * <Panels.Trigger for={panelIdMoreInfo}>
83
+ * <ListItem.Action>More details</ListItem.Action>
84
+ * </Panels.Trigger>
85
+ * </ListItem>
86
+ * </Surface.Body>
87
+ * </Panels.Panel>
88
+ *
89
+ * <Panels.Panel
90
+ * id={panelIdMoreInfo}
91
+ * as={Surface}
92
+ * border={false}
93
+ * elevation={0}
94
+ * >
95
+ * <Surface.Header as={Panels.Header}>More details</Surface.Header>
96
+ * <Surface.Body isPadded>
97
+ * <Text>Content</Text>
98
+ * </Surface.Body>
99
+ * </Panels.Panel>
100
+ * </Panels.Wrapper>
101
+ */
102
+ Wrapper: PolymorphicForwardRefComponent<"div", PanelsWrapperProps>;
103
+ /**
104
+ * Takes an `id` and the panel content.
105
+ * Match this `id` with a `Panels.Triggers`'s `for` prop to create a link between them.
106
+ *
107
+ * @example
108
+ * <Panels.Panel id={panelIdRoot} as={Surface} border={false} elevation={0}>
109
+ * <Surface.Header as={Panels.Header}>Root</Surface.Header>
110
+ * <Surface.Body as={List}>
111
+ * <ListItem>
112
+ * <Panels.Trigger for={panelIdMoreInfo}>
113
+ * <ListItem.Action>More details</ListItem.Action>
114
+ * </Panels.Trigger>
115
+ * </ListItem>
116
+ * </Surface.Body>
117
+ * </Panels.Panel>
118
+ */
119
+ Panel: PolymorphicForwardRefComponent<"div", PanelProps>;
120
+ /**
121
+ * Wraps the clickable element and appends an `onClick` to change the active panel to the one specified in the `for`
122
+ * prop. Also appends some attributes for accessibility.
123
+ *
124
+ * @example
125
+ * <Panels.Trigger for={nextPanelId}>
126
+ * <Button>go to next panel</Button>
127
+ * </Panels.Trigger>
128
+ *
129
+ * @example
130
+ * <ListItem>
131
+ * <Panels.Trigger for={panelIdMoreInfo}>
132
+ * <ListItem.Action>More details</ListItem.Action>
133
+ * </Panels.Trigger>
134
+ * </ListItem>
135
+ */
136
+ Trigger: {
137
+ (props: PanelTriggerProps): string | number | true | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null;
138
+ displayName: string;
139
+ };
140
+ /**
141
+ * Required component to add an accessible name and also a back button (if previous panel exists) to the panel.
142
+ *
143
+ * @example
144
+ * <Panels.Panel id={panelIdRoot}>
145
+ * <Panels.Header>Root</Panels.Header>
146
+ * …
147
+ * </Panels.Panel>
148
+ *
149
+ * @example
150
+ * <Panels.Panel
151
+ * id={panelIdMoreInfo}
152
+ * as={Surface}
153
+ * border={false}
154
+ * elevation={0}
155
+ * >
156
+ * <Surface.Header as={Panels.Header}>More details</Surface.Header>
157
+ * <Surface.Body isPadded>
158
+ * <Text>Content</Text>
159
+ * </Surface.Body>
160
+ * </Panels.Panel>
161
+ */
162
+ Header: PolymorphicForwardRefComponent<"div", PanelHeaderProps>;
163
+ /**
164
+ * You can use methods from `Panels.useInstance()` to control the state programmatically.
165
+ *
166
+ * @example
167
+ * const panels = Panels.useInstance();
168
+ *
169
+ * <Button onClick={() => panels.goBack()}>Go back</Button>
170
+ * <Panels.Wrapper instance={panels}>{…}</Panels.Wrapper>;
171
+ */
172
+ useInstance: () => PanelsInstance;
173
+ };
174
+ export {};