@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.
Files changed (104) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +836 -836
  2. package/es/components/Checkbox/Checkbox.js +2 -3
  3. package/es/components/CheckboxGroup/CheckboxGroup.js +2 -3
  4. package/es/components/ComboBox/ComboBox.d.ts +10 -6
  5. package/es/components/ComboBox/ComboBox.js +14 -4
  6. package/es/components/ComboButton/index.d.ts +9 -6
  7. package/es/components/ComboButton/index.js +5 -0
  8. package/es/components/DataTable/DataTable.d.ts +25 -11
  9. package/es/components/DataTable/DataTable.js +6 -1
  10. package/es/components/DataTable/TableBatchActions.d.ts +2 -2
  11. package/es/components/DataTable/TableHeader.d.ts +7 -13
  12. package/es/components/DataTable/TableSelectRow.js +3 -2
  13. package/es/components/DataTable/TableToolbarSearch.d.ts +5 -2
  14. package/es/components/DataTable/TableToolbarSearch.js +7 -4
  15. package/es/components/DatePickerInput/DatePickerInput.js +2 -3
  16. package/es/components/Dropdown/Dropdown.d.ts +2 -6
  17. package/es/components/Dropdown/Dropdown.js +3 -6
  18. package/es/components/FluidSearch/FluidSearch.Skeleton.js +40 -0
  19. package/es/components/FluidSearch/FluidSearch.js +96 -0
  20. package/es/components/FormGroup/FormGroup.d.ts +9 -1
  21. package/es/components/FormGroup/FormGroup.js +8 -1
  22. package/es/components/ListBox/ListBoxMenuIcon.d.ts +2 -7
  23. package/es/components/ListBox/ListBoxSelection.d.ts +8 -9
  24. package/es/components/ListBox/ListBoxSelection.js +5 -0
  25. package/es/components/Modal/Modal.js +2 -3
  26. package/es/components/MultiSelect/FilterableMultiSelect.d.ts +10 -5
  27. package/es/components/MultiSelect/FilterableMultiSelect.js +20 -8
  28. package/es/components/MultiSelect/MultiSelect.d.ts +2 -2
  29. package/es/components/MultiSelect/MultiSelect.js +11 -11
  30. package/es/components/NumberInput/NumberInput.d.ts +8 -7
  31. package/es/components/NumberInput/NumberInput.js +5 -0
  32. package/es/components/Pagination/experimental/PageSelector.js +2 -3
  33. package/es/components/PaginationNav/PaginationNav.d.ts +13 -6
  34. package/es/components/PaginationNav/PaginationNav.js +5 -0
  35. package/es/components/ProgressIndicator/ProgressIndicator.d.ts +12 -6
  36. package/es/components/ProgressIndicator/ProgressIndicator.js +5 -0
  37. package/es/components/RadioButtonGroup/RadioButtonGroup.js +2 -5
  38. package/es/components/Select/Select.js +3 -6
  39. package/es/components/Slider/Slider.d.ts +11 -9
  40. package/es/components/Slider/Slider.js +6 -1
  41. package/es/components/Tag/DismissibleTag.js +2 -3
  42. package/es/components/Tag/OperationalTag.js +2 -3
  43. package/es/components/Tag/SelectableTag.js +2 -3
  44. package/es/components/Tag/Tag.js +3 -5
  45. package/es/components/TextArea/TextArea.js +32 -6
  46. package/es/components/TextInput/ControlledPasswordInput.js +3 -6
  47. package/es/components/TextInput/TextInput.js +29 -2
  48. package/es/index.d.ts +1 -0
  49. package/es/index.js +2 -0
  50. package/es/internal/Selection.js +1 -1
  51. package/es/internal/useAnnouncer.js +8 -3
  52. package/es/types/common.d.ts +6 -1
  53. package/lib/components/Checkbox/Checkbox.js +2 -3
  54. package/lib/components/CheckboxGroup/CheckboxGroup.js +2 -3
  55. package/lib/components/ComboBox/ComboBox.d.ts +10 -6
  56. package/lib/components/ComboBox/ComboBox.js +14 -4
  57. package/lib/components/ComboButton/index.d.ts +9 -6
  58. package/lib/components/ComboButton/index.js +5 -0
  59. package/lib/components/DataTable/DataTable.d.ts +25 -11
  60. package/lib/components/DataTable/DataTable.js +6 -1
  61. package/lib/components/DataTable/TableBatchActions.d.ts +2 -2
  62. package/lib/components/DataTable/TableHeader.d.ts +7 -13
  63. package/lib/components/DataTable/TableSelectRow.js +2 -1
  64. package/lib/components/DataTable/TableToolbarSearch.d.ts +5 -2
  65. package/lib/components/DataTable/TableToolbarSearch.js +6 -3
  66. package/lib/components/DatePickerInput/DatePickerInput.js +2 -3
  67. package/lib/components/Dropdown/Dropdown.d.ts +2 -6
  68. package/lib/components/Dropdown/Dropdown.js +2 -5
  69. package/lib/components/FluidSearch/FluidSearch.Skeleton.js +50 -0
  70. package/lib/components/FluidSearch/FluidSearch.js +106 -0
  71. package/lib/components/FormGroup/FormGroup.d.ts +9 -1
  72. package/lib/components/FormGroup/FormGroup.js +8 -1
  73. package/lib/components/ListBox/ListBoxMenuIcon.d.ts +2 -7
  74. package/lib/components/ListBox/ListBoxSelection.d.ts +8 -9
  75. package/lib/components/ListBox/ListBoxSelection.js +5 -0
  76. package/lib/components/Modal/Modal.js +2 -3
  77. package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +10 -5
  78. package/lib/components/MultiSelect/FilterableMultiSelect.js +19 -7
  79. package/lib/components/MultiSelect/MultiSelect.d.ts +2 -2
  80. package/lib/components/MultiSelect/MultiSelect.js +10 -10
  81. package/lib/components/NumberInput/NumberInput.d.ts +8 -7
  82. package/lib/components/NumberInput/NumberInput.js +5 -0
  83. package/lib/components/Pagination/experimental/PageSelector.js +2 -3
  84. package/lib/components/PaginationNav/PaginationNav.d.ts +13 -6
  85. package/lib/components/PaginationNav/PaginationNav.js +5 -0
  86. package/lib/components/ProgressIndicator/ProgressIndicator.d.ts +12 -6
  87. package/lib/components/ProgressIndicator/ProgressIndicator.js +5 -0
  88. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +2 -5
  89. package/lib/components/Select/Select.js +2 -5
  90. package/lib/components/Slider/Slider.d.ts +11 -9
  91. package/lib/components/Slider/Slider.js +6 -1
  92. package/lib/components/Tag/DismissibleTag.js +2 -3
  93. package/lib/components/Tag/OperationalTag.js +2 -3
  94. package/lib/components/Tag/SelectableTag.js +2 -3
  95. package/lib/components/Tag/Tag.js +3 -5
  96. package/lib/components/TextArea/TextArea.js +32 -6
  97. package/lib/components/TextInput/ControlledPasswordInput.js +2 -5
  98. package/lib/components/TextInput/TextInput.js +28 -1
  99. package/lib/index.d.ts +1 -0
  100. package/lib/index.js +4 -0
  101. package/lib/internal/Selection.js +1 -1
  102. package/lib/internal/useAnnouncer.js +8 -3
  103. package/lib/types/common.d.ts +6 -1
  104. package/package.json +18 -18
