@carbon/react 1.30.0 → 1.31.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 (121) hide show
  1. package/es/components/Accordion/Accordion.js +3 -1
  2. package/es/components/AspectRatio/AspectRatio.d.ts +67 -0
  3. package/es/components/AspectRatio/AspectRatio.js +2 -2
  4. package/es/components/AspectRatio/index.d.ts +7 -0
  5. package/es/components/Button/Button.js +6 -1
  6. package/es/components/Checkbox/Checkbox.js +2 -2
  7. package/es/components/CodeSnippet/CodeSnippet.js +1 -0
  8. package/es/components/ComboButton/index.js +6 -5
  9. package/es/components/ContainedList/ContainedList.js +12 -4
  10. package/es/components/ContainedList/ContainedListItem/ContainedListItem.js +6 -1
  11. package/es/components/ContentSwitcher/ContentSwitcher.js +10 -1
  12. package/es/components/CopyButton/CopyButton.js +8 -2
  13. package/es/components/DataTable/DataTable.js +8 -2
  14. package/es/components/DataTable/Table.d.ts +6 -1
  15. package/es/components/DataTable/Table.js +78 -3
  16. package/es/components/DataTable/TableHeader.js +2 -1
  17. package/es/components/DataTableSkeleton/DataTableSkeleton.js +1 -2
  18. package/es/components/DataTableSkeleton/index.d.ts +9 -0
  19. package/es/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
  20. package/es/components/ExpandableSearch/ExpandableSearch.js +6 -2
  21. package/es/components/FileUploader/FileUploaderButton.js +2 -1
  22. package/es/components/IconButton/index.js +10 -2
  23. package/es/components/Layout/index.js +118 -0
  24. package/es/components/Link/Link.d.ts +53 -0
  25. package/es/components/Link/Link.js +4 -3
  26. package/es/components/Link/index.d.ts +9 -0
  27. package/es/components/ListBox/ListBoxPropTypes.d.ts +1 -1
  28. package/es/components/Menu/MenuItem.js +2 -1
  29. package/es/components/MenuButton/index.js +7 -4
  30. package/es/components/OverflowMenu/index.js +9 -1
  31. package/es/components/OverflowMenu/next/index.js +98 -0
  32. package/es/components/OverflowMenuV2/index.js +15 -73
  33. package/es/components/RadioButtonGroup/RadioButtonGroup.js +0 -1
  34. package/es/components/Search/Search.d.ts +4 -0
  35. package/es/components/Search/Search.js +8 -2
  36. package/es/components/Select/Select.d.ts +1 -1
  37. package/es/components/Tabs/Tabs.js +5 -1
  38. package/es/components/Tag/Tag.js +2 -0
  39. package/es/components/TextArea/TextArea.Skeleton.js +1 -2
  40. package/es/components/TextArea/TextArea.js +1 -2
  41. package/es/components/TextArea/index.d.ts +10 -0
  42. package/es/components/TextInput/PasswordInput.js +1 -2
  43. package/es/components/TextInput/TextInput.Skeleton.js +1 -2
  44. package/es/components/TextInput/TextInput.js +5 -4
  45. package/es/components/TextInput/index.d.ts +4 -0
  46. package/es/components/TimePicker/TimePicker.d.ts +8 -0
  47. package/es/components/TimePicker/TimePicker.js +26 -6
  48. package/es/components/Tooltip/Tooltip.js +4 -2
  49. package/es/components/UIShell/HeaderMenuItem.d.ts +22 -0
  50. package/es/components/UIShell/HeaderMenuItem.js +4 -3
  51. package/es/components/UIShell/HeaderPanel.js +3 -11
  52. package/es/components/UIShell/Link.d.ts +48 -0
  53. package/es/components/UIShell/Link.js +30 -19
  54. package/es/components/UIShell/SideNav.d.ts +2 -1
  55. package/es/components/UIShell/SideNav.js +25 -7
  56. package/es/index.d.ts +21 -20
  57. package/es/index.js +30 -28
  58. package/lib/components/Accordion/Accordion.js +3 -1
  59. package/lib/components/AspectRatio/AspectRatio.d.ts +67 -0
  60. package/lib/components/AspectRatio/AspectRatio.js +2 -2
  61. package/lib/components/AspectRatio/index.d.ts +7 -0
  62. package/lib/components/Button/Button.js +6 -1
  63. package/lib/components/Checkbox/Checkbox.js +2 -2
  64. package/lib/components/CodeSnippet/CodeSnippet.js +1 -0
  65. package/lib/components/ComboButton/index.js +6 -5
  66. package/lib/components/ContainedList/ContainedList.js +12 -4
  67. package/lib/components/ContainedList/ContainedListItem/ContainedListItem.js +6 -1
  68. package/lib/components/ContentSwitcher/ContentSwitcher.js +10 -1
  69. package/lib/components/CopyButton/CopyButton.js +8 -2
  70. package/lib/components/DataTable/DataTable.js +8 -2
  71. package/lib/components/DataTable/Table.d.ts +6 -1
  72. package/lib/components/DataTable/Table.js +78 -2
  73. package/lib/components/DataTable/TableHeader.js +2 -1
  74. package/lib/components/DataTableSkeleton/DataTableSkeleton.js +1 -2
  75. package/lib/components/DataTableSkeleton/index.d.ts +9 -0
  76. package/lib/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
  77. package/lib/components/ExpandableSearch/ExpandableSearch.js +6 -2
  78. package/lib/components/FileUploader/FileUploaderButton.js +2 -1
  79. package/lib/components/IconButton/index.js +10 -2
  80. package/lib/components/Layout/index.js +129 -0
  81. package/lib/components/Link/Link.d.ts +53 -0
  82. package/lib/components/Link/Link.js +4 -3
  83. package/lib/components/Link/index.d.ts +9 -0
  84. package/lib/components/ListBox/ListBoxPropTypes.d.ts +1 -1
  85. package/lib/components/Menu/MenuItem.js +2 -1
  86. package/lib/components/MenuButton/index.js +7 -4
  87. package/lib/components/OverflowMenu/index.js +13 -1
  88. package/lib/components/OverflowMenu/next/index.js +108 -0
  89. package/lib/components/OverflowMenuV2/index.js +14 -74
  90. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +0 -1
  91. package/lib/components/Search/Search.d.ts +4 -0
  92. package/lib/components/Search/Search.js +8 -2
  93. package/lib/components/Select/Select.d.ts +1 -1
  94. package/lib/components/Tabs/Tabs.js +5 -1
  95. package/lib/components/Tag/Tag.js +2 -0
  96. package/lib/components/TextArea/TextArea.Skeleton.js +1 -2
  97. package/lib/components/TextArea/TextArea.js +1 -2
  98. package/lib/components/TextArea/index.d.ts +10 -0
  99. package/lib/components/TextInput/PasswordInput.js +1 -2
  100. package/lib/components/TextInput/TextInput.Skeleton.js +1 -2
  101. package/lib/components/TextInput/TextInput.js +5 -4
  102. package/lib/components/TextInput/index.d.ts +4 -0
  103. package/lib/components/TimePicker/TimePicker.d.ts +8 -0
  104. package/lib/components/TimePicker/TimePicker.js +26 -6
  105. package/lib/components/Tooltip/Tooltip.js +4 -2
  106. package/lib/components/UIShell/HeaderMenuItem.d.ts +22 -0
  107. package/lib/components/UIShell/HeaderMenuItem.js +3 -2
  108. package/lib/components/UIShell/HeaderPanel.js +3 -11
  109. package/lib/components/UIShell/Link.d.ts +48 -0
  110. package/lib/components/UIShell/Link.js +29 -18
  111. package/lib/components/UIShell/SideNav.d.ts +2 -1
  112. package/lib/components/UIShell/SideNav.js +24 -6
  113. package/lib/index.d.ts +21 -20
  114. package/lib/index.js +92 -89
  115. package/package.json +10 -9
  116. /package/es/components/{Layout → LayoutDirection}/LayoutDirection.js +0 -0
  117. /package/es/components/{Layout → LayoutDirection}/LayoutDirectionContext.js +0 -0
  118. /package/es/components/{Layout → LayoutDirection}/useLayoutDirection.js +0 -0
  119. /package/lib/components/{Layout → LayoutDirection}/LayoutDirection.js +0 -0
  120. /package/lib/components/{Layout → LayoutDirection}/LayoutDirectionContext.js +0 -0
  121. /package/lib/components/{Layout → LayoutDirection}/useLayoutDirection.js +0 -0
