@carbon/react 1.84.0-rc.0 → 1.85.0-rc.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/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +943 -943
- package/es/components/AILabel/index.js +6 -1
- package/es/components/Checkbox/Checkbox.d.ts +2 -2
- package/es/components/Checkbox/Checkbox.js +8 -8
- package/es/components/CheckboxGroup/CheckboxGroup.d.ts +2 -2
- package/es/components/CheckboxGroup/CheckboxGroup.js +9 -8
- package/es/components/CodeSnippet/CodeSnippet.js +2 -4
- package/es/components/ComboBox/ComboBox.d.ts +1 -1
- package/es/components/ComboBox/ComboBox.js +8 -7
- package/es/components/ComposedModal/ComposedModal.d.ts +1 -1
- package/es/components/ComposedModal/ComposedModal.js +34 -12
- package/es/components/ContainedList/ContainedList.d.ts +1 -1
- package/es/components/ContainedList/ContainedList.js +4 -2
- package/es/components/ContentSwitcher/ContentSwitcher.js +6 -5
- package/es/components/DataTable/DataTable.js +3 -0
- package/es/components/DataTable/TableDecoratorRow.d.ts +2 -2
- package/es/components/DataTable/TableDecoratorRow.js +8 -8
- package/es/components/DataTable/TableExpandRow.d.ts +1 -1
- package/es/components/DataTable/TableExpandRow.js +15 -6
- package/es/components/DataTable/TableHeader.js +10 -10
- package/es/components/DataTable/TableRow.js +12 -4
- package/es/components/DataTable/tools/normalize.js +2 -1
- package/es/components/DatePickerInput/DatePickerInput.js +8 -7
- package/es/components/Dialog/index.d.ts +5 -1
- package/es/components/Dialog/index.js +20 -0
- package/es/components/Dropdown/Dropdown.d.ts +1 -1
- package/es/components/Dropdown/Dropdown.js +8 -10
- package/es/components/FileUploader/FileUploaderButton.js +2 -2
- package/es/components/FileUploader/FileUploaderDropContainer.js +2 -2
- package/es/components/FileUploader/FileUploaderItem.js +2 -2
- package/es/components/Layer/index.d.ts +1 -3
- package/es/components/Layer/index.js +9 -8
- package/es/components/Menu/Menu.js +0 -6
- package/es/components/Modal/Modal.d.ts +2 -2
- package/es/components/Modal/Modal.js +39 -11
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
- package/es/components/MultiSelect/FilterableMultiSelect.js +29 -7
- package/es/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/es/components/MultiSelect/MultiSelect.js +8 -7
- package/es/components/NumberInput/NumberInput.d.ts +1 -1
- package/es/components/NumberInput/NumberInput.js +9 -8
- package/es/components/OverflowMenu/OverflowMenu.js +4 -5
- package/es/components/PageHeader/PageHeader.d.ts +10 -9
- package/es/components/PageHeader/PageHeader.js +94 -34
- package/es/components/PageHeader/index.d.ts +2 -2
- package/es/components/PageHeader/index.js +1 -1
- package/es/components/Popover/index.js +2 -1
- package/es/components/RadioButton/RadioButton.d.ts +2 -2
- package/es/components/RadioButton/RadioButton.js +8 -8
- package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +2 -2
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +9 -8
- package/es/components/RadioTile/RadioTile.d.ts +1 -1
- package/es/components/RadioTile/RadioTile.js +8 -7
- package/es/components/Search/Search.js +0 -1
- package/es/components/Select/Select.d.ts +2 -2
- package/es/components/Select/Select.js +8 -7
- package/es/components/Slider/Slider.js +6 -0
- package/es/components/Tag/DismissibleTag.d.ts +1 -1
- package/es/components/Tag/DismissibleTag.js +9 -8
- package/es/components/Tag/Tag.d.ts +1 -1
- package/es/components/Tag/Tag.js +9 -8
- package/es/components/TextArea/TextArea.js +12 -11
- package/es/components/TextInput/TextInput.d.ts +1 -1
- package/es/components/TextInput/TextInput.js +20 -9
- package/es/components/Tile/Tile.d.ts +2 -2
- package/es/components/Tile/Tile.js +30 -36
- package/es/components/TileGroup/TileGroup.d.ts +4 -4
- package/es/components/TileGroup/TileGroup.js +45 -53
- package/es/components/TileGroup/index.d.ts +3 -3
- package/es/components/Toggletip/index.js +2 -2
- package/es/components/Tooltip/DefinitionTooltip.js +1 -0
- package/es/components/TreeView/TreeNode.js +3 -3
- package/es/components/TreeView/TreeView.js +3 -3
- package/es/components/UIShell/Content.d.ts +5 -3
- package/es/components/UIShell/HeaderMenuItem.js +2 -1
- package/es/components/UIShell/HeaderPanel.d.ts +2 -2
- package/es/components/UIShell/HeaderPanel.js +9 -5
- package/es/index.js +1 -1
- package/es/internal/Selection.js +8 -3
- package/es/internal/environment.js +1 -12
- package/es/internal/{__mocks__/mockHTMLElement.d.ts → index.d.ts} +2 -4
- package/es/internal/useOverflowItems.d.ts +29 -0
- package/es/internal/useOverflowItems.js +122 -0
- package/es/internal/useResizeObserver.d.ts +1 -1
- package/es/internal/utils.d.ts +14 -0
- package/es/internal/utils.js +18 -0
- package/es/tools/uniqueId.d.ts +1 -6
- package/lib/components/AILabel/index.js +6 -1
- package/lib/components/Checkbox/Checkbox.d.ts +2 -2
- package/lib/components/Checkbox/Checkbox.js +7 -7
- package/lib/components/CheckboxGroup/CheckboxGroup.d.ts +2 -2
- package/lib/components/CheckboxGroup/CheckboxGroup.js +8 -7
- package/lib/components/CodeSnippet/CodeSnippet.js +2 -4
- package/lib/components/ComboBox/ComboBox.d.ts +1 -1
- package/lib/components/ComboBox/ComboBox.js +11 -10
- package/lib/components/ComposedModal/ComposedModal.d.ts +1 -1
- package/lib/components/ComposedModal/ComposedModal.js +35 -13
- package/lib/components/ContainedList/ContainedList.d.ts +1 -1
- package/lib/components/ContainedList/ContainedList.js +4 -2
- package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -4
- package/lib/components/DataTable/DataTable.js +3 -0
- package/lib/components/DataTable/TableDecoratorRow.d.ts +2 -2
- package/lib/components/DataTable/TableDecoratorRow.js +8 -8
- package/lib/components/DataTable/TableExpandRow.d.ts +1 -1
- package/lib/components/DataTable/TableExpandRow.js +14 -5
- package/lib/components/DataTable/TableHeader.js +9 -9
- package/lib/components/DataTable/TableRow.js +11 -3
- package/lib/components/DataTable/tools/normalize.js +2 -1
- package/lib/components/DatePickerInput/DatePickerInput.js +7 -6
- package/lib/components/Dialog/index.d.ts +5 -1
- package/lib/components/Dialog/index.js +20 -0
- package/lib/components/Dropdown/Dropdown.d.ts +1 -1
- package/lib/components/Dropdown/Dropdown.js +12 -14
- package/lib/components/FileUploader/FileUploaderButton.js +2 -2
- package/lib/components/FileUploader/FileUploaderDropContainer.js +2 -2
- package/lib/components/FileUploader/FileUploaderItem.js +2 -2
- package/lib/components/Layer/index.d.ts +1 -3
- package/lib/components/Layer/index.js +9 -8
- package/lib/components/Menu/Menu.js +0 -6
- package/lib/components/Modal/Modal.d.ts +2 -2
- package/lib/components/Modal/Modal.js +47 -19
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
- package/lib/components/MultiSelect/FilterableMultiSelect.js +33 -11
- package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/lib/components/MultiSelect/MultiSelect.js +13 -12
- package/lib/components/NumberInput/NumberInput.d.ts +1 -1
- package/lib/components/NumberInput/NumberInput.js +8 -7
- package/lib/components/OverflowMenu/OverflowMenu.js +4 -5
- package/lib/components/PageHeader/PageHeader.d.ts +10 -9
- package/lib/components/PageHeader/PageHeader.js +92 -34
- package/lib/components/PageHeader/index.d.ts +2 -2
- package/lib/components/PageHeader/index.js +0 -2
- package/lib/components/Popover/index.js +2 -1
- package/lib/components/RadioButton/RadioButton.d.ts +2 -2
- package/lib/components/RadioButton/RadioButton.js +7 -7
- package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +2 -2
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +10 -9
- package/lib/components/RadioTile/RadioTile.d.ts +1 -1
- package/lib/components/RadioTile/RadioTile.js +7 -6
- package/lib/components/Search/Search.js +0 -1
- package/lib/components/Select/Select.d.ts +2 -2
- package/lib/components/Select/Select.js +7 -6
- package/lib/components/Slider/Slider.js +6 -0
- package/lib/components/Tag/DismissibleTag.d.ts +1 -1
- package/lib/components/Tag/DismissibleTag.js +8 -7
- package/lib/components/Tag/Tag.d.ts +1 -1
- package/lib/components/Tag/Tag.js +8 -7
- package/lib/components/TextArea/TextArea.js +11 -10
- package/lib/components/TextInput/TextInput.d.ts +1 -1
- package/lib/components/TextInput/TextInput.js +19 -8
- package/lib/components/Tile/Tile.d.ts +2 -2
- package/lib/components/Tile/Tile.js +29 -35
- package/lib/components/TileGroup/TileGroup.d.ts +4 -4
- package/lib/components/TileGroup/TileGroup.js +44 -52
- package/lib/components/TileGroup/index.d.ts +3 -3
- package/lib/components/Toggletip/index.js +2 -2
- package/lib/components/Tooltip/DefinitionTooltip.js +1 -0
- package/lib/components/TreeView/TreeNode.js +3 -3
- package/lib/components/TreeView/TreeView.js +3 -3
- package/lib/components/UIShell/Content.d.ts +5 -3
- package/lib/components/UIShell/HeaderMenuItem.js +2 -1
- package/lib/components/UIShell/HeaderPanel.d.ts +2 -2
- package/lib/components/UIShell/HeaderPanel.js +8 -4
- package/lib/index.js +1 -1
- package/lib/internal/Selection.js +8 -3
- package/lib/internal/environment.js +1 -12
- package/lib/internal/{__mocks__/mockHTMLElement.d.ts → index.d.ts} +2 -4
- package/lib/internal/useOverflowItems.d.ts +29 -0
- package/lib/internal/useOverflowItems.js +126 -0
- package/lib/internal/useResizeObserver.d.ts +1 -1
- package/lib/internal/utils.d.ts +14 -0
- package/lib/internal/utils.js +22 -0
- package/lib/tools/uniqueId.d.ts +1 -6
- package/package.json +14 -23
- package/telemetry.yml +3 -0
- package/es/tools/uniqueId.js +0 -14
- package/lib/tools/uniqueId.js +0 -18
|
@@ -6,16 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
|
-
import React, { useState,
|
|
9
|
+
import React, { useRef, useState, useEffect, useContext, cloneElement } from 'react';
|
|
10
10
|
import cx from 'classnames';
|
|
11
11
|
import { useNormalizedInputProps } from '../../internal/useNormalizedInputProps.js';
|
|
12
12
|
import deprecate from '../../prop-types/deprecate.js';
|
|
13
13
|
import { textInputProps } from './util.js';
|
|
14
14
|
import '../FluidForm/FluidForm.js';
|
|
15
15
|
import { FormContext } from '../FluidForm/FormContext.js';
|
|
16
|
+
import { useMergedRefs } from '../../internal/useMergedRefs.js';
|
|
16
17
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
17
18
|
import { getAnnouncement } from '../../internal/getAnnouncement.js';
|
|
18
19
|
import '../Text/index.js';
|
|
20
|
+
import { AILabel } from '../AILabel/index.js';
|
|
21
|
+
import { isComponentElement } from '../../internal/utils.js';
|
|
19
22
|
import { Text } from '../Text/Text.js';
|
|
20
23
|
|
|
21
24
|
const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
|
|
@@ -48,7 +51,16 @@ const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
|
|
|
48
51
|
defaultValue,
|
|
49
52
|
value
|
|
50
53
|
} = rest;
|
|
51
|
-
const
|
|
54
|
+
const inputRef = useRef(null);
|
|
55
|
+
const mergedRef = useMergedRefs([ref, inputRef]);
|
|
56
|
+
function getInitialTextCount() {
|
|
57
|
+
const targetValue = defaultValue || value || inputRef.current?.value || '';
|
|
58
|
+
return targetValue.toString().length;
|
|
59
|
+
}
|
|
60
|
+
const [textCount, setTextCount] = useState(getInitialTextCount());
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setTextCount(getInitialTextCount());
|
|
63
|
+
}, [value, defaultValue, enableCounter]);
|
|
52
64
|
const normalizedProps = useNormalizedInputProps({
|
|
53
65
|
id,
|
|
54
66
|
readOnly,
|
|
@@ -81,7 +93,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
|
|
|
81
93
|
},
|
|
82
94
|
placeholder,
|
|
83
95
|
type,
|
|
84
|
-
ref,
|
|
96
|
+
ref: mergedRef,
|
|
85
97
|
className: textInputClasses,
|
|
86
98
|
title: placeholder,
|
|
87
99
|
disabled: normalizedProps.disabled,
|
|
@@ -179,12 +191,11 @@ const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
|
|
|
179
191
|
const Icon = normalizedProps.icon;
|
|
180
192
|
|
|
181
193
|
// AILabel is always size `mini`
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
194
|
+
const candidate = slug ?? decorator;
|
|
195
|
+
const candidateIsAILabel = isComponentElement(candidate, AILabel);
|
|
196
|
+
const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
|
|
197
|
+
size: 'mini'
|
|
198
|
+
}) : null;
|
|
188
199
|
return /*#__PURE__*/React.createElement("div", {
|
|
189
200
|
className: inputWrapperClasses
|
|
190
201
|
}, !inline ? labelWrapper : /*#__PURE__*/React.createElement("div", {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, { type
|
|
7
|
+
import React, { type HTMLAttributes, type KeyboardEvent, type MouseEvent, type ReactNode } from 'react';
|
|
8
8
|
export interface TileProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
9
|
children?: ReactNode;
|
|
10
10
|
className?: string;
|
|
@@ -105,7 +105,7 @@ export interface SelectableTileProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
105
105
|
/**
|
|
106
106
|
* The empty handler of the `<input>`.
|
|
107
107
|
*/
|
|
108
|
-
onChange?(event:
|
|
108
|
+
onChange?(event: MouseEvent<HTMLDivElement> | KeyboardEvent<HTMLDivElement>, selected?: boolean, id?: string): void;
|
|
109
109
|
/**
|
|
110
110
|
* Specify the function to run when the SelectableTile is clicked
|
|
111
111
|
*/
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React, { useState, useRef,
|
|
9
|
+
import React, { useState, useEffect, useCallback, useRef, cloneElement } from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import { AiLabel, CheckboxCheckedFilled, Checkbox, ChevronDown, ArrowRight, Error } from '@carbon/icons-react';
|
|
@@ -22,6 +22,8 @@ import { useMergedRefs } from '../../internal/useMergedRefs.js';
|
|
|
22
22
|
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
23
23
|
import { useId } from '../../internal/useId.js';
|
|
24
24
|
import '../Text/index.js';
|
|
25
|
+
import { AILabel } from '../AILabel/index.js';
|
|
26
|
+
import { isComponentElement } from '../../internal/utils.js';
|
|
25
27
|
import { Text } from '../Text/Text.js';
|
|
26
28
|
|
|
27
29
|
var _CheckboxCheckedFille, _Checkbox, _ChevronDown, _ChevronDown2;
|
|
@@ -224,7 +226,11 @@ const SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile({
|
|
|
224
226
|
const clickHandler = onClick;
|
|
225
227
|
const keyDownHandler = onKeyDown;
|
|
226
228
|
const [isSelected, setIsSelected] = useState(selected);
|
|
227
|
-
|
|
229
|
+
|
|
230
|
+
// Use useEffect to sync with prop changes instead of render-time logic
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
setIsSelected(selected);
|
|
233
|
+
}, [selected]);
|
|
228
234
|
const classes = cx(`${prefix}--tile`, `${prefix}--tile--selectable`, {
|
|
229
235
|
[`${prefix}--tile--is-selected`]: isSelected,
|
|
230
236
|
[`${prefix}--tile--light`]: light,
|
|
@@ -234,50 +240,40 @@ const SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile({
|
|
|
234
240
|
[`${prefix}--tile--decorator`]: decorator,
|
|
235
241
|
[`${prefix}--tile--decorator-rounded`]: decorator && hasRoundedCorners
|
|
236
242
|
}, className);
|
|
243
|
+
|
|
244
|
+
// Single function to handle selection changes
|
|
245
|
+
const handleSelectionChange = useCallback((evt, newSelected) => {
|
|
246
|
+
setIsSelected(newSelected);
|
|
247
|
+
onChange(evt, newSelected, id);
|
|
248
|
+
}, [onChange, id]);
|
|
237
249
|
function handleClick(evt) {
|
|
238
250
|
evt.preventDefault();
|
|
239
251
|
evt?.persist?.();
|
|
240
|
-
if (normalizedDecorator && decoratorRef.current && decoratorRef.current.contains(evt.target)) {
|
|
252
|
+
if (normalizedDecorator && decoratorRef.current && evt.target instanceof Node && decoratorRef.current.contains(evt.target)) {
|
|
241
253
|
return;
|
|
242
254
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
onChange(evt, newSelected, id);
|
|
246
|
-
return newSelected;
|
|
247
|
-
});
|
|
255
|
+
const newSelected = !isSelected;
|
|
256
|
+
handleSelectionChange(evt, newSelected);
|
|
248
257
|
clickHandler(evt);
|
|
249
258
|
}
|
|
250
259
|
function handleKeyDown(evt) {
|
|
251
260
|
evt?.persist?.();
|
|
252
261
|
if (matches(evt, [Enter, Space])) {
|
|
253
262
|
evt.preventDefault();
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
onChange(evt, newSelected, id);
|
|
257
|
-
return newSelected;
|
|
258
|
-
});
|
|
263
|
+
const newSelected = !isSelected;
|
|
264
|
+
handleSelectionChange(evt, newSelected);
|
|
259
265
|
}
|
|
260
266
|
keyDownHandler(evt);
|
|
261
267
|
}
|
|
262
|
-
function handleChange(event) {
|
|
263
|
-
const newSelected = event.target.checked;
|
|
264
|
-
setIsSelected(newSelected);
|
|
265
|
-
onChange(event, newSelected, id);
|
|
266
|
-
}
|
|
267
|
-
if (selected !== prevSelected) {
|
|
268
|
-
setIsSelected(selected);
|
|
269
|
-
setPrevSelected(selected);
|
|
270
|
-
}
|
|
271
268
|
|
|
272
269
|
// AILabel is always size `xs`
|
|
273
270
|
const decoratorRef = useRef(null);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
271
|
+
const candidate = slug ?? decorator;
|
|
272
|
+
const candidateIsAILabel = isComponentElement(candidate, AILabel);
|
|
273
|
+
const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
|
|
274
|
+
size: 'xs',
|
|
275
|
+
ref: decoratorRef
|
|
276
|
+
}) : null;
|
|
281
277
|
return (
|
|
282
278
|
/*#__PURE__*/
|
|
283
279
|
// eslint-disable-next-line jsx-a11y/interactive-supports-focus
|
|
@@ -292,7 +288,6 @@ const SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile({
|
|
|
292
288
|
tabIndex: !disabled ? tabIndex : undefined,
|
|
293
289
|
ref: ref,
|
|
294
290
|
id: id,
|
|
295
|
-
onChange: !disabled ? handleChange : undefined,
|
|
296
291
|
title: title
|
|
297
292
|
}, rest), /*#__PURE__*/React.createElement("span", {
|
|
298
293
|
className: `${prefix}--tile__checkmark ${prefix}--tile__checkmark--persistent`
|
|
@@ -505,12 +500,11 @@ const ExpandableTile = /*#__PURE__*/React.forwardRef(function ExpandableTile({
|
|
|
505
500
|
const belowTheFoldId = useId('expandable-tile-interactive');
|
|
506
501
|
|
|
507
502
|
// AILabel is always size `xs`
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
503
|
+
const candidate = slug ?? decorator;
|
|
504
|
+
const candidateIsAILabel = isComponentElement(candidate, AILabel);
|
|
505
|
+
const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
|
|
506
|
+
size: 'xs'
|
|
507
|
+
}) : null;
|
|
514
508
|
return interactive ? /*#__PURE__*/React.createElement("div", _extends({
|
|
515
509
|
ref: ref,
|
|
516
510
|
className: interactiveClassNames
|
|
@@ -45,8 +45,9 @@ export interface TileGroupProps extends Omit<HTMLAttributes<HTMLFieldSetElement>
|
|
|
45
45
|
*/
|
|
46
46
|
required?: boolean;
|
|
47
47
|
}
|
|
48
|
-
declare const TileGroup: {
|
|
49
|
-
(
|
|
48
|
+
export declare const TileGroup: {
|
|
49
|
+
({ children, className, defaultSelected, disabled, legend, name, onChange, valueSelected, required, }: TileGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
displayName: string;
|
|
50
51
|
propTypes: {
|
|
51
52
|
/**
|
|
52
53
|
* Provide a collection of <RadioTile> components to render in the group
|
|
@@ -86,6 +87,5 @@ declare const TileGroup: {
|
|
|
86
87
|
*/
|
|
87
88
|
valueSelected: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
|
|
88
89
|
};
|
|
89
|
-
displayName: string;
|
|
90
90
|
};
|
|
91
|
-
export
|
|
91
|
+
export {};
|
|
@@ -7,40 +7,42 @@
|
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
|
-
import React, { useState } from 'react';
|
|
10
|
+
import React, { useState, useEffect, Children, isValidElement, cloneElement } from 'react';
|
|
11
11
|
import RadioTile from '../RadioTile/RadioTile.js';
|
|
12
12
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
13
13
|
import { noopFn } from '../../internal/noopFn.js';
|
|
14
14
|
|
|
15
|
-
const TileGroup =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = props;
|
|
15
|
+
const TileGroup = ({
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
defaultSelected,
|
|
19
|
+
disabled,
|
|
20
|
+
legend,
|
|
21
|
+
name,
|
|
22
|
+
onChange = noopFn,
|
|
23
|
+
valueSelected,
|
|
24
|
+
required
|
|
25
|
+
}) => {
|
|
27
26
|
const prefix = usePrefix();
|
|
28
27
|
const [selected, setSelected] = useState(valueSelected ?? defaultSelected);
|
|
29
|
-
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (typeof valueSelected !== 'undefined' && valueSelected !== selected) {
|
|
30
|
+
setSelected(valueSelected);
|
|
31
|
+
}
|
|
32
|
+
}, [valueSelected, selected]);
|
|
33
|
+
const handleChange = (value, name, evt) => {
|
|
34
|
+
if (value !== selected) {
|
|
35
|
+
setSelected(value);
|
|
36
|
+
onChange(value, name ?? '', evt);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const getRadioTilesWithWrappers = elements => {
|
|
40
|
+
const traverseAndModifyChildren = elements => {
|
|
41
|
+
return Children.map(elements, child => {
|
|
42
|
+
if (! /*#__PURE__*/isValidElement(child)) return child;
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* only update if selected prop changes
|
|
34
|
-
*/
|
|
35
|
-
if (valueSelected !== prevValueSelected) {
|
|
36
|
-
setSelected(valueSelected);
|
|
37
|
-
setPrevValueSelected(valueSelected);
|
|
38
|
-
}
|
|
39
|
-
const getRadioTilesWithWrappers = children => {
|
|
40
|
-
const traverseAndModifyChildren = children => {
|
|
41
|
-
return React.Children.map(children, child => {
|
|
42
|
-
// If RadioTile found, return it with necessary props
|
|
43
|
-
if (child?.type === RadioTile) {
|
|
44
|
+
// If a `RadioTile` is found, return it with necessary props,
|
|
45
|
+
if (/*#__PURE__*/isValidElement(child) && child.type === RadioTile) {
|
|
44
46
|
const {
|
|
45
47
|
value,
|
|
46
48
|
...otherProps
|
|
@@ -53,38 +55,29 @@ const TileGroup = props => {
|
|
|
53
55
|
onChange: handleChange,
|
|
54
56
|
checked: value === selected
|
|
55
57
|
}));
|
|
56
|
-
} else if (child?.props?.children) {
|
|
57
|
-
// If the child is not RadioTile and has children, recheck the children
|
|
58
|
-
return /*#__PURE__*/React.cloneElement(child, {
|
|
59
|
-
...child.props,
|
|
60
|
-
children: traverseAndModifyChildren(child.props.children)
|
|
61
|
-
});
|
|
62
|
-
} else {
|
|
63
|
-
// If the child is neither a RadioTile nor has children, return it as is
|
|
64
|
-
return child;
|
|
65
58
|
}
|
|
59
|
+
|
|
60
|
+
// If the child is not RadioTile and has children, recheck the children
|
|
61
|
+
const children = child.props.children;
|
|
62
|
+
const hasChildren = Children.count(children) > 0;
|
|
63
|
+
if (hasChildren) {
|
|
64
|
+
return /*#__PURE__*/cloneElement(child, undefined, traverseAndModifyChildren(children));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If the child is neither a RadioTile nor has children, return it as is
|
|
68
|
+
return child;
|
|
66
69
|
});
|
|
67
70
|
};
|
|
68
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, traverseAndModifyChildren(
|
|
69
|
-
};
|
|
70
|
-
const handleChange = (newSelection, value, evt) => {
|
|
71
|
-
if (newSelection !== selected) {
|
|
72
|
-
setSelected(newSelection);
|
|
73
|
-
onChange(newSelection, name, evt);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const renderLegend = legend => {
|
|
77
|
-
if (legend) {
|
|
78
|
-
return /*#__PURE__*/React.createElement("legend", {
|
|
79
|
-
className: `${prefix}--label`
|
|
80
|
-
}, legend);
|
|
81
|
-
}
|
|
71
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, traverseAndModifyChildren(elements));
|
|
82
72
|
};
|
|
83
73
|
return /*#__PURE__*/React.createElement("fieldset", {
|
|
84
74
|
className: className ?? `${prefix}--tile-group`,
|
|
85
75
|
disabled: disabled
|
|
86
|
-
},
|
|
76
|
+
}, legend && /*#__PURE__*/React.createElement("legend", {
|
|
77
|
+
className: `${prefix}--label`
|
|
78
|
+
}, legend), /*#__PURE__*/React.createElement("div", null, getRadioTilesWithWrappers(children)));
|
|
87
79
|
};
|
|
80
|
+
TileGroup.displayName = 'TileGroup';
|
|
88
81
|
TileGroup.propTypes = {
|
|
89
82
|
/**
|
|
90
83
|
* Provide a collection of <RadioTile> components to render in the group
|
|
@@ -124,6 +117,5 @@ TileGroup.propTypes = {
|
|
|
124
117
|
*/
|
|
125
118
|
valueSelected: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
126
119
|
};
|
|
127
|
-
TileGroup.displayName = 'TileGroup';
|
|
128
120
|
|
|
129
|
-
export { TileGroup
|
|
121
|
+
export { TileGroup };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright IBM Corp. 2016,
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import { TileGroup } from './TileGroup';
|
|
8
8
|
export default TileGroup;
|
|
9
|
-
export
|
|
9
|
+
export * from './TileGroup';
|
|
@@ -88,6 +88,7 @@ function Toggletip({
|
|
|
88
88
|
buttonProps: {
|
|
89
89
|
'aria-expanded': open,
|
|
90
90
|
'aria-controls': id,
|
|
91
|
+
'aria-describedby': open ? id : undefined,
|
|
91
92
|
onClick: actions.toggle
|
|
92
93
|
},
|
|
93
94
|
contentProps: {
|
|
@@ -259,8 +260,7 @@ const ToggletipContent = /*#__PURE__*/React.forwardRef(function ToggletipContent
|
|
|
259
260
|
return /*#__PURE__*/React.createElement(PopoverContent, _extends({
|
|
260
261
|
className: customClassName
|
|
261
262
|
}, toggletip?.contentProps, {
|
|
262
|
-
ref: ref
|
|
263
|
-
"aria-live": "polite"
|
|
263
|
+
ref: ref
|
|
264
264
|
}), /*#__PURE__*/React.createElement("div", {
|
|
265
265
|
className: `${prefix}--toggletip-content`
|
|
266
266
|
}, children));
|
|
@@ -57,6 +57,7 @@ const DefinitionTooltip = ({
|
|
|
57
57
|
}, /*#__PURE__*/React.createElement("button", _extends({}, rest, {
|
|
58
58
|
className: cx(`${prefix}--definition-term`, triggerClassName),
|
|
59
59
|
"aria-controls": tooltipId,
|
|
60
|
+
"aria-describedby": tooltipId,
|
|
60
61
|
"aria-expanded": isOpen,
|
|
61
62
|
onBlur: () => {
|
|
62
63
|
setOpen(false);
|
|
@@ -14,7 +14,7 @@ import { ArrowLeft, ArrowRight, Enter, Space } from '../../internal/keyboard/key
|
|
|
14
14
|
import { matches, match } from '../../internal/keyboard/match.js';
|
|
15
15
|
import { useControllableState } from '../../internal/useControllableState.js';
|
|
16
16
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
17
|
-
import {
|
|
17
|
+
import { useId } from '../../internal/useId.js';
|
|
18
18
|
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
19
19
|
|
|
20
20
|
const TreeNode = /*#__PURE__*/React.forwardRef(({
|
|
@@ -43,7 +43,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
|
|
|
43
43
|
const enableTreeviewControllable = useFeatureFlag('enable-treeview-controllable');
|
|
44
44
|
const {
|
|
45
45
|
current: id
|
|
46
|
-
} = useRef(nodeId ||
|
|
46
|
+
} = useRef(nodeId || useId());
|
|
47
47
|
const controllableExpandedState = useControllableState({
|
|
48
48
|
value: isExpanded,
|
|
49
49
|
onChange: newValue => {
|
|
@@ -72,7 +72,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
|
|
|
72
72
|
function enhanceTreeNodes(children) {
|
|
73
73
|
return React.Children.map(children, node => {
|
|
74
74
|
if (! /*#__PURE__*/React.isValidElement(node)) return node;
|
|
75
|
-
const isTreeNode = node.type
|
|
75
|
+
const isTreeNode = node.type === TreeNode;
|
|
76
76
|
if (isTreeNode) {
|
|
77
77
|
return /*#__PURE__*/React.cloneElement(node, {
|
|
78
78
|
active,
|
|
@@ -13,7 +13,7 @@ import { ArrowUp, ArrowDown, Home, End } from '../../internal/keyboard/keys.js';
|
|
|
13
13
|
import { matches, match } from '../../internal/keyboard/match.js';
|
|
14
14
|
import { useControllableState } from '../../internal/useControllableState.js';
|
|
15
15
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
16
|
-
import {
|
|
16
|
+
import { useId } from '../../internal/useId.js';
|
|
17
17
|
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
18
18
|
import TreeNode from './TreeNode.js';
|
|
19
19
|
|
|
@@ -33,7 +33,7 @@ const TreeView = ({
|
|
|
33
33
|
const enableTreeviewControllable = useFeatureFlag('enable-treeview-controllable');
|
|
34
34
|
const {
|
|
35
35
|
current: treeId
|
|
36
|
-
} = useRef(rest.id ||
|
|
36
|
+
} = useRef(rest.id || useId());
|
|
37
37
|
const prefix = usePrefix();
|
|
38
38
|
const treeClasses = cx(className, `${prefix}--tree`, {
|
|
39
39
|
// @ts-ignore - will always be false according to prop types
|
|
@@ -112,7 +112,7 @@ const TreeView = ({
|
|
|
112
112
|
function enhanceTreeNodes(children) {
|
|
113
113
|
return React.Children.map(children, child => {
|
|
114
114
|
if (! /*#__PURE__*/React.isValidElement(child)) return child;
|
|
115
|
-
const isTreeNode = child.type
|
|
115
|
+
const isTreeNode = child.type === TreeNode;
|
|
116
116
|
if (isTreeNode) {
|
|
117
117
|
const node = child;
|
|
118
118
|
const sharedNodeProps = {
|
|
@@ -75,6 +75,8 @@ declare const Content: {
|
|
|
75
75
|
inert?: boolean | undefined;
|
|
76
76
|
inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined;
|
|
77
77
|
is?: string | undefined;
|
|
78
|
+
exportparts?: string | undefined;
|
|
79
|
+
part?: string | undefined;
|
|
78
80
|
"aria-activedescendant"?: string | undefined;
|
|
79
81
|
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
80
82
|
"aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined;
|
|
@@ -149,7 +151,7 @@ declare const Content: {
|
|
|
149
151
|
onBlurCapture?: React.FocusEventHandler<HTMLElement> | undefined;
|
|
150
152
|
onChange?: React.FormEventHandler<HTMLElement> | undefined;
|
|
151
153
|
onChangeCapture?: React.FormEventHandler<HTMLElement> | undefined;
|
|
152
|
-
onBeforeInput?: React.
|
|
154
|
+
onBeforeInput?: React.InputEventHandler<HTMLElement> | undefined;
|
|
153
155
|
onBeforeInputCapture?: React.FormEventHandler<HTMLElement> | undefined;
|
|
154
156
|
onInput?: React.FormEventHandler<HTMLElement> | undefined;
|
|
155
157
|
onInputCapture?: React.FormEventHandler<HTMLElement> | undefined;
|
|
@@ -199,8 +201,6 @@ declare const Content: {
|
|
|
199
201
|
onProgressCapture?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
200
202
|
onRateChange?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
201
203
|
onRateChangeCapture?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
202
|
-
onResize?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
203
|
-
onResizeCapture?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
204
204
|
onSeeked?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
205
205
|
onSeekedCapture?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
206
206
|
onSeeking?: React.ReactEventHandler<HTMLElement> | undefined;
|
|
@@ -281,6 +281,8 @@ declare const Content: {
|
|
|
281
281
|
onLostPointerCaptureCapture?: React.PointerEventHandler<HTMLElement> | undefined;
|
|
282
282
|
onScroll?: React.UIEventHandler<HTMLElement> | undefined;
|
|
283
283
|
onScrollCapture?: React.UIEventHandler<HTMLElement> | undefined;
|
|
284
|
+
onScrollEnd?: React.UIEventHandler<HTMLElement> | undefined;
|
|
285
|
+
onScrollEndCapture?: React.UIEventHandler<HTMLElement> | undefined;
|
|
284
286
|
onWheel?: React.WheelEventHandler<HTMLElement> | undefined;
|
|
285
287
|
onWheelCapture?: React.WheelEventHandler<HTMLElement> | undefined;
|
|
286
288
|
onAnimationStart?: React.AnimationEventHandler<HTMLElement> | undefined;
|
|
@@ -24,6 +24,7 @@ const HeaderMenuItem = /*#__PURE__*/forwardRef(function HeaderMenuItem({
|
|
|
24
24
|
...rest
|
|
25
25
|
}, ref) {
|
|
26
26
|
const prefix = usePrefix();
|
|
27
|
+
const resolvedTabIndex = tabIndex ?? 0;
|
|
27
28
|
if (isCurrentPage) {
|
|
28
29
|
isActive = isCurrentPage;
|
|
29
30
|
}
|
|
@@ -42,7 +43,7 @@ const HeaderMenuItem = /*#__PURE__*/forwardRef(function HeaderMenuItem({
|
|
|
42
43
|
"aria-current": hasCurrentClass ? true : ariaCurrent,
|
|
43
44
|
className: linkClassName,
|
|
44
45
|
ref: ref,
|
|
45
|
-
tabIndex:
|
|
46
|
+
tabIndex: resolvedTabIndex
|
|
46
47
|
}), /*#__PURE__*/React.createElement("span", {
|
|
47
48
|
className: `${prefix}--text-truncate--end`
|
|
48
49
|
}, children)));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright IBM Corp. 2016,
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, { ReactNode } from 'react';
|
|
7
|
+
import React, { type ReactNode } from 'react';
|
|
8
8
|
export interface HeaderPanelProps {
|
|
9
9
|
/**
|
|
10
10
|
* Specify whether focus and blur listeners are added. They are by default.
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import cx from 'classnames';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
|
-
import React, { useRef, useState } from 'react';
|
|
11
|
+
import React, { useRef, useState, isValidElement } from 'react';
|
|
12
12
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
13
13
|
import { Escape } from '../../internal/keyboard/keys.js';
|
|
14
14
|
import { match } from '../../internal/keyboard/match.js';
|
|
15
15
|
import { useWindowEvent } from '../../internal/useEvent.js';
|
|
16
16
|
import { useMergedRefs } from '../../internal/useMergedRefs.js';
|
|
17
|
+
import Switcher from './Switcher.js';
|
|
17
18
|
|
|
18
19
|
const noopFn = () => {};
|
|
19
20
|
const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel({
|
|
@@ -58,10 +59,13 @@ const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel({
|
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
useWindowEvent('click', () => {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (
|
|
62
|
+
const {
|
|
63
|
+
activeElement
|
|
64
|
+
} = document;
|
|
65
|
+
if (!(activeElement instanceof HTMLElement)) return;
|
|
66
|
+
setLastClickedElement(activeElement);
|
|
67
|
+
const isChildASwitcher = /*#__PURE__*/isValidElement(children) && typeof children.type !== 'string' && children.type === Switcher;
|
|
68
|
+
if (isChildASwitcher && !activeElement.closest(`.${prefix}--header-panel--expanded`) && !activeElement.closest(`.${prefix}--header__action`) && !headerPanelReference?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
|
|
65
69
|
setExpandedState(false);
|
|
66
70
|
onHeaderPanelFocus();
|
|
67
71
|
}
|
package/es/index.js
CHANGED
|
@@ -148,7 +148,7 @@ export { default as TextAreaSkeleton } from './components/TextArea/TextArea.Skel
|
|
|
148
148
|
export { default as TextInput } from './components/TextInput/TextInput.js';
|
|
149
149
|
export { default as TextInputSkeleton } from './components/TextInput/TextInput.Skeleton.js';
|
|
150
150
|
export { ClickableTile, ExpandableTile, SelectableTile, Tile, TileAboveTheFoldContent, TileBelowTheFoldContent } from './components/Tile/Tile.js';
|
|
151
|
-
export {
|
|
151
|
+
export { TileGroup } from './components/TileGroup/TileGroup.js';
|
|
152
152
|
export { default as TimePicker } from './components/TimePicker/TimePicker.js';
|
|
153
153
|
export { default as TimePickerSelect } from './components/TimePickerSelect/TimePickerSelect.js';
|
|
154
154
|
export { Toggle } from './components/Toggle/Toggle.js';
|
package/es/internal/Selection.js
CHANGED
|
@@ -17,9 +17,14 @@ const callOnChangeHandler = ({
|
|
|
17
17
|
}) => {
|
|
18
18
|
if (isControlled) {
|
|
19
19
|
if (isMounted && onChangeHandlerControlled) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// Use setTimeout to defer the controlled onChange call,
|
|
21
|
+
// avoiding React’s warning: "Cannot update a component while rendering a different component".
|
|
22
|
+
// This ensures the parent state updates after rendering completes.
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
onChangeHandlerControlled({
|
|
25
|
+
selectedItems
|
|
26
|
+
});
|
|
27
|
+
}, 0);
|
|
23
28
|
}
|
|
24
29
|
} else {
|
|
25
30
|
onChangeHandlerUncontrolled(selectedItems);
|
|
@@ -10,17 +10,6 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
|
|
12
12
|
*/
|
|
13
|
-
const canUseDOM = !!(typeof window !== 'undefined' &&
|
|
14
|
-
// TODO: `ssr-friendly` doesn't support ESLint v9.
|
|
15
|
-
// https://github.com/kopiro/eslint-plugin-ssr-friendly/issues/30
|
|
16
|
-
// https://github.com/carbon-design-system/carbon/issues/18991
|
|
17
|
-
/*
|
|
18
|
-
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
19
|
-
*/
|
|
20
|
-
window.document &&
|
|
21
|
-
/*
|
|
22
|
-
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
23
|
-
*/
|
|
24
|
-
window.document.createElement);
|
|
13
|
+
const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
25
14
|
|
|
26
15
|
export { canUseDOM };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright IBM Corp. 2025
|
|
2
|
+
* Copyright IBM Corp. 2025
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
mockRestore: () => void;
|
|
9
|
-
};
|
|
7
|
+
export * from './utils';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2025, 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { ReactNode, RefObject } from 'react';
|
|
8
|
+
type Item = {
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Manages overflow items in a container by automatically hiding items that don't fit.
|
|
13
|
+
* @param items - Array of items to manage for overflow, each must have an `id` property.
|
|
14
|
+
* @param containerRef - React ref to the container element that holds the items.
|
|
15
|
+
* @param offsetRef - Optional ref to an offset element (like a "more" button) whose width is reserved when calculating available space.
|
|
16
|
+
* @param maxItems - Optional maximum number of visible items. If undefined, only container space constrains visibility.
|
|
17
|
+
* @param onChange - Optional callback called when hidden items change. Receives array of currently hidden items.
|
|
18
|
+
* @returns Object with `visibleItems` (items to display), `hiddenItems` (items that don't fit), and `itemRefHandler` (function to attach refs to items for width measurement).
|
|
19
|
+
*/
|
|
20
|
+
declare const useOverflowItems: <T extends Item>(items: T[] | ReactNode, containerRef: RefObject<HTMLDivElement>, offsetRef?: RefObject<HTMLDivElement>, maxItems?: number, onChange?: (hiddenItems: T[]) => void) => {
|
|
21
|
+
visibleItems: T[];
|
|
22
|
+
hiddenItems: T[];
|
|
23
|
+
itemRefHandler: () => void;
|
|
24
|
+
} | {
|
|
25
|
+
visibleItems: T[];
|
|
26
|
+
itemRefHandler: (id: string, node: HTMLDivElement | null) => () => void;
|
|
27
|
+
hiddenItems: T[];
|
|
28
|
+
};
|
|
29
|
+
export default useOverflowItems;
|