@@ -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 setupGetInstanceId from '../../tools/setupGetInstanceId.js';
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 SelectableTag = _ref => {
23
22
  let {
24
23
  className,
@@ -33,7 +32,7 @@ const SelectableTag = _ref => {
33
32
  } = _ref;
34
33
  const prefix = usePrefix();
35
34
  const tagRef = useRef();
36
- const tagId = id || `tag-${getInstanceId()}`;
35
+ const tagId = id || `tag-${useId()}`;
37
36
  const [selectedTag, setSelectedTag] = useState(selected);
38
37
  const tagClasses = cx(`${prefix}--tag--selectable`, className, {
39
38
  [`${prefix}--tag--selectable-selected`]: selectedTag
@@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
10
10
  import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { Close } from '@carbon/icons-react';
13
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
13
+ import { useId } from '../../internal/useId.js';
14
14
  import { usePrefix } from '../../internal/usePrefix.js';
15
15
  import '../Text/index.js';
16
16
  import deprecate from '../../prop-types/deprecate.js';
@@ -21,7 +21,6 @@ import { useMergeRefs } from '@floating-ui/react';
21
21
  import { Text } from '../Text/Text.js';
22
22
 
23
23
  var _Close;
24
- const getInstanceId = setupGetInstanceId();
25
24
  const TYPES = {
26
25
  red: 'Red',
27
26
  magenta: 'Magenta',
@@ -63,7 +62,7 @@ const Tag = /*#__PURE__*/React__default.forwardRef(function Tag(_ref, forwardRef
63
62
  const prefix = usePrefix();
64
63
  const tagRef = useRef();
65
64
  const ref = useMergeRefs([forwardRef, tagRef]);
66
- const tagId = id || `tag-${getInstanceId()}`;
65
+ const tagId = id || `tag-${useId()}`;
67
66
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
68
67
  useLayoutEffect(() => {
69
68
  const newElement = tagRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
@@ -117,8 +116,7 @@ const Tag = /*#__PURE__*/React__default.forwardRef(function Tag(_ref, forwardRef
117
116
  }
118
117
  const ComponentTag = BaseComponent ?? (other.onClick || className?.includes(`${prefix}--tag--operational`) ? 'button' : 'div');
119
118
  const labelClasses = cx({
120
- [`${prefix}--tag__label`]: !isInteractiveTag,
121
- [`${prefix}--tag--${type}`]: type && !isInteractiveTag
119
+ [`${prefix}--tag__label`]: !isInteractiveTag
122
120
  });
123
121
  return /*#__PURE__*/React__default.createElement(ComponentTag, _extends({
124
122
  ref: ref,
@@ -17,12 +17,11 @@ import { FormContext } from '../FluidForm/FormContext.js';
17
17
  import { useAnnouncer } from '../../internal/useAnnouncer.js';
18
18
  import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
19
19
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
20
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
20
+ import { useId } from '../../internal/useId.js';
21
21
  import { noopFn } from '../../internal/noopFn.js';
22
22
  import '../Text/index.js';
23
23
  import { Text } from '../Text/Text.js';
24
24
 
25
- const getInstanceId = setupGetInstanceId();
26
25
  const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
27
26
  const {
28
27
  className,
@@ -55,9 +54,7 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
55
54
  defaultValue,
56
55
  value
57
56
  } = other;
58
- const {
59
- current: textAreaInstanceId
60
- } = useRef(getInstanceId());
57
+ const textAreaInstanceId = useId();
61
58
  const textareaRef = useRef(null);
62
59
  const ref = useMergedRefs([forwardRef, textareaRef]);
63
60
  function getInitialTextCount() {
@@ -217,7 +214,33 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
217
214
  textareaProps.maxLength = maxCount;
218
215
  }
219
216
  }
217
+ const announcerRef = useRef(null);
218
+ const [prevAnnouncement, setPrevAnnouncement] = useState('');
220
219
  const ariaAnnouncement = useAnnouncer(textCount, maxCount, counterMode === 'word' ? 'words' : undefined);
220
+ useEffect(() => {
221
+ if (ariaAnnouncement && ariaAnnouncement !== prevAnnouncement) {
222
+ const announcer = announcerRef.current;
223
+ if (announcer) {
224
+ // Clear the content first
225
+ announcer.textContent = '';
226
+
227
+ // Set the new content after a small delay
228
+ const timeoutId = setTimeout(() => {
229
+ if (announcer) {
230
+ announcer.textContent = ariaAnnouncement;
231
+ setPrevAnnouncement(ariaAnnouncement);
232
+ }
233
+ }, counterMode === 'word' ? 2000 : 1000);
234
+
235
+ //clear the timeout
236
+ return () => {
237
+ if (timeoutId) {
238
+ clearTimeout(timeoutId);
239
+ }
240
+ };
241
+ }
242
+ }
243
+ }, [ariaAnnouncement, prevAnnouncement, counterMode]);
221
244
  const input = /*#__PURE__*/React__default.createElement("textarea", _extends({}, other, textareaProps, {
222
245
  placeholder: placeholder,
223
246
  "aria-readonly": other.readOnly ? true : false,
@@ -250,7 +273,10 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
250
273
  className: `${prefix}--text-area__invalid-icon ${prefix}--text-area__invalid-icon--warning`
251
274
  }), input, normalizedSlug, /*#__PURE__*/React__default.createElement("span", {
252
275
  className: `${prefix}--text-area__counter-alert`,
253
- role: "alert"
276
+ role: "alert",
277
+ "aria-live": "assertive",
278
+ "aria-atomic": "true",
279
+ ref: announcerRef
254
280
  }, ariaAnnouncement), isFluid && /*#__PURE__*/React__default.createElement("hr", {
255
281
  className: `${prefix}--text-area__divider`
256
282
  }), isFluid && invalid ? error : null, isFluid && warn && !invalid ? warning : null), !invalid && !warn && !isFluid ? helper : null, invalid && !isFluid ? error : null, warn && !invalid && !isFluid ? warning : null);
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useRef } from 'react';
9
+ import React__default from 'react';
10
10
  import cx from 'classnames';
11
11
  import PropTypes from 'prop-types';
12
12
  import { WarningFilled, ViewOff, View } from '@carbon/icons-react';
@@ -14,10 +14,9 @@ import { textInputProps } from './util.js';
14
14
  import { warning } from '../../internal/warning.js';
15
15
  import deprecate from '../../prop-types/deprecate.js';
16
16
  import { usePrefix } from '../../internal/usePrefix.js';
17
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
17
+ import { useId } from '../../internal/useId.js';
18
18
  import { noopFn } from '../../internal/noopFn.js';
19
19
 
20
- const getInstanceId = setupGetInstanceId();
21
20
  let didWarnAboutDeprecation = false;
22
21
  const ControlledPasswordInput = /*#__PURE__*/React__default.forwardRef(function ControlledPasswordInput(_ref, ref) {
23
22
  let {
@@ -45,9 +44,7 @@ const ControlledPasswordInput = /*#__PURE__*/React__default.forwardRef(function
45
44
  ...other
46
45
  } = _ref;
47
46
  const prefix = usePrefix();
48
- const {
49
- current: controlledPasswordInstanceId
50
- } = useRef(getInstanceId());
47
+ const controlledPasswordInstanceId = useId();
51
48
  if (process.env.NODE_ENV !== "production") {
52
49
  process.env.NODE_ENV !== "production" ? warning(didWarnAboutDeprecation, '`<TextInput.ControlledPasswordInput>` has been deprecated in favor of `<TextInput.PasswordInput />` and will be removed in the next major release of `carbon-components-react`') : void 0;
53
50
  didWarnAboutDeprecation = true;
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import PropTypes from 'prop-types';
9
- import React__default, { useState, useContext } from 'react';
9
+ import React__default, { useState, useContext, useRef, useEffect } from 'react';
10
10
  import cx from 'classnames';
11
11
  import { useNormalizedInputProps } from '../../internal/useNormalizedInputProps.js';
12
12
  import PasswordInput from './PasswordInput.js';
@@ -152,7 +152,31 @@ const TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref
152
152
  const {
153
153
  isFluid
154
154
  } = useContext(FormContext);
155
+ const announcerRef = useRef(null);
156
+ const [prevAnnouncement, setPrevAnnouncement] = useState('');
155
157
  const ariaAnnouncement = useAnnouncer(textCount, maxCount);
158
+ useEffect(() => {
159
+ if (ariaAnnouncement && ariaAnnouncement !== prevAnnouncement) {
160
+ const announcer = announcerRef.current;
161
+ if (announcer) {
162
+ // Clear the content first
163
+ announcer.textContent = '';
164
+ // Set the new content after a small delay
165
+ const timeoutId = setTimeout(() => {
166
+ if (announcer) {
167
+ announcer.textContent = ariaAnnouncement;
168
+ setPrevAnnouncement(ariaAnnouncement);
169
+ }
170
+ }, 1000);
171
+ // clear the timeout
172
+ return () => {
173
+ if (timeoutId) {
174
+ clearTimeout(timeoutId);
175
+ }
176
+ };
177
+ }
178
+ }
179
+ }, [ariaAnnouncement, prevAnnouncement]);
156
180
  const Icon = normalizedProps.icon;
157
181
 
158
182
  // Slug is always size `mini`
@@ -175,7 +199,10 @@ const TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref
175
199
  className: iconClasses
176
200
  }), input, normalizedSlug, /*#__PURE__*/React__default.createElement("span", {
177
201
  className: `${prefix}--text-input__counter-alert`,
178
- role: "alert"
202
+ role: "alert",
203
+ "aria-live": "assertive",
204
+ "aria-atomic": "true",
205
+ ref: announcerRef
179
206
  }, ariaAnnouncement), isFluid && /*#__PURE__*/React__default.createElement("hr", {
180
207
  className: `${prefix}--text-input__divider`
181
208
  }), isFluid && !inline && normalizedProps.validation), !isFluid && !inline && (normalizedProps.validation || helper)));
package/es/index.d.ts CHANGED
@@ -102,6 +102,7 @@ export { FluidDatePickerInput as unstable__FluidDatePickerInput } from './compon
102
102
  export { FluidDropdown as unstable__FluidDropdown, FluidDropdownSkeleton as unstable__FluidDropdownSkeleton, } from './components/FluidDropdown';
103
103
  export { FluidMultiSelect as unstable__FluidMultiSelect, FluidMultiSelectSkeleton as unstable__FluidMultiSelectSkeleton, } from './components/FluidMultiSelect';
104
104
  export { FluidSelect as unstable__FluidSelect, FluidSelectSkeleton as unstable__FluidSelectSkeleton, } from './components/FluidSelect';
105
+ export { FluidSearch as unstable__FluidSearch, FluidSearchSkeleton as unstable__FluidSearchSkeleton, } from './components/FluidSearch';
105
106
  export { FluidTextArea as unstable__FluidTextArea, FluidTextAreaSkeleton as unstable__FluidTextAreaSkeleton, } from './components/FluidTextArea';
106
107
  export { FluidTextInput as unstable__FluidTextInput, FluidTextInputSkeleton as unstable__FluidTextInputSkeleton, } from './components/FluidTextInput';
107
108
  export { FluidTimePicker as unstable__FluidTimePicker, FluidTimePickerSkeleton as unstable__FluidTimePickerSkeleton, } from './components/FluidTimePicker';
package/es/index.js CHANGED
@@ -175,6 +175,7 @@ export { GlobalTheme, Theme, ThemeContext, usePrefersDarkScheme, useTheme } from
175
175
  export { PrefixContext, usePrefix } from './internal/usePrefix.js';
176
176
  export { useIdPrefix } from './internal/useIdPrefix.js';
177
177
  export { default as unstable__FluidDatePickerSkeleton } from './components/FluidDatePicker/FluidDatePicker.Skeleton.js';
178
+ export { default as unstable__FluidSearchSkeleton } from './components/FluidSearch/FluidSearch.Skeleton.js';
178
179
  export { default as unstable__FluidTextArea } from './components/FluidTextArea/FluidTextArea.js';
179
180
  export { default as unstable__FluidTextAreaSkeleton } from './components/FluidTextArea/FluidTextArea.Skeleton.js';
180
181
  export { default as unstable__FluidTextInput } from './components/FluidTextInput/FluidTextInput.js';
@@ -198,6 +199,7 @@ export { default as unstable__FluidMultiSelect } from './components/FluidMultiSe
198
199
  export { default as unstable__FluidMultiSelectSkeleton } from './components/FluidMultiSelect/FluidMultiSelect.Skeleton.js';
199
200
  export { default as unstable__FluidSelect } from './components/FluidSelect/FluidSelect.js';
200
201
  export { default as unstable__FluidSelectSkeleton } from './components/FluidSelect/FluidSelect.Skeleton.js';
202
+ export { default as unstable__FluidSearch } from './components/FluidSearch/FluidSearch.js';
201
203
  export { default as unstable__FluidTimePicker } from './components/FluidTimePicker/FluidTimePicker.js';
202
204
  export { default as unstable__FluidTimePickerSkeleton } from './components/FluidTimePicker/FluidTimePicker.Skeleton.js';
203
205
  export { default as unstable__FluidTimePickerSelect } from './components/FluidTimePickerSelect/FluidTimePickerSelect.js';
@@ -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 'lodash.isequal';
11
+ import isEqual from 'react-fast-compare';
12
12
 
13
13
  function callOnChangeHandler(_ref) {
14
14
  let {
@@ -7,10 +7,15 @@
7
7
 
8
8
  function useAnnouncer(textCount, maxCount) {
9
9
  let entityName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'characters';
10
- const lastTen = maxCount - 10;
11
- if (textCount >= lastTen) {
12
- return `${maxCount - textCount} ${entityName} left.`;
10
+ const remaining = maxCount - textCount;
11
+ if (remaining <= 10 && remaining > 0) {
12
+ const entity = remaining === 1 ? entityName.slice(0, -1) : entityName;
13
+ return `${remaining} ${entity} left.`;
13
14
  }
15
+ if (remaining <= 0) {
16
+ return `Maximum ${entityName} reached.`;
17
+ }
18
+ return null;
14
19
  }
15
20
 
16
21
  export { useAnnouncer };
@@ -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 InternationalProps<MID = string, ARGS = Record<string, unknown>> {
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>;
@@ -16,7 +16,7 @@ var cx = require('classnames');
16
16
  require('../Text/index.js');
17
17
  var usePrefix = require('../../internal/usePrefix.js');
18
18
  var iconsReact = require('@carbon/icons-react');
19
- var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
19
+ var useId = require('../../internal/useId.js');
20
20
  var noopFn = require('../../internal/noopFn.js');
21
21
  var Text = require('../Text/Text.js');
22
22
 
@@ -26,7 +26,6 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
26
26
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
27
27
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
28
28
 
29
- const getInstanceId = setupGetInstanceId["default"]();
30
29
  const Checkbox = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) => {
31
30
  let {
32
31
  className,
@@ -49,7 +48,7 @@ const Checkbox = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
49
48
  const prefix = usePrefix.usePrefix();
50
49
  const showWarning = !readOnly && !invalid && warn;
51
50
  const showHelper = !invalid && !warn;
52
- const checkboxGroupInstanceId = getInstanceId();
51
+ const checkboxGroupInstanceId = useId.useId();
53
52
  const helperId = !helperText ? undefined : `checkbox-helper-text-${checkboxGroupInstanceId}`;
54
53
  const helper = helperText ? /*#__PURE__*/React__default["default"].createElement("div", {
55
54
  id: helperId,
@@ -15,7 +15,7 @@ var React = require('react');
15
15
  var cx = require('classnames');
16
16
  var usePrefix = require('../../internal/usePrefix.js');
17
17
  var iconsReact = require('@carbon/icons-react');
18
- var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
18
+ var useId = require('../../internal/useId.js');
19
19
 
20
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
21
 
@@ -23,7 +23,6 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
23
23
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
24
24
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
25
25
 
26
- const getInstanceId = setupGetInstanceId["default"]();
27
26
  const CheckboxGroup = _ref => {
28
27
  let {
29
28
  children,
@@ -43,7 +42,7 @@ const CheckboxGroup = _ref => {
43
42
  const prefix = usePrefix.usePrefix();
44
43
  const showWarning = !readOnly && !invalid && warn;
45
44
  const showHelper = !invalid && !warn;
46
- const checkboxGroupInstanceId = getInstanceId();
45
+ const checkboxGroupInstanceId = useId.useId();
47
46
  const helperId = !helperText ? undefined : `checkbox-group-helper-text-${checkboxGroupInstanceId}`;
48
47
  const helper = helperText ? /*#__PURE__*/React__default["default"].createElement("div", {
49
48
  id: helperId,
@@ -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
@@ -150,11 +159,6 @@ export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLIn
150
159
  * combobox via ARIA attributes.
151
160
  */
152
161
  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
162
  /**
159
163
  * Specify whether the control is currently in warning state
160
164
  */
@@ -17,7 +17,7 @@ var React = require('react');
17
17
  require('../Text/index.js');
18
18
  var iconsReact = require('@carbon/icons-react');
19
19
  var index = require('../ListBox/index.js');
20
- var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
20
+ var useId = require('../../internal/useId.js');
21
21
  var mergeRefs = require('../../tools/mergeRefs.js');
22
22
  var deprecate = require('../../prop-types/deprecate.js');
23
23
  var usePrefix = require('../../internal/usePrefix.js');
@@ -92,7 +92,15 @@ const findHighlightedIndex = (_ref2, inputValue) => {
92
92
  }
93
93
  return -1;
94
94
  };
95
- const getInstanceId = setupGetInstanceId["default"]();
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
+
96
104
  const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
97
105
  const {
98
106
  ['aria-label']: ariaLabel = 'Choose an item',
@@ -154,7 +162,7 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
154
162
  isFluid
155
163
  } = React.useContext(FormContext.FormContext);
156
164
  const textInput = React.useRef(null);
157
- const comboBoxInstanceId = getInstanceId();
165
+ const comboBoxInstanceId = useId.useId();
158
166
  const [inputValue, setInputValue] = React.useState(getInputValue({
159
167
  initialSelectedItem,
160
168
  inputValue: '',
@@ -393,10 +401,12 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
393
401
  // when both the message is supplied *and* when the component is in
394
402
  // the matching state (invalid, warn, etc).
395
403
  const ariaDescribedBy = invalid && invalidText && invalidTextId || warn && warnText && warnTextId || helperText && !isFluid && helperTextId || undefined;
404
+
405
+ // Memoize the value of getMenuProps to avoid an infinite loop
396
406
  const menuProps = React.useMemo(() => getMenuProps({
397
407
  'aria-label': deprecatedAriaLabel || ariaLabel,
398
408
  ref: autoAlign ? refs.setFloating : null
399
- }), [autoAlign, deprecatedAriaLabel, ariaLabel]);
409
+ }), [autoAlign, deprecatedAriaLabel, ariaLabel, getMenuProps, refs.setFloating]);
400
410
  return /*#__PURE__*/React__default["default"].createElement("div", {
401
411
  className: wrapperClasses
402
412
  }, titleText && /*#__PURE__*/React__default["default"].createElement(Text.Text, _rollupPluginBabelHelpers["extends"]({
@@ -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
- interface ComboButtonProps {
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
  }
@@ -28,6 +28,21 @@ import TableToolbarAction from './TableToolbarAction';
28
28
  import TableToolbarContent from './TableToolbarContent';
29
29
  import TableToolbarSearch from './TableToolbarSearch';
30
30
  import TableToolbarMenu from './TableToolbarMenu';
31
+ import { TranslateWithId } from '../../types/common';
32
+ declare const translationKeys: {
33
+ readonly expandRow: "carbon.table.row.expand";
34
+ readonly collapseRow: "carbon.table.row.collapse";
35
+ readonly expandAll: "carbon.table.all.expand";
36
+ readonly collapseAll: "carbon.table.all.collapse";
37
+ readonly selectAll: "carbon.table.all.select";
38
+ readonly unselectAll: "carbon.table.all.unselect";
39
+ readonly selectRow: "carbon.table.row.select";
40
+ readonly unselectRow: "carbon.table.row.unselect";
41
+ };
42
+ /**
43
+ * Message ids that will be passed to translateWithId().
44
+ */
45
+ type TranslationKey = (typeof translationKeys)[keyof typeof translationKeys];
31
46
  export type DataTableSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
32
47
  export interface DataTableCell<T> {
33
48
  id: string;
@@ -168,7 +183,7 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
168
183
  expandAll: () => void;
169
184
  radio: boolean | undefined;
170
185
  }
171
- export interface DataTableProps<RowType, ColTypes extends any[]> {
186
+ export interface DataTableProps<RowType, ColTypes extends any[]> extends TranslateWithId<TranslationKey> {
172
187
  children?: (renderProps: DataTableRenderProps<RowType, ColTypes>) => React.ReactElement;
173
188
  experimentalAutoAlign?: boolean;
174
189
  filterRows?: (filterRowsArgs: {
@@ -192,7 +207,6 @@ export interface DataTableProps<RowType, ColTypes extends any[]> {
192
207
  locale: string;
193
208
  }) => number;
194
209
  stickyHeader?: boolean;
195
- translateWithId?: (id: string) => string;
196
210
  useStaticWidth?: boolean;
197
211
  useZebraStyles?: boolean;
198
212
  }
@@ -295,7 +309,7 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
295
309
  */
296
310
  useZebraStyles: PropTypes.Requireable<boolean>;
297
311
  };
298
- static translationKeys: string[];
312
+ static translationKeys: ("carbon.table.row.expand" | "carbon.table.row.collapse" | "carbon.table.all.expand" | "carbon.table.all.collapse" | "carbon.table.all.select" | "carbon.table.all.unselect" | "carbon.table.row.select" | "carbon.table.row.unselect")[];
299
313
  static Table: typeof Table;
300
314
  static TableActionList: typeof TableActionList;
301
315
  static TableBatchAction: typeof TableBatchAction;
@@ -360,8 +374,8 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
360
374
  }) => void) | undefined;
361
375
  onExpand?: ((e: MouseEvent) => void) | undefined;
362
376
  }) => {
363
- ariaLabel: string;
364
- 'aria-label': string;
377
+ ariaLabel: any;
378
+ 'aria-label': any;
365
379
  'aria-controls': string;
366
380
  isExpanded: boolean;
367
381
  onExpand: any;
@@ -398,8 +412,8 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
398
412
  key: string;
399
413
  onExpand: any;
400
414
  isExpanded: boolean | undefined;
401
- ariaLabel: string;
402
- 'aria-label': string;
415
+ ariaLabel: any;
416
+ 'aria-label': any;
403
417
  'aria-controls': string;
404
418
  isSelected: boolean | undefined;
405
419
  disabled: boolean | undefined;
@@ -436,13 +450,13 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
436
450
  onSelect: any;
437
451
  id: string;
438
452
  name: string;
439
- ariaLabel: string;
440
- 'aria-label': string;
453
+ ariaLabel: any;
454
+ 'aria-label': any;
441
455
  disabled: boolean | undefined;
442
456
  radio: true | null;
443
457
  } | {
444
- ariaLabel: string;
445
- 'aria-label': string;
458
+ ariaLabel: any;
459
+ 'aria-label': any;
446
460
  checked: boolean;
447
461
  id: string;
448
462
  indeterminate: boolean;
@@ -12,7 +12,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
12
12
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
13
13
  var PropTypes = require('prop-types');
14
14
  var React = require('react');
15
- var isEqual = require('lodash.isequal');
15
+ var isEqual = require('react-fast-compare');
16
16
  var getDerivedStateFromProps = require('./state/getDerivedStateFromProps.js');
17
17
  var sorting = require('./state/sorting.js');
18
18
  var cells = require('./tools/cells.js');
@@ -59,6 +59,11 @@ const translationKeys = {
59
59
  selectRow: 'carbon.table.row.select',
60
60
  unselectRow: 'carbon.table.row.unselect'
61
61
  };
62
+
63
+ /**
64
+ * Message ids that will be passed to translateWithId().
65
+ */
66
+
62
67
  const defaultTranslations = {
63
68
  [translationKeys.expandAll]: 'Expand all rows',
64
69
  [translationKeys.collapseAll]: 'Collapse all rows',
@@ -5,14 +5,14 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { type MouseEventHandler } from 'react';
8
- import type { InternationalProps } from '../../types/common';
8
+ import type { TranslateWithId } from '../../types/common';
9
9
  declare const TableBatchActionsTranslationKeys: readonly ["carbon.table.batch.cancel", "carbon.table.batch.items.selected", "carbon.table.batch.item.selected", "carbon.table.batch.selectAll"];
10
10
  export type TableBatchActionsTranslationKey = (typeof TableBatchActionsTranslationKeys)[number];
11
11
  export interface TableBatchActionsTranslationArgs {
12
12
  totalSelected?: number;
13
13
  totalCount?: number;
14
14
  }
15
- export interface TableBatchActionsProps extends React.HTMLAttributes<HTMLDivElement>, InternationalProps<TableBatchActionsTranslationKey, TableBatchActionsTranslationArgs> {
15
+ export interface TableBatchActionsProps extends React.HTMLAttributes<HTMLDivElement>, TranslateWithId<TableBatchActionsTranslationKey, TableBatchActionsTranslationArgs> {
16
16
  /**
17
17
  * Provide elements to be rendered inside of the component.
18
18
  */
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import React, { type MouseEventHandler, ReactNode } from 'react';
8
8
  import { sortStates } from './state/sorting';
9
- import { ReactAttr } from '../../types/common';
9
+ import { TranslateWithId, ReactAttr } from '../../types/common';
10
10
  import { DataTableSortState } from './state/sortStates';
11
11
  export type TableHeaderTranslationKey = 'carbon.table.header.icon.description';
12
12
  export interface TableHeaderTranslationArgs {
@@ -15,7 +15,12 @@ export interface TableHeaderTranslationArgs {
15
15
  sortDirection?: DataTableSortState;
16
16
  sortStates: typeof sortStates;
17
17
  }
18
- interface TableHeaderProps extends ReactAttr<HTMLTableCellElement & HTMLButtonElement> {
18
+ interface TableHeaderProps extends ReactAttr<HTMLTableCellElement & HTMLButtonElement>, TranslateWithId<TableHeaderTranslationKey, {
19
+ header: any;
20
+ sortDirection: any;
21
+ isSortHeader: any;
22
+ sortStates: any;
23
+ }> {
19
24
  /**
20
25
  * Pass in children that will be embedded in the table header label
21
26
  */
@@ -61,17 +66,6 @@ interface TableHeaderProps extends ReactAttr<HTMLTableCellElement & HTMLButtonEl
61
66
  * NONE, or ASC.
62
67
  */
63
68
  sortDirection?: string;
64
- /**
65
- * Supply a method to translate internal strings with your i18n tool of
66
- * choice. Translation keys are available on the `translationKeys` field for
67
- * this component.
68
- */
69
- translateWithId?: (key: TableHeaderTranslationKey, { header, sortDirection, isSortHeader, sortStates }: {
70
- header: any;
71
- sortDirection: any;
72
- isSortHeader: any;
73
- sortStates: any;
74
- }) => string;
75
69
  }
76
70
  declare const TableHeader: React.ForwardRefExoticComponent<TableHeaderProps & React.RefAttributes<HTMLTableCellElement>>;
77
71
  export default TableHeader;