@carbon/react 1.31.3 → 1.32.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 (182) hide show
  1. package/README.md +1 -1
  2. package/es/components/Accordion/Accordion.Skeleton.d.ts +64 -0
  3. package/es/components/Accordion/Accordion.Skeleton.js +3 -3
  4. package/es/components/Accordion/Accordion.d.ts +65 -0
  5. package/es/components/Accordion/Accordion.js +5 -6
  6. package/es/components/Accordion/AccordionItem.d.ts +105 -0
  7. package/es/components/Accordion/AccordionItem.js +12 -9
  8. package/es/components/Accordion/AccordionProvider.d.ts +20 -0
  9. package/es/components/Accordion/AccordionProvider.js +25 -0
  10. package/es/components/Accordion/index.d.ts +11 -0
  11. package/es/components/Button/Button.Skeleton.d.ts +28 -0
  12. package/es/components/Button/Button.Skeleton.js +5 -3
  13. package/es/components/Button/Button.d.ts +72 -0
  14. package/es/components/Button/Button.js +13 -10
  15. package/es/components/Button/index.d.ts +11 -0
  16. package/es/components/Button/index.js +2 -1
  17. package/es/components/ButtonSet/ButtonSet.d.ts +17 -0
  18. package/es/components/ButtonSet/ButtonSet.js +1 -2
  19. package/es/components/ButtonSet/index.d.ts +9 -0
  20. package/es/components/CodeSnippet/CodeSnippet.js +1 -0
  21. package/es/components/ComboButton/index.js +1 -0
  22. package/es/components/ComposedModal/ComposedModal.d.ts +70 -0
  23. package/es/components/ComposedModal/ComposedModal.js +58 -67
  24. package/es/components/ComposedModal/ModalFooter.d.ts +71 -0
  25. package/es/components/ComposedModal/ModalFooter.js +22 -19
  26. package/es/components/ComposedModal/ModalHeader.d.ts +58 -0
  27. package/es/components/ComposedModal/ModalHeader.js +8 -25
  28. package/es/components/ComposedModal/index.d.ts +9 -0
  29. package/es/components/ContainedList/ContainedList.js +12 -1
  30. package/es/components/ContentSwitcher/ContentSwitcher.d.ts +109 -0
  31. package/es/components/ContentSwitcher/ContentSwitcher.js +14 -6
  32. package/es/components/DangerButton/DangerButton.d.ts +9 -0
  33. package/es/components/DangerButton/DangerButton.js +2 -2
  34. package/es/components/DangerButton/index.d.ts +9 -0
  35. package/es/components/DataTable/TableBatchAction.js +1 -0
  36. package/es/components/DataTable/TableBatchActions.js +1 -0
  37. package/es/components/DataTable/TableBody.d.ts +29 -0
  38. package/es/components/DataTable/TableBody.js +2 -3
  39. package/es/components/DataTable/TableContainer.d.ts +51 -0
  40. package/es/components/DataTable/TableContainer.js +3 -4
  41. package/es/components/DataTable/TableExpandHeader.d.ts +86 -0
  42. package/es/components/DataTable/TableExpandHeader.js +4 -5
  43. package/es/components/DatePicker/plugins/fixEventsPlugin.js +12 -16
  44. package/es/components/Dropdown/Dropdown.js +1 -0
  45. package/es/components/FluidTextInput/FluidTextInput.js +1 -0
  46. package/es/components/FormGroup/FormGroup.d.ts +80 -0
  47. package/es/components/IconButton/index.js +3 -2
  48. package/es/components/Layout/index.d.ts +74 -0
  49. package/es/components/Layout/index.js +14 -5
  50. package/es/components/Link/Link.d.ts +2 -2
  51. package/es/components/Link/Link.js +2 -1
  52. package/es/components/MenuButton/index.js +1 -0
  53. package/es/components/Modal/Modal.js +1 -0
  54. package/es/components/ModalWrapper/ModalWrapper.js +1 -0
  55. package/es/components/Notification/Notification.d.ts +531 -0
  56. package/es/components/Notification/Notification.js +40 -6
  57. package/es/components/Notification/index.d.ts +7 -0
  58. package/es/components/PrimaryButton/PrimaryButton.js +1 -0
  59. package/es/components/SecondaryButton/SecondaryButton.js +1 -0
  60. package/es/components/Select/Select.d.ts +1 -1
  61. package/es/components/SkeletonText/SkeletonText.d.ts +61 -0
  62. package/es/components/SkeletonText/SkeletonText.js +15 -17
  63. package/es/components/SkeletonText/index.d.ts +9 -0
  64. package/es/components/Switch/Switch.d.ts +56 -0
  65. package/es/components/Switch/Switch.js +4 -4
  66. package/es/components/Tab/index.d.ts +9 -0
  67. package/es/components/TabContent/TabContent.d.ts +40 -0
  68. package/es/components/TabContent/TabContent.js +6 -12
  69. package/es/components/TabContent/index.d.ts +10 -0
  70. package/es/components/Tabs/Tabs.Skeleton.d.ts +33 -0
  71. package/es/components/Tabs/Tabs.Skeleton.js +2 -2
  72. package/es/components/Tabs/Tabs.d.ts +303 -0
  73. package/es/components/Tabs/Tabs.js +136 -95
  74. package/es/components/Tabs/index.d.ts +10 -0
  75. package/es/components/Tabs/usePressable.js +11 -0
  76. package/es/components/TextInput/ControlledPasswordInput.d.ts +90 -0
  77. package/es/components/TextInput/ControlledPasswordInput.js +5 -6
  78. package/es/components/Tile/Tile.d.ts +153 -0
  79. package/es/components/Tile/Tile.js +62 -74
  80. package/es/components/Tile/index.d.ts +7 -0
  81. package/es/components/Toggle/Toggle.Skeleton.d.ts +3 -47
  82. package/es/components/Toggle/Toggle.Skeleton.js +24 -64
  83. package/es/components/Toggle/Toggle.js +1 -1
  84. package/es/components/UIShell/HeaderGlobalAction.js +1 -0
  85. package/es/components/UIShell/SideNav.d.ts +1 -1
  86. package/es/index.js +16 -16
  87. package/es/internal/keyboard/match.js +2 -2
  88. package/es/internal/useControllableState.js +2 -2
  89. package/es/internal/wrapFocus.js +6 -6
  90. package/es/prop-types/requiredIfGivenPropIsTruthy.js +1 -1
  91. package/es/prop-types/types.js +3 -0
  92. package/lib/components/Accordion/Accordion.Skeleton.d.ts +64 -0
  93. package/lib/components/Accordion/Accordion.Skeleton.js +3 -3
  94. package/lib/components/Accordion/Accordion.d.ts +65 -0
  95. package/lib/components/Accordion/Accordion.js +5 -6
  96. package/lib/components/Accordion/AccordionItem.d.ts +105 -0
  97. package/lib/components/Accordion/AccordionItem.js +11 -8
  98. package/lib/components/Accordion/AccordionProvider.d.ts +20 -0
  99. package/lib/components/Accordion/AccordionProvider.js +34 -0
  100. package/lib/components/Accordion/index.d.ts +11 -0
  101. package/lib/components/Button/Button.Skeleton.d.ts +28 -0
  102. package/lib/components/Button/Button.Skeleton.js +5 -3
  103. package/lib/components/Button/Button.d.ts +72 -0
  104. package/lib/components/Button/Button.js +18 -11
  105. package/lib/components/Button/index.d.ts +11 -0
  106. package/lib/components/Button/index.js +6 -0
  107. package/lib/components/ButtonSet/ButtonSet.d.ts +17 -0
  108. package/lib/components/ButtonSet/ButtonSet.js +1 -2
  109. package/lib/components/ButtonSet/index.d.ts +9 -0
  110. package/lib/components/CodeSnippet/CodeSnippet.js +1 -0
  111. package/lib/components/ComboButton/index.js +1 -0
  112. package/lib/components/ComposedModal/ComposedModal.d.ts +70 -0
  113. package/lib/components/ComposedModal/ComposedModal.js +58 -67
  114. package/lib/components/ComposedModal/ModalFooter.d.ts +71 -0
  115. package/lib/components/ComposedModal/ModalFooter.js +22 -19
  116. package/lib/components/ComposedModal/ModalHeader.d.ts +58 -0
  117. package/lib/components/ComposedModal/ModalHeader.js +8 -25
  118. package/lib/components/ComposedModal/index.d.ts +9 -0
  119. package/lib/components/ContainedList/ContainedList.js +12 -1
  120. package/lib/components/ContentSwitcher/ContentSwitcher.d.ts +109 -0
  121. package/lib/components/ContentSwitcher/ContentSwitcher.js +14 -6
  122. package/lib/components/DangerButton/DangerButton.d.ts +9 -0
  123. package/lib/components/DangerButton/DangerButton.js +2 -2
  124. package/lib/components/DangerButton/index.d.ts +9 -0
  125. package/lib/components/DataTable/TableBatchAction.js +1 -0
  126. package/lib/components/DataTable/TableBatchActions.js +1 -0
  127. package/lib/components/DataTable/TableBody.d.ts +29 -0
  128. package/lib/components/DataTable/TableBody.js +3 -4
  129. package/lib/components/DataTable/TableContainer.d.ts +51 -0
  130. package/lib/components/DataTable/TableContainer.js +3 -4
  131. package/lib/components/DataTable/TableExpandHeader.d.ts +86 -0
  132. package/lib/components/DataTable/TableExpandHeader.js +4 -5
  133. package/lib/components/DatePicker/plugins/fixEventsPlugin.js +12 -16
  134. package/lib/components/Dropdown/Dropdown.js +1 -0
  135. package/lib/components/FluidTextInput/FluidTextInput.js +1 -0
  136. package/lib/components/FormGroup/FormGroup.d.ts +80 -0
  137. package/lib/components/IconButton/index.js +3 -2
  138. package/lib/components/Layout/index.d.ts +74 -0
  139. package/lib/components/Layout/index.js +14 -5
  140. package/lib/components/Link/Link.d.ts +2 -2
  141. package/lib/components/Link/Link.js +2 -1
  142. package/lib/components/MenuButton/index.js +1 -0
  143. package/lib/components/Modal/Modal.js +1 -0
  144. package/lib/components/ModalWrapper/ModalWrapper.js +1 -0
  145. package/lib/components/Notification/Notification.d.ts +531 -0
  146. package/lib/components/Notification/Notification.js +40 -6
  147. package/lib/components/Notification/index.d.ts +7 -0
  148. package/lib/components/PrimaryButton/PrimaryButton.js +1 -0
  149. package/lib/components/SecondaryButton/SecondaryButton.js +1 -0
  150. package/lib/components/Select/Select.d.ts +1 -1
  151. package/lib/components/SkeletonText/SkeletonText.d.ts +61 -0
  152. package/lib/components/SkeletonText/SkeletonText.js +15 -17
  153. package/lib/components/SkeletonText/index.d.ts +9 -0
  154. package/lib/components/Switch/Switch.d.ts +56 -0
  155. package/lib/components/Switch/Switch.js +4 -4
  156. package/lib/components/Tab/index.d.ts +9 -0
  157. package/lib/components/TabContent/TabContent.d.ts +40 -0
  158. package/lib/components/TabContent/TabContent.js +6 -12
  159. package/lib/components/TabContent/index.d.ts +10 -0
  160. package/lib/components/Tabs/Tabs.Skeleton.d.ts +33 -0
  161. package/lib/components/Tabs/Tabs.Skeleton.js +2 -2
  162. package/lib/components/Tabs/Tabs.d.ts +303 -0
  163. package/lib/components/Tabs/Tabs.js +135 -94
  164. package/lib/components/Tabs/index.d.ts +10 -0
  165. package/lib/components/Tabs/usePressable.js +11 -0
  166. package/lib/components/TextInput/ControlledPasswordInput.d.ts +90 -0
  167. package/lib/components/TextInput/ControlledPasswordInput.js +5 -6
  168. package/lib/components/Tile/Tile.d.ts +153 -0
  169. package/lib/components/Tile/Tile.js +62 -74
  170. package/lib/components/Tile/index.d.ts +7 -0
  171. package/lib/components/Toggle/Toggle.Skeleton.d.ts +3 -47
  172. package/lib/components/Toggle/Toggle.Skeleton.js +22 -62
  173. package/lib/components/Toggle/Toggle.js +1 -1
  174. package/lib/components/UIShell/HeaderGlobalAction.js +1 -0
  175. package/lib/components/UIShell/SideNav.d.ts +1 -1
  176. package/lib/index.js +51 -47
  177. package/lib/internal/keyboard/match.js +2 -2
  178. package/lib/internal/useControllableState.js +2 -2
  179. package/lib/internal/wrapFocus.js +6 -6
  180. package/lib/prop-types/requiredIfGivenPropIsTruthy.js +1 -1
  181. package/lib/prop-types/types.js +3 -0
  182. package/package.json +4 -3
@@ -10,7 +10,8 @@ import { ChevronLeft, ChevronRight, Close } from '@carbon/icons-react';
10
10
  import cx from 'classnames';
11
11
  import debounce from 'lodash.debounce';
12
12
  import PropTypes from 'prop-types';
13
- import React__default, { useState, useRef, useCallback, useEffect } from 'react';
13
+ import React__default, { useState, useRef, useCallback, useEffect, forwardRef } from 'react';
14
+ import { isElement } from 'react-is';
14
15
  import '../Tooltip/DefinitionTooltip.js';
15
16
  import { Tooltip } from '../Tooltip/Tooltip.js';
16
17
  import { useControllableState } from '../../internal/useControllableState.js';
@@ -29,13 +30,31 @@ import { ArrowRight, ArrowLeft, Home, End, Delete } from '../../internal/keyboar
29
30
  var _ChevronLeft, _ChevronRight, _Close;
30
31
 
31
32
  // Used to manage the overall state of the Tabs
32
- const TabsContext = /*#__PURE__*/React__default.createContext();
33
+
34
+ const TabsContext = /*#__PURE__*/React__default.createContext({
35
+ baseId: '',
36
+ activeIndex: 0,
37
+ defaultSelectedIndex: 0,
38
+ dismissable: false,
39
+ onTabCloseRequest() {},
40
+ setActiveIndex() {},
41
+ selectedIndex: 0,
42
+ setSelectedIndex() {}
43
+ });
33
44
 
34
45
  // Used to keep track of position in a tablist
35
- const TabContext = /*#__PURE__*/React__default.createContext();
46
+ const TabContext = /*#__PURE__*/React__default.createContext({
47
+ index: 0,
48
+ hasSecondaryLabel: false
49
+ });
36
50
 
37
51
  // Used to keep track of position in a list of tab panels
38
- const TabPanelContext = /*#__PURE__*/React__default.createContext();
52
+ const TabPanelContext = /*#__PURE__*/React__default.createContext(0);
53
+
54
+ /**
55
+ * Tabs
56
+ */
57
+
39
58
  function Tabs(_ref) {
40
59
  let {
41
60
  children,
@@ -52,13 +71,9 @@ function Tabs(_ref) {
52
71
  const [selectedIndex, setSelectedIndex] = useControllableState({
53
72
  value: controlledSelectedIndex,
54
73
  defaultValue: defaultSelectedIndex,
55
- onChange: value => {
56
- if (onChange) {
57
- onChange({
58
- selectedIndex: value
59
- });
60
- }
61
- }
74
+ onChange: value => onChange?.({
75
+ selectedIndex: value
76
+ })
62
77
  });
63
78
  const value = {
64
79
  baseId,
@@ -76,7 +91,7 @@ function Tabs(_ref) {
76
91
  }
77
92
  Tabs.propTypes = {
78
93
  /**
79
- * Provide child elements to be rendered inside of the `Tabs`.
94
+ * Provide child elements to be rendered inside the `Tabs`.
80
95
  * These elements should render either `TabsList` or `TabsPanels`
81
96
  */
82
97
  children: PropTypes.node,
@@ -112,24 +127,28 @@ Tabs.propTypes = {
112
127
  };
113
128
 
114
129
  /**
115
- * Get the next index for a given keyboard event given a count of the total
116
- * items and the current index
117
- * @param {Event} event
118
- * @param {number} total
119
- * @param {number} index
120
- * @returns {number}
130
+ * Get the next index for a given keyboard event
131
+ * given a count of the total items and the current index
121
132
  */
122
133
  function getNextIndex(event, total, index) {
123
- if (match(event, ArrowRight)) {
124
- return (index + 1) % total;
125
- } else if (match(event, ArrowLeft)) {
126
- return (total + index - 1) % total;
127
- } else if (match(event, Home)) {
128
- return 0;
129
- } else if (match(event, End)) {
130
- return total - 1;
134
+ switch (true) {
135
+ case match(event, ArrowRight):
136
+ return (index + 1) % total;
137
+ case match(event, ArrowLeft):
138
+ return (total + index - 1) % total;
139
+ case match(event, Home):
140
+ return 0;
141
+ case match(event, End):
142
+ return total - 1;
143
+ default:
144
+ return index;
131
145
  }
132
146
  }
147
+
148
+ /**
149
+ * TabList
150
+ */
151
+
133
152
  function TabList(_ref2) {
134
153
  let {
135
154
  activation = 'automatic',
@@ -157,7 +176,20 @@ function TabList(_ref2) {
157
176
  const previousButton = useRef(null);
158
177
  const nextButton = useRef(null);
159
178
  const [isScrollable, setIsScrollable] = useState(false);
160
- const [scrollLeft, setScrollLeft] = useState(null);
179
+ const [scrollLeft, setScrollLeft] = useState(0);
180
+ let hasSecondaryLabelTabs = false;
181
+ if (contained) {
182
+ hasSecondaryLabelTabs = React__default.Children.toArray(children).some(child => {
183
+ return isElement(child) && !!child.props.secondaryLabel;
184
+ });
185
+ }
186
+ const className = cx(`${prefix}--tabs`, {
187
+ [`${prefix}--tabs--contained`]: contained,
188
+ [`${prefix}--tabs--light`]: light,
189
+ [`${prefix}--tabs__icon--default`]: iconSize === 'default',
190
+ [`${prefix}--tabs__icon--lg`]: iconSize === 'lg',
191
+ [`${prefix}--tabs--tall`]: hasSecondaryLabelTabs
192
+ }, customClassName);
161
193
 
162
194
  // Previous Button
163
195
  // VISIBLE IF:
@@ -169,14 +201,6 @@ function TabList(_ref2) {
169
201
  // SCROLLABLE
170
202
  // AND SCROLL_LEFT + CLIENT_WIDTH < SCROLL_WIDTH
171
203
  const [isNextButtonVisible, setIsNextButtonVisible] = useState(ref.current ? scrollLeft + buttonWidth + ref.current.clientWidth < ref.current.scrollWidth : false);
172
- const hasSecondaryLabelTabs = contained && !!React__default.Children.toArray(children).filter(child => child.props.secondaryLabel).length;
173
- const className = cx(`${prefix}--tabs`, customClassName, {
174
- [`${prefix}--tabs--contained`]: contained,
175
- [`${prefix}--tabs--light`]: light,
176
- [`${prefix}--tabs__icon--default`]: iconSize === 'default',
177
- [`${prefix}--tabs__icon--lg`]: iconSize === 'lg',
178
- [`${prefix}--tabs--tall`]: hasSecondaryLabelTabs
179
- });
180
204
  const isPreviousButtonVisible = ref.current ? isScrollable && scrollLeft > 0 : false;
181
205
  const previousButtonClasses = cx(`${prefix}--tab--overflow-nav-button`, `${prefix}--tab--overflow-nav-button--previous`, {
182
206
  [`${prefix}--tab--overflow-nav-button--hidden`]: !isPreviousButtonVisible
@@ -193,9 +217,7 @@ function TabList(_ref2) {
193
217
  function onKeyDown(event) {
194
218
  if (matches(event, [ArrowRight, ArrowLeft, Home, End])) {
195
219
  event.preventDefault();
196
- const activeTabs = tabs.current.filter(tab => {
197
- return !tab.disabled;
198
- });
220
+ const activeTabs = tabs.current.filter(tab => !tab.disabled);
199
221
  const currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
200
222
  const nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
201
223
  if (activation === 'automatic') {
@@ -203,7 +225,7 @@ function TabList(_ref2) {
203
225
  } else if (activation === 'manual') {
204
226
  setActiveIndex(nextIndex);
205
227
  }
206
- tabs.current[nextIndex].focus();
228
+ tabs.current[nextIndex]?.focus();
207
229
  }
208
230
  }
209
231
  useEffectOnce(() => {
@@ -253,12 +275,12 @@ function TabList(_ref2) {
253
275
 
254
276
  // updates scroll location for all scroll behavior.
255
277
  useIsomorphicEffect(() => {
256
- if (scrollLeft !== null) {
278
+ if (scrollLeft !== null && ref.current) {
257
279
  ref.current.scrollLeft = scrollLeft;
258
280
  }
259
281
  }, [scrollLeft]);
260
282
  useIsomorphicEffect(() => {
261
- if (!isScrollable) {
283
+ if (!isScrollable || !ref.current) {
262
284
  return;
263
285
  }
264
286
  const tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
@@ -292,7 +314,7 @@ function TabList(_ref2) {
292
314
  let {
293
315
  longPress
294
316
  } = _ref3;
295
- if (!longPress) {
317
+ if (!longPress && ref.current) {
296
318
  setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
297
319
  }
298
320
  },
@@ -305,7 +327,7 @@ function TabList(_ref2) {
305
327
  let {
306
328
  longPress
307
329
  } = _ref4;
308
- if (!longPress) {
330
+ if (!longPress && ref.current) {
309
331
  setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
310
332
  }
311
333
  },
@@ -317,7 +339,7 @@ function TabList(_ref2) {
317
339
  className: className
318
340
  }, /*#__PURE__*/React__default.createElement("button", _extends({
319
341
  "aria-hidden": "true",
320
- tabIndex: "-1",
342
+ tabIndex: -1,
321
343
  "aria-label": "Scroll left",
322
344
  ref: previousButton,
323
345
  className: previousButtonClasses,
@@ -330,7 +352,7 @@ function TabList(_ref2) {
330
352
  onScroll: debouncedOnScroll,
331
353
  onKeyDown: onKeyDown
332
354
  }), React__default.Children.map(children, (child, index) => {
333
- return /*#__PURE__*/React__default.createElement(TabContext.Provider, {
355
+ return !isElement(child) ? null : /*#__PURE__*/React__default.createElement(TabContext.Provider, {
334
356
  value: {
335
357
  index,
336
358
  hasSecondaryLabel: hasSecondaryLabelTabs,
@@ -343,7 +365,7 @@ function TabList(_ref2) {
343
365
  }));
344
366
  })), /*#__PURE__*/React__default.createElement("button", _extends({
345
367
  "aria-hidden": "true",
346
- tabIndex: "-1",
368
+ tabIndex: -1,
347
369
  "aria-label": "Scroll right",
348
370
  ref: nextButton,
349
371
  className: nextButtonClasses,
@@ -362,7 +384,7 @@ TabList.propTypes = {
362
384
  */
363
385
  'aria-label': PropTypes.string.isRequired,
364
386
  /**
365
- * Provide child elements to be rendered inside of `ContentTabs`.
387
+ * Provide child elements to be rendered inside `ContentTabs`.
366
388
  * These elements should render a `ContentTab`
367
389
  */
368
390
  children: PropTypes.node,
@@ -383,7 +405,7 @@ TabList.propTypes = {
383
405
  */
384
406
  leftOverflowButtonProps: PropTypes.object,
385
407
  /**
386
- * Specify whether or not to use the light component variant
408
+ * Specify whether to use the light component variant
387
409
  */
388
410
  light: deprecate(PropTypes.bool, 'The `light` prop for `TabList` has ' + 'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.'),
389
411
  /**
@@ -397,53 +419,60 @@ TabList.propTypes = {
397
419
  */
398
420
  scrollDebounceWait: PropTypes.number,
399
421
  /**
400
- * Choose whether or not to automatically scroll to newly selected tabs
401
- * on component rerender
422
+ * Choose whether to automatically scroll
423
+ * to newly selected tabs on component rerender
402
424
  */
403
425
  scrollIntoView: PropTypes.bool
404
426
  };
405
427
 
406
428
  /**
407
- * Helper function to setup the behavior when a button is "long pressed". This
408
- * function will take a ref to the tablist, a direction, and a setter for
409
- * scrollLeft and will update the scroll position within a
410
- * requestAnimationFrame.
411
- *
412
- * It returns a cleanup function to be run when the long press is
413
- * deactivated
429
+ * Helper function to set up the behavior when a button is "long pressed".
430
+ * This function will take a ref to the tablist, a direction, and a setter
431
+ * for scrollLeft and will update the scroll position within a requestAnimationFrame.
414
432
  *
415
- * @param {RefObject} ref
416
- * @param {'forward' | 'backward'} direction
417
- * @param {Function} setScrollLeft
418
- * @returns {Function}
433
+ * It returns a cleanup function to be run
434
+ * when the long press is deactivated
419
435
  */
420
436
  function createLongPressBehavior(ref, direction, setScrollLeft) {
421
- // We manually override the scroll behavior to be "auto". If it is set as
422
- // smooth, this animation does not update correctly
423
- let defaultScrollBehavior = ref.current.style['scroll-behavior'];
424
- ref.current.style['scroll-behavior'] = 'auto';
437
+ const node = ref.current;
438
+ if (!node) {
439
+ return () => {};
440
+ }
441
+
442
+ // We manually override the scroll behavior to be "auto".
443
+ // If it is set as smooth, this animation does not update correctly
444
+ const defaultScrollBehavior = node?.style['scroll-behavior'];
445
+ node.style['scroll-behavior'] = 'auto';
425
446
  const scrollDelta = direction === 'forward' ? 5 : -5;
426
447
  let frameId = null;
427
448
  function tick() {
428
- ref.current.scrollLeft = ref.current.scrollLeft + scrollDelta;
449
+ if (!node) {
450
+ return;
451
+ }
452
+ node.scrollLeft = node.scrollLeft + scrollDelta;
429
453
  frameId = requestAnimationFrame(tick);
430
454
  }
431
455
  frameId = requestAnimationFrame(tick);
432
456
  return () => {
433
457
  // Restore the previous scroll behavior
434
- ref.current.style['scroll-behavior'] = defaultScrollBehavior;
458
+ node.style['scroll-behavior'] = defaultScrollBehavior;
435
459
 
436
460
  // Make sure that our `scrollLeft` value is in sync with the existing
437
461
  // `ref` after our requestAnimationFrame loop above
438
- setScrollLeft(ref.current.scrollLeft);
462
+ setScrollLeft(node.scrollLeft);
439
463
  if (frameId) {
440
464
  cancelAnimationFrame(frameId);
441
465
  }
442
466
  };
443
467
  }
444
- const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRef) {
468
+
469
+ /**
470
+ * Tab
471
+ */
472
+
473
+ const Tab = /*#__PURE__*/forwardRef(function Tab(_ref5, forwardRef) {
445
474
  let {
446
- as: BaseComponent = 'button',
475
+ as = 'button',
447
476
  children,
448
477
  className: customClassName,
449
478
  disabled,
@@ -472,20 +501,21 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
472
501
  const [ignoreHover, setIgnoreHover] = useState(false);
473
502
  const id = `${baseId}-tab-${index}`;
474
503
  const panelId = `${baseId}-tabpanel-${index}`;
475
- const className = cx(`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, customClassName, {
504
+ const className = cx(`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, {
476
505
  [`${prefix}--tabs__nav-item--selected`]: selectedIndex === index,
477
506
  [`${prefix}--tabs__nav-item--disabled`]: disabled,
478
507
  [`${prefix}--tabs__nav-item--hover-off`]: ignoreHover
479
- });
508
+ }, customClassName);
509
+ const BaseComponent = as;
480
510
  const onDismissIconMouseEnter = evt => {
481
- if (contained) {
511
+ if (contained && tabRef.current) {
482
512
  evt.stopPropagation();
483
513
  setIgnoreHover(true);
484
514
  tabRef.current.classList.add(`${prefix}--tabs__nav-item--hover-off`);
485
515
  }
486
516
  };
487
517
  const onDismissIconMouseLeave = () => {
488
- if (contained) {
518
+ if (contained && tabRef.current) {
489
519
  tabRef.current.classList.remove(`${prefix}--tabs__nav-item--hover-off`);
490
520
  setIgnoreHover(false);
491
521
  }
@@ -517,7 +547,7 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
517
547
  title: "Close tab",
518
548
  ref: dismissIconRef
519
549
  }, _Close || (_Close = /*#__PURE__*/React__default.createElement(Close, null)));
520
- const hasIcon = Icon || dismissable;
550
+ const hasIcon = Icon ?? dismissable;
521
551
  return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
522
552
  "aria-controls": panelId,
523
553
  "aria-disabled": disabled,
@@ -532,9 +562,7 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
532
562
  return;
533
563
  }
534
564
  setSelectedIndex(index);
535
- if (onClick) {
536
- onClick(evt);
537
- }
565
+ onClick?.(evt);
538
566
  },
539
567
  onKeyDown: handleKeyDown,
540
568
  tabIndex: selectedIndex === index ? '0' : '-1',
@@ -551,7 +579,7 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
551
579
  className: cx(`${prefix}--tabs__nav-item--icon`, {
552
580
  [`${prefix}--visually-hidden`]: !hasIcon
553
581
  })
554
- }, DismissIcon, !dismissable && hasIcon && /*#__PURE__*/React__default.createElement(Icon, {
582
+ }, DismissIcon, !dismissable && Icon && /*#__PURE__*/React__default.createElement(Icon, {
555
583
  size: 16
556
584
  }))), hasSecondaryLabel && /*#__PURE__*/React__default.createElement("div", {
557
585
  className: `${prefix}--tabs__nav-item-secondary-label`
@@ -561,9 +589,10 @@ Tab.propTypes = {
561
589
  /**
562
590
  * Provide a custom element to render instead of the default button
563
591
  */
592
+ // @ts-expect-error: Invalid prop type derivation
564
593
  as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
565
594
  /**
566
- * Provide child elements to be rendered inside of `Tab`.
595
+ * Provide child elements to be rendered inside `Tab`.
567
596
  */
568
597
  children: PropTypes.node,
569
598
  /**
@@ -592,6 +621,7 @@ Tab.propTypes = {
592
621
  * Optional prop to render an icon next to the label.
593
622
  * Can be a React component class
594
623
  */
624
+ // @ts-expect-error: Invalid prop type derivation
595
625
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
596
626
  /*
597
627
  * An optional label to render under the primary tab label.
@@ -599,6 +629,11 @@ Tab.propTypes = {
599
629
  **/
600
630
  secondaryLabel: PropTypes.string
601
631
  };
632
+
633
+ /**
634
+ * IconTab
635
+ */
636
+
602
637
  const IconTab = /*#__PURE__*/React__default.forwardRef(function IconTab(_ref6, ref) {
603
638
  let {
604
639
  children,
@@ -625,7 +660,7 @@ const IconTab = /*#__PURE__*/React__default.forwardRef(function IconTab(_ref6, r
625
660
  });
626
661
  IconTab.propTypes = {
627
662
  /**
628
- * Provide an icon to be rendered inside of `IconTab` as the visual label for Tab.
663
+ * Provide an icon to be rendered inside `IconTab` as the visual label for Tab.
629
664
  */
630
665
  children: PropTypes.node,
631
666
  /**
@@ -641,7 +676,7 @@ IconTab.propTypes = {
641
676
  */
642
677
  enterDelayMs: PropTypes.number,
643
678
  /**
644
- * Provide the label to be rendered inside of the Tooltip. The label will use
679
+ * Provide the label to be rendered inside the Tooltip. The label will use
645
680
  * `aria-labelledby` and will fully describe the child node that is provided.
646
681
  * This means that if you have text in the child node it will not be
647
682
  * announced to the screen reader.
@@ -652,6 +687,11 @@ IconTab.propTypes = {
652
687
  */
653
688
  leaveDelayMs: PropTypes.number
654
689
  };
690
+
691
+ /**
692
+ * TabPanel
693
+ */
694
+
655
695
  const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7, forwardRef) {
656
696
  let {
657
697
  children,
@@ -661,7 +701,7 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
661
701
  const prefix = usePrefix();
662
702
  const panel = useRef(null);
663
703
  const ref = useMergedRefs([forwardRef, panel]);
664
- const [tabIndex, setTabIndex] = useState('0');
704
+ const [tabIndex, setTabIndex] = useState(0);
665
705
  const [interactiveContent, setInteractiveContent] = useState(false);
666
706
  const {
667
707
  selectedIndex,
@@ -680,26 +720,24 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
680
720
  const content = getInteractiveContent(panel.current);
681
721
  if (content) {
682
722
  setInteractiveContent(true);
683
- setTabIndex('-1');
723
+ setTabIndex(-1);
684
724
  }
685
725
  });
686
726
 
687
727
  // tabindex should only be 0 if no interactive content in children
688
728
  useEffect(() => {
689
- if (!panel.current) {
729
+ const node = panel.current;
730
+ if (!node) {
690
731
  return;
691
732
  }
692
- const {
693
- current: node
694
- } = panel;
695
733
  function callback() {
696
734
  const content = getInteractiveContent(node);
697
735
  if (content) {
698
736
  setInteractiveContent(true);
699
- setTabIndex('-1');
737
+ setTabIndex(-1);
700
738
  } else {
701
739
  setInteractiveContent(false);
702
- setTabIndex('0');
740
+ setTabIndex(0);
703
741
  }
704
742
  }
705
743
  const observer = new MutationObserver(callback);
@@ -707,9 +745,7 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
707
745
  childList: true,
708
746
  subtree: true
709
747
  });
710
- return () => {
711
- observer.disconnect(node);
712
- };
748
+ return () => observer.disconnect();
713
749
  }, []);
714
750
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
715
751
  "aria-labelledby": tabId,
@@ -723,7 +759,7 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
723
759
  });
724
760
  TabPanel.propTypes = {
725
761
  /**
726
- * Provide child elements to be rendered inside of `TabPanel`.
762
+ * Provide child elements to be rendered inside `TabPanel`.
727
763
  */
728
764
  children: PropTypes.node,
729
765
  /**
@@ -731,6 +767,11 @@ TabPanel.propTypes = {
731
767
  */
732
768
  className: PropTypes.string
733
769
  };
770
+
771
+ /**
772
+ * TabPanels
773
+ */
774
+
734
775
  function TabPanels(_ref8) {
735
776
  let {
736
777
  children
@@ -743,7 +784,7 @@ function TabPanels(_ref8) {
743
784
  }
744
785
  TabPanels.propTypes = {
745
786
  /**
746
- * Provide child elements to be rendered inside of `TabPanels`.
787
+ * Provide child elements to be rendered inside `TabPanels`.
747
788
  */
748
789
  children: PropTypes.node
749
790
  };
@@ -0,0 +1,10 @@
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 { Tabs } from './Tabs';
8
+ export default Tabs;
9
+ export { default as TabsSkeleton } from './Tabs.Skeleton';
10
+ export { TabPanels, type TabPanelsProps, TabPanel, type TabPanelProps, TabList, type TabListProps, IconTab, type IconTabProps, Tabs, type TabsProps, } from './Tabs';
@@ -7,6 +7,17 @@
7
7
 
8
8
  import { useRef, useState, useEffect } from 'react';
9
9
 
10
+ /**
11
+ * @param {React.RefObject<HTMLElement>} ref
12
+ *
13
+ * @param {{
14
+ * onPress?(state: { longPress: boolean }): void,
15
+ * onPressIn?(): void,
16
+ * onPressOut?(): void,
17
+ * onLongPress?(): void,
18
+ * delayLongPressMs?: number,
19
+ * }} options
20
+ */
10
21
  function usePressable(ref) {
11
22
  let {
12
23
  onPress,
@@ -0,0 +1,90 @@
1
+ import React from 'react';
2
+ import { ReactAttr } from '../../types/common';
3
+ export interface ControlledPasswordInputProps extends ReactAttr<HTMLInputElement> {
4
+ /**
5
+ * Provide a custom className that is applied directly to the underlying
6
+ * `<input>` node
7
+ */
8
+ className?: string;
9
+ /**
10
+ * Optionally provide the default value of the `<input>`
11
+ */
12
+ defaultValue?: string | number;
13
+ /**
14
+ * Specify whether the control is disabled
15
+ */
16
+ disabled?: boolean;
17
+ /**
18
+ * Provide text that is used alongside the control label for additional help
19
+ */
20
+ helperText?: React.ReactNode;
21
+ /**
22
+ * Specify whether or not the underlying label is visually hidden
23
+ */
24
+ hideLabel?: boolean;
25
+ /**
26
+ * "Hide password" tooltip text on password visibility toggle
27
+ */
28
+ hidePasswordLabel?: string;
29
+ /**
30
+ * Provide a unique identifier for the input field
31
+ */
32
+ id: string;
33
+ /**
34
+ * Specify whether the control is currently invalid
35
+ */
36
+ invalid?: boolean;
37
+ /**
38
+ * Provide the text that is displayed when the control is in an invalid state
39
+ */
40
+ invalidText?: React.ReactNode;
41
+ /**
42
+ * Provide the text that will be read by a screen reader when visiting this
43
+ * control
44
+ */
45
+ labelText: React.ReactNode;
46
+ /**
47
+ * @deprecated The `light` prop for `ControlledPasswordInput` has been deprecated in favor of the new `Layer` component. It will be removed in the next major release.
48
+ */
49
+ light?: boolean;
50
+ /**
51
+ * Optionally provide an `onChange` handler that is called whenever `<input>`
52
+ * is updated
53
+ */
54
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
55
+ /**
56
+ * Optionally provide an `onClick` handler that is called whenever the
57
+ * `<input>` is clicked
58
+ */
59
+ onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;
60
+ /**
61
+ * Specify the placeholder attribute for the `<input>`
62
+ */
63
+ placeholder?: string;
64
+ /**
65
+ * "Show password" tooltip text on password visibility toggle
66
+ */
67
+ showPasswordLabel?: string;
68
+ /**
69
+ * Specify the size of the Text Input.
70
+ */
71
+ size?: 'sm' | 'md' | 'lg';
72
+ /**
73
+ * Specify the alignment of the tooltip to the icon-only button.
74
+ * Can be one of?: start, center, or end.
75
+ */
76
+ tooltipAlignment?: 'start' | 'center' | 'end';
77
+ /**
78
+ * Specify the direction of the tooltip for icon-only buttons.
79
+ * Can be either top, right, bottom, or left.
80
+ */
81
+ tooltipPosition?: 'top' | 'right' | 'bottom' | 'left';
82
+ /**
83
+ * Provide the current value of the `<input>`
84
+ */
85
+ value?: string | number;
86
+ togglePasswordVisibility?(event: React.MouseEvent<HTMLButtonElement>): void;
87
+ type?: string;
88
+ }
89
+ declare const ControlledPasswordInput: React.ForwardRefExoticComponent<ControlledPasswordInputProps & React.RefAttributes<unknown>>;
90
+ export default ControlledPasswordInput;
@@ -60,12 +60,12 @@ const ControlledPasswordInput = /*#__PURE__*/React__default.forwardRef(function
60
60
  id,
61
61
  onChange: evt => {
62
62
  if (!other.disabled) {
63
- onChange(evt);
63
+ onChange?.(evt);
64
64
  }
65
65
  },
66
66
  onClick: evt => {
67
67
  if (!other.disabled) {
68
- onClick(evt);
68
+ onClick?.(evt);
69
69
  }
70
70
  },
71
71
  placeholder,
@@ -104,7 +104,7 @@ const ControlledPasswordInput = /*#__PURE__*/React__default.forwardRef(function
104
104
  invalid,
105
105
  sharedTextInputProps,
106
106
  invalidId: errorId,
107
- hasHelper: !error && helperText,
107
+ hasHelper: !error && helperText ? true : false,
108
108
  helperId
109
109
  }), {
110
110
  "data-toggle-password-visibility": type === 'password'
@@ -221,8 +221,7 @@ ControlledPasswordInput.defaultProps = {
221
221
  invalid: false,
222
222
  invalidText: '',
223
223
  helperText: '',
224
- size: ''
224
+ size: undefined
225
225
  };
226
- var ControlledPasswordInput$1 = ControlledPasswordInput;
227
226
 
228
- export { ControlledPasswordInput$1 as default };
227
+ export { ControlledPasswordInput as default };