@carbon/react 1.44.0 → 1.45.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 (134) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +820 -902
  2. package/es/components/Checkbox/Checkbox.d.ts +1 -1
  3. package/es/components/Checkbox/Checkbox.js +1 -1
  4. package/es/components/CheckboxGroup/CheckboxGroup.js +2 -2
  5. package/es/components/ComboBox/ComboBox.d.ts +1 -1
  6. package/es/components/ComboBox/ComboBox.js +2 -2
  7. package/es/components/ComboButton/index.js +1 -1
  8. package/es/components/ComposedModal/ModalFooter.d.ts +2 -1
  9. package/es/components/ContentSwitcher/ContentSwitcher.js +1 -1
  10. package/es/components/DataTable/DataTable.d.ts +2 -0
  11. package/es/components/DataTable/DataTable.js +3 -0
  12. package/es/components/DataTable/TableExpandRow.js +20 -3
  13. package/es/components/DataTable/TableHeader.d.ts +5 -0
  14. package/es/components/DataTable/TableHeader.js +30 -6
  15. package/es/components/DataTable/TableSlugRow.d.ts +31 -0
  16. package/es/components/DataTable/TableSlugRow.js +49 -0
  17. package/es/components/DataTable/index.d.ts +2 -1
  18. package/es/components/DataTable/index.js +3 -0
  19. package/es/components/DatePickerInput/DatePickerInput.d.ts +1 -1
  20. package/es/components/DatePickerInput/DatePickerInput.js +2 -2
  21. package/es/components/Dropdown/Dropdown.d.ts +1 -1
  22. package/es/components/Dropdown/Dropdown.js +2 -2
  23. package/es/components/InlineLoading/InlineLoading.d.ts +68 -0
  24. package/es/components/InlineLoading/InlineLoading.js +4 -4
  25. package/es/components/InlineLoading/index.d.ts +9 -0
  26. package/es/components/Layer/LayerContext.d.ts +8 -0
  27. package/es/components/Layer/LayerLevel.d.ts +5 -0
  28. package/es/components/Layer/LayerLevel.js +12 -0
  29. package/es/components/Layer/index.d.ts +38 -0
  30. package/es/components/Layer/index.js +9 -8
  31. package/es/components/Menu/MenuItem.js +2 -1
  32. package/es/components/MenuButton/index.js +1 -1
  33. package/es/components/Modal/Modal.d.ts +3 -2
  34. package/es/components/MultiSelect/FilterableMultiSelect.js +2 -2
  35. package/es/components/MultiSelect/MultiSelect.d.ts +1 -1
  36. package/es/components/MultiSelect/MultiSelect.js +5 -2
  37. package/es/components/Notification/Notification.js +1 -0
  38. package/es/components/NumberInput/NumberInput.d.ts +1 -1
  39. package/es/components/NumberInput/NumberInput.js +3 -3
  40. package/es/components/ProgressIndicator/ProgressIndicator.js +4 -0
  41. package/es/components/RadioButton/RadioButton.d.ts +1 -1
  42. package/es/components/RadioButton/RadioButton.js +1 -1
  43. package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +1 -1
  44. package/es/components/RadioButtonGroup/RadioButtonGroup.js +2 -2
  45. package/es/components/Select/Select.d.ts +1 -1
  46. package/es/components/Select/Select.js +2 -2
  47. package/es/components/Slider/Slider.Skeleton.js +17 -3
  48. package/es/components/Slider/Slider.js +132 -93
  49. package/es/components/Slider/SliderHandles.d.ts +4 -0
  50. package/es/components/Slider/SliderHandles.js +65 -0
  51. package/es/components/Slug/index.js +1 -0
  52. package/es/components/Tabs/Tabs.js +1 -1
  53. package/es/components/Tag/Tag.d.ts +18 -10
  54. package/es/components/Tag/Tag.js +23 -7
  55. package/es/components/TextArea/TextArea.d.ts +7 -3
  56. package/es/components/TextArea/TextArea.js +85 -18
  57. package/es/components/TextInput/TextInput.d.ts +1 -1
  58. package/es/components/TextInput/TextInput.js +2 -2
  59. package/es/components/Tile/Tile.d.ts +8 -8
  60. package/es/components/Tile/Tile.js +11 -7
  61. package/es/components/Tooltip/Tooltip.js +48 -2
  62. package/es/components/UIShell/HeaderPanel.d.ts +36 -0
  63. package/es/components/UIShell/HeaderPanel.js +6 -6
  64. package/es/components/UIShell/Switcher.js +1 -1
  65. package/es/index.js +2 -1
  66. package/es/internal/useAnnouncer.js +2 -1
  67. package/es/internal/useNoInteractiveChildren.js +2 -6
  68. package/lib/components/Checkbox/Checkbox.d.ts +1 -1
  69. package/lib/components/Checkbox/Checkbox.js +1 -1
  70. package/lib/components/CheckboxGroup/CheckboxGroup.js +2 -2
  71. package/lib/components/ComboBox/ComboBox.d.ts +1 -1
  72. package/lib/components/ComboBox/ComboBox.js +2 -2
  73. package/lib/components/ComboButton/index.js +1 -1
  74. package/lib/components/ComposedModal/ModalFooter.d.ts +2 -1
  75. package/lib/components/ContentSwitcher/ContentSwitcher.js +1 -1
  76. package/lib/components/DataTable/DataTable.d.ts +2 -0
  77. package/lib/components/DataTable/DataTable.js +3 -0
  78. package/lib/components/DataTable/TableExpandRow.js +20 -3
  79. package/lib/components/DataTable/TableHeader.d.ts +5 -0
  80. package/lib/components/DataTable/TableHeader.js +29 -5
  81. package/lib/components/DataTable/TableSlugRow.d.ts +31 -0
  82. package/lib/components/DataTable/TableSlugRow.js +59 -0
  83. package/lib/components/DataTable/index.d.ts +2 -1
  84. package/lib/components/DataTable/index.js +3 -0
  85. package/lib/components/DatePickerInput/DatePickerInput.d.ts +1 -1
  86. package/lib/components/DatePickerInput/DatePickerInput.js +2 -2
  87. package/lib/components/Dropdown/Dropdown.d.ts +1 -1
  88. package/lib/components/Dropdown/Dropdown.js +2 -2
  89. package/lib/components/InlineLoading/InlineLoading.d.ts +68 -0
  90. package/lib/components/InlineLoading/InlineLoading.js +4 -4
  91. package/lib/components/InlineLoading/index.d.ts +9 -0
  92. package/lib/components/Layer/LayerContext.d.ts +8 -0
  93. package/lib/components/Layer/LayerLevel.d.ts +5 -0
  94. package/lib/components/Layer/LayerLevel.js +18 -0
  95. package/lib/components/Layer/index.d.ts +38 -0
  96. package/lib/components/Layer/index.js +10 -9
  97. package/lib/components/Menu/MenuItem.js +2 -1
  98. package/lib/components/MenuButton/index.js +1 -1
  99. package/lib/components/Modal/Modal.d.ts +3 -2
  100. package/lib/components/MultiSelect/FilterableMultiSelect.js +2 -2
  101. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  102. package/lib/components/MultiSelect/MultiSelect.js +5 -2
  103. package/lib/components/Notification/Notification.js +1 -0
  104. package/lib/components/NumberInput/NumberInput.d.ts +1 -1
  105. package/lib/components/NumberInput/NumberInput.js +3 -3
  106. package/lib/components/ProgressIndicator/ProgressIndicator.js +4 -0
  107. package/lib/components/RadioButton/RadioButton.d.ts +1 -1
  108. package/lib/components/RadioButton/RadioButton.js +1 -1
  109. package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +1 -1
  110. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +2 -2
  111. package/lib/components/Select/Select.d.ts +1 -1
  112. package/lib/components/Select/Select.js +2 -2
  113. package/lib/components/Slider/Slider.Skeleton.js +17 -3
  114. package/lib/components/Slider/Slider.js +132 -93
  115. package/lib/components/Slider/SliderHandles.d.ts +4 -0
  116. package/lib/components/Slider/SliderHandles.js +76 -0
  117. package/lib/components/Slug/index.js +1 -0
  118. package/lib/components/Tabs/Tabs.js +1 -1
  119. package/lib/components/Tag/Tag.d.ts +18 -10
  120. package/lib/components/Tag/Tag.js +23 -7
  121. package/lib/components/TextArea/TextArea.d.ts +7 -3
  122. package/lib/components/TextArea/TextArea.js +84 -17
  123. package/lib/components/TextInput/TextInput.d.ts +1 -1
  124. package/lib/components/TextInput/TextInput.js +2 -2
  125. package/lib/components/Tile/Tile.d.ts +8 -8
  126. package/lib/components/Tile/Tile.js +11 -7
  127. package/lib/components/Tooltip/Tooltip.js +47 -1
  128. package/lib/components/UIShell/HeaderPanel.d.ts +36 -0
  129. package/lib/components/UIShell/HeaderPanel.js +7 -7
  130. package/lib/components/UIShell/Switcher.js +1 -1
  131. package/lib/index.js +4 -2
  132. package/lib/internal/useAnnouncer.js +2 -1
  133. package/lib/internal/useNoInteractiveChildren.js +2 -6
  134. package/package.json +4 -7
