@carbon/react 1.62.1 → 1.63.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 +836 -836
- package/es/components/Checkbox/Checkbox.js +2 -3
- package/es/components/CheckboxGroup/CheckboxGroup.js +2 -3
- package/es/components/ComboBox/ComboBox.d.ts +10 -6
- package/es/components/ComboBox/ComboBox.js +14 -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 +6 -1
- package/es/components/DataTable/TableBatchActions.d.ts +2 -2
- package/es/components/DataTable/TableHeader.d.ts +7 -13
- package/es/components/DataTable/TableSelectRow.js +3 -2
- package/es/components/DataTable/TableToolbarSearch.d.ts +5 -2
- package/es/components/DataTable/TableToolbarSearch.js +7 -4
- package/es/components/DatePickerInput/DatePickerInput.js +2 -3
- package/es/components/Dropdown/Dropdown.d.ts +2 -6
- package/es/components/Dropdown/Dropdown.js +3 -6
- package/es/components/FluidSearch/FluidSearch.Skeleton.js +40 -0
- package/es/components/FluidSearch/FluidSearch.js +96 -0
- 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/Modal/Modal.js +2 -3
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +10 -5
- package/es/components/MultiSelect/FilterableMultiSelect.js +20 -8
- package/es/components/MultiSelect/MultiSelect.d.ts +2 -2
- package/es/components/MultiSelect/MultiSelect.js +11 -11
- package/es/components/NumberInput/NumberInput.d.ts +8 -7
- package/es/components/NumberInput/NumberInput.js +5 -0
- package/es/components/Pagination/experimental/PageSelector.js +2 -3
- 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/RadioButtonGroup/RadioButtonGroup.js +2 -5
- package/es/components/Select/Select.js +3 -6
- package/es/components/Slider/Slider.d.ts +11 -9
- package/es/components/Slider/Slider.js +6 -1
- package/es/components/Tag/DismissibleTag.js +2 -3
- package/es/components/Tag/OperationalTag.js +2 -3
- package/es/components/Tag/SelectableTag.js +2 -3
- package/es/components/Tag/Tag.js +3 -5
- package/es/components/TextArea/TextArea.js +32 -6
- package/es/components/TextInput/ControlledPasswordInput.js +3 -6
- package/es/components/TextInput/TextInput.js +29 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -0
- package/es/internal/Selection.js +1 -1
- package/es/internal/useAnnouncer.js +8 -3
- package/es/types/common.d.ts +6 -1
- package/lib/components/Checkbox/Checkbox.js +2 -3
- package/lib/components/CheckboxGroup/CheckboxGroup.js +2 -3
- package/lib/components/ComboBox/ComboBox.d.ts +10 -6
- package/lib/components/ComboBox/ComboBox.js +14 -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 +6 -1
- package/lib/components/DataTable/TableBatchActions.d.ts +2 -2
- package/lib/components/DataTable/TableHeader.d.ts +7 -13
- package/lib/components/DataTable/TableSelectRow.js +2 -1
- package/lib/components/DataTable/TableToolbarSearch.d.ts +5 -2
- package/lib/components/DataTable/TableToolbarSearch.js +6 -3
- package/lib/components/DatePickerInput/DatePickerInput.js +2 -3
- package/lib/components/Dropdown/Dropdown.d.ts +2 -6
- package/lib/components/Dropdown/Dropdown.js +2 -5
- package/lib/components/FluidSearch/FluidSearch.Skeleton.js +50 -0
- package/lib/components/FluidSearch/FluidSearch.js +106 -0
- 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/Modal/Modal.js +2 -3
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +10 -5
- package/lib/components/MultiSelect/FilterableMultiSelect.js +19 -7
- package/lib/components/MultiSelect/MultiSelect.d.ts +2 -2
- package/lib/components/MultiSelect/MultiSelect.js +10 -10
- package/lib/components/NumberInput/NumberInput.d.ts +8 -7
- package/lib/components/NumberInput/NumberInput.js +5 -0
- package/lib/components/Pagination/experimental/PageSelector.js +2 -3
- 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/RadioButtonGroup/RadioButtonGroup.js +2 -5
- package/lib/components/Select/Select.js +2 -5
- package/lib/components/Slider/Slider.d.ts +11 -9
- package/lib/components/Slider/Slider.js +6 -1
- package/lib/components/Tag/DismissibleTag.js +2 -3
- package/lib/components/Tag/OperationalTag.js +2 -3
- package/lib/components/Tag/SelectableTag.js +2 -3
- package/lib/components/Tag/Tag.js +3 -5
- package/lib/components/TextArea/TextArea.js +32 -6
- package/lib/components/TextInput/ControlledPasswordInput.js +2 -5
- package/lib/components/TextInput/TextInput.js +28 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/internal/Selection.js +1 -1
- package/lib/internal/useAnnouncer.js +8 -3
- package/lib/types/common.d.ts +6 -1
- package/package.json +18 -18
|
@@ -13,6 +13,7 @@ import { usePrefix } from '../../internal/usePrefix.js';
|
|
|
13
13
|
|
|
14
14
|
const FormGroup = _ref => {
|
|
15
15
|
let {
|
|
16
|
+
disabled = false,
|
|
16
17
|
legendId,
|
|
17
18
|
legendText,
|
|
18
19
|
invalid = false,
|
|
@@ -24,7 +25,9 @@ const FormGroup = _ref => {
|
|
|
24
25
|
} = _ref;
|
|
25
26
|
const prefix = usePrefix();
|
|
26
27
|
const classNamesFieldset = cx(`${prefix}--fieldset`, className);
|
|
27
|
-
return /*#__PURE__*/React__default.createElement("fieldset", _extends({
|
|
28
|
+
return /*#__PURE__*/React__default.createElement("fieldset", _extends({
|
|
29
|
+
disabled: disabled
|
|
30
|
+
}, invalid && {
|
|
28
31
|
'data-invalid': ''
|
|
29
32
|
}, {
|
|
30
33
|
className: classNamesFieldset
|
|
@@ -46,6 +49,10 @@ FormGroup.propTypes = {
|
|
|
46
49
|
* Provide a custom className to be applied to the containing <fieldset> node
|
|
47
50
|
*/
|
|
48
51
|
className: PropTypes.string,
|
|
52
|
+
/**
|
|
53
|
+
* Specify whether the FormGroup should be disabled
|
|
54
|
+
*/
|
|
55
|
+
disabled: PropTypes.bool,
|
|
49
56
|
/**
|
|
50
57
|
* Specify whether the <FormGroup> is invalid
|
|
51
58
|
*/
|
|
@@ -5,19 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import { TranslateWithId } from '../../types/common';
|
|
8
9
|
export type ListBoxMenuIconTranslationKey = 'close.menu' | 'open.menu';
|
|
9
|
-
export interface ListBoxMenuIconProps {
|
|
10
|
+
export interface ListBoxMenuIconProps extends TranslateWithId<ListBoxMenuIconTranslationKey> {
|
|
10
11
|
/**
|
|
11
12
|
* Specify whether the menu is currently open, which will influence the
|
|
12
13
|
* direction of the menu icon
|
|
13
14
|
*/
|
|
14
15
|
isOpen: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* i18n hook used to provide the appropriate description for the given menu
|
|
17
|
-
* icon. This function takes in a ListBoxMenuIconTranslationKey and should
|
|
18
|
-
* return a string message for that given message id.
|
|
19
|
-
*/
|
|
20
|
-
translateWithId?(messageId: ListBoxMenuIconTranslationKey, args?: Record<string, unknown>): string;
|
|
21
16
|
}
|
|
22
17
|
export type ListBoxMenuIconComponent = React.FC<ListBoxMenuIconProps>;
|
|
23
18
|
/**
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { KeyboardEvent, MouseEvent } from 'react';
|
|
9
|
-
|
|
9
|
+
import { TranslateWithId } from '../../types/common';
|
|
10
|
+
export interface ListBoxSelectionProps extends TranslateWithId<TranslationKey> {
|
|
10
11
|
/**
|
|
11
12
|
* Specify a function to be invoked when a user interacts with the clear
|
|
12
13
|
* selection element.
|
|
@@ -30,18 +31,16 @@ export interface ListBoxSelectionProps {
|
|
|
30
31
|
* whether the selection should display a badge or a single clear icon.
|
|
31
32
|
*/
|
|
32
33
|
selectionCount?: number;
|
|
33
|
-
/**
|
|
34
|
-
* i18n hook used to provide the appropriate description for the given menu
|
|
35
|
-
* icon. This function takes in an id defined in `translationIds` and should
|
|
36
|
-
* return a string message for that given message id.
|
|
37
|
-
*/
|
|
38
|
-
translateWithId?(messageId: string, args?: Record<string, unknown>): string;
|
|
39
34
|
}
|
|
40
35
|
export type ListBoxSelectionComponent = React.FC<ListBoxSelectionProps>;
|
|
41
36
|
export declare const translationIds: {
|
|
42
|
-
'clear.all':
|
|
43
|
-
'clear.selection':
|
|
37
|
+
readonly 'clear.all': "clear.all";
|
|
38
|
+
readonly 'clear.selection': "clear.selection";
|
|
44
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Message ids that will be passed to translateWithId().
|
|
42
|
+
*/
|
|
43
|
+
type TranslationKey = keyof typeof translationIds;
|
|
45
44
|
/**
|
|
46
45
|
* `ListBoxSelection` is used to provide controls for clearing a selection, in
|
|
47
46
|
* addition to conditionally rendering a badge if the control has more than one
|
|
@@ -16,6 +16,11 @@ const translationIds = {
|
|
|
16
16
|
'clear.all': 'clear.all',
|
|
17
17
|
'clear.selection': 'clear.selection'
|
|
18
18
|
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Message ids that will be passed to translateWithId().
|
|
22
|
+
*/
|
|
23
|
+
|
|
19
24
|
const defaultTranslations = {
|
|
20
25
|
[translationIds['clear.all']]: 'Clear all selected items',
|
|
21
26
|
[translationIds['clear.selection']]: 'Clear selected item'
|
|
@@ -20,7 +20,7 @@ import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsT
|
|
|
20
20
|
import wrapFocus, { wrapFocusWithoutSentinels, elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
|
|
21
21
|
import debounce from 'lodash.debounce';
|
|
22
22
|
import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
|
|
23
|
-
import
|
|
23
|
+
import { useId } from '../../internal/useId.js';
|
|
24
24
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
25
25
|
import { IconButton } from '../IconButton/index.js';
|
|
26
26
|
import { noopFn } from '../../internal/noopFn.js';
|
|
@@ -31,7 +31,6 @@ import { Text } from '../Text/Text.js';
|
|
|
31
31
|
import { match } from '../../internal/keyboard/match.js';
|
|
32
32
|
import { Escape, Enter, Tab } from '../../internal/keyboard/keys.js';
|
|
33
33
|
|
|
34
|
-
const getInstanceId = setupGetInstanceId();
|
|
35
34
|
const ModalSizes = ['xs', 'sm', 'md', 'lg'];
|
|
36
35
|
const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
37
36
|
let {
|
|
@@ -76,7 +75,7 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
76
75
|
const startTrap = useRef(null);
|
|
77
76
|
const endTrap = useRef(null);
|
|
78
77
|
const [isScrollable, setIsScrollable] = useState(false);
|
|
79
|
-
const modalInstanceId = `modal-${
|
|
78
|
+
const modalInstanceId = `modal-${useId()}`;
|
|
80
79
|
const modalLabelId = `${prefix}--modal-header__label--${modalInstanceId}`;
|
|
81
80
|
const modalHeadingId = `${prefix}--modal-header__heading--${modalInstanceId}`;
|
|
82
81
|
const modalBodyId = `${prefix}--modal-body--${modalInstanceId}`;
|
|
@@ -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
|
|
@@ -154,10 +163,6 @@ export interface FilterableMultiSelectProps<ItemType> extends MultiSelectSorting
|
|
|
154
163
|
* combobox via ARIA attributes.
|
|
155
164
|
*/
|
|
156
165
|
titleText?: ReactNode;
|
|
157
|
-
/**
|
|
158
|
-
* Callback function for translating ListBoxMenuIcon SVG title
|
|
159
|
-
*/
|
|
160
|
-
translateWithId?(messageId: string, args?: Record<string, unknown>): string;
|
|
161
166
|
type?: 'default' | 'inline';
|
|
162
167
|
/**
|
|
163
168
|
* Specify title to show title on hover
|
|
@@ -9,9 +9,9 @@ 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
|
-
import React__default, { useContext, useState, useLayoutEffect, useRef, useEffect } from 'react';
|
|
14
|
+
import React__default, { useContext, useState, useLayoutEffect, useRef, useEffect, useMemo } from 'react';
|
|
15
15
|
import { defaultFilterItems } from '../ComboBox/tools/filter.js';
|
|
16
16
|
import { sortingPropTypes } from './MultiSelectPropTypes.js';
|
|
17
17
|
import ListBox from '../ListBox/index.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,
|
|
@@ -460,9 +469,13 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
460
469
|
setInputValue('');
|
|
461
470
|
}
|
|
462
471
|
}));
|
|
463
|
-
|
|
472
|
+
|
|
473
|
+
// Memoize the value of getMenuProps to avoid an infinite loop
|
|
474
|
+
const menuProps = useMemo(() => getMenuProps({
|
|
475
|
+
ref: autoAlign ? refs.setFloating : null
|
|
476
|
+
}, {
|
|
464
477
|
suppressRefError: true
|
|
465
|
-
});
|
|
478
|
+
}), [autoAlign, getMenuProps, refs.setFloating]);
|
|
466
479
|
const handleFocus = evt => {
|
|
467
480
|
if (evt?.target.classList.contains(`${prefix}--tag__close-icon`) || evt?.target.classList.contains(`${prefix}--list-box__selection`)) {
|
|
468
481
|
setIsFocused(false);
|
|
@@ -488,6 +501,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
488
501
|
disabled: disabled,
|
|
489
502
|
light: light,
|
|
490
503
|
ref: ref,
|
|
504
|
+
id: id,
|
|
491
505
|
invalid: invalid,
|
|
492
506
|
invalidText: invalidText,
|
|
493
507
|
warn: warn,
|
|
@@ -496,7 +510,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
496
510
|
size: size$1
|
|
497
511
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
498
512
|
className: `${prefix}--list-box__field`,
|
|
499
|
-
ref: refs.setReference
|
|
513
|
+
ref: autoAlign ? refs.setReference : null
|
|
500
514
|
}, controlledSelectedItems.length > 0 &&
|
|
501
515
|
/*#__PURE__*/
|
|
502
516
|
// @ts-expect-error: It is expecting a non-required prop called: "onClearSelection"
|
|
@@ -537,9 +551,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
537
551
|
// @ts-expect-error
|
|
538
552
|
isOpen: isOpen,
|
|
539
553
|
translateWithId: translateWithId
|
|
540
|
-
}))), normalizedSlug, /*#__PURE__*/React__default.createElement(ListBox.Menu,
|
|
541
|
-
ref: refs.setFloating
|
|
542
|
-
}), isOpen ? sortedItems.map((item, index) => {
|
|
554
|
+
}))), normalizedSlug, /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, isOpen ? sortedItems.map((item, index) => {
|
|
543
555
|
const isChecked = controlledSelectedItems.filter(selected => isEqual(selected, item)).length > 0;
|
|
544
556
|
const itemProps = getItemProps({
|
|
545
557
|
item,
|
|
@@ -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
|
|
@@ -9,14 +9,14 @@ 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
|
-
import React__default, { useContext,
|
|
14
|
+
import React__default, { useContext, useState, useLayoutEffect, useMemo } from 'react';
|
|
15
15
|
import ListBox from '../ListBox/index.js';
|
|
16
16
|
import { sortingPropTypes } from './MultiSelectPropTypes.js';
|
|
17
17
|
import { defaultSortItems, defaultCompareItems } from './tools/sorting.js';
|
|
18
18
|
import { useSelection } from '../../internal/Selection.js';
|
|
19
|
-
import
|
|
19
|
+
import { useId } from '../../internal/useId.js';
|
|
20
20
|
import mergeRefs from '../../tools/mergeRefs.js';
|
|
21
21
|
import deprecate from '../../prop-types/deprecate.js';
|
|
22
22
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
@@ -28,7 +28,6 @@ import { match } from '../../internal/keyboard/match.js';
|
|
|
28
28
|
import { ListBoxSize } from '../ListBox/ListBoxPropTypes.js';
|
|
29
29
|
import { Delete, Escape, Space, ArrowDown, Enter } from '../../internal/keyboard/keys.js';
|
|
30
30
|
|
|
31
|
-
const getInstanceId = setupGetInstanceId();
|
|
32
31
|
const {
|
|
33
32
|
ItemClick,
|
|
34
33
|
ToggleButtonBlur,
|
|
@@ -99,9 +98,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
99
98
|
const {
|
|
100
99
|
isFluid
|
|
101
100
|
} = useContext(FormContext);
|
|
102
|
-
const
|
|
103
|
-
current: multiSelectInstanceId
|
|
104
|
-
} = useRef(getInstanceId());
|
|
101
|
+
const multiSelectInstanceId = useId();
|
|
105
102
|
const [isFocused, setIsFocused] = useState(false);
|
|
106
103
|
const [inputFocused, setInputFocused] = useState(false);
|
|
107
104
|
const [isOpen, setIsOpen] = useState(open || false);
|
|
@@ -395,6 +392,11 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
395
392
|
});
|
|
396
393
|
}
|
|
397
394
|
const itemsSelectedText = selectedItems.length > 0 && selectedItems.map(item => item?.text);
|
|
395
|
+
|
|
396
|
+
// Memoize the value of getMenuProps to avoid an infinite loop
|
|
397
|
+
const menuProps = useMemo(() => getMenuProps({
|
|
398
|
+
ref: autoAlign ? refs.setFloating : null
|
|
399
|
+
}), [autoAlign]);
|
|
398
400
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
399
401
|
className: wrapperClasses
|
|
400
402
|
}, /*#__PURE__*/React__default.createElement("label", _extends({
|
|
@@ -421,7 +423,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
421
423
|
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
422
424
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
423
425
|
className: multiSelectFieldWrapperClasses,
|
|
424
|
-
ref: refs.setReference
|
|
426
|
+
ref: autoAlign ? refs.setReference : null
|
|
425
427
|
}, selectedItems.length > 0 && /*#__PURE__*/React__default.createElement(ListBox.Selection, {
|
|
426
428
|
readOnly: readOnly,
|
|
427
429
|
clearSelection: !disabled && !readOnly ? clearSelection : noopFn,
|
|
@@ -444,9 +446,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
444
446
|
}, label), /*#__PURE__*/React__default.createElement(ListBox.MenuIcon, {
|
|
445
447
|
isOpen: isOpen,
|
|
446
448
|
translateWithId: translateWithId
|
|
447
|
-
})), normalizedSlug), /*#__PURE__*/React__default.createElement(ListBox.Menu,
|
|
448
|
-
ref: refs.setFloating
|
|
449
|
-
}), isOpen &&
|
|
449
|
+
})), normalizedSlug), /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, isOpen &&
|
|
450
450
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
451
451
|
sortItems(filteredItems, sortOptions).map((item, index) => {
|
|
452
452
|
const isChecked = selectedItems.filter(selected => isEqual(selected, item)).length > 0;
|
|
@@ -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'
|
|
@@ -9,13 +9,12 @@ import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers
|
|
|
9
9
|
import React__default from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import cx from 'classnames';
|
|
12
|
-
import
|
|
12
|
+
import { useId } from '../../../internal/useId.js';
|
|
13
13
|
import Select from '../../Select/Select.js';
|
|
14
14
|
import '../../Select/Select.Skeleton.js';
|
|
15
15
|
import SelectItem from '../../SelectItem/SelectItem.js';
|
|
16
16
|
import { usePrefix } from '../../../internal/usePrefix.js';
|
|
17
17
|
|
|
18
|
-
const getInstanceId = setupGetInstanceId();
|
|
19
18
|
function PageSelector(_ref) {
|
|
20
19
|
let {
|
|
21
20
|
className = null,
|
|
@@ -27,7 +26,7 @@ function PageSelector(_ref) {
|
|
|
27
26
|
} = _ref;
|
|
28
27
|
const prefix = usePrefix();
|
|
29
28
|
const namespace = `${prefix}--unstable-pagination__page-selector`;
|
|
30
|
-
const instanceId = `${namespace}__select-${
|
|
29
|
+
const instanceId = `${namespace}__select-${useId()}`;
|
|
31
30
|
const renderPages = total => {
|
|
32
31
|
const pages = [];
|
|
33
32
|
for (let counter = 1; counter <= total; counter += 1) {
|
|
@@ -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
|
}
|
|
@@ -13,9 +13,8 @@ import { Legend } from '../Text/index.js';
|
|
|
13
13
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
14
|
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
|
|
15
15
|
import mergeRefs from '../../tools/mergeRefs.js';
|
|
16
|
-
import
|
|
16
|
+
import { useId } from '../../internal/useId.js';
|
|
17
17
|
|
|
18
|
-
const getInstanceId = setupGetInstanceId();
|
|
19
18
|
const RadioButtonGroup = /*#__PURE__*/React__default.forwardRef((props, ref) => {
|
|
20
19
|
const {
|
|
21
20
|
children,
|
|
@@ -41,9 +40,7 @@ const RadioButtonGroup = /*#__PURE__*/React__default.forwardRef((props, ref) =>
|
|
|
41
40
|
const prefix = usePrefix();
|
|
42
41
|
const [selected, setSelected] = useState(valueSelected ?? defaultSelected);
|
|
43
42
|
const [prevValueSelected, setPrevValueSelected] = useState(valueSelected);
|
|
44
|
-
const
|
|
45
|
-
current: radioButtonGroupInstanceId
|
|
46
|
-
} = useRef(getInstanceId());
|
|
43
|
+
const radioButtonGroupInstanceId = useId();
|
|
47
44
|
|
|
48
45
|
/**
|
|
49
46
|
* prop + state alignment - getDerivedStateFromProps
|
|
@@ -7,19 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
|
-
import React__default, { useContext, useState
|
|
10
|
+
import React__default, { useContext, useState } from 'react';
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import { ChevronDown, WarningFilled, WarningAltFilled } from '@carbon/icons-react';
|
|
13
13
|
import deprecate from '../../prop-types/deprecate.js';
|
|
14
14
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
15
15
|
import '../FluidForm/FluidForm.js';
|
|
16
16
|
import { FormContext } from '../FluidForm/FormContext.js';
|
|
17
|
-
import
|
|
17
|
+
import { useId } from '../../internal/useId.js';
|
|
18
18
|
import { composeEventHandlers } from '../../tools/events.js';
|
|
19
19
|
import '../Text/index.js';
|
|
20
20
|
import { Text } from '../Text/Text.js';
|
|
21
21
|
|
|
22
|
-
const getInstanceId = setupGetInstanceId();
|
|
23
22
|
const Select = /*#__PURE__*/React__default.forwardRef(function Select(_ref, ref) {
|
|
24
23
|
let {
|
|
25
24
|
className,
|
|
@@ -50,9 +49,7 @@ const Select = /*#__PURE__*/React__default.forwardRef(function Select(_ref, ref)
|
|
|
50
49
|
} = useContext(FormContext);
|
|
51
50
|
const [isFocused, setIsFocused] = useState(false);
|
|
52
51
|
const [title, setTitle] = useState('');
|
|
53
|
-
const
|
|
54
|
-
current: selectInstanceId
|
|
55
|
-
} = useRef(getInstanceId());
|
|
52
|
+
const selectInstanceId = useId();
|
|
56
53
|
const selectClasses = cx({
|
|
57
54
|
[`${prefix}--select`]: true,
|
|
58
55
|
[`${prefix}--select--inline`]: inline,
|
|
@@ -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;
|
|
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
|
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import React__default, { useRef, useState, useLayoutEffect } from 'react';
|
|
11
11
|
import cx from 'classnames';
|
|
12
|
-
import
|
|
12
|
+
import { useId } from '../../internal/useId.js';
|
|
13
13
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
14
|
import Tag, { SIZES, TYPES } from './Tag.js';
|
|
15
15
|
import { Close } from '@carbon/icons-react';
|
|
@@ -20,7 +20,6 @@ import { isEllipsisActive } from './isEllipsisActive.js';
|
|
|
20
20
|
import { Text } from '../Text/Text.js';
|
|
21
21
|
|
|
22
22
|
var _Close;
|
|
23
|
-
const getInstanceId = setupGetInstanceId();
|
|
24
23
|
const DismissibleTag = _ref => {
|
|
25
24
|
let {
|
|
26
25
|
className,
|
|
@@ -37,7 +36,7 @@ const DismissibleTag = _ref => {
|
|
|
37
36
|
} = _ref;
|
|
38
37
|
const prefix = usePrefix();
|
|
39
38
|
const tagLabelRef = useRef();
|
|
40
|
-
const tagId = id || `tag-${
|
|
39
|
+
const tagId = id || `tag-${useId()}`;
|
|
41
40
|
const tagClasses = cx(`${prefix}--tag--filter`, className);
|
|
42
41
|
const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
|
|
43
42
|
useLayoutEffect(() => {
|
|
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
|
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import React__default, { useRef, useState, useLayoutEffect } from 'react';
|
|
11
11
|
import cx from 'classnames';
|
|
12
|
-
import
|
|
12
|
+
import { useId } from '../../internal/useId.js';
|
|
13
13
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
14
|
import Tag, { SIZES } from './Tag.js';
|
|
15
15
|
import '../Tooltip/DefinitionTooltip.js';
|
|
@@ -18,7 +18,6 @@ import '../Text/index.js';
|
|
|
18
18
|
import { isEllipsisActive } from './isEllipsisActive.js';
|
|
19
19
|
import { Text } from '../Text/Text.js';
|
|
20
20
|
|
|
21
|
-
const getInstanceId = setupGetInstanceId();
|
|
22
21
|
const TYPES = {
|
|
23
22
|
red: 'Red',
|
|
24
23
|
magenta: 'Magenta',
|
|
@@ -45,7 +44,7 @@ const OperationalTag = _ref => {
|
|
|
45
44
|
} = _ref;
|
|
46
45
|
const prefix = usePrefix();
|
|
47
46
|
const tagRef = useRef();
|
|
48
|
-
const tagId = id || `tag-${
|
|
47
|
+
const tagId = id || `tag-${useId()}`;
|
|
49
48
|
const tagClasses = cx(`${prefix}--tag--operational`, className);
|
|
50
49
|
const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
|
|
51
50
|
useLayoutEffect(() => {
|