@@ -18,13 +18,15 @@ function Accordion(_ref) {
18
18
  className: customClassName,
19
19
  disabled = false,
20
20
  isFlush = false,
21
- size = 'md',
21
+ size,
22
22
  ...rest
23
23
  } = _ref;
24
24
  const prefix = usePrefix();
25
25
  const className = cx(`${prefix}--accordion`, customClassName, {
26
26
  [`${prefix}--accordion--${align}`]: align,
27
27
  [`${prefix}--accordion--${size}`]: size,
28
+ // TODO: V12 - Remove this class
29
+ [`${prefix}--layout--size-${size}`]: size,
28
30
  [`${prefix}--accordion--flush`]: isFlush && align !== 'start'
29
31
  });
30
32
  return /*#__PURE__*/React__default.createElement("ul", _extends({
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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 PropTypes from 'prop-types';
8
+ import { PropsWithChildren, ReactHTML } from 'react';
9
+ interface AspectRatioProps {
10
+ /**
11
+ * Provide a custom component or string to be rendered as
12
+ * the outermost node of the component. This is useful if you want
13
+ * to deviate from the default `div` tag, where you could specify
14
+ * `section` or `article` instead.
15
+ *
16
+ * ```jsx
17
+ * <AspectRatio as="article">My content</AspectRatio>
18
+ * ```
19
+ */
20
+ as?: keyof ReactHTML;
21
+ /**
22
+ * Specify a class name for the outermost node
23
+ * of the component.
24
+ */
25
+ className?: string;
26
+ /**
27
+ * Specify the ratio to be used by the aspect ratio
28
+ * container. This will determine what aspect ratio your content
29
+ * will be displayed in.
30
+ */
31
+ ratio?: '1x1' | '2x3' | '3x2' | '3x4' | '4x3' | '1x2' | '2x1' | '9x16' | '16x9';
32
+ }
33
+ /**
34
+ * The AspectRatio component provides a `ratio` prop that will be used to
35
+ * specify the aspect ratio that the children you provide will be displayed in.
36
+ * This is often useful alongside our grid components, or for media assets like
37
+ * images or videos.
38
+ */
39
+ declare const AspectRatio: {
40
+ ({ as: BaseComponent, className: containerClassName, children, ratio, ...rest }: PropsWithChildren<AspectRatioProps>): JSX.Element;
41
+ propTypes: {
42
+ /**
43
+ * Provide a custom component or string to be rendered as the outermost node
44
+ * of the component. This is useful if you want to deviate from the default
45
+ * `div` tag, where you could specify `section` or `article` instead.
46
+ *
47
+ * ```jsx
48
+ * <AspectRatio as="article">My content</AspectRatio>
49
+ * ```
50
+ */
51
+ as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
52
+ /**
53
+ * Specify the content that will be placed in the aspect ratio
54
+ */
55
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
56
+ /**
57
+ * Specify a class name for the outermost node of the component
58
+ */
59
+ className: PropTypes.Requireable<string>;
60
+ /**
61
+ * Specify the ratio to be used by the aspect ratio container. This will
62
+ * determine what aspect ratio your content will be displayed in.
63
+ */
64
+ ratio: PropTypes.Requireable<string>;
65
+ };
66
+ };
67
+ export default AspectRatio;
@@ -17,7 +17,7 @@ import { usePrefix } from '../../internal/usePrefix.js';
17
17
  * This is often useful alongside our grid components, or for media assets like
18
18
  * images or videos.
19
19
  */
20
- function AspectRatio(_ref) {
20
+ const AspectRatio = _ref => {
21
21
  let {
22
22
  as: BaseComponent = 'div',
23
23
  className: containerClassName,
@@ -30,7 +30,7 @@ function AspectRatio(_ref) {
30
30
  return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({
31
31
  className: className
32
32
  }, rest), children);
33
- }
33
+ };
34
34
  AspectRatio.propTypes = {
35
35
  /**
36
36
  * Provide a custom component or string to be rendered as the outermost node
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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
+ export { default as AspectRatio } from './AspectRatio';
@@ -34,7 +34,7 @@ const Button = /*#__PURE__*/React__default.forwardRef(function Button(_ref, ref)
34
34
  onMouseEnter,
35
35
  onMouseLeave,
36
36
  renderIcon: ButtonImageElement,
37
- size = 'lg',
37
+ size,
38
38
  tabIndex,
39
39
  tooltipAlignment = 'center',
40
40
  tooltipPosition = 'top',
@@ -53,9 +53,14 @@ const Button = /*#__PURE__*/React__default.forwardRef(function Button(_ref, ref)
53
53
  const buttonClasses = cx(className, {
54
54
  [`${prefix}--btn`]: true,
55
55
  [`${prefix}--btn--sm`]: size === 'sm' && !isExpressive,
56
+ // TODO: V12 - Remove this class
56
57
  [`${prefix}--btn--md`]: size === 'md' && !isExpressive,
58
+ // TODO: V12 - Remove this class
57
59
  [`${prefix}--btn--xl`]: size === 'xl',
60
+ // TODO: V12 - Remove this class
58
61
  [`${prefix}--btn--2xl`]: size === '2xl',
62
+ // TODO: V12 - Remove this class
63
+ [`${prefix}--layout--size-${size}`]: size,
59
64
  [`${prefix}--btn--${kind}`]: kind,
60
65
  [`${prefix}--btn--disabled`]: disabled,
61
66
  [`${prefix}--btn--expressive`]: isExpressive,
@@ -67,8 +67,8 @@ const Checkbox = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
67
67
  className: `${prefix}--checkbox`,
68
68
  id: id,
69
69
  ref: el => {
70
- if (el && indeterminate) {
71
- el.indeterminate = indeterminate;
70
+ if (el) {
71
+ el.indeterminate = indeterminate ?? false;
72
72
  }
73
73
  if (typeof ref === 'function') {
74
74
  ref(el);
@@ -199,6 +199,7 @@ function CodeSnippet(_ref) {
199
199
  }), hasRightOverflow && type !== 'multi' && /*#__PURE__*/React__default.createElement("div", {
200
200
  className: `${prefix}--snippet__overflow-indicator--right`
201
201
  }), !hideCopyButton && /*#__PURE__*/React__default.createElement(CopyButton, {
202
+ size: type === 'multi' ? 'sm' : 'md',
202
203
  disabled: disabled,
203
204
  onClick: handleCopyClick,
204
205
  feedback: feedback,
@@ -34,7 +34,7 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
34
34
  label,
35
35
  onClick,
36
36
  size = 'lg',
37
- tooltipAlign,
37
+ tooltipAlignment,
38
38
  translateWithId: t = defaultTranslateWithId,
39
39
  ...rest
40
40
  } = _ref;
@@ -76,7 +76,8 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
76
76
  const triggerClasses = cx(`${prefix}--combo-button__trigger`);
77
77
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
78
78
  className: containerClasses,
79
- ref: ref
79
+ ref: ref,
80
+ "aria-owns": open ? id : null
80
81
  }), /*#__PURE__*/React__default.createElement("div", {
81
82
  className: primaryActionClasses
82
83
  }, /*#__PURE__*/React__default.createElement(Button, {
@@ -88,12 +89,12 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
88
89
  label: t('carbon.combo-button.additional-actions'),
89
90
  size: size,
90
91
  disabled: disabled,
91
- align: tooltipAlign,
92
+ align: tooltipAlignment,
92
93
  "aria-haspopup": true,
93
94
  "aria-expanded": open,
94
95
  onClick: handleTriggerClick,
95
96
  onMouseDown: handleTriggerMousedown,
96
- "aria-owns": open ? id : null
97
+ "aria-controls": open ? id : null
97
98
  }, _ChevronDown || (_ChevronDown = /*#__PURE__*/React__default.createElement(ChevronDown, null))), /*#__PURE__*/React__default.createElement(Menu, {
98
99
  ref: menuRef,
99
100
  id: id,
@@ -134,7 +135,7 @@ ComboButton.propTypes = {
134
135
  /**
135
136
  * Specify how the trigger tooltip should be aligned.
136
137
  */
137
- tooltipAlign: PropTypes.oneOf(['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'right']),
138
+ tooltipAlignment: PropTypes.oneOf(['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'right']),
138
139
  /**
139
140
  * Optional method that takes in a message id and returns an
140
141
  * internationalized string.
@@ -8,6 +8,7 @@
8
8
  import React__default from 'react';
9
9
  import PropTypes from 'prop-types';
10
10
  import cx from 'classnames';
11
+ import { LayoutConstraint } from '../Layout/index.js';
11
12
  import { useId } from '../../internal/useId.js';
12
13
  import { usePrefix } from '../../internal/usePrefix.js';
13
14
 
@@ -43,13 +44,16 @@ function ContainedList(_ref) {
43
44
  isInset,
44
45
  kind = variants[0],
45
46
  label,
46
- size = 'lg'
47
+ size
47
48
  } = _ref;
48
49
  const labelId = `${useId('contained-list')}-header`;
49
50
  const prefix = usePrefix();
50
51
  const classes = cx(`${prefix}--contained-list`, {
51
- [`${prefix}--contained-list--inset-rulers`]: isInset
52
- }, `${prefix}--contained-list--${kind}`, `${prefix}--contained-list--${size}`, className);
52
+ [`${prefix}--contained-list--inset-rulers`]: isInset,
53
+ [`${prefix}--contained-list--${size}`]: size,
54
+ // TODO: V12 - Remove this class
55
+ [`${prefix}--layout--size-${size}`]: size
56
+ }, `${prefix}--contained-list--${kind}`, className);
53
57
  const filteredChildren = filterChildren(children);
54
58
  const isActionSearch = ['Search', 'ExpandableSearch'].includes(action?.type?.displayName);
55
59
  const renderedChildren = renderChildren(children);
@@ -60,7 +64,11 @@ function ContainedList(_ref) {
60
64
  }, /*#__PURE__*/React__default.createElement("div", {
61
65
  id: labelId,
62
66
  className: `${prefix}--contained-list__label`
63
- }, label), /*#__PURE__*/React__default.createElement("div", {
67
+ }, label), /*#__PURE__*/React__default.createElement(LayoutConstraint, {
68
+ size: {
69
+ min: 'sm',
70
+ max: 'xl'
71
+ },
64
72
  className: `${prefix}--contained-list__action`
65
73
  }, action)), children && /*#__PURE__*/React__default.createElement("ul", {
66
74
  "aria-labelledby": labelId
@@ -8,6 +8,7 @@
8
8
  import React__default from 'react';
9
9
  import PropTypes from 'prop-types';
10
10
  import cx from 'classnames';
11
+ import { LayoutConstraint } from '../../Layout/index.js';
11
12
  import { usePrefix } from '../../../internal/usePrefix.js';
12
13
 
13
14
  function ContainedListItem(_ref) {
@@ -38,7 +39,11 @@ function ContainedListItem(_ref) {
38
39
  onClick: onClick
39
40
  }, content) : /*#__PURE__*/React__default.createElement("div", {
40
41
  className: `${prefix}--contained-list-item__content`
41
- }, content), action && /*#__PURE__*/React__default.createElement("div", {
42
+ }, content), action && /*#__PURE__*/React__default.createElement(LayoutConstraint, {
43
+ size: {
44
+ min: 'sm',
45
+ max: 'lg'
46
+ },
42
47
  className: `${prefix}--contained-list-item__action`
43
48
  }, action));
44
49
  }
@@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
10
10
  import React__default from 'react';
11
11
  import cx from 'classnames';
12
12
  import deprecate from '../../prop-types/deprecate.js';
13
+ import { LayoutConstraint } from '../Layout/index.js';
13
14
  import { composeEventHandlers } from '../../tools/events.js';
14
15
  import { PrefixContext } from '../../internal/usePrefix.js';
15
16
  import { matches } from '../../internal/keyboard/match.js';
@@ -107,9 +108,17 @@ class ContentSwitcher extends React__default.Component {
107
108
  const classes = cx(`${prefix}--content-switcher`, className, {
108
109
  [`${prefix}--content-switcher--light`]: light,
109
110
  [`${prefix}--content-switcher--${size}`]: size,
111
+ // TODO: V12 - Remove this class
112
+ [`${prefix}--layout--size-${size}`]: size,
110
113
  [`${prefix}--content-switcher--icon-only`]: isIconOnly
111
114
  });
112
- return /*#__PURE__*/React__default.createElement("div", _extends({}, other, {
115
+ return /*#__PURE__*/React__default.createElement(LayoutConstraint, _extends({
116
+ size: {
117
+ default: 'md',
118
+ min: 'sm',
119
+ max: 'lg'
120
+ }
121
+ }, other, {
113
122
  className: classes,
114
123
  role: "tablist"
115
124
  }), React__default.Children.map(children, (child, index) => /*#__PURE__*/React__default.cloneElement(child, {
@@ -11,6 +11,7 @@ import React__default from 'react';
11
11
  import cx from 'classnames';
12
12
  import { Copy as Copy$1 } from '@carbon/icons-react';
13
13
  import Copy from '../Copy/Copy.js';
14
+ import { LayoutConstraint } from '../Layout/index.js';
14
15
  import { usePrefix } from '../../internal/usePrefix.js';
15
16
 
16
17
  function CopyButton(_ref) {
@@ -20,12 +21,17 @@ function CopyButton(_ref) {
20
21
  ...other
21
22
  } = _ref;
22
23
  const prefix = usePrefix();
23
- return /*#__PURE__*/React__default.createElement(Copy, _extends({
24
+ return /*#__PURE__*/React__default.createElement(LayoutConstraint, {
25
+ size: {
26
+ default: 'md',
27
+ max: 'lg'
28
+ }
29
+ }, /*#__PURE__*/React__default.createElement(Copy, _extends({
24
30
  className: cx(className, `${prefix}--copy-btn`),
25
31
  "aria-label": iconDescription
26
32
  }, other), /*#__PURE__*/React__default.createElement(Copy$1, {
27
33
  className: `${prefix}--snippet__icon`
28
- }));
34
+ })));
29
35
  }
30
36
  CopyButton.propTypes = {
31
37
  /**
@@ -234,7 +234,8 @@ class DataTable extends React__default.Component {
234
234
  isSortable,
235
235
  useStaticWidth,
236
236
  stickyHeader,
237
- overflowMenuOnHover
237
+ overflowMenuOnHover,
238
+ experimentalAutoAlign
238
239
  } = this.props;
239
240
  return {
240
241
  useZebraStyles,
@@ -242,7 +243,8 @@ class DataTable extends React__default.Component {
242
243
  isSortable,
243
244
  useStaticWidth,
244
245
  stickyHeader,
245
- overflowMenuOnHover
246
+ overflowMenuOnHover,
247
+ experimentalAutoAlign
246
248
  };
247
249
  });
248
250
  _defineProperty(this, "getTableContainerProps", () => {
@@ -621,6 +623,10 @@ class DataTable extends React__default.Component {
621
623
  }
622
624
  }
623
625
  _defineProperty(DataTable, "propTypes", {
626
+ /**
627
+ * Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
628
+ */
629
+ experimentalAutoAlign: PropTypes.bool,
624
630
  /**
625
631
  * Optional hook to manually control filtering of the rows from the
626
632
  * TableToolbarSearch component
@@ -7,6 +7,7 @@
7
7
  import { PropsWithChildren } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  interface TableProps {
10
+ experimentalAutoAlign?: boolean;
10
11
  className?: string;
11
12
  /**
12
13
  * `false` If true, will apply sorting styles
@@ -34,13 +35,17 @@ interface TableProps {
34
35
  useZebraStyles?: boolean;
35
36
  }
36
37
  export declare const Table: {
37
- ({ className, children, useZebraStyles, size, isSortable, useStaticWidth, stickyHeader, overflowMenuOnHover, ...other }: PropsWithChildren<TableProps>): JSX.Element;
38
+ ({ className, children, useZebraStyles, size, isSortable, useStaticWidth, stickyHeader, overflowMenuOnHover, experimentalAutoAlign, ...other }: PropsWithChildren<TableProps>): JSX.Element;
38
39
  propTypes: {
39
40
  /**
40
41
  * Pass in the children that will be rendered within the Table
41
42
  */
42
43
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
43
44
  className: PropTypes.Requireable<string>;
45
+ /**
46
+ * Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
47
+ */
48
+ experimentalAutoAlign: PropTypes.Requireable<boolean>;
44
49
  /**
45
50
  * `false` If true, will apply sorting styles
46
51
  */
@@ -6,22 +6,53 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useContext } from 'react';
9
+ import React__default, { useContext, useRef, useCallback, useLayoutEffect } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
+ import debounce from 'lodash.debounce';
12
13
  import { usePrefix } from '../../internal/usePrefix.js';
13
14
  import { TableContext } from './TableContext.js';
15
+ import { useWindowEvent } from '../../internal/useEvent.js';
14
16
 
17
+ const isElementWrappingContent = (element, context) => {
18
+ if (element.children.length > 0) {
19
+ return false;
20
+ }
21
+ const computedStyles = window.getComputedStyle(element);
22
+ context.font = computedStyles.font ? computedStyles.font : `${computedStyles.fontSize}" "${computedStyles.fontFamily}`;
23
+ const measuredText = context?.measureText(element.textContent ?? '');
24
+ let textWidth = measuredText.width ?? 0;
25
+ // account for letter spacing
26
+ const letterSpacing = computedStyles.letterSpacing?.split('px');
27
+ if (letterSpacing && letterSpacing.length && !isNaN(Number(letterSpacing[0]))) {
28
+ textWidth += Number(letterSpacing[0]) * (element.textContent?.length ?? 0);
29
+ }
30
+ // account for padding
31
+ const paddingLeft = computedStyles.paddingLeft?.split('px');
32
+ if (paddingLeft && paddingLeft.length && !isNaN(Number(paddingLeft[0]))) {
33
+ textWidth += Number(paddingLeft[0]);
34
+ }
35
+ const paddingRight = computedStyles.paddingLeft?.split('px');
36
+ if (paddingRight && paddingRight.length && !isNaN(Number(paddingRight[0]))) {
37
+ textWidth += Number(paddingRight[0]);
38
+ }
39
+ // if measured textWidth is larger than the cell's width, then the content is being wrapped
40
+ if (textWidth > element.getBoundingClientRect().width) {
41
+ return true;
42
+ }
43
+ return false;
44
+ };
15
45
  const Table = _ref => {
16
46
  let {
17
47
  className,
18
48
  children,
19
49
  useZebraStyles,
20
- size,
50
+ size = 'lg',
21
51
  isSortable = false,
22
52
  useStaticWidth,
23
53
  stickyHeader,
24
54
  overflowMenuOnHover = true,
55
+ experimentalAutoAlign = false,
25
56
  ...other
26
57
  } = _ref;
27
58
  const {
@@ -29,6 +60,7 @@ const Table = _ref => {
29
60
  descriptionId
30
61
  } = useContext(TableContext);
31
62
  const prefix = usePrefix();
63
+ const tableRef = useRef(null);
32
64
  const componentClass = cx(`${prefix}--data-table`, className, {
33
65
  [`${prefix}--data-table--${size}`]: size,
34
66
  [`${prefix}--data-table--sort`]: isSortable,
@@ -37,13 +69,52 @@ const Table = _ref => {
37
69
  [`${prefix}--data-table--sticky-header`]: stickyHeader,
38
70
  [`${prefix}--data-table--visible-overflow-menu`]: !overflowMenuOnHover
39
71
  });
72
+ const toggleTableBodyAlignmentClass = useCallback(function () {
73
+ let alignTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
74
+ alignTop ? tableRef.current?.classList.add(`${prefix}--data-table--top-aligned-body`) : tableRef.current?.classList.remove(`${prefix}--data-table--top-aligned-body`);
75
+ }, [prefix]);
76
+ const toggleTableHeaderAlignmentClass = useCallback(function () {
77
+ let alignTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
78
+ alignTop ? tableRef.current?.classList.add(`${prefix}--data-table--top-aligned-header`) : tableRef.current?.classList.remove(`${prefix}--data-table--top-aligned-header`);
79
+ }, [prefix]);
80
+ const setTableAlignment = useCallback(() => {
81
+ if (experimentalAutoAlign) {
82
+ const canvas = document.createElement('canvas');
83
+ const context = canvas.getContext('2d');
84
+ if (tableRef.current && context) {
85
+ const isBodyMultiline = Array.from(tableRef.current.querySelectorAll('td')).some(td => isElementWrappingContent(td, context));
86
+ const isHeaderMultiline = Array.from(tableRef.current.querySelectorAll('th')).some(th => {
87
+ const label = th.querySelector(`.${prefix}--table-header-label`);
88
+ return label && isElementWrappingContent(label, context);
89
+ });
90
+ toggleTableBodyAlignmentClass(isBodyMultiline);
91
+ toggleTableHeaderAlignmentClass(isHeaderMultiline);
92
+ }
93
+ } else {
94
+ toggleTableBodyAlignmentClass(false);
95
+ toggleTableHeaderAlignmentClass(false);
96
+ }
97
+ }, [experimentalAutoAlign, toggleTableBodyAlignmentClass, toggleTableHeaderAlignmentClass, prefix]);
98
+ const debouncedSetTableAlignment = debounce(setTableAlignment, 100);
99
+ useWindowEvent('resize', debouncedSetTableAlignment);
100
+
101
+ // recalculate table alignment once fonts have loaded
102
+ if (document?.fonts?.status && document.fonts.status !== 'loaded') {
103
+ document.fonts.ready.then(() => {
104
+ setTableAlignment();
105
+ });
106
+ }
107
+ useLayoutEffect(() => {
108
+ setTableAlignment();
109
+ }, [setTableAlignment, size]);
40
110
  const table = /*#__PURE__*/React__default.createElement("div", {
41
111
  className: `${prefix}--data-table-content`
42
112
  }, /*#__PURE__*/React__default.createElement("table", _extends({
43
113
  "aria-labelledby": titleId,
44
114
  "aria-describedby": descriptionId
45
115
  }, other, {
46
- className: componentClass
116
+ className: componentClass,
117
+ ref: tableRef
47
118
  }), children));
48
119
  return stickyHeader ? /*#__PURE__*/React__default.createElement("section", {
49
120
  className: `${prefix}--data-table_inner-container`
@@ -55,6 +126,10 @@ Table.propTypes = {
55
126
  */
56
127
  children: PropTypes.node,
57
128
  className: PropTypes.string,
129
+ /**
130
+ * Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
131
+ */
132
+ experimentalAutoAlign: PropTypes.bool,
58
133
  /**
59
134
  * `false` If true, will apply sorting styles
60
135
  */
@@ -80,10 +80,11 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
80
80
  isSortHeader,
81
81
  sortStates
82
82
  });
83
+ const headerClasses = cx(headerClassName, `${prefix}--table-sort__header`);
83
84
  return /*#__PURE__*/React__default.createElement("th", {
84
85
  id: id,
85
86
  "aria-sort": ariaSort,
86
- className: headerClassName,
87
+ className: headerClasses,
87
88
  colSpan: colSpan,
88
89
  ref: ref,
89
90
  scope: scope
@@ -111,6 +111,5 @@ DataTableSkeleton.defaultProps = {
111
111
  showHeader: true,
112
112
  showToolbar: true
113
113
  };
114
- var DataTableSkeleton$1 = DataTableSkeleton;
115
114
 
116
- export { DataTableSkeleton$1 as default };
115
+ export { DataTableSkeleton as default };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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 DataTableSkeleton from './DataTableSkeleton';
8
+ export default DataTableSkeleton;
9
+ export { DataTableSkeleton };
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import { type SearchProps } from '../Search';
9
- declare function ExpandableSearch({ onBlur, onChange, onExpand, onFocus, ...props }: SearchProps): JSX.Element;
9
+ declare function ExpandableSearch({ onBlur, onChange, onExpand, onFocus, defaultValue, isExpanded, ...props }: SearchProps): JSX.Element;
10
10
  declare namespace ExpandableSearch {
11
11
  var propTypes: React.WeakValidationMap<SearchProps & React.RefAttributes<HTMLInputElement>> | undefined;
12
12
  var displayName: string;
@@ -19,10 +19,12 @@ function ExpandableSearch(_ref) {
19
19
  onChange,
20
20
  onExpand,
21
21
  onFocus,
22
+ defaultValue,
23
+ isExpanded,
22
24
  ...props
23
25
  } = _ref;
24
- const [expanded, setExpanded] = useState(false);
25
- const [hasContent, setHasContent] = useState(false);
26
+ const [expanded, setExpanded] = useState(isExpanded || false);
27
+ const [hasContent, setHasContent] = useState(defaultValue ? true : false);
26
28
  const searchRef = useRef(null);
27
29
  const prefix = usePrefix();
28
30
  function handleFocus() {
@@ -46,6 +48,8 @@ function ExpandableSearch(_ref) {
46
48
  [`${prefix}--search--expanded`]: expanded
47
49
  }, props.className);
48
50
  return /*#__PURE__*/React__default.createElement(Search, _extends({}, props, {
51
+ defaultValue: defaultValue,
52
+ isExpanded: expanded,
49
53
  ref: searchRef,
50
54
  className: classes,
51
55
  onFocus: composeEventHandlers([onFocus, handleFocus]),
@@ -46,7 +46,8 @@ function FileUploaderButton(_ref) {
46
46
  [`${prefix}--btn--disabled`]: disabled,
47
47
  // V11: remove field, small
48
48
  [`${prefix}--btn--md`]: size === 'field' || size === 'md',
49
- [`${prefix}--btn--sm`]: size === 'small' || size === 'sm'
49
+ [`${prefix}--btn--sm`]: size === 'small' || size === 'sm',
50
+ [`${prefix}--layout--size-${size}`]: size
50
51
  });
51
52
 
52
53
  // Adjust label text state based on changes to the labelText prop
@@ -21,16 +21,19 @@ const IconButton = /*#__PURE__*/React__default.forwardRef(function IconButton(pr
21
21
  className,
22
22
  closeOnActivation = true,
23
23
  defaultOpen = false,
24
+ disabled,
24
25
  enterDelayMs,
25
26
  kind,
26
27
  label,
27
28
  leaveDelayMs,
28
29
  wrapperClasses,
29
- size = 'md',
30
+ size,
30
31
  ...rest
31
32
  } = props;
32
33
  const prefix = usePrefix();
33
- const tooltipClasses = cx(wrapperClasses, `${prefix}--icon-tooltip`);
34
+ const tooltipClasses = cx(wrapperClasses, `${prefix}--icon-tooltip`, {
35
+ [`${prefix}--icon-tooltip--disabled`]: disabled
36
+ });
34
37
  return /*#__PURE__*/React__default.createElement(Tooltip, {
35
38
  align: align,
36
39
  closeOnActivation: closeOnActivation,
@@ -40,6 +43,7 @@ const IconButton = /*#__PURE__*/React__default.forwardRef(function IconButton(pr
40
43
  label: label,
41
44
  leaveDelayMs: leaveDelayMs
42
45
  }, /*#__PURE__*/React__default.createElement(Button, _extends({}, rest, {
46
+ disabled: disabled,
43
47
  kind: kind,
44
48
  ref: ref,
45
49
  size: size,
@@ -67,6 +71,10 @@ IconButton.propTypes = {
67
71
  * Specify whether the tooltip should be open when it first renders
68
72
  */
69
73
  defaultOpen: PropTypes.bool,
74
+ /**
75
+ * Specify whether the Button should be disabled, or not
76
+ */
77
+ disabled: PropTypes.bool,
70
78
  /**
71
79
  * Specify the duration in milliseconds to delay before displaying the tooltip
72
80
  */