@carbon/react 1.78.1 → 1.79.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +844 -844
  2. package/es/components/Button/Button.js +28 -17
  3. package/es/components/Button/ButtonBase.js +2 -0
  4. package/es/components/DataTable/TableContainer.js +3 -2
  5. package/es/components/Grid/Column.d.ts +2 -2
  6. package/es/components/Grid/Column.js +7 -8
  7. package/es/components/IconButton/index.d.ts +2 -2
  8. package/es/components/IconButton/index.js +1 -1
  9. package/es/components/MultiSelect/index.d.ts +1 -1
  10. package/es/components/MultiSelect/index.js +1 -8
  11. package/es/components/OverflowMenu/OverflowMenu.d.ts +21 -196
  12. package/es/components/OverflowMenu/OverflowMenu.js +267 -336
  13. package/es/components/OverflowMenu/index.d.ts +5 -5
  14. package/es/components/OverflowMenu/index.js +2 -2
  15. package/es/components/OverflowMenu/next/index.d.ts +2 -2
  16. package/es/components/Slider/Slider.d.ts +23 -29
  17. package/es/components/Slider/Slider.js +35 -37
  18. package/es/components/Tabs/Tabs.js +8 -9
  19. package/es/components/Tile/Tile.js +8 -4
  20. package/es/index.js +1 -1
  21. package/es/internal/FloatingMenu.d.ts +2 -2
  22. package/es/internal/FloatingMenu.js +4 -1
  23. package/es/internal/createClassWrapper.d.ts +3 -3
  24. package/es/internal/createClassWrapper.js +4 -4
  25. package/es/internal/useMatchMedia.d.ts +8 -0
  26. package/es/internal/useMatchMedia.js +10 -20
  27. package/es/internal/useNormalizedInputProps.d.ts +52 -0
  28. package/es/internal/useNormalizedInputProps.js +9 -36
  29. package/lib/components/Button/Button.js +28 -17
  30. package/lib/components/Button/ButtonBase.js +2 -0
  31. package/lib/components/DataTable/TableContainer.js +3 -2
  32. package/lib/components/Grid/Column.d.ts +2 -2
  33. package/lib/components/Grid/Column.js +7 -8
  34. package/lib/components/IconButton/index.d.ts +2 -2
  35. package/lib/components/IconButton/index.js +1 -1
  36. package/lib/components/MultiSelect/index.d.ts +1 -1
  37. package/lib/components/MultiSelect/index.js +1 -8
  38. package/lib/components/OverflowMenu/OverflowMenu.d.ts +21 -196
  39. package/lib/components/OverflowMenu/OverflowMenu.js +266 -334
  40. package/lib/components/OverflowMenu/index.d.ts +5 -5
  41. package/lib/components/OverflowMenu/index.js +2 -2
  42. package/lib/components/OverflowMenu/next/index.d.ts +2 -2
  43. package/lib/components/Slider/Slider.d.ts +23 -29
  44. package/lib/components/Slider/Slider.js +35 -37
  45. package/lib/components/Tabs/Tabs.js +8 -9
  46. package/lib/components/Tile/Tile.js +8 -4
  47. package/lib/index.js +2 -2
  48. package/lib/internal/FloatingMenu.d.ts +2 -2
  49. package/lib/internal/FloatingMenu.js +4 -1
  50. package/lib/internal/createClassWrapper.d.ts +3 -3
  51. package/lib/internal/createClassWrapper.js +4 -4
  52. package/lib/internal/useMatchMedia.d.ts +8 -0
  53. package/lib/internal/useMatchMedia.js +10 -20
  54. package/lib/internal/useNormalizedInputProps.d.ts +52 -0
  55. package/lib/internal/useNormalizedInputProps.js +9 -36
  56. package/package.json +6 -6
  57. package/es/internal/useEffectOnce.js +0 -30
  58. package/lib/internal/useEffectOnce.js +0 -34
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2025
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type OverflowMenuProps } from './OverflowMenu';
8
- declare function OverflowMenu(props: any): import("react/jsx-runtime").JSX.Element;
9
- declare namespace OverflowMenu {
10
- var displayName: string;
11
- }
8
+ declare const OverflowMenu: {
9
+ (props: OverflowMenuProps): import("react/jsx-runtime").JSX.Element;
10
+ displayName: string;
11
+ };
12
12
  export default OverflowMenu;
13
13
  export { OverflowMenu, type OverflowMenuProps };
@@ -20,10 +20,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
20
20
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
21
 
22
22
  const OverflowMenuV11 = createClassWrapper.createClassWrapper(OverflowMenu$1.OverflowMenu);
23
- function OverflowMenu(props) {
23
+ const OverflowMenu = props => {
24
24
  const enableV12OverflowMenu = index.useFeatureFlag('enable-v12-overflowmenu');
25
25
  return enableV12OverflowMenu ? /*#__PURE__*/React__default["default"].createElement(index$1.OverflowMenu, props) : /*#__PURE__*/React__default["default"].createElement(OverflowMenuV11, props);
26
- }
26
+ };
27
27
  OverflowMenu.displayName = 'OverflowMenu';
28
28
 
29
29
  exports.OverflowMenu = OverflowMenu;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { type ComponentType, type FunctionComponent } from 'react';
7
+ import React, { type ElementType } from 'react';
8
8
  interface OverflowMenuProps {
9
9
  /**
10
10
  * **Experimental**: Will attempt to automatically align the floating element to avoid collisions with the viewport and being clipped by ancestor elements.
@@ -29,7 +29,7 @@ interface OverflowMenuProps {
29
29
  /**
30
30
  * A component used to render an icon.
31
31
  */
32
- renderIcon?: ComponentType | FunctionComponent;
32
+ renderIcon?: ElementType;
33
33
  /**
34
34
  * Specify the size of the menu, from a list of available sizes.
35
35
  */
@@ -164,11 +164,6 @@ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
164
164
  */
165
165
  warnText?: React.ReactNode;
166
166
  }