@@ -44,6 +44,7 @@ const Tag = _ref => {
44
44
  onClose,
45
45
  size,
46
46
  as: BaseComponent,
47
+ slug,
47
48
  ...other
48
49
  } = _ref;
49
50
  const prefix = usePrefix();
@@ -64,15 +65,26 @@ const Tag = _ref => {
64
65
  onClose(event);
65
66
  }
66
67
  };
68
+
69
+ // Slug is always size `md` and `inline`
70
+ let normalizedSlug;
71
+ if (slug && slug['type']?.displayName === 'Slug') {
72
+ normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
73
+ size: 'sm',
74
+ kind: 'inline'
75
+ });
76
+ }
67
77
  if (filter) {
68
78
  const ComponentTag = BaseComponent ?? 'div';
69
79
  return /*#__PURE__*/React__default.createElement(ComponentTag, _extends({
70
80
  className: tagClasses,
71
81
  id: tagId
72
- }, other), /*#__PURE__*/React__default.createElement(Text, {
82
+ }, other), CustomIconElement ? /*#__PURE__*/React__default.createElement("div", {
83
+ className: `${prefix}--tag__custom-icon`
84
+ }, /*#__PURE__*/React__default.createElement(CustomIconElement, null)) : '', /*#__PURE__*/React__default.createElement(Text, {
73
85
  className: `${prefix}--tag__label`,
74
86
  title: typeof children === 'string' ? children : undefined
75
- }, children !== null && children !== undefined ? children : typeText), /*#__PURE__*/React__default.createElement("button", {
87
+ }, children !== null && children !== undefined ? children : typeText), normalizedSlug, /*#__PURE__*/React__default.createElement("button", {
76
88
  type: "button",
77
89
  className: `${prefix}--tag__close-icon`,
78
90
  onClick: handleClose,
@@ -90,7 +102,7 @@ const Tag = _ref => {
90
102
  className: `${prefix}--tag__custom-icon`
91
103
  }, /*#__PURE__*/React__default.createElement(CustomIconElement, null)) : '', /*#__PURE__*/React__default.createElement(Text, {
92
104
  title: typeof children === 'string' ? children : undefined
93
- }, children !== null && children !== undefined ? children : typeText));
105
+ }, children !== null && children !== undefined ? children : typeText), normalizedSlug);
94
106
  };
95
107
  Tag.propTypes = {
96
108
  /**
@@ -99,7 +111,7 @@ Tag.propTypes = {
99
111
  */
100
112
  as: PropTypes.elementType,
101
113
  /**
102
- * Provide content to be rendered inside of a <Tag>
114
+ * Provide content to be rendered inside of a `Tag`
103
115
  */
104
116
  children: PropTypes.node,
105
117
  /**
@@ -107,11 +119,11 @@ Tag.propTypes = {
107
119
  */
108
120
  className: PropTypes.string,
109
121
  /**
110
- * Specify if the <Tag> is disabled
122
+ * Specify if the `Tag` is disabled
111
123
  */
112
124
  disabled: PropTypes.bool,
113
125
  /**
114
- * Determine if <Tag> is a filter/chip
126
+ * Determine if `Tag` is a filter/chip
115
127
  */
116
128
  filter: PropTypes.bool,
117
129
  /**
@@ -132,12 +144,16 @@ Tag.propTypes = {
132
144
  * 'md' (default) sizes.
133
145
  */
134
146
  size: PropTypes.oneOf(['sm', 'md']),
147
+ /**
148
+ * **Experimental:** Provide a `Slug` component to be rendered inside the `Tag` component
149
+ */
150
+ slug: PropTypes.node,
135
151
  /**
136
152
  * Text to show on clear filters
137
153
  */
138
154
  title: PropTypes.string,
139
155
  /**
140
- * Specify the type of the <Tag>
156
+ * Specify the type of the `Tag`
141
157
  */
142
158
  type: PropTypes.oneOf(Object.keys(TYPES))
143
159
  };
@@ -25,7 +25,7 @@ export interface TextAreaProps extends React.InputHTMLAttributes<HTMLTextAreaEle
25
25
  */
26
26
  disabled?: boolean;
27
27
  /**
28
- * Specify whether to display the character counter
28
+ * Specify whether to display the counter
29
29
  */
30
30
  enableCounter?: boolean;
31
31
  /**
@@ -60,7 +60,7 @@ export interface TextAreaProps extends React.InputHTMLAttributes<HTMLTextAreaEle
60
60
  */
61
61
  light?: boolean;
62
62
  /**
63
- * Max character count allowed for the textarea. This is needed in order for enableCounter to display
63
+ * Max entity count allowed for the textarea. This is needed in order for enableCounter to display
64
64
  */
65
65
  maxCount?: number;
66
66
  /**
@@ -86,7 +86,7 @@ export interface TextAreaProps extends React.InputHTMLAttributes<HTMLTextAreaEle
86
86
  */
87
87
  rows?: number;
88
88
  /**
89
- * Provide a `Slug` component to be rendered inside the `TextArea` component
89
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `TextArea` component
90
90
  */
91
91
  slug?: ReactNodeLike;
92
92
  /**
@@ -101,6 +101,10 @@ export interface TextAreaProps extends React.InputHTMLAttributes<HTMLTextAreaEle
101
101
  * Provide the text that is displayed when the control is in warning state
102
102
  */
103
103
  warnText?: ReactNodeLike;
104
+ /**
105
+ * Specify the method used for calculating the counter number
106
+ */
107
+ counterMode?: 'character' | 'word';
104
108
  }
105
109
  declare const TextArea: React.ForwardRefExoticComponent<TextAreaProps & React.RefAttributes<unknown>>;
106
110
  export default TextArea;
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default, { useContext, useState, useRef, useEffect } from 'react';
10
+ import React__default, { useContext, useRef, useState, useEffect } from 'react';
11
11
  import cx from 'classnames';
12
12
  import deprecate from '../../prop-types/deprecate.js';
13
13
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
@@ -39,6 +39,7 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
39
39
  placeholder = '',
40
40
  enableCounter = false,
41
41
  maxCount = undefined,
42
+ counterMode = 'character',
42
43
  warn = false,
43
44
  warnText = '',
44
45
  rows = 4,
@@ -53,15 +54,25 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
53
54
  defaultValue,
54
55
  value
55
56
  } = other;
56
- const [textCount, setTextCount] = useState(defaultValue?.toString()?.length || value?.toString()?.length || 0);
57
57
  const {
58
58
  current: textAreaInstanceId
59
59
  } = useRef(getInstanceId());
60
60
  const textareaRef = useRef(null);
61
61
  const ref = useMergedRefs([forwardRef, textareaRef]);
62
+ function getInitialTextCount() {
63
+ const targetValue = defaultValue || value || textareaRef.current?.value || '';
64
+ const strValue = targetValue.toString();
65
+ if (counterMode === 'character') {
66
+ return strValue.length;
67
+ } else {
68
+ return strValue.match(/\w+/g)?.length || 0;
69
+ }
70
+ }
71
+ const [textCount, setTextCount] = useState(getInitialTextCount());
62
72
  useEffect(() => {
63
- setTextCount(defaultValue?.toString()?.length || value?.toString()?.length || 0);
64
- }, [value, defaultValue]);
73
+ setTextCount(getInitialTextCount());
74
+ // eslint-disable-next-line react-hooks/exhaustive-deps
75
+ }, [value, defaultValue, counterMode]);
65
76
  useIsomorphicEffect(() => {
66
77
  if (other.cols && textareaRef.current) {
67
78
  textareaRef.current.style.width = '';
@@ -72,14 +83,63 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
72
83
  }, [other.cols]);
73
84
  const textareaProps = {
74
85
  id,
86
+ onKeyDown: evt => {
87
+ if (!disabled && enableCounter && counterMode === 'word') {
88
+ const key = evt.which;
89
+ if (maxCount && textCount >= maxCount && key === 32) {
90
+ evt.preventDefault();
91
+ }
92
+ }
93
+ },
94
+ onPaste: evt => {
95
+ if (!disabled) {
96
+ if (counterMode === 'word' && enableCounter && typeof maxCount !== 'undefined' && textareaRef.current !== null) {
97
+ const existingWords = textareaRef.current.value.match(/\w+/g) || [];
98
+ const pastedWords = evt.clipboardData.getData('Text').match(/\w+/g) || [];
99
+ const totalWords = existingWords.length + pastedWords.length;
100
+ if (totalWords > maxCount) {
101
+ evt.preventDefault();
102
+ const allowedWords = existingWords.concat(pastedWords).slice(0, maxCount);
103
+ setTimeout(() => {
104
+ setTextCount(maxCount);
105
+ }, 0);
106
+ textareaRef.current.value = allowedWords.join(' ');
107
+ }
108
+ }
109
+ }
110
+ },
75
111
  onChange: evt => {
76
- if (!disabled && onChange) {
77
- evt?.persist?.();
78
- // delay textCount assignation to give the textarea element value time to catch up if is a controlled input
79
- setTimeout(() => {
80
- setTextCount(evt.target?.value?.length);
81
- }, 0);
82
- onChange(evt);
112
+ if (!disabled) {
113
+ if (counterMode == 'character') {
114
+ evt?.persist?.();
115
+ // delay textCount assignation to give the textarea element value time to catch up if is a controlled input
116
+ setTimeout(() => {
117
+ setTextCount(evt.target?.value?.length);
118
+ }, 0);
119
+ } else if (counterMode == 'word') {
120
+ if (!evt.target.value) {
121
+ setTimeout(() => {
122
+ setTextCount(0);
123
+ }, 0);
124
+ return;
125
+ }
126
+ if (enableCounter && typeof maxCount !== 'undefined' && textareaRef.current !== null) {
127
+ const matchedWords = evt.target?.value?.match(/\w+/g);
128
+ if (matchedWords && matchedWords.length <= maxCount) {
129
+ textareaRef.current.removeAttribute('maxLength');
130
+ setTimeout(() => {
131
+ setTextCount(matchedWords.length);
132
+ }, 0);
133
+ } else if (matchedWords && matchedWords.length > maxCount) {
134
+ setTimeout(() => {
135
+ setTextCount(matchedWords.length);
136
+ }, 0);
137
+ }
138
+ }
139
+ }
140
+ if (onChange) {
141
+ onChange(evt);
142
+ }
83
143
  }
84
144
  },
85
145
  onClick: evt => {
@@ -114,7 +174,7 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
114
174
  htmlFor: id,
115
175
  className: labelClasses
116
176
  }, labelText) : null;
117
- const counter = enableCounter && maxCount ? /*#__PURE__*/React__default.createElement(Text, {
177
+ const counter = enableCounter && maxCount && (counterMode === 'character' || counterMode === 'word') ? /*#__PURE__*/React__default.createElement(Text, {
118
178
  as: "div",
119
179
  className: counterClasses
120
180
  }, `${textCount}/${maxCount}`) : null;
@@ -147,9 +207,12 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
147
207
  ariaDescribedBy = helperId;
148
208
  }
149
209
  if (enableCounter) {
150
- textareaProps.maxLength = maxCount;
210
+ // handle different counter mode
211
+ if (counterMode == 'character') {
212
+ textareaProps.maxLength = maxCount;
213
+ }
151
214
  }
152
- const ariaAnnouncement = useAnnouncer(textCount, maxCount);
215
+ const ariaAnnouncement = useAnnouncer(textCount, maxCount, counterMode === 'word' ? 'words' : undefined);
153
216
  const input = /*#__PURE__*/React__default.createElement("textarea", _extends({}, other, textareaProps, {
154
217
  placeholder: placeholder,
155
218
  className: textareaClasses,
@@ -163,7 +226,7 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
163
226
 
164
227
  // Slug is always size `mini`
165
228
  let normalizedSlug;
166
- if (slug) {
229
+ if (slug && slug['type']?.displayName === 'Slug') {
167
230
  normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
168
231
  size: 'mini'
169
232
  });
@@ -197,6 +260,10 @@ TextArea.propTypes = {
197
260
  * Specify the `cols` attribute for the underlying `<textarea>` node
198
261
  */
199
262
  cols: PropTypes.number,
263
+ /**
264
+ * Specify the method used for calculating the counter number
265
+ */
266
+ counterMode: PropTypes.oneOf(['character', 'word']),
200
267
  /**
201
268
  * Optionally provide the default value of the `<textarea>`
202
269
  */
@@ -206,7 +273,7 @@ TextArea.propTypes = {
206
273
  */
207
274
  disabled: PropTypes.bool,
208
275
  /**
209
- * Specify whether to display the character counter
276
+ * Specify whether to display the counter
210
277
  */
211
278
  enableCounter: PropTypes.bool,
212
279
  /**
@@ -240,7 +307,7 @@ TextArea.propTypes = {
240
307
  */
241
308
  light: deprecate(PropTypes.bool, 'The `light` prop for `TextArea` has ' + 'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.'),
242
309
  /**
243
- * Max character count allowed for the textarea. This is needed in order for enableCounter to display
310
+ * Max entity count allowed for the textarea. This is needed in order for enableCounter to display
244
311
  */
245
312
  maxCount: PropTypes.number,
246
313
  /**
@@ -266,7 +333,7 @@ TextArea.propTypes = {
266
333
  */
267
334
  rows: PropTypes.number,
268
335
  /**
269
- * Provide a `Slug` component to be rendered inside the `TextArea` component
336
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `TextArea` component
270
337
  */
271
338
  slug: PropTypes.node,
272
339
  /**
@@ -87,7 +87,7 @@ export interface TextInputProps extends Omit<React.InputHTMLAttributes<HTMLInput
87
87
  */
88
88
  size?: 'sm' | 'md' | 'lg' | 'xl';
89
89
  /**
90
- * Provide a `Slug` component to be rendered inside the `TextInput` component
90
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `TextInput` component
91
91
  */
92
92
  slug?: ReactNodeLike;
93
93
  /**
@@ -157,7 +157,7 @@ const TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref
157
157
 
158
158
  // Slug is always size `mini`
159
159
  let normalizedSlug;
160
- if (slug) {
160
+ if (slug && slug['type']?.displayName === 'Slug') {
161
161
  normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
162
162
  size: 'mini'
163
163
  });
@@ -261,7 +261,7 @@ TextInput.propTypes = {
261
261
  */
262
262
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
263
263
  /**
264
- * Provide a `Slug` component to be rendered inside the `TextInput` component
264
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `TextInput` component
265
265
  */
266
266
  slug: PropTypes.node,
267
267
  /**
@@ -6,12 +6,12 @@ export interface TileProps extends HTMLAttributes<HTMLDivElement> {
6
6
  /** @deprecated */
7
7
  light?: boolean;
8
8
  /**
9
- * Specify if the `Tile` component should be rendered with rounded corners. Only valid
9
+ * **Experimental**: Specify if the `Tile` component should be rendered with rounded corners. Only valid
10
10
  * when `slug` prop is present
11
11
  */
12
12
  hasRoundedCorners?: boolean;
13
13
  /**
14
- * Provide a `Slug` component to be rendered inside the `SelectableTile` component
14
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `SelectableTile` component
15
15
  */
16
16
  slug?: ReactNodeLike;
17
17
  }
@@ -30,7 +30,7 @@ export interface ClickableTileProps extends HTMLAttributes<HTMLAnchorElement> {
30
30
  */
31
31
  disabled?: boolean;
32
32
  /**
33
- * Specify if the `ClickableTile` component should be rendered with rounded corners.
33
+ * **Experimental**: Specify if the `ClickableTile` component should be rendered with rounded corners.
34
34
  * Only valid when `slug` prop is present
35
35
  */
36
36
  hasRoundedCorners?: boolean;
@@ -57,7 +57,7 @@ export interface ClickableTileProps extends HTMLAttributes<HTMLAnchorElement> {
57
57
  */
58
58
  rel?: string;
59
59
  /**
60
- * Specify if a `Slug` icon should be rendered inside the `ClickableTile`
60
+ * **Experimental**: Specify if a `Slug` icon should be rendered inside the `ClickableTile`
61
61
  */
62
62
  slug?: boolean;
63
63
  }
@@ -72,7 +72,7 @@ export interface SelectableTileProps extends HTMLAttributes<HTMLDivElement> {
72
72
  */
73
73
  disabled?: boolean;
74
74
  /**
75
- * Specify if the `SelectableTile` component should be rendered with rounded corners.
75
+ * **Experimental**: Specify if the `SelectableTile` component should be rendered with rounded corners.
76
76
  * Only valid when `slug` prop is present
77
77
  */
78
78
  hasRoundedCorners?: boolean;
@@ -102,7 +102,7 @@ export interface SelectableTileProps extends HTMLAttributes<HTMLDivElement> {
102
102
  */
103
103
  selected?: boolean;
104
104
  /**
105
- * Provide a `Slug` component to be rendered inside the `SelectableTile` component
105
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `SelectableTile` component
106
106
  */
107
107
  slug?: ReactNodeLike;
108
108
  /**
@@ -130,7 +130,7 @@ export interface ExpandableTileProps extends HTMLAttributes<HTMLDivElement> {
130
130
  */
131
131
  expanded?: boolean;
132
132
  /**
133
- * Specify if the `ExpandableTile` component should be rendered with rounded corners.
133
+ * **Experimental**: Specify if the `ExpandableTile` component should be rendered with rounded corners.
134
134
  * Only valid when `slug` prop is present
135
135
  */
136
136
  hasRoundedCorners?: boolean;
@@ -147,7 +147,7 @@ export interface ExpandableTileProps extends HTMLAttributes<HTMLDivElement> {
147
147
  */
148
148
  onKeyUp?(event: KeyboardEvent): void;
149
149
  /**
150
- * Provide a `Slug` component to be rendered inside the `ExpandableTile` component
150
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `ExpandableTile` component
151
151
  */
152
152
  slug?: ReactNodeLike;
153
153
  /**
@@ -56,7 +56,7 @@ Tile.propTypes = {
56
56
  */
57
57
  className: PropTypes.string,
58
58
  /**
59
- * Specify if the `Tile` component should be rendered with rounded corners. Only valid
59
+ * **Experimental**: Specify if the `Tile` component should be rendered with rounded corners. Only valid
60
60
  * when `slug` prop is present
61
61
  */
62
62
  hasRoundedCorners: PropTypes.bool,
@@ -68,7 +68,7 @@ Tile.propTypes = {
68
68
  */
69
69
  light: deprecate(PropTypes.bool, 'The `light` prop for `Tile` is no longer needed and has been deprecated. It will be removed in the next major release. Use the Layer component instead.'),
70
70
  /**
71
- * Provide a `Slug` component to be rendered inside the `Tile` component
71
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `Tile` component
72
72
  */
73
73
  slug: PropTypes.node
74
74
  };
@@ -173,7 +173,7 @@ ClickableTile.propTypes = {
173
173
  */
174
174
  disabled: PropTypes.bool,
175
175
  /**
176
- * Specify if the `ClickableTile` component should be rendered with rounded corners.
176
+ * **Experimental**: Specify if the `ClickableTile` component should be rendered with rounded corners.
177
177
  * Only valid when `slug` prop is present
178
178
  */
179
179
  hasRoundedCorners: PropTypes.bool,
@@ -269,7 +269,7 @@ const SelectableTile = /*#__PURE__*/React__default.forwardRef(function Selectabl
269
269
  // Slug is always size `xs`
270
270
  const slugRef = useRef(null);
271
271
  let normalizedSlug;
272
- if (slug) {
272
+ if (slug && slug['type']?.displayName === 'Slug') {
273
273
  normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
274
274
  size: 'xs',
275
275
  ref: slugRef
@@ -308,7 +308,7 @@ SelectableTile.propTypes = {
308
308
  */
309
309
  disabled: PropTypes.bool,
310
310
  /**
311
- * Specify if the `SelectableTile` component should be rendered with rounded corners.
311
+ * **Experimental**: Specify if the `SelectableTile` component should be rendered with rounded corners.
312
312
  * Only valid when `slug` prop is present
313
313
  */
314
314
  hasRoundedCorners: PropTypes.bool,
@@ -343,7 +343,7 @@ SelectableTile.propTypes = {
343
343
  */
344
344
  selected: PropTypes.bool,
345
345
  /**
346
- * Provide a `Slug` component to be rendered inside the `SelectableTile` component
346
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `SelectableTile` component
347
347
  */
348
348
  slug: PropTypes.node,
349
349
  /**
@@ -494,7 +494,7 @@ const ExpandableTile = /*#__PURE__*/React__default.forwardRef(function Expandabl
494
494
 
495
495
  // Slug is always size `xs`
496
496
  let normalizedSlug;
497
- if (slug) {
497
+ if (slug && slug['type']?.displayName === 'Slug') {
498
498
  normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
499
499
  size: 'xs'
500
500
  });
@@ -573,6 +573,10 @@ ExpandableTile.propTypes = {
573
573
  * optional handler to trigger a function when a key is pressed
574
574
  */
575
575
  onKeyUp: PropTypes.func,
576
+ /**
577
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `ExpandableTile` component
578
+ */
579
+ slug: PropTypes.node,
576
580
  /**
577
581
  * The `tabindex` attribute.
578
582
  */
@@ -8,7 +8,7 @@
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
- import React__default, { useRef, useEffect } from 'react';
11
+ import React__default, { useRef, useState, useCallback, useEffect } from 'react';
12
12
  import { Popover, PopoverContent } from '../Popover/index.js';
13
13
  import { useDelayedState } from '../../internal/useDelayedState.js';
14
14
  import { useId } from '../../internal/useId.js';
@@ -17,6 +17,10 @@ import { usePrefix } from '../../internal/usePrefix.js';
17
17
  import { match } from '../../internal/keyboard/match.js';
18
18
  import { Escape, Enter, Space } from '../../internal/keyboard/keys.js';
19
19
 
20
+ /**
21
+ * Event types that trigger a "drag" to stop.
22
+ */
23
+ const DRAG_STOP_EVENT_TYPES = new Set(['mouseup', 'touchend', 'touchcancel']);
20
24
  function Tooltip(_ref) {
21
25
  let {
22
26
  align = 'top',
@@ -33,6 +37,8 @@ function Tooltip(_ref) {
33
37
  const containerRef = useRef(null);
34
38
  const tooltipRef = useRef(null);
35
39
  const [open, setOpen] = useDelayedState(defaultOpen);
40
+ const [isDragging, setIsDragging] = useState(false);
41
+ const [isPointerIntersecting, setIsPointerIntersecting] = useState(false);
36
42
  const id = useId('tooltip');
37
43
  const prefix = usePrefix();
38
44
  const child = React__default.Children.only(children);
@@ -41,7 +47,11 @@ function Tooltip(_ref) {
41
47
  onBlur: () => setOpen(false),
42
48
  onClick: () => closeOnActivation && setOpen(false),
43
49
  // This should be placed on the trigger in case the element is disabled
44
- onMouseEnter
50
+ onMouseEnter,
51
+ onMouseLeave,
52
+ onMouseDown: onDragStart,
53
+ onMouseMove: onMouseMove,
54
+ onTouchStart: onDragStart
45
55
  };
46
56
  function getChildEventHandlers(childProps) {
47
57
  const eventHandlerFunctions = ['onFocus', 'onBlur', 'onClick', 'onMouseEnter'];
@@ -71,11 +81,34 @@ function Tooltip(_ref) {
71
81
  }
72
82
  }
73
83
  function onMouseEnter() {
84
+ setIsPointerIntersecting(true);
74
85
  setOpen(true, enterDelayMs);
75
86
  }
76
87
  function onMouseLeave() {
88
+ setIsPointerIntersecting(false);
89
+ if (isDragging) {
90
+ return;
91
+ }
77
92
  setOpen(false, leaveDelayMs);
78
93
  }
94
+ function onMouseMove(evt) {
95
+ if (evt.buttons === 1) {
96
+ setIsDragging(true);
97
+ } else {
98
+ setIsDragging(false);
99
+ }
100
+ }
101
+ function onDragStart() {
102
+ setIsDragging(true);
103
+ }
104
+ const onDragStop = useCallback(() => {
105
+ setIsDragging(false);
106
+ // Close the tooltip, unless the mouse pointer is within the bounds of the
107
+ // trigger.
108
+ if (!isPointerIntersecting) {
109
+ setOpen(false, leaveDelayMs);
110
+ }
111
+ }, [isPointerIntersecting, leaveDelayMs, setOpen]);
79
112
  useNoInteractiveChildren(tooltipRef, 'The Tooltip component must have no interactive content rendered by the' + '`label` or `description` prop');
80
113
  useEffect(() => {
81
114
  if (containerRef !== null && containerRef.current) {
@@ -85,6 +118,19 @@ function Tooltip(_ref) {
85
118
  }
86
119
  }
87
120
  });
121
+ useEffect(() => {
122
+ if (isDragging) {
123
+ // Register drag stop handlers.
124
+ DRAG_STOP_EVENT_TYPES.forEach(eventType => {
125
+ document.addEventListener(eventType, onDragStop);
126
+ });
127
+ }
128
+ return () => {
129
+ DRAG_STOP_EVENT_TYPES.forEach(eventType => {
130
+ document.removeEventListener(eventType, onDragStop);
131
+ });
132
+ };
133
+ }, [isDragging, onDragStop]);
88
134
  return /*#__PURE__*/React__default.createElement(Popover, _extends({}, rest, {
89
135
  align: align,
90
136
  className: cx(`${prefix}--tooltip`, customClassName),
@@ -0,0 +1,36 @@
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 React, { ReactNode } from 'react';
8
+ interface HeaderPanelProps {
9
+ /**
10
+ * Specify whether focus and blur listeners are added. They are by default.
11
+ */
12
+ addFocusListeners?: boolean;
13
+ /**
14
+ * The content that will render inside of the `HeaderPanel`
15
+ */
16
+ children?: ReactNode;
17
+ /**
18
+ * Optionally provide a custom class to apply to the underlying `<li>` node
19
+ */
20
+ className?: string;
21
+ /**
22
+ * Specify whether the panel is expanded
23
+ */
24
+ expanded?: boolean;
25
+ /**
26
+ * Provide the `href` to the id of the element on your package that could
27
+ * be target.
28
+ */
29
+ href?: string;
30
+ /**
31
+ * An optional listener that is called a callback to collapse the HeaderPanel
32
+ */
33
+ onHeaderPanelFocus?: () => void;
34
+ }
35
+ declare const HeaderPanel: React.FC<HeaderPanelProps>;
36
+ export default HeaderPanel;
@@ -6,9 +6,9 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useRef, useState } from 'react';
10
9
  import cx from 'classnames';
11
10
  import PropTypes from 'prop-types';
11
+ import React__default, { useRef, useState } from 'react';
12
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
13
  import { useWindowEvent } from '../../internal/useEvent.js';
14
14
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
@@ -24,7 +24,7 @@ const HeaderPanel = /*#__PURE__*/React__default.forwardRef(function HeaderPanel(
24
24
  addFocusListeners = true,
25
25
  onHeaderPanelFocus = noopFn,
26
26
  href,
27
- ...other
27
+ ...rest
28
28
  } = _ref;
29
29
  const prefix = usePrefix();
30
30
  const headerPanelReference = useRef(null);
@@ -61,12 +61,13 @@ const HeaderPanel = /*#__PURE__*/React__default.forwardRef(function HeaderPanel(
61
61
  useWindowEvent('click', () => {
62
62
  const focusedElement = document.activeElement;
63
63
  setLastClickedElement(focusedElement);
64
- if (children.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelRef?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
64
+ const childJsxElement = children;
65
+ if (childJsxElement.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelReference?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
65
66
  setExpandedState(false);
66
67
  onHeaderPanelFocus();
67
68
  }
68
69
  });
69
- return /*#__PURE__*/React__default.createElement("div", _extends({}, other, {
70
+ return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
70
71
  className: className,
71
72
  ref: headerPanelRef
72
73
  }, eventHandlers), children);
@@ -99,6 +100,5 @@ HeaderPanel.propTypes = {
99
100
  onHeaderPanelFocus: PropTypes.func
100
101
  };
101
102
  HeaderPanel.displayName = 'HeaderPanel';
102
- var HeaderPanel$1 = HeaderPanel;
103
103
 
104
- export { HeaderPanel$1 as default };
104
+ export { HeaderPanel as default };
@@ -60,7 +60,7 @@ const Switcher = /*#__PURE__*/forwardRef(function Switcher(props, forwardRef) {
60
60
  switcherItem.focus();
61
61
  }
62
62
  };
63
- const childrenWithProps = React__default.Children.map(children, (child, index) => {
63
+ const childrenWithProps = React__default.Children.toArray(children).map((child, index) => {
64
64
  // only setup click handlers if onChange event is passed
65
65
  if ( /*#__PURE__*/React__default.isValidElement(child) && child.type && getDisplayName(child.type) === 'Switcher') {
66
66
  return /*#__PURE__*/React__default.cloneElement(child, {