@carbon/react 1.63.0-rc.0 → 1.63.1
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 +1043 -1014
- package/es/components/ComboBox/ComboBox.d.ts +14 -7
- package/es/components/ComboBox/ComboBox.js +31 -4
- package/es/components/ComboButton/index.d.ts +9 -6
- package/es/components/ComboButton/index.js +5 -0
- package/es/components/DataTable/DataTable.d.ts +25 -11
- package/es/components/DataTable/DataTable.js +5 -0
- package/es/components/DataTable/TableBatchActions.d.ts +2 -2
- package/es/components/DataTable/TableHeader.d.ts +7 -13
- package/es/components/DataTable/TableToolbarSearch.d.ts +5 -2
- package/es/components/DataTable/TableToolbarSearch.js +4 -0
- package/es/components/Dropdown/Dropdown.d.ts +6 -7
- package/es/components/Dropdown/Dropdown.js +23 -22
- package/es/components/FluidMultiSelect/FluidMultiSelect.js +4 -1
- package/es/components/FormGroup/FormGroup.d.ts +9 -1
- package/es/components/FormGroup/FormGroup.js +8 -1
- package/es/components/ListBox/ListBoxMenuIcon.d.ts +2 -7
- package/es/components/ListBox/ListBoxSelection.d.ts +8 -9
- package/es/components/ListBox/ListBoxSelection.js +5 -0
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +14 -6
- package/es/components/MultiSelect/FilterableMultiSelect.js +17 -5
- package/es/components/MultiSelect/MultiSelect.d.ts +6 -3
- package/es/components/MultiSelect/MultiSelect.js +7 -4
- package/es/components/NumberInput/NumberInput.d.ts +8 -7
- package/es/components/NumberInput/NumberInput.js +5 -0
- package/es/components/PaginationNav/PaginationNav.d.ts +13 -6
- package/es/components/PaginationNav/PaginationNav.js +5 -0
- package/es/components/ProgressIndicator/ProgressIndicator.d.ts +12 -6
- package/es/components/ProgressIndicator/ProgressIndicator.js +5 -0
- package/es/components/Slider/Slider.d.ts +11 -9
- package/es/components/Slider/Slider.js +6 -1
- package/es/internal/Selection.js +1 -1
- package/es/internal/useId.js +39 -18
- package/es/types/common.d.ts +6 -1
- package/lib/components/ComboBox/ComboBox.d.ts +14 -7
- package/lib/components/ComboBox/ComboBox.js +31 -4
- package/lib/components/ComboButton/index.d.ts +9 -6
- package/lib/components/ComboButton/index.js +5 -0
- package/lib/components/DataTable/DataTable.d.ts +25 -11
- package/lib/components/DataTable/DataTable.js +5 -0
- package/lib/components/DataTable/TableBatchActions.d.ts +2 -2
- package/lib/components/DataTable/TableHeader.d.ts +7 -13
- package/lib/components/DataTable/TableToolbarSearch.d.ts +5 -2
- package/lib/components/DataTable/TableToolbarSearch.js +4 -0
- package/lib/components/Dropdown/Dropdown.d.ts +6 -7
- package/lib/components/Dropdown/Dropdown.js +23 -22
- package/lib/components/FluidMultiSelect/FluidMultiSelect.js +4 -1
- package/lib/components/FormGroup/FormGroup.d.ts +9 -1
- package/lib/components/FormGroup/FormGroup.js +8 -1
- package/lib/components/ListBox/ListBoxMenuIcon.d.ts +2 -7
- package/lib/components/ListBox/ListBoxSelection.d.ts +8 -9
- package/lib/components/ListBox/ListBoxSelection.js +5 -0
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +14 -6
- package/lib/components/MultiSelect/FilterableMultiSelect.js +17 -5
- package/lib/components/MultiSelect/MultiSelect.d.ts +6 -3
- package/lib/components/MultiSelect/MultiSelect.js +7 -4
- package/lib/components/NumberInput/NumberInput.d.ts +8 -7
- package/lib/components/NumberInput/NumberInput.js +5 -0
- package/lib/components/PaginationNav/PaginationNav.d.ts +13 -6
- package/lib/components/PaginationNav/PaginationNav.js +5 -0
- package/lib/components/ProgressIndicator/ProgressIndicator.d.ts +12 -6
- package/lib/components/ProgressIndicator/ProgressIndicator.js +5 -0
- package/lib/components/Slider/Slider.d.ts +11 -9
- package/lib/components/Slider/Slider.js +6 -1
- package/lib/internal/Selection.js +1 -1
- package/lib/internal/useId.js +39 -17
- package/lib/types/common.d.ts +6 -1
- package/package.json +8 -9
|
@@ -7,7 +7,16 @@
|
|
|
7
7
|
import { type UseComboboxProps, type UseMultipleSelectionProps } from 'downshift';
|
|
8
8
|
import { ReactNode, FunctionComponent, ReactElement } from 'react';
|
|
9
9
|
import { type MultiSelectSortingProps } from './MultiSelectPropTypes';
|
|
10
|
-
|
|
10
|
+
import { TranslateWithId } from '../../types/common';
|
|
11
|
+
/**
|
|
12
|
+
* Message ids that will be passed to translateWithId().
|
|
13
|
+
* Combination of message ids from ListBox/next/ListBoxSelection.js and
|
|
14
|
+
* ListBox/next/ListBoxTrigger.js, but we can't access those values directly
|
|
15
|
+
* because those components aren't Typescript. (If you try, TranslationKey
|
|
16
|
+
* ends up just being defined as "string".)
|
|
17
|
+
*/
|
|
18
|
+
type TranslationKey = 'close.menu' | 'open.menu' | 'clear.all' | 'clear.selection';
|
|
19
|
+
export interface FilterableMultiSelectProps<ItemType> extends MultiSelectSortingProps<ItemType>, TranslateWithId<TranslationKey> {
|
|
11
20
|
/**
|
|
12
21
|
* Specify a label to be read by screen readers on the container node
|
|
13
22
|
* @deprecated
|
|
@@ -39,7 +48,10 @@ export interface FilterableMultiSelectProps<ItemType> extends MultiSelectSorting
|
|
|
39
48
|
*/
|
|
40
49
|
disabled?: boolean;
|
|
41
50
|
/**
|
|
42
|
-
* Additional props passed to Downshift
|
|
51
|
+
* Additional props passed to Downshift. Use with caution: anything you define
|
|
52
|
+
* here overrides the components' internal handling of that prop. Downshift
|
|
53
|
+
* internals are subject to change, and in some cases they can not be shimmed
|
|
54
|
+
* to shield you from potentially breaking changes.
|
|
43
55
|
*/
|
|
44
56
|
downshiftProps?: UseMultipleSelectionProps<ItemType>;
|
|
45
57
|
/**
|
|
@@ -154,10 +166,6 @@ export interface FilterableMultiSelectProps<ItemType> extends MultiSelectSorting
|
|
|
154
166
|
* combobox via ARIA attributes.
|
|
155
167
|
*/
|
|
156
168
|
titleText?: ReactNode;
|
|
157
|
-
/**
|
|
158
|
-
* Callback function for translating ListBoxMenuIcon SVG title
|
|
159
|
-
*/
|
|
160
|
-
translateWithId?(messageId: string, args?: Record<string, unknown>): string;
|
|
161
169
|
type?: 'default' | 'inline';
|
|
162
170
|
/**
|
|
163
171
|
* Specify title to show title on hover
|
|
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
|
|
|
9
9
|
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
|
|
10
10
|
import cx from 'classnames';
|
|
11
11
|
import Downshift, { useCombobox, useMultipleSelection } from 'downshift';
|
|
12
|
-
import isEqual from '
|
|
12
|
+
import isEqual from 'react-fast-compare';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import React__default, { useContext, useState, useLayoutEffect, useRef, useEffect, useMemo } from 'react';
|
|
15
15
|
import { defaultFilterItems } from '../ComboBox/tools/filter.js';
|
|
@@ -52,6 +52,15 @@ const {
|
|
|
52
52
|
DropdownKeyDownBackspace,
|
|
53
53
|
FunctionRemoveSelectedItem
|
|
54
54
|
} = useMultipleSelection.stateChangeTypes;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Message ids that will be passed to translateWithId().
|
|
58
|
+
* Combination of message ids from ListBox/next/ListBoxSelection.js and
|
|
59
|
+
* ListBox/next/ListBoxTrigger.js, but we can't access those values directly
|
|
60
|
+
* because those components aren't Typescript. (If you try, TranslationKey
|
|
61
|
+
* ends up just being defined as "string".)
|
|
62
|
+
*/
|
|
63
|
+
|
|
55
64
|
const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function FilterableMultiSelect(_ref, ref) {
|
|
56
65
|
let {
|
|
57
66
|
autoAlign = false,
|
|
@@ -339,7 +348,6 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
339
348
|
const {
|
|
340
349
|
getDropdownProps
|
|
341
350
|
} = useMultipleSelection({
|
|
342
|
-
...downshiftProps,
|
|
343
351
|
activeIndex: highlightedIndex,
|
|
344
352
|
initialSelectedItems,
|
|
345
353
|
selectedItems: controlledSelectedItems,
|
|
@@ -355,7 +363,8 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
355
363
|
break;
|
|
356
364
|
}
|
|
357
365
|
}
|
|
358
|
-
}
|
|
366
|
+
},
|
|
367
|
+
...downshiftProps
|
|
359
368
|
});
|
|
360
369
|
useEffect(() => {
|
|
361
370
|
if (isOpen && !isMenuOpen) {
|
|
@@ -466,7 +475,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
466
475
|
ref: autoAlign ? refs.setFloating : null
|
|
467
476
|
}, {
|
|
468
477
|
suppressRefError: true
|
|
469
|
-
}), [autoAlign]);
|
|
478
|
+
}), [autoAlign, getMenuProps, refs.setFloating]);
|
|
470
479
|
const handleFocus = evt => {
|
|
471
480
|
if (evt?.target.classList.contains(`${prefix}--tag__close-icon`) || evt?.target.classList.contains(`${prefix}--list-box__selection`)) {
|
|
472
481
|
setIsFocused(false);
|
|
@@ -613,7 +622,10 @@ FilterableMultiSelect.propTypes = {
|
|
|
613
622
|
*/
|
|
614
623
|
disabled: PropTypes.bool,
|
|
615
624
|
/**
|
|
616
|
-
* Additional props passed to Downshift
|
|
625
|
+
* Additional props passed to Downshift. Use with caution: anything you define
|
|
626
|
+
* here overrides the components' internal handling of that prop. Downshift
|
|
627
|
+
* internals are subject to change, and in some cases they can not be shimmed
|
|
628
|
+
* to shield you from potentially breaking changes.
|
|
617
629
|
*/
|
|
618
630
|
// @ts-ignore
|
|
619
631
|
downshiftProps: PropTypes.shape(Downshift.propTypes),
|
|
@@ -9,11 +9,11 @@ import React, { ReactNode } from 'react';
|
|
|
9
9
|
import { ListBoxSize, ListBoxType } from '../ListBox';
|
|
10
10
|
import { MultiSelectSortingProps } from './MultiSelectPropTypes';
|
|
11
11
|
import { ListBoxProps } from '../ListBox/ListBox';
|
|
12
|
-
import type {
|
|
12
|
+
import type { TranslateWithId } from '../../types/common';
|
|
13
13
|
interface OnChangeData<ItemType> {
|
|
14
14
|
selectedItems: ItemType[] | null;
|
|
15
15
|
}
|
|
16
|
-
export interface MultiSelectProps<ItemType> extends MultiSelectSortingProps<ItemType>,
|
|
16
|
+
export interface MultiSelectProps<ItemType> extends MultiSelectSortingProps<ItemType>, TranslateWithId<'close.menu' | 'open.menu' | 'clear.all' | 'clear.selection'> {
|
|
17
17
|
/**
|
|
18
18
|
* **Experimental**: Will attempt to automatically align the floating
|
|
19
19
|
* element to avoid collisions with the viewport and being clipped by
|
|
@@ -42,7 +42,10 @@ export interface MultiSelectProps<ItemType> extends MultiSelectSortingProps<Item
|
|
|
42
42
|
*/
|
|
43
43
|
disabled?: ListBoxProps['disabled'];
|
|
44
44
|
/**
|
|
45
|
-
* Additional props passed to Downshift
|
|
45
|
+
* Additional props passed to Downshift. Use with caution: anything you define
|
|
46
|
+
* here overrides the components' internal handling of that prop. Downshift
|
|
47
|
+
* internals are subject to change, and in some cases they can not be shimmed
|
|
48
|
+
* to shield you from potentially breaking changes.
|
|
46
49
|
*/
|
|
47
50
|
downshiftProps?: Partial<UseSelectProps<ItemType>>;
|
|
48
51
|
/**
|
|
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
|
|
|
9
9
|
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
|
|
10
10
|
import cx from 'classnames';
|
|
11
11
|
import { useSelect } from 'downshift';
|
|
12
|
-
import isEqual from '
|
|
12
|
+
import isEqual from 'react-fast-compare';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import React__default, { useContext, useState, useLayoutEffect, useMemo } from 'react';
|
|
15
15
|
import ListBox from '../ListBox/index.js';
|
|
@@ -166,7 +166,6 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
166
166
|
});
|
|
167
167
|
}, [items]);
|
|
168
168
|
const selectProps = {
|
|
169
|
-
...downshiftProps,
|
|
170
169
|
stateReducer,
|
|
171
170
|
isOpen,
|
|
172
171
|
itemToString: filteredItems => {
|
|
@@ -178,7 +177,8 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
178
177
|
items: filteredItems,
|
|
179
178
|
isItemDisabled(item, _index) {
|
|
180
179
|
return item.disabled;
|
|
181
|
-
}
|
|
180
|
+
},
|
|
181
|
+
...downshiftProps
|
|
182
182
|
};
|
|
183
183
|
const {
|
|
184
184
|
getToggleButtonProps,
|
|
@@ -518,7 +518,10 @@ MultiSelect.propTypes = {
|
|
|
518
518
|
*/
|
|
519
519
|
disabled: PropTypes.bool,
|
|
520
520
|
/**
|
|
521
|
-
* Additional props passed to Downshift
|
|
521
|
+
* Additional props passed to Downshift. Use with caution: anything you define
|
|
522
|
+
* here overrides the components' internal handling of that prop. Downshift
|
|
523
|
+
* internals are subject to change, and in some cases they can not be shimmed
|
|
524
|
+
* to shield you from potentially breaking changes.
|
|
522
525
|
*/
|
|
523
526
|
downshiftProps: PropTypes.object,
|
|
524
527
|
/**
|
|
@@ -5,12 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { ReactNode } from 'react';
|
|
8
|
+
import { TranslateWithId } from '../../types/common';
|
|
8
9
|
export declare const translationIds: {
|
|
9
|
-
'increment.number':
|
|
10
|
-
'decrement.number':
|
|
10
|
+
readonly 'increment.number': "increment.number";
|
|
11
|
+
readonly 'decrement.number': "decrement.number";
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Message ids that will be passed to translateWithId().
|
|
15
|
+
*/
|
|
16
|
+
type TranslationKey = keyof typeof translationIds;
|
|
12
17
|
type ExcludedAttributes = 'defaultValue' | 'id' | 'min' | 'max' | 'onChange' | 'onClick' | 'size' | 'step' | 'value';
|
|
13
|
-
export interface NumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
|
|
18
|
+
export interface NumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes>, TranslateWithId<TranslationKey> {
|
|
14
19
|
/**
|
|
15
20
|
* `true` to allow empty string.
|
|
16
21
|
*/
|
|
@@ -115,10 +120,6 @@ export interface NumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInp
|
|
|
115
120
|
* Specify how much the values should increase/decrease upon clicking on up/down button
|
|
116
121
|
*/
|
|
117
122
|
step?: number;
|
|
118
|
-
/**
|
|
119
|
-
* Provide custom text for the component for each translation id
|
|
120
|
-
*/
|
|
121
|
-
translateWithId?: (id: string) => string;
|
|
122
123
|
/**
|
|
123
124
|
* Specify the value of the input
|
|
124
125
|
*/
|
|
@@ -24,6 +24,11 @@ const translationIds = {
|
|
|
24
24
|
'increment.number': 'increment.number',
|
|
25
25
|
'decrement.number': 'decrement.number'
|
|
26
26
|
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Message ids that will be passed to translateWithId().
|
|
30
|
+
*/
|
|
31
|
+
|
|
27
32
|
const defaultTranslations = {
|
|
28
33
|
[translationIds['increment.number']]: 'Increment number',
|
|
29
34
|
[translationIds['decrement.number']]: 'Decrement number'
|
|
@@ -5,7 +5,19 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
|
|
8
|
+
import { TranslateWithId } from '../../types/common';
|
|
9
|
+
declare const translationIds: {
|
|
10
|
+
readonly 'carbon.pagination-nav.next': "Next";
|
|
11
|
+
readonly 'carbon.pagination-nav.previous': "Previous";
|
|
12
|
+
readonly 'carbon.pagination-nav.item': "Page";
|
|
13
|
+
readonly 'carbon.pagination-nav.active': "Active";
|
|
14
|
+
readonly 'carbon.pagination-nav.of': "of";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Message ids that will be passed to translateWithId().
|
|
18
|
+
*/
|
|
19
|
+
type TranslationKey = keyof typeof translationIds;
|
|
20
|
+
interface PaginationNavProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'>, TranslateWithId<TranslationKey> {
|
|
9
21
|
/**
|
|
10
22
|
* Additional CSS class names.
|
|
11
23
|
*/
|
|
@@ -35,11 +47,6 @@ interface PaginationNavProps extends Omit<React.HTMLAttributes<HTMLElement>, 'on
|
|
|
35
47
|
* The total number of items.
|
|
36
48
|
*/
|
|
37
49
|
totalItems?: number;
|
|
38
|
-
/**
|
|
39
|
-
* Specify a custom translation function that takes in a message identifier
|
|
40
|
-
* and returns the localized string for the message
|
|
41
|
-
*/
|
|
42
|
-
translateWithId?: (id: string) => string;
|
|
43
50
|
}
|
|
44
51
|
declare const PaginationNav: React.ForwardRefExoticComponent<PaginationNavProps & React.RefAttributes<HTMLElement>>;
|
|
45
52
|
export default PaginationNav;
|
|
@@ -21,6 +21,11 @@ const translationIds = {
|
|
|
21
21
|
'carbon.pagination-nav.active': 'Active',
|
|
22
22
|
'carbon.pagination-nav.of': 'of'
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Message ids that will be passed to translateWithId().
|
|
27
|
+
*/
|
|
28
|
+
|
|
24
29
|
function translateWithId(messageId) {
|
|
25
30
|
return translationIds[messageId];
|
|
26
31
|
}
|
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import React from 'react';
|
|
9
|
+
import { TranslateWithId } from '../../types/common';
|
|
10
|
+
declare const defaultTranslations: {
|
|
11
|
+
readonly 'carbon.progress-step.complete': "Complete";
|
|
12
|
+
readonly 'carbon.progress-step.incomplete': "Incomplete";
|
|
13
|
+
readonly 'carbon.progress-step.current': "Current";
|
|
14
|
+
readonly 'carbon.progress-step.invalid': "Invalid";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Message ids that will be passed to translateWithId().
|
|
18
|
+
*/
|
|
19
|
+
type TranslationKey = keyof typeof defaultTranslations;
|
|
9
20
|
export interface ProgressIndicatorProps extends Omit<React.HTMLAttributes<HTMLUListElement>, 'onChange'> {
|
|
10
21
|
/**
|
|
11
22
|
* Provide `<ProgressStep>` components to be rendered in the
|
|
@@ -63,7 +74,7 @@ declare namespace ProgressIndicator {
|
|
|
63
74
|
vertical: PropTypes.Requireable<boolean>;
|
|
64
75
|
};
|
|
65
76
|
}
|
|
66
|
-
export interface ProgressStepProps {
|
|
77
|
+
export interface ProgressStepProps extends TranslateWithId<TranslationKey> {
|
|
67
78
|
/**
|
|
68
79
|
* Provide an optional className to be applied to the containing `<li>` node
|
|
69
80
|
*/
|
|
@@ -112,11 +123,6 @@ export interface ProgressStepProps {
|
|
|
112
123
|
* The ID of the tooltip content.
|
|
113
124
|
*/
|
|
114
125
|
tooltipId?: string;
|
|
115
|
-
/**
|
|
116
|
-
* Optional method that takes in a message id and returns an
|
|
117
|
-
* internationalized string.
|
|
118
|
-
*/
|
|
119
|
-
translateWithId?: (id: string) => string;
|
|
120
126
|
}
|
|
121
127
|
declare function ProgressStep({ label, description, className, current, complete, invalid, secondaryLabel, disabled, onClick, translateWithId: t, ...rest }: ProgressStepProps): import("react/jsx-runtime").JSX.Element;
|
|
122
128
|
declare namespace ProgressStep {
|
|
@@ -22,6 +22,11 @@ const defaultTranslations = {
|
|
|
22
22
|
'carbon.progress-step.current': 'Current',
|
|
23
23
|
'carbon.progress-step.invalid': 'Invalid'
|
|
24
24
|
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Message ids that will be passed to translateWithId().
|
|
28
|
+
*/
|
|
29
|
+
|
|
25
30
|
function translateWithId(messageId) {
|
|
26
31
|
return defaultTranslations[messageId];
|
|
27
32
|
}
|
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React, { type KeyboardEventHandler, PureComponent, ReactNode } from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
|
+
import { TranslateWithId } from '../../types/common';
|
|
10
|
+
declare const translationIds: {
|
|
11
|
+
readonly autoCorrectAnnouncement: "carbon.slider.auto-correct-announcement";
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Message ids that will be passed to translateWithId().
|
|
15
|
+
*/
|
|
16
|
+
type TranslationKey = (typeof translationIds)[keyof typeof translationIds];
|
|
9
17
|
/**
|
|
10
18
|
* Distinguish two handles by lower and upper positions.
|
|
11
19
|
*/
|
|
@@ -14,7 +22,9 @@ declare enum HandlePosition {
|
|
|
14
22
|
UPPER = "upper"
|
|
15
23
|
}
|
|
16
24
|
type ExcludedAttributes = 'onChange' | 'onBlur';
|
|
17
|
-
export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes
|
|
25
|
+
export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes>, TranslateWithId<TranslationKey, {
|
|
26
|
+
correctedValue?: string;
|
|
27
|
+
}> {
|
|
18
28
|
/**
|
|
19
29
|
* The `ariaLabel` for the `<input>`.
|
|
20
30
|
*/
|
|
@@ -136,14 +146,6 @@ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
|
|
|
136
146
|
* which will be `(max - min) / stepMultiplier`.
|
|
137
147
|
*/
|
|
138
148
|
stepMultiplier?: number;
|
|
139
|
-
/**
|
|
140
|
-
* Supply a method to translate internal strings with your i18n tool of
|
|
141
|
-
* choice. Translation keys are available on the `translationIds` field for
|
|
142
|
-
* this component.
|
|
143
|
-
*/
|
|
144
|
-
translateWithId?: (translationId: string, translationState: {
|
|
145
|
-
correctedValue?: string;
|
|
146
|
-
}) => string;
|
|
147
149
|
/**
|
|
148
150
|
* The value of the slider. When there are two handles, value is the lower
|
|
149
151
|
* bound.
|
|
@@ -72,8 +72,13 @@ ThumbWrapper.propTypes = {
|
|
|
72
72
|
const translationIds = {
|
|
73
73
|
autoCorrectAnnouncement: 'carbon.slider.auto-correct-announcement'
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Message ids that will be passed to translateWithId().
|
|
78
|
+
*/
|
|
79
|
+
|
|
75
80
|
function translateWithId(translationId, translationState) {
|
|
76
|
-
if (
|
|
81
|
+
if (translationState?.correctedValue) {
|
|
77
82
|
const {
|
|
78
83
|
correctedValue
|
|
79
84
|
} = translationState;
|
package/es/internal/Selection.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { defineProperty as _defineProperty } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import React__default, { useRef, useState, useCallback, useEffect } from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
|
-
import isEqual from '
|
|
11
|
+
import isEqual from 'react-fast-compare';
|
|
12
12
|
|
|
13
13
|
function callOnChangeHandler(_ref) {
|
|
14
14
|
let {
|
package/es/internal/useId.js
CHANGED
|
@@ -10,49 +10,70 @@ import setupGetInstanceId from '../tools/setupGetInstanceId.js';
|
|
|
10
10
|
import { canUseDOM } from './environment.js';
|
|
11
11
|
import { useIdPrefix } from './useIdPrefix.js';
|
|
12
12
|
|
|
13
|
-
// This file was heavily inspired by
|
|
14
|
-
|
|
13
|
+
// This file was heavily inspired by:
|
|
14
|
+
|
|
15
|
+
// This tricks bundlers so they can't statically analyze this and produce
|
|
16
|
+
// compilation warnings/errors.
|
|
17
|
+
// https://github.com/webpack/webpack/issues/14814
|
|
18
|
+
// https://github.com/mui/material-ui/issues/41190
|
|
19
|
+
const _React = {
|
|
20
|
+
...React__default
|
|
21
|
+
};
|
|
22
|
+
const instanceId = setupGetInstanceId();
|
|
15
23
|
const useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
|
|
16
24
|
let serverHandoffCompleted = false;
|
|
25
|
+
const defaultId = 'id';
|
|
17
26
|
|
|
18
27
|
/**
|
|
19
|
-
* Generate a unique ID with an optional prefix prepended to it
|
|
28
|
+
* Generate a unique ID for React <=17 with an optional prefix prepended to it.
|
|
29
|
+
* This is an internal utility, not intended for public usage.
|
|
20
30
|
* @param {string} [prefix]
|
|
21
31
|
* @returns {string}
|
|
22
32
|
*/
|
|
23
|
-
function
|
|
24
|
-
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
25
|
-
const
|
|
33
|
+
function useCompatibleId() {
|
|
34
|
+
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultId;
|
|
35
|
+
const contextPrefix = useIdPrefix();
|
|
26
36
|
const [id, setId] = useState(() => {
|
|
27
37
|
if (serverHandoffCompleted) {
|
|
28
|
-
return `${
|
|
38
|
+
return `${contextPrefix ? `${contextPrefix}-` : ``}${prefix}-${instanceId()}`;
|
|
29
39
|
}
|
|
30
40
|
return null;
|
|
31
41
|
});
|
|
32
42
|
useIsomorphicLayoutEffect(() => {
|
|
33
43
|
if (id === null) {
|
|
34
|
-
setId(`${
|
|
44
|
+
setId(`${contextPrefix ? `${contextPrefix}-` : ``}${prefix}-${instanceId()}`);
|
|
35
45
|
}
|
|
36
|
-
}, [
|
|
46
|
+
}, [instanceId]);
|
|
37
47
|
useEffect(() => {
|
|
38
48
|
if (serverHandoffCompleted === false) {
|
|
39
49
|
serverHandoffCompleted = true;
|
|
40
50
|
}
|
|
41
51
|
}, []);
|
|
42
|
-
if (typeof React__default['useId'] === 'function') {
|
|
43
|
-
const id = nativeReactUseId(_prefix, prefix);
|
|
44
|
-
return id;
|
|
45
|
-
}
|
|
46
52
|
return id;
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generate a unique ID for React >=18 with an optional prefix prepended to it.
|
|
57
|
+
* This is an internal utility, not intended for public usage.
|
|
58
|
+
* @param {string} [prefix]
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
function useReactId() {
|
|
62
|
+
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultId;
|
|
63
|
+
const contextPrefix = useIdPrefix();
|
|
64
|
+
return `${contextPrefix ? `${contextPrefix}-` : ``}${prefix}-${_React.useId()}`;
|
|
52
65
|
}
|
|
53
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Uses React 18's built-in `useId()` when available, or falls back to a
|
|
69
|
+
* slightly less performant (requiring a double render) implementation for
|
|
70
|
+
* earlier React versions.
|
|
71
|
+
*/
|
|
72
|
+
const useId = _React.useId ? useReactId : useCompatibleId;
|
|
73
|
+
|
|
54
74
|
/**
|
|
55
75
|
* Generate a unique id if a given `id` is not provided
|
|
76
|
+
* This is an internal utility, not intended for public usage.
|
|
56
77
|
* @param {string|undefined} id
|
|
57
78
|
* @returns {string}
|
|
58
79
|
*/
|
|
@@ -61,4 +82,4 @@ function useFallbackId(id) {
|
|
|
61
82
|
return id ?? fallback;
|
|
62
83
|
}
|
|
63
84
|
|
|
64
|
-
export { useFallbackId, useId };
|
|
85
|
+
export { useCompatibleId, useFallbackId, useId };
|
package/es/types/common.d.ts
CHANGED
|
@@ -9,10 +9,15 @@ export type ForwardRefReturn<T, P = unknown> = React.ForwardRefExoticComponent<F
|
|
|
9
9
|
export type PolymorphicProps<Element extends React.ElementType, Props> = Props & Omit<React.ComponentProps<Element>, 'as'> & {
|
|
10
10
|
as?: Element;
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
12
|
+
export interface TranslateWithId<MID = string, ARGS = Record<string, unknown>> {
|
|
13
13
|
/**
|
|
14
14
|
* Supply a method to translate internal strings with your i18n tool of
|
|
15
15
|
* choice.
|
|
16
16
|
*/
|
|
17
17
|
translateWithId?(messageId: MID, args?: ARGS): string;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Alias of TranslateWithId. Will be removed in v12
|
|
21
|
+
* @deprecated Use TranslateWithId instead
|
|
22
|
+
*/
|
|
23
|
+
export type InternationalProps<MID = string, ARGS = Record<string, unknown>> = TranslateWithId<MID, ARGS>;
|
|
@@ -7,13 +7,22 @@
|
|
|
7
7
|
import { UseComboboxProps } from 'downshift';
|
|
8
8
|
import { type ReactNode, type ComponentType, type ReactElement, type RefAttributes, type PropsWithChildren, type PropsWithRef, type InputHTMLAttributes, type MouseEvent } from 'react';
|
|
9
9
|
import { ListBoxSize } from '../ListBox';
|
|
10
|
+
import { TranslateWithId } from '../../types/common';
|
|
10
11
|
type ExcludedAttributes = 'id' | 'onChange' | 'onClick' | 'type' | 'size';
|
|
11
12
|
interface OnChangeData<ItemType> {
|
|
12
13
|
selectedItem: ItemType | null | undefined;
|
|
13
14
|
inputValue?: string | null;
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Message ids that will be passed to translateWithId().
|
|
18
|
+
* Combination of message ids from ListBox/next/ListBoxSelection.js and
|
|
19
|
+
* ListBox/next/ListBoxTrigger.js, but we can't access those values directly
|
|
20
|
+
* because those components aren't Typescript. (If you try, TranslationKey
|
|
21
|
+
* ends up just being defined as "string".)
|
|
22
|
+
*/
|
|
23
|
+
type TranslationKey = 'close.menu' | 'open.menu' | 'clear.all' | 'clear.selection';
|
|
15
24
|
type ItemToStringHandler<ItemType> = (item: ItemType | null) => string;
|
|
16
|
-
export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
|
|
25
|
+
export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes>, TranslateWithId<TranslationKey> {
|
|
17
26
|
/**
|
|
18
27
|
* Specify whether or not the ComboBox should allow a value that is
|
|
19
28
|
* not in the list to be entered in the input
|
|
@@ -48,7 +57,10 @@ export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLIn
|
|
|
48
57
|
*/
|
|
49
58
|
disabled?: boolean;
|
|
50
59
|
/**
|
|
51
|
-
* Additional props passed to Downshift
|
|
60
|
+
* Additional props passed to Downshift. Use with caution: anything you define
|
|
61
|
+
* here overrides the components' internal handling of that prop. Downshift
|
|
62
|
+
* internals are subject to change, and in some cases they can not be shimmed
|
|
63
|
+
* to shield you from potentially breaking changes.
|
|
52
64
|
*/
|
|
53
65
|
downshiftProps?: Partial<UseComboboxProps<ItemType>>;
|
|
54
66
|
/**
|
|
@@ -150,11 +162,6 @@ export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLIn
|
|
|
150
162
|
* combobox via ARIA attributes.
|
|
151
163
|
*/
|
|
152
164
|
titleText?: ReactNode;
|
|
153
|
-
/**
|
|
154
|
-
* Specify a custom translation function that takes in a message identifier
|
|
155
|
-
* and returns the localized string for the message
|
|
156
|
-
*/
|
|
157
|
-
translateWithId?: (id: string) => string;
|
|
158
165
|
/**
|
|
159
166
|
* Specify whether the control is currently in warning state
|
|
160
167
|
*/
|
|
@@ -92,6 +92,15 @@ const findHighlightedIndex = (_ref2, inputValue) => {
|
|
|
92
92
|
}
|
|
93
93
|
return -1;
|
|
94
94
|
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Message ids that will be passed to translateWithId().
|
|
98
|
+
* Combination of message ids from ListBox/next/ListBoxSelection.js and
|
|
99
|
+
* ListBox/next/ListBoxTrigger.js, but we can't access those values directly
|
|
100
|
+
* because those components aren't Typescript. (If you try, TranslationKey
|
|
101
|
+
* ends up just being defined as "string".)
|
|
102
|
+
*/
|
|
103
|
+
|
|
95
104
|
const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
96
105
|
const {
|
|
97
106
|
['aria-label']: ariaLabel = 'Choose an item',
|
|
@@ -330,7 +339,6 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
330
339
|
toggleMenu,
|
|
331
340
|
setHighlightedIndex
|
|
332
341
|
} = Downshift.useCombobox({
|
|
333
|
-
...downshiftProps,
|
|
334
342
|
items: filterItems(items, itemToString, inputValue),
|
|
335
343
|
inputValue: inputValue,
|
|
336
344
|
itemToString: item => {
|
|
@@ -351,12 +359,28 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
351
359
|
selectedItem
|
|
352
360
|
});
|
|
353
361
|
},
|
|
362
|
+
onHighlightedIndexChange: _ref5 => {
|
|
363
|
+
let {
|
|
364
|
+
highlightedIndex
|
|
365
|
+
} = _ref5;
|
|
366
|
+
if (highlightedIndex > -1 && typeof window !== undefined) {
|
|
367
|
+
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
368
|
+
const highlightedItem = itemArray[highlightedIndex];
|
|
369
|
+
if (highlightedItem) {
|
|
370
|
+
highlightedItem.scrollIntoView({
|
|
371
|
+
behavior: 'smooth',
|
|
372
|
+
block: 'nearest'
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
},
|
|
354
377
|
initialSelectedItem: initialSelectedItem,
|
|
355
378
|
inputId: id,
|
|
356
379
|
stateReducer,
|
|
357
380
|
isItemDisabled(item, _index) {
|
|
358
381
|
return item.disabled;
|
|
359
|
-
}
|
|
382
|
+
},
|
|
383
|
+
...downshiftProps
|
|
360
384
|
});
|
|
361
385
|
const buttonProps = getToggleButtonProps({
|
|
362
386
|
disabled: disabled || readOnly,
|
|
@@ -397,7 +421,7 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
397
421
|
const menuProps = React.useMemo(() => getMenuProps({
|
|
398
422
|
'aria-label': deprecatedAriaLabel || ariaLabel,
|
|
399
423
|
ref: autoAlign ? refs.setFloating : null
|
|
400
|
-
}), [autoAlign, deprecatedAriaLabel, ariaLabel]);
|
|
424
|
+
}), [autoAlign, deprecatedAriaLabel, ariaLabel, getMenuProps, refs.setFloating]);
|
|
401
425
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
402
426
|
className: wrapperClasses
|
|
403
427
|
}, titleText && /*#__PURE__*/React__default["default"].createElement(Text.Text, _rollupPluginBabelHelpers["extends"]({
|
|
@@ -572,7 +596,10 @@ ComboBox.propTypes = {
|
|
|
572
596
|
*/
|
|
573
597
|
disabled: PropTypes__default["default"].bool,
|
|
574
598
|
/**
|
|
575
|
-
* Additional props passed to Downshift
|
|
599
|
+
* Additional props passed to Downshift. Use with caution: anything you define
|
|
600
|
+
* here overrides the components' internal handling of that prop. Downshift
|
|
601
|
+
* internals are subject to change, and in some cases they can not be shimmed
|
|
602
|
+
* to shield you from potentially breaking changes.
|
|
576
603
|
*/
|
|
577
604
|
downshiftProps: PropTypes__default["default"].object,
|
|
578
605
|
/**
|
|
@@ -9,7 +9,15 @@ import { IconButton } from '../IconButton';
|
|
|
9
9
|
import Button from '../Button';
|
|
10
10
|
import { Menu } from '../Menu';
|
|
11
11
|
import { MenuAlignment } from '../MenuButton';
|
|
12
|
-
|
|
12
|
+
import { TranslateWithId } from '../../types/common';
|
|
13
|
+
declare const defaultTranslations: {
|
|
14
|
+
'carbon.combo-button.additional-actions': string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Message ids that will be passed to translateWithId().
|
|
18
|
+
*/
|
|
19
|
+
type TranslationKey = keyof typeof defaultTranslations;
|
|
20
|
+
interface ComboButtonProps extends TranslateWithId<TranslationKey> {
|
|
13
21
|
/**
|
|
14
22
|
* A collection of `MenuItems` to be rendered as additional actions for this `ComboButton`.
|
|
15
23
|
*/
|
|
@@ -42,11 +50,6 @@ interface ComboButtonProps {
|
|
|
42
50
|
* Specify how the trigger tooltip should be aligned.
|
|
43
51
|
*/
|
|
44
52
|
tooltipAlignment?: React.ComponentProps<typeof IconButton>['align'];
|
|
45
|
-
/**
|
|
46
|
-
* Optional method that takes in a message `id` and returns an
|
|
47
|
-
* internationalized string.
|
|
48
|
-
*/
|
|
49
|
-
translateWithId?: (id: string) => string;
|
|
50
53
|
}
|
|
51
54
|
declare const ComboButton: React.ForwardRefExoticComponent<ComboButtonProps & React.RefAttributes<HTMLDivElement>>;
|
|
52
55
|
export { ComboButton, type ComboButtonProps };
|
|
@@ -35,6 +35,11 @@ var _ChevronDown;
|
|
|
35
35
|
const defaultTranslations = {
|
|
36
36
|
'carbon.combo-button.additional-actions': 'Additional actions'
|
|
37
37
|
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Message ids that will be passed to translateWithId().
|
|
41
|
+
*/
|
|
42
|
+
|
|
38
43
|
function defaultTranslateWithId(messageId) {
|
|
39
44
|
return defaultTranslations[messageId];
|
|
40
45
|
}
|