167
- interface CalcValueProps {
168
- clientX?: number;
169
- value?: number;
170
- useRawValue?: boolean;
171
- }
172
167
  interface CalcLeftPercentProps {
173
168
  clientX?: number;
174
169
  value?: number;
@@ -415,30 +410,29 @@ declare class Slider extends PureComponent<SliderProps> {
415
410
  onInputKeyDown: (evt: any) => void;
416
411
  processNewInputValue: (input: HTMLInputElement) => void;
417
412
  calcLeftPercent: ({ clientX, value, range }: CalcLeftPercentProps) => number;
418
- calcSteppedValuePercent: ({ leftPercent, range }: {
419
- leftPercent: any;
420
- range: any;
421
- }) => number[];
422
- /**
423
- * Calculates a new Slider `value` and `left` (thumb offset) given a `clientX`,
424
- * `value`, or neither of those.
425
- * - If `clientX` is specified, it will be used in
426
- * conjunction with the Slider's bounding rectangle to calculate the new
427
- * values.
428
- * - If `clientX` is not specified and `value` is, it will be used to
429
- * calculate new values as though it were the current value of the Slider.
430
- * - If neither `clientX` nor `value` are specified, `this.props.value` will
431
- * be used to calculate the new values as though it were the current value
432
- * of the Slider.
433
- *
434
- * @param {object} params
435
- * @param {number} [params.clientX] Optional clientX value expected to be from
436
- * an event fired by one of the Slider's `DRAG_EVENT_TYPES` events.
437
- * @param {number} [params.value] Optional value use during calculations if
438
- * clientX is not provided.
439
- * @param {boolean} [params.useRawValue=false] `true` to use the given value as-is.
440
- */
441
- calcValue: ({ clientX, value, useRawValue }: CalcValueProps) => {
413
+ /**
414
+ * Calculates the discrete value (snapped to the nearest step) along
415
+ * with the corresponding handle position percentage.
416
+ */
417
+ calcDiscreteValueAndPercent: ({ leftPercent, }: {
418
+ /** The percentage representing the position on the track. */
419
+ leftPercent: number;
420
+ }) => {
421
+ discreteValue: number;
422
+ discretePercent: number;
423
+ };
424
+ /**
425
+ * Calculates the slider's value and handle position based on either a
426
+ * mouse/touch event or an explicit value.
427
+ */
428
+ calcValue: ({ clientX, value, useRawValue, }: {
429
+ /** The x-coordinate from a mouse/touch event. */
430
+ clientX?: number;
431
+ /** Value to base the calculations on (if no `clientX`). */
432
+ value?: number;
433
+ /** Whether to bypass the stepping logic and use the raw value. */
434
+ useRawValue?: boolean;
435
+ }) => {
442
436
  value: number | undefined;
443
437
  left: number;
444
438
  };
@@ -533,67 +533,65 @@ class Slider extends React.PureComponent {
533
533
  // re-assure Typescript, return 0.
534
534
  return 0;
535
535
  });
536
- _rollupPluginBabelHelpers.defineProperty(this, "calcSteppedValuePercent", _ref3 => {
536
+ /**
537
+ * Calculates the discrete value (snapped to the nearest step) along
538
+ * with the corresponding handle position percentage.
539
+ */
540
+ _rollupPluginBabelHelpers.defineProperty(this, "calcDiscreteValueAndPercent", _ref3 => {
537
541
  let {
538
- leftPercent,
539
- range
542
+ leftPercent
540
543
  } = _ref3;
541
544
  const {
542
- step = 1
545
+ step = 1,
546
+ min,
547
+ max
543
548
  } = this.props;
544
- const totalSteps = range / step;
545
- let steppedValue = Math.round(leftPercent * totalSteps) * step;
546
- const steppedPercent = this.clamp(steppedValue / range, 0, 1);
547
- steppedValue = this.clamp(steppedValue + this.props.min, this.props.min, this.props.max);
548
- return [steppedValue, steppedPercent];
549
+ const numSteps = Math.floor((max - min) / step) + ((max - min) % step === 0 ? 1 : 2);
550
+ /** Index of the step that corresponds to `leftPercent`. */
551
+ const stepIndex = Math.round(leftPercent * (numSteps - 1));
552
+ const discreteValue = stepIndex === numSteps - 1 ? max : min + step * stepIndex;
553
+ /** Percentage corresponding to the step index. */
554
+ const discretePercent = stepIndex / (numSteps - 1);
555
+ return {
556
+ discreteValue,
557
+ discretePercent
558
+ };
549
559
  });
550
560
  /**
551
- * Calculates a new Slider `value` and `left` (thumb offset) given a `clientX`,
552
- * `value`, or neither of those.
553
- * - If `clientX` is specified, it will be used in
554
- * conjunction with the Slider's bounding rectangle to calculate the new
555
- * values.
556
- * - If `clientX` is not specified and `value` is, it will be used to
557
- * calculate new values as though it were the current value of the Slider.
558
- * - If neither `clientX` nor `value` are specified, `this.props.value` will
559
- * be used to calculate the new values as though it were the current value
560
- * of the Slider.
561
- *
562
- * @param {object} params
563
- * @param {number} [params.clientX] Optional clientX value expected to be from
564
- * an event fired by one of the Slider's `DRAG_EVENT_TYPES` events.
565
- * @param {number} [params.value] Optional value use during calculations if
566
- * clientX is not provided.
567
- * @param {boolean} [params.useRawValue=false] `true` to use the given value as-is.
561
+ * Calculates the slider's value and handle position based on either a
562
+ * mouse/touch event or an explicit value.
568
563
  */
569
564
  _rollupPluginBabelHelpers.defineProperty(this, "calcValue", _ref4 => {
570
565
  let {
571
566
  clientX,
572
567
  value,
573
- useRawValue = false
568
+ useRawValue
574
569
  } = _ref4;
575
570
  const range = this.props.max - this.props.min;
576
-
577
- // @todo solve for rtl.
578
- const leftPercent = this.calcLeftPercent({
571
+ const leftPercentRaw = this.calcLeftPercent({
579
572
  clientX,
580
573
  value,
581
574
  range
582
575
  });
576
+ /** `leftPercentRaw` clamped between 0 and 1. */
577
+ const leftPercent = Math.min(1, Math.max(0, leftPercentRaw));
583
578
  if (useRawValue) {
584
- // Adjusts only for min/max of thumb position
585
579
  return {
586
580
  value,
587
- left: Math.min(1, Math.max(0, leftPercent)) * 100
581
+ left: leftPercent * 100
588
582
  };
589
583
  }
590
- const [steppedValue, steppedPercent] = this.calcSteppedValuePercent({
591
- leftPercent,
592
- range
584
+
585
+ // Use the discrete value and percentage for snapping.
586
+ const {
587
+ discreteValue,
588
+ discretePercent
589
+ } = this.calcDiscreteValueAndPercent({
590
+ leftPercent
593
591
  });
594
592
  return {
595
- value: steppedValue,
596
- left: steppedPercent * 100
593
+ value: discreteValue,
594
+ left: discretePercent * 100
597
595
  };
598
596
  });
599
597
  _rollupPluginBabelHelpers.defineProperty(this, "calcDistanceToHandle", (handle, clientX) => {
@@ -25,7 +25,6 @@ var reactIs = require('react-is');
25
25
  require('../Tooltip/DefinitionTooltip.js');
26
26
  var Tooltip = require('../Tooltip/Tooltip.js');
27
27
  var useControllableState = require('../../internal/useControllableState.js');
28
- var useEffectOnce = require('../../internal/useEffectOnce.js');
29
28
  var useId = require('../../internal/useId.js');
30
29
  var useIsomorphicEffect = require('../../internal/useIsomorphicEffect.js');
31
30
  var useMergedRefs = require('../../internal/useMergedRefs.js');
@@ -392,7 +391,7 @@ function TabList(_ref4) {
392
391
  }
393
392
  }
394
393
  }
395
- useEffectOnce.useEffectOnce(() => {
394
+ React.useEffect(() => {
396
395
  const tab = tabs.current[selectedIndex];
397
396
  if (scrollIntoView && tab) {
398
397
  tab.scrollIntoView({
@@ -400,7 +399,7 @@ function TabList(_ref4) {
400
399
  inline: 'nearest'
401
400
  });
402
401
  }
403
- });
402
+ }, []);
404
403
  React.useEffect(() => {
405
404
  //adding 1 in calculation for firefox support
406
405
  setIsNextButtonVisible(ref.current ? scrollLeft + buttonWidth + ref.current.clientWidth + 1 < ref.current.scrollWidth : false);
@@ -410,7 +409,7 @@ function TabList(_ref4) {
410
409
  }
411
410
  }
412
411
  }, [scrollLeft, children, dismissable, isScrollable]);
413
- useEffectOnce.useEffectOnce(() => {
412
+ React.useEffect(() => {
414
413
  if (tabs.current[selectedIndex]?.disabled) {
415
414
  const activeTabs = tabs.current.filter(tab => {
416
415
  return !tab.disabled;
@@ -420,7 +419,7 @@ function TabList(_ref4) {
420
419
  setSelectedIndex(tabs.current.indexOf(tab));
421
420
  }
422
421
  }
423
- });
422
+ }, []);
424
423
  useIsomorphicEffect["default"](() => {
425
424
  if (ref.current) {
426
425
  // adding 1 in calculation for firefox support
@@ -634,7 +633,7 @@ function TabListVertical(_ref8) {
634
633
  setActiveIndex(selectedIndex);
635
634
  }
636
635
  }
637
- useEffectOnce.useEffectOnce(() => {
636
+ React.useEffect(() => {
638
637
  if (tabs.current[selectedIndex]?.disabled) {
639
638
  const activeTabs = tabs.current.filter(tab => {
640
639
  return !tab.disabled;
@@ -644,7 +643,7 @@ function TabListVertical(_ref8) {
644
643
  setSelectedIndex(tabs.current.indexOf(tab));
645
644
  }
646
645
  }
647
- });
646
+ }, []);
648
647
  React.useEffect(() => {
649
648
  function handler() {
650
649
  const containerHeight = ref.current?.offsetHeight;
@@ -1133,7 +1132,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
1133
1132
  const className = cx__default["default"](`${prefix}--tab-content`, customClassName, {
1134
1133
  [`${prefix}--tab-content--interactive`]: interactiveContent
1135
1134
  });
1136
- useEffectOnce.useEffectOnce(() => {
1135
+ React.useEffect(() => {
1137
1136
  if (!panel.current) {
1138
1137
  return;
1139
1138
  }
@@ -1142,7 +1141,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
1142
1141
  setInteractiveContent(true);
1143
1142
  setTabIndex(-1);
1144
1143
  }
1145
- });
1144
+ }, []);
1146
1145
 
1147
1146
  // tabindex should only be 0 if no interactive content in children
1148
1147
  React.useEffect(() => {
@@ -265,14 +265,18 @@ const SelectableTile = /*#__PURE__*/React__default["default"].forwardRef(functio
265
265
  evt?.persist?.();
266
266
  if (match.matches(evt, [keys.Enter, keys.Space])) {
267
267
  evt.preventDefault();
268
- setIsSelected(!isSelected);
269
- onChange(evt, isSelected, id);
268
+ setIsSelected(prevSelected => {
269
+ const newSelected = !prevSelected;
270
+ onChange(evt, newSelected, id);
271
+ return newSelected;
272
+ });
270
273
  }
271
274
  keyDownHandler(evt);
272
275
  }
273
276
  function handleChange(event) {
274
- setIsSelected(event.target.checked);
275
- onChange(event, isSelected, id);
277
+ const newSelected = event.target.checked;
278
+ setIsSelected(newSelected);
279
+ onChange(event, newSelected, id);
276
280
  }
277
281
  if (selected !== prevSelected) {
278
282
  setIsSelected(selected);
package/lib/index.js CHANGED
@@ -211,6 +211,7 @@ var PageSelector = require('./components/Pagination/experimental/PageSelector.js
211
211
  var Pagination = require('./components/Pagination/experimental/Pagination.js');
212
212
  var ContainedListItem = require('./components/ContainedList/ContainedListItem/ContainedListItem.js');
213
213
  var ContainedList = require('./components/ContainedList/ContainedList.js');
214
+ var MultiSelect = require('./components/MultiSelect/MultiSelect.js');
214
215
  var Slider_Skeleton = require('./components/Slider/Slider.Skeleton.js');
215
216
  var TextInput_Skeleton = require('./components/TextInput/TextInput.Skeleton.js');
216
217
  var TextInput = require('./components/TextInput/TextInput.js');
@@ -242,7 +243,6 @@ var TableToolbarContent = require('./components/DataTable/TableToolbarContent.js
242
243
  var TableToolbarSearch = require('./components/DataTable/TableToolbarSearch.js');
243
244
  var TableToolbarMenu = require('./components/DataTable/TableToolbarMenu.js');
244
245
  var FilterableMultiSelect = require('./components/MultiSelect/FilterableMultiSelect.js');
245
- var MultiSelect = require('./components/MultiSelect/MultiSelect.js');
246
246
 
247
247
 
248
248
 
@@ -497,6 +497,7 @@ exports.unstable_PageSelector = PageSelector["default"];
497
497
  exports.unstable_Pagination = Pagination["default"];
498
498
  exports.ContainedListItem = ContainedListItem["default"];
499
499
  exports.ContainedList = ContainedList["default"];
500
+ exports.MultiSelect = MultiSelect["default"];
500
501
  exports.SliderSkeleton = Slider_Skeleton["default"];
501
502
  exports.TextInputSkeleton = TextInput_Skeleton["default"];
502
503
  exports.TextInput = TextInput["default"];
@@ -528,4 +529,3 @@ exports.TableToolbarContent = TableToolbarContent["default"];
528
529
  exports.TableToolbarSearch = TableToolbarSearch["default"];
529
530
  exports.TableToolbarMenu = TableToolbarMenu["default"];
530
531
  exports.FilterableMultiSelect = FilterableMultiSelect["default"];
531
- exports.MultiSelect = MultiSelect["default"];
@@ -10,8 +10,8 @@ export declare const DIRECTION_TOP = "top";
10
10
  export declare const DIRECTION_RIGHT = "right";
11
11
  export declare const DIRECTION_BOTTOM = "bottom";
12
12
  export interface Offset {
13
- top?: number;
14
- left?: number;
13
+ top: number;
14
+ left: number;
15
15
  }
16
16
  interface Container {
17
17
  rect: DOMRect;
@@ -112,7 +112,10 @@ const FloatingMenu = _ref2 => {
112
112
  flipped,
113
113
  focusTrap,
114
114
  menuDirection = DIRECTION_BOTTOM,
115
- menuOffset = {},
115
+ menuOffset = {
116
+ top: 0,
117
+ left: 0
118
+ },
116
119
  menuRef: externalMenuRef,
117
120
  onPlace,
118
121
  selectorPrimaryFocus,
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2025
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { ComponentClass, FunctionComponent } from 'react';
7
+ import { type ComponentClass, type ForwardRefExoticComponent, type FunctionComponent, type PropsWithChildren } from 'react';
8
8
  /**
9
9
  * Wrap a class component with a functional component. This prevents an end-user
10
10
  * from being able to pass `ref` and access the underlying class instance.
11
11
  */
12
- export declare function createClassWrapper<Props>(Component: ComponentClass<Props>): FunctionComponent<Props>;
12
+ export declare const createClassWrapper: <Props extends PropsWithChildren>(Component: ComponentClass<Props> | ForwardRefExoticComponent<Props>) => FunctionComponent<Props>;
@@ -19,13 +19,13 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
19
  * Wrap a class component with a functional component. This prevents an end-user
20
20
  * from being able to pass `ref` and access the underlying class instance.
21
21
  */
22
- function createClassWrapper(Component) {
23
- function ClassWrapper(props) {
22
+ const createClassWrapper = Component => {
23
+ const ClassWrapper = props => {
24
24
  return /*#__PURE__*/React__default["default"].createElement(Component, props);
25
- }
25
+ };
26
26
  const name = Component.displayName || Component.name;
27
27
  ClassWrapper.displayName = `ClassWrapper(${name})`;
28
28
  return ClassWrapper;
29
- }
29
+ };
30
30
 
31
31
  exports.createClassWrapper = createClassWrapper;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2025
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ /** Listens to changes in a media query and returns whether it matches. */
8
+ export declare const useMatchMedia: (mediaQuery: string) => boolean;
@@ -12,37 +12,27 @@ Object.defineProperty(exports, '__esModule', { value: true });
12
12
  var React = require('react');
13
13
  var environment = require('./environment.js');
14
14
 
15
- function useMatchMedia(mediaQueryString) {
15
+ /** Listens to changes in a media query and returns whether it matches. */
16
+ const useMatchMedia = mediaQuery => {
16
17
  const [matches, setMatches] = React.useState(() => {
17
18
  if (environment.canUseDOM) {
18
- const mediaQueryList = window.matchMedia(mediaQueryString);
19
+ const mediaQueryList = window.matchMedia(mediaQuery);
19
20
  return mediaQueryList.matches;
20
21
  }
21
22
  return false;
22
23
  });
23
24
  React.useEffect(() => {
24
- function listener(event) {
25
+ const listener = event => {
25
26
  setMatches(event.matches);
26
- }
27
- const mediaQueryList = window.matchMedia(mediaQueryString);
28
- // Support fallback to `addListener` for broader browser support
29
- if (mediaQueryList.addEventListener) {
30
- mediaQueryList.addEventListener('change', listener);
31
- } else {
32
- mediaQueryList.addListener(listener);
33
- }
34
-
35
- // Make sure the media query list is in sync with the matches state
27
+ };
28
+ const mediaQueryList = window.matchMedia(mediaQuery);
29
+ mediaQueryList.addEventListener('change', listener);
36
30
  setMatches(mediaQueryList.matches);
37
31
  return () => {
38
- if (mediaQueryList.addEventListener) {
39
- mediaQueryList.removeEventListener('change', listener);
40
- } else {
41
- mediaQueryList.removeListener(listener);
42
- }
32
+ mediaQueryList.removeEventListener('change', listener);
43
33
  };
44
- }, [mediaQueryString]);
34
+ }, [mediaQuery]);
45
35
  return matches;
46
- }
36
+ };
47
37
 
48
38
  exports.useMatchMedia = useMatchMedia;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright IBM Corp. 2021, 2025
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type ComponentType, type ReactNode } from 'react';
8
+ interface InputProps {
9
+ /** The ID for the input. */
10
+ id: string;
11
+ /** Whether the input is read-only. */
12
+ readOnly?: boolean;
13
+ /** Whether the input is disabled. */
14
+ disabled: boolean;
15
+ /** Whether the input is an invalid state. */
16
+ invalid: boolean;
17
+ /** The message displayed when the input is invalid. */
18
+ invalidText?: ReactNode;
19
+ /** Whether the input is in a warning state. */
20
+ warn: boolean;
21
+ /** The message displayed when the input is in a warning state. */
22
+ warnText?: ReactNode;
23
+ }
24
+ interface NormalizedInputProps {
25
+ /** Disabled state. */
26
+ disabled: boolean;
27
+ /** Invalid state. */
28
+ invalid: boolean;
29
+ /** The generated ID for the error message. */
30
+ invalidId: string;
31
+ /** The generated ID for the helper text. */
32
+ helperId: string;
33
+ /** Warning state. */
34
+ warn: boolean;
35
+ /** The generated ID for the warning message. */
36
+ warnId: string;
37
+ /** A React node containing the validation message. */
38
+ validation: ReactNode | null;
39
+ /** A React component representing the accompanying icon. */
40
+ icon: ComponentType | null;
41
+ }
42
+ /**
43
+ * Returns an object containing normalized properties for an input component.
44
+ *
45
+ * This hook ensures that only one of `invalid` or `warn` is active (with
46
+ * `invalid` taking precedence) and that `readOnly` overrides the `disabled`,
47
+ * `invalid`, and `warn` states. It generates unique IDs for error, warning, and
48
+ * helper messages, and conditionally provides the appropriate validation
49
+ * message and accompanying icon.
50
+ */
51
+ export declare const useNormalizedInputProps: ({ id, readOnly, disabled, invalid, invalidText, warn, warnText, }: InputProps) => NormalizedInputProps;
52
+ export {};
@@ -11,8 +11,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var React = require('react');
13
13
  var iconsReact = require('@carbon/icons-react');
14
- var usePrefix = require('./usePrefix.js');
15
14
  require('../components/Text/index.js');
15
+ var usePrefix = require('./usePrefix.js');
16
16
  var Text = require('../components/Text/Text.js');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -20,42 +20,15 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
20
20
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
21
 
22
22
  /**
23
- * @typedef {object} InputProps
24
- * @property {string} id - The input's id
25
- * @property {boolean | undefined} readOnly - Whether the input should be readonly
26
- * @property {boolean} disabled - Whether the input should be disabled
27
- * @property {boolean} invalid - Whether the input should be marked as invalid
28
- * @property {React.ReactNode | undefined} invalidText - The validation message displayed in case the input is considered invalid
29
- * @property {boolean} warn - Whether the input should be in warning state
30
- * @property {React.ReactNode | undefined} warnText - The validation message displayed in case the input is in warning state
31
- */
32
-
33
- /**
34
- * @typedef {object} NormalizedInputProps
35
- * @property {boolean} disabled - Whether the input is disabled
36
- * @property {boolean} invalid - Whether the input is invalid (takes precedence over warn)
37
- * @property {string} invalidId - The invalid message's id
38
- * @property {string} helperId - id used for helper text
39
- * @property {boolean} warn - Whether the input is in warning state
40
- * @property {string} warnId - The warning message's id
41
- * @property {React.ReactNode | null} validation – React node rendering the appropriate validation message (if any)
42
- * @property {React.ReactNode | null} icon – React node rendering the appropriate accompanying icon (if any)
43
- */
44
-
45
- /**
46
- * Returns an object containing non-colliding props and additional, generated ones.
47
- * This hook ensures that only either "invalid" or "warn" is true but never both at
48
- * the same time. Regardless whether "invalid" or "warn", the appropriate validation
49
- * message is passed as "validation". If the input should be accompanied by an icon
50
- * (to visually represent a readonly, invalid or warning state), the appropriate icon
51
- * is passed as "icon".
52
- * It also ensure that neither "invalid", nor "warn", nor "disabled" are enabled when
53
- * "readonly" is passed as "readonly" takes precedence over these variants.
23
+ * Returns an object containing normalized properties for an input component.
54
24
  *
55
- * @param {InputProps} props - The props passed to the component
56
- * @returns {NormalizedInputProps}
25
+ * This hook ensures that only one of `invalid` or `warn` is active (with
26
+ * `invalid` taking precedence) and that `readOnly` overrides the `disabled`,
27
+ * `invalid`, and `warn` states. It generates unique IDs for error, warning, and
28
+ * helper messages, and conditionally provides the appropriate validation
29
+ * message and accompanying icon.
57
30
  */
58
- function useNormalizedInputProps(_ref) {
31
+ const useNormalizedInputProps = _ref => {
59
32
  let {
60
33
  id,
61
34
  readOnly,
@@ -92,6 +65,6 @@ function useNormalizedInputProps(_ref) {
92
65
  }, warnText);
93
66
  }
94
67
  return normalizedProps;
95
- }
68
+ };
96
69
 
97
70
  exports.useNormalizedInputProps = useNormalizedInputProps;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/react",
3
3
  "description": "React components for the Carbon Design System",
4
- "version": "1.78.1",
4
+ "version": "1.79.0-rc.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -51,10 +51,10 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@babel/runtime": "^7.24.7",
54
- "@carbon/feature-flags": "^0.24.1",
54
+ "@carbon/feature-flags": "^0.25.0-rc.0",
55
55
  "@carbon/icons-react": "^11.57.0",
56
- "@carbon/layout": "^11.30.1",
57
- "@carbon/styles": "^1.77.1",
56
+ "@carbon/layout": "^11.31.0-rc.0",
57
+ "@carbon/styles": "^1.78.0-rc.0",
58
58
  "@floating-ui/react": "^0.27.4",
59
59
  "@ibm/telemetry-js": "^1.5.0",
60
60
  "classnames": "2.5.1",
@@ -79,7 +79,7 @@
79
79
  "@babel/preset-react": "^7.24.7",
80
80
  "@babel/preset-typescript": "^7.24.7",
81
81
  "@carbon/test-utils": "^10.35.0",
82
- "@carbon/themes": "^11.48.1",
82
+ "@carbon/themes": "^11.49.0-rc.0",
83
83
  "@figma/code-connect": "^1.2.4",
84
84
  "@rollup/plugin-babel": "^6.0.0",
85
85
  "@rollup/plugin-commonjs": "^28.0.0",
@@ -146,5 +146,5 @@
146
146
  "**/*.scss",
147
147
  "**/*.css"
148
148
  ],
149
- "gitHead": "538413f7766dea6ef4bc4eb5e752b0119779f10a"
149
+ "gitHead": "0c142888f7e3aefd5a5b5b0b2c34c2552894bb56"
150
150
  }