@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
@@ -76,23 +76,34 @@ const Button = /*#__PURE__*/React__default.forwardRef((props, ref) => {
76
76
  if (tooltipPosition === 'right' || tooltipPosition === 'left') {
77
77
  align = tooltipPosition;
78
78
  }
79
- return /*#__PURE__*/React__default.createElement(IconButton, _extends({}, rest, {
80
- ref: ref,
81
- as: as,
82
- align: align,
83
- label: iconDescription,
84
- kind: kind,
85
- size: size,
86
- highContrast: tooltipHighContrast,
87
- dropShadow: tooltipDropShadow,
88
- onMouseEnter: onMouseEnter,
89
- onMouseLeave: onMouseLeave,
90
- onFocus: onFocus,
91
- onBlur: onBlur,
92
- autoAlign: autoAlign,
93
- onClick: composeEventHandlers([onClick, handleClick]),
94
- renderIcon: iconOnlyImage ? null : ButtonImageElement // avoid doubling the icon.
95
- }), iconOnlyImage ?? children);
79
+ return (
80
+ /*#__PURE__*/
81
+ // @ts-expect-error - `IconButton` does not support all `size`s that
82
+ // `Button` supports.
83
+ //
84
+ // TODO: What should be done here?
85
+ // 1. Should the `IconButton` not be rendered if the `size` is not
86
+ // supported?
87
+ // 2. Should an error be thrown?
88
+ // 3. Something else?
89
+ React__default.createElement(IconButton, _extends({}, rest, {
90
+ ref: ref,
91
+ as: as,
92
+ align: align,
93
+ label: iconDescription,
94
+ kind: kind,
95
+ size: size,
96
+ highContrast: tooltipHighContrast,
97
+ dropShadow: tooltipDropShadow,
98
+ onMouseEnter: onMouseEnter,
99
+ onMouseLeave: onMouseLeave,
100
+ onFocus: onFocus,
101
+ onBlur: onBlur,
102
+ autoAlign: autoAlign,
103
+ onClick: composeEventHandlers([onClick, handleClick]),
104
+ renderIcon: iconOnlyImage ? null : ButtonImageElement // avoid doubling the icon.
105
+ }), iconOnlyImage ?? children)
106
+ );
96
107
  }
97
108
  });
98
109
  Button.displayName = 'Button';
@@ -41,6 +41,8 @@ const ButtonBase = /*#__PURE__*/React__default.forwardRef(function ButtonBase(_r
41
41
  // TODO: V12 - Remove this class
42
42
  [`${prefix}--btn--md`]: size === 'md' && !isExpressive,
43
43
  // TODO: V12 - Remove this class
44
+ [`${prefix}--btn--lg`]: size === 'lg' && !isExpressive,
45
+ // TODO: V12 - Remove this class
44
46
  [`${prefix}--btn--xl`]: size === 'xl',
45
47
  // TODO: V12 - Remove this class
46
48
  [`${prefix}--btn--2xl`]: size === '2xl',
@@ -12,6 +12,7 @@ import React__default, { useMemo } from 'react';
12
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
13
  import { useId } from '../../internal/useId.js';
14
14
  import { TableContext } from './TableContext.js';
15
+ import { Section, Heading } from '../Heading/index.js';
15
16
 
16
17
  const TableContainer = _ref => {
17
18
  let {
@@ -39,11 +40,11 @@ const TableContainer = _ref => {
39
40
  }, [title, description, titleId, descriptionId]);
40
41
  return /*#__PURE__*/React__default.createElement(TableContext.Provider, {
41
42
  value: value
42
- }, /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
43
+ }, /*#__PURE__*/React__default.createElement(Section, _extends({}, rest, {
43
44
  className: tableContainerClasses
44
45
  }), (title || description) && /*#__PURE__*/React__default.createElement("div", {
45
46
  className: `${prefix}--data-table-header`
46
- }, title && /*#__PURE__*/React__default.createElement("h4", {
47
+ }, title && /*#__PURE__*/React__default.createElement(Heading, {
47
48
  className: `${prefix}--data-table-header__title`,
48
49
  id: titleId
49
50
  }, title), description && /*#__PURE__*/React__default.createElement("p", {
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
- import { PolymorphicProps } from '../../types/common';
8
+ import { PolymorphicComponentPropWithRef } from '../../internal/PolymorphicProps';
9
9
  type ColumnSpanPercent = '25%' | '50%' | '75%' | '100%';
10
10
  type ColumnSpanSimple = boolean | number | ColumnSpanPercent;
11
11
  export interface ColumnSpanObject {
@@ -65,7 +65,7 @@ export interface ColumnBaseProps {
65
65
  */
66
66
  span?: ColumnSpan;
67
67
  }
68
- export type ColumnProps<T extends React.ElementType> = PolymorphicProps<T, ColumnBaseProps>;
68
+ export type ColumnProps<T extends React.ElementType> = PolymorphicComponentPropWithRef<T, ColumnBaseProps>;
69
69
  export interface ColumnComponent {
70
70
  <T extends React.ElementType>(props: ColumnProps<T>, context?: any): React.ReactElement<any, any> | null;
71
71
  }
@@ -13,9 +13,9 @@ import React__default from 'react';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import { useGridSettings } from './GridContext.js';
15
15
 
16
- function Column(_ref) {
16
+ const Column = /*#__PURE__*/React__default.forwardRef(function Column(_ref, ref) {
17
17
  let {
18
- as: BaseComponent = 'div',
18
+ as,
19
19
  children,
20
20
  className: customClassName,
21
21
  sm,
@@ -29,6 +29,7 @@ function Column(_ref) {
29
29
  mode
30
30
  } = useGridSettings();
31
31
  const prefix = usePrefix();
32
+ const BaseComponent = as || 'div';
32
33
  if (mode === 'css-grid') {
33
34
  return /*#__PURE__*/React__default.createElement(CSSGridColumn, _extends({
34
35
  as: BaseComponent,
@@ -44,13 +45,11 @@ function Column(_ref) {
44
45
  const className = cx(customClassName, columnClassName, {
45
46
  [`${prefix}--col`]: columnClassName.length === 0
46
47
  });
47
-
48
- // cast as any to let TypeScript allow passing in attributes to base component
49
- const BaseComponentAsAny = BaseComponent;
50
- return /*#__PURE__*/React__default.createElement(BaseComponentAsAny, _extends({
51
- className: className
48
+ return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({
49
+ className: className,
50
+ ref: ref
52
51
  }, rest), children);
53
- }
52
+ });
54
53
  const percentSpanType = PropTypes.oneOf(['25%', '50%', '75%', '100%']);
55
54
  const spanPropType = FeatureFlags.enabled('enable-css-grid') ? PropTypes.oneOfType([PropTypes.bool, PropTypes.number, PropTypes.shape({
56
55
  span: PropTypes.oneOfType([PropTypes.number, percentSpanType]),
@@ -86,9 +86,9 @@ export interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonEl
86
86
  */
87
87
  rel?: React.AnchorHTMLAttributes<HTMLAnchorElement>['rel'];
88
88
  /**
89
- * Specify the size of the Button. Defaults to `md`.
89
+ * Specify the size of the Button.
90
90
  */
91
- size?: ButtonSize;
91
+ size?: Extract<ButtonSize, 'sm' | 'md' | 'lg'>;
92
92
  /**
93
93
  * Optionally specify a `target` when using an `<a>` element.
94
94
  */
@@ -184,7 +184,7 @@ IconButton.propTypes = {
184
184
  */
185
185
  rel: PropTypes.string,
186
186
  /**
187
- * Specify the size of the Button. Defaults to `md`.
187
+ * Specify the size of the Button.
188
188
  */
189
189
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
190
190
  /**
@@ -1,5 +1,5 @@
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.
@@ -5,16 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { deprecateFieldOnObject } from '../../internal/deprecateFieldOnObject.js';
9
8
  import MultiSelect from './MultiSelect.js';
10
9
  export { default as MultiSelect, default } from './MultiSelect.js';
11
10
  import FilterableMultiSelect from './FilterableMultiSelect.js';
12
11
  export { default as FilterableMultiSelect } from './FilterableMultiSelect.js';
13
12
 
14
- FilterableMultiSelect.displayName = 'MultiSelect.Filterable';
15
- // @ts-expect-error: The attribute indeed does not exist on the object,
16
- // but since it is already deprecated, we do not have to fix it.
17
- MultiSelect.Filterable = FilterableMultiSelect;
18
- if (process.env.NODE_ENV !== "production") {
19
- deprecateFieldOnObject(MultiSelect, 'Filterable', FilterableMultiSelect);
20
- }
13
+ FilterableMultiSelect.displayName = 'FilterableMultiSelect';
@@ -4,9 +4,16 @@
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 ElementType, type ReactNode, type Ref } from 'react';
7
8
  import { type MenuDirection, type MenuOffset } from '../../internal/FloatingMenu';
8
- import React from 'react';
9
- import PropTypes from 'prop-types';
9
+ /**
10
+ * Calculates the offset for the floating menu.
11
+ *
12
+ * @param menuBody - The menu body with the menu arrow.
13
+ * @param direction - The floating menu direction.
14
+ * @returns The adjustment of the floating menu position, upon the position of
15
+ * the menu arrow.
16
+ */
10
17
  export declare const getMenuOffset: MenuOffset;
11
18
  export interface OverflowMenuProps {
12
19
  /**
@@ -14,18 +21,18 @@ export interface OverflowMenuProps {
14
21
  */
15
22
  ['aria-label']?: string;
16
23
  /**
17
- * Deprecated, please use `aria-label` instead.
18
24
  * Specify a label to be read by screen readers on the container note.
19
- * @deprecated
20
- * */
21
- ariaLabel: string;
25
+ *
26
+ * @deprecated - Use `aria-label` instead.
27
+ */
28
+ ariaLabel?: string;
22
29
  /**
23
30
  * The child nodes.
24
- * */
25
- children: React.ReactNode;
31
+ */
32
+ children: ReactNode;
26
33
  /**
27
- * The CSS class names.
28
- * */
34
+ * The CSS class names.
35
+ */
29
36
  className?: string;
30
37
  /**
31
38
  * The menu direction.
@@ -87,7 +94,7 @@ export interface OverflowMenuProps {
87
94
  /**
88
95
  * A component used to render an icon.
89
96
  */
90
- renderIcon?: React.ElementType;
97
+ renderIcon?: ElementType;
91
98
  /**
92
99
  * Specify a CSS selector that matches the DOM element that should
93
100
  * be focused when the OverflowMenu opens
@@ -100,189 +107,7 @@ export interface OverflowMenuProps {
100
107
  /**
101
108
  * The ref to the HTML element that should receive focus when the OverflowMenu opens
102
109
  */
103
- innerRef?: React.Ref<any>;
104
- }
105
- export interface OverflowMenuState {
106
- open: boolean;
107
- prevOpen?: boolean;
108
- hasMountedTrigger: boolean;
109
- click: boolean;
110
- }
111
- interface ReleaseHandle {
112
- release: () => null;
113
- }
114
- declare class OverflowMenu extends React.Component<OverflowMenuProps, OverflowMenuState> {
115
- state: OverflowMenuState;
116
- instanceId: number;
117
- static propTypes: {
118
- /**
119
- * Specify a label to be read by screen readers on the container node
120
- */
121
- "aria-label": PropTypes.Requireable<string>;
122
- /**
123
- * Deprecated, please use `aria-label` instead.
124
- * Specify a label to be read by screen readers on the container note.
125
- */
126
- ariaLabel: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
127
- /**
128
- * The child nodes.
129
- */
130
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
131
- /**
132
- * The CSS class names.
133
- */
134
- className: PropTypes.Requireable<string>;
135
- /**
136
- * The menu direction.
137
- */
138
- direction: PropTypes.Requireable<string>;
139
- /**
140
- * `true` if the menu alignment should be flipped.
141
- */
142
- flipped: PropTypes.Requireable<boolean>;
143
- /**
144
- * Enable or disable focus trap behavior
145
- */
146
- focusTrap: PropTypes.Requireable<boolean>;
147
- /**
148
- * The CSS class for the icon.
149
- */
150
- iconClass: PropTypes.Requireable<string>;
151
- /**
152
- * The icon description.
153
- */
154
- iconDescription: PropTypes.Requireable<string>;
155
- /**
156
- * The element ID.
157
- */
158
- id: PropTypes.Requireable<string>;
159
- /**
160
- * `true` to use the light version. For use on $ui-01 backgrounds only.
161
- * Don't use this to make OverflowMenu background color same as container background color.
162
- */
163
- light: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
164
- /**
165
- * The adjustment in position applied to the floating menu.
166
- */
167
- menuOffset: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.InferProps<{
168
- top: PropTypes.Requireable<number>;
169
- left: PropTypes.Requireable<number>;
170
- }> | null | undefined>>;
171
- /**
172
- * The adjustment in position applied to the floating menu.
173
- */
174
- menuOffsetFlip: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.InferProps<{
175
- top: PropTypes.Requireable<number>;
176
- left: PropTypes.Requireable<number>;
177
- }> | null | undefined>>;
178
- /**
179
- * The class to apply to the menu options
180
- */
181
- menuOptionsClass: PropTypes.Requireable<string>;
182
- /**
183
- * The event handler for the `click` event.
184
- */
185
- onClick: PropTypes.Requireable<(...args: any[]) => any>;
186
- /**
187
- * Function called when menu is closed
188
- */
189
- onClose: PropTypes.Requireable<(...args: any[]) => any>;
190
- /**
191
- * The event handler for the `focus` event.
192
- */
193
- onFocus: PropTypes.Requireable<(...args: any[]) => any>;
194
- /**
195
- * The event handler for the `keydown` event.
196
- */
197
- onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
198
- /**
199
- * Function called when menu is opened
200
- */
201
- onOpen: PropTypes.Requireable<(...args: any[]) => any>;
202
- /**
203
- * `true` if the menu should be open.
204
- */
205
- open: PropTypes.Requireable<boolean>;
206
- /**
207
- * A component used to render an icon.
208
- */
209
- renderIcon: PropTypes.Requireable<object>;
210
- /**
211
- * Specify a CSS selector that matches the DOM element that should
212
- * be focused when the OverflowMenu opens
213
- */
214
- selectorPrimaryFocus: PropTypes.Requireable<string>;
215
- /**
216
- * Specify the size of the OverflowMenu. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
217
- */
218
- size: PropTypes.Requireable<string>;
219
- };
220
- static contextType: React.Context<string>;
221
- /**
222
- * The handle of `onfocusin` or `focus` event handler.
223
- * @private
224
- */
225
- _hFocusIn: ReleaseHandle | null;
226
- /**
227
- * The timeout handle for handling `blur` event.
228
- * @private
229
- */
230
- _hBlurTimeout: any;
231
- /**
232
- * The element ref of the tooltip's trigger button.
233
- * @type {React.RefObject<HTMLElement>}
234
- * @private
235
- */
236
- _triggerRef: React.RefObject<HTMLElement>;
237
- componentDidUpdate(_: any, prevState: any): void;
238
- componentDidMount(): void;
239
- static getDerivedStateFromProps({ open }: {
240
- open: any;
241
- }, state: any): {
242
- open: any;
243
- prevOpen: any;
244
- } | null;
245
- componentWillUnmount(): void;
246
- handleClick: (evt: any) => void;
247
- closeMenuAndFocus: () => void;
248
- closeMenuOnEscape: () => void;
249
- handleKeyPress: (evt: any) => void;
250
- handleClickOutside: (evt: any) => void;
251
- closeMenu: (onCloseMenu?: any) => void;
252
- focusMenuEl: () => void;
253
- /**
254
- * Focuses the next enabled overflow menu item given the currently focused
255
- * item index and direction to move
256
- * @param {object} params
257
- * @param {number} params.currentIndex - the index of the currently focused
258
- * overflow menu item in the list of overflow menu items
259
- * @param {number} params.direction - number denoting the direction to move
260
- * focus (1 for forwards, -1 for backwards)
261
- */
262
- handleOverflowMenuItemFocus: ({ currentIndex, direction }: {
263
- currentIndex: any;
264
- direction: any;
265
- }) => void;
266
- /**
267
- * Handles the floating menu being unmounted or non-floating menu being
268
- * mounted or unmounted.
269
- * @param {Element} menuBody The DOM element of the menu body.
270
- * @private
271
- */
272
- _menuBody: HTMLElement | null;
273
- _bindMenuBody: (menuBody: HTMLElement | null) => void;
274
- /**
275
- * Handles the floating menu being placed.
276
- * @param {Element} menuBody The DOM element of the menu body.
277
- * @private
278
- */
279
- _handlePlace: (menuBody: any) => void;
280
- /**
281
- * @returns {Element} The DOM element where the floating menu is placed in.
282
- */
283
- _getTarget: () => Element;
284
- render(): import("react/jsx-runtime").JSX.Element;
110
+ innerRef?: Ref<any>;
285
111
  }
286
- export { OverflowMenu };
287
- declare const _default: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<unknown>>;
288
- export default _default;
112
+ export declare const OverflowMenu: React.ForwardRefExoticComponent<OverflowMenuProps & React.RefAttributes<HTMLButtonElement>>;
113
+ export default OverflowMenu;