@carbon/react 1.31.2 → 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 (184) 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
  183. package/scss/components/contained-list/_contained-list.scss +9 -0
  184. package/scss/components/contained-list/_index.scss +9 -0
@@ -15,6 +15,7 @@ var cx = require('classnames');
15
15
  var debounce = require('lodash.debounce');
16
16
  var PropTypes = require('prop-types');
17
17
  var React = require('react');
18
+ var reactIs = require('react-is');
18
19
  require('../Tooltip/DefinitionTooltip.js');
19
20
  var Tooltip = require('../Tooltip/Tooltip.js');
20
21
  var useControllableState = require('../../internal/useControllableState.js');
@@ -40,13 +41,31 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
40
41
  var _ChevronLeft, _ChevronRight, _Close;
41
42
 
42
43
  // Used to manage the overall state of the Tabs
43
- const TabsContext = /*#__PURE__*/React__default["default"].createContext();
44
+
45
+ const TabsContext = /*#__PURE__*/React__default["default"].createContext({
46
+ baseId: '',
47
+ activeIndex: 0,
48
+ defaultSelectedIndex: 0,
49
+ dismissable: false,
50
+ onTabCloseRequest() {},
51
+ setActiveIndex() {},
52
+ selectedIndex: 0,
53
+ setSelectedIndex() {}
54
+ });
44
55
 
45
56
  // Used to keep track of position in a tablist
46
- const TabContext = /*#__PURE__*/React__default["default"].createContext();
57
+ const TabContext = /*#__PURE__*/React__default["default"].createContext({
58
+ index: 0,
59
+ hasSecondaryLabel: false
60
+ });
47
61
 
48
62
  // Used to keep track of position in a list of tab panels
49
- const TabPanelContext = /*#__PURE__*/React__default["default"].createContext();
63
+ const TabPanelContext = /*#__PURE__*/React__default["default"].createContext(0);
64
+
65
+ /**
66
+ * Tabs
67
+ */
68
+
50
69
  function Tabs(_ref) {
51
70
  let {
52
71
  children,
@@ -63,13 +82,9 @@ function Tabs(_ref) {
63
82
  const [selectedIndex, setSelectedIndex] = useControllableState.useControllableState({
64
83
  value: controlledSelectedIndex,
65
84
  defaultValue: defaultSelectedIndex,
66
- onChange: value => {
67
- if (onChange) {
68
- onChange({
69
- selectedIndex: value
70
- });
71
- }
72
- }
85
+ onChange: value => onChange?.({
86
+ selectedIndex: value
87
+ })
73
88
  });
74
89
  const value = {
75
90
  baseId,
@@ -87,7 +102,7 @@ function Tabs(_ref) {
87
102
  }
88
103
  Tabs.propTypes = {
89
104
  /**
90
- * Provide child elements to be rendered inside of the `Tabs`.
105
+ * Provide child elements to be rendered inside the `Tabs`.
91
106
  * These elements should render either `TabsList` or `TabsPanels`
92
107
  */
93
108
  children: PropTypes__default["default"].node,
@@ -123,24 +138,28 @@ Tabs.propTypes = {
123
138
  };
124
139
 
125
140
  /**
126
- * Get the next index for a given keyboard event given a count of the total
127
- * items and the current index
128
- * @param {Event} event
129
- * @param {number} total
130
- * @param {number} index
131
- * @returns {number}
141
+ * Get the next index for a given keyboard event
142
+ * given a count of the total items and the current index
132
143
  */
133
144
  function getNextIndex(event, total, index) {
134
- if (match.match(event, keys.ArrowRight)) {
135
- return (index + 1) % total;
136
- } else if (match.match(event, keys.ArrowLeft)) {
137
- return (total + index - 1) % total;
138
- } else if (match.match(event, keys.Home)) {
139
- return 0;
140
- } else if (match.match(event, keys.End)) {
141
- return total - 1;
145
+ switch (true) {
146
+ case match.match(event, keys.ArrowRight):
147
+ return (index + 1) % total;
148
+ case match.match(event, keys.ArrowLeft):
149
+ return (total + index - 1) % total;
150
+ case match.match(event, keys.Home):
151
+ return 0;
152
+ case match.match(event, keys.End):
153
+ return total - 1;
154
+ default:
155
+ return index;
142
156
  }
143
157
  }
158
+
159
+ /**
160
+ * TabList
161
+ */
162
+
144
163
  function TabList(_ref2) {
145
164
  let {
146
165
  activation = 'automatic',
@@ -168,7 +187,20 @@ function TabList(_ref2) {
168
187
  const previousButton = React.useRef(null);
169
188
  const nextButton = React.useRef(null);
170
189
  const [isScrollable, setIsScrollable] = React.useState(false);
171
- const [scrollLeft, setScrollLeft] = React.useState(null);
190
+ const [scrollLeft, setScrollLeft] = React.useState(0);
191
+ let hasSecondaryLabelTabs = false;
192
+ if (contained) {
193
+ hasSecondaryLabelTabs = React__default["default"].Children.toArray(children).some(child => {
194
+ return reactIs.isElement(child) && !!child.props.secondaryLabel;
195
+ });
196
+ }
197
+ const className = cx__default["default"](`${prefix}--tabs`, {
198
+ [`${prefix}--tabs--contained`]: contained,
199
+ [`${prefix}--tabs--light`]: light,
200
+ [`${prefix}--tabs__icon--default`]: iconSize === 'default',
201
+ [`${prefix}--tabs__icon--lg`]: iconSize === 'lg',
202
+ [`${prefix}--tabs--tall`]: hasSecondaryLabelTabs
203
+ }, customClassName);
172
204
 
173
205
  // Previous Button
174
206
  // VISIBLE IF:
@@ -180,14 +212,6 @@ function TabList(_ref2) {
180
212
  // SCROLLABLE
181
213
  // AND SCROLL_LEFT + CLIENT_WIDTH < SCROLL_WIDTH
182
214
  const [isNextButtonVisible, setIsNextButtonVisible] = React.useState(ref.current ? scrollLeft + buttonWidth + ref.current.clientWidth < ref.current.scrollWidth : false);
183
- const hasSecondaryLabelTabs = contained && !!React__default["default"].Children.toArray(children).filter(child => child.props.secondaryLabel).length;
184
- const className = cx__default["default"](`${prefix}--tabs`, customClassName, {
185
- [`${prefix}--tabs--contained`]: contained,
186
- [`${prefix}--tabs--light`]: light,
187
- [`${prefix}--tabs__icon--default`]: iconSize === 'default',
188
- [`${prefix}--tabs__icon--lg`]: iconSize === 'lg',
189
- [`${prefix}--tabs--tall`]: hasSecondaryLabelTabs
190
- });
191
215
  const isPreviousButtonVisible = ref.current ? isScrollable && scrollLeft > 0 : false;
192
216
  const previousButtonClasses = cx__default["default"](`${prefix}--tab--overflow-nav-button`, `${prefix}--tab--overflow-nav-button--previous`, {
193
217
  [`${prefix}--tab--overflow-nav-button--hidden`]: !isPreviousButtonVisible
@@ -204,9 +228,7 @@ function TabList(_ref2) {
204
228
  function onKeyDown(event) {
205
229
  if (match.matches(event, [keys.ArrowRight, keys.ArrowLeft, keys.Home, keys.End])) {
206
230
  event.preventDefault();
207
- const activeTabs = tabs.current.filter(tab => {
208
- return !tab.disabled;
209
- });
231
+ const activeTabs = tabs.current.filter(tab => !tab.disabled);
210
232
  const currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
211
233
  const nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
212
234
  if (activation === 'automatic') {
@@ -214,7 +236,7 @@ function TabList(_ref2) {
214
236
  } else if (activation === 'manual') {
215
237
  setActiveIndex(nextIndex);
216
238
  }
217
- tabs.current[nextIndex].focus();
239
+ tabs.current[nextIndex]?.focus();
218
240
  }
219
241
  }
220
242
  useEffectOnce.useEffectOnce(() => {
@@ -264,12 +286,12 @@ function TabList(_ref2) {
264
286
 
265
287
  // updates scroll location for all scroll behavior.
266
288
  useIsomorphicEffect["default"](() => {
267
- if (scrollLeft !== null) {
289
+ if (scrollLeft !== null && ref.current) {
268
290
  ref.current.scrollLeft = scrollLeft;
269
291
  }
270
292
  }, [scrollLeft]);
271
293
  useIsomorphicEffect["default"](() => {
272
- if (!isScrollable) {
294
+ if (!isScrollable || !ref.current) {
273
295
  return;
274
296
  }
275
297
  const tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
@@ -303,7 +325,7 @@ function TabList(_ref2) {
303
325
  let {
304
326
  longPress
305
327
  } = _ref3;
306
- if (!longPress) {
328
+ if (!longPress && ref.current) {
307
329
  setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
308
330
  }
309
331
  },
@@ -316,7 +338,7 @@ function TabList(_ref2) {
316
338
  let {
317
339
  longPress
318
340
  } = _ref4;
319
- if (!longPress) {
341
+ if (!longPress && ref.current) {
320
342
  setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
321
343
  }
322
344
  },
@@ -328,7 +350,7 @@ function TabList(_ref2) {
328
350
  className: className
329
351
  }, /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({
330
352
  "aria-hidden": "true",
331
- tabIndex: "-1",
353
+ tabIndex: -1,
332
354
  "aria-label": "Scroll left",
333
355
  ref: previousButton,
334
356
  className: previousButtonClasses,
@@ -341,7 +363,7 @@ function TabList(_ref2) {
341
363
  onScroll: debouncedOnScroll,
342
364
  onKeyDown: onKeyDown
343
365
  }), React__default["default"].Children.map(children, (child, index) => {
344
- return /*#__PURE__*/React__default["default"].createElement(TabContext.Provider, {
366
+ return !reactIs.isElement(child) ? null : /*#__PURE__*/React__default["default"].createElement(TabContext.Provider, {
345
367
  value: {
346
368
  index,
347
369
  hasSecondaryLabel: hasSecondaryLabelTabs,
@@ -354,7 +376,7 @@ function TabList(_ref2) {
354
376
  }));
355
377
  })), /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({
356
378
  "aria-hidden": "true",
357
- tabIndex: "-1",
379
+ tabIndex: -1,
358
380
  "aria-label": "Scroll right",
359
381
  ref: nextButton,
360
382
  className: nextButtonClasses,
@@ -373,7 +395,7 @@ TabList.propTypes = {
373
395
  */
374
396
  'aria-label': PropTypes__default["default"].string.isRequired,
375
397
  /**
376
- * Provide child elements to be rendered inside of `ContentTabs`.
398
+ * Provide child elements to be rendered inside `ContentTabs`.
377
399
  * These elements should render a `ContentTab`
378
400
  */
379
401
  children: PropTypes__default["default"].node,
@@ -394,7 +416,7 @@ TabList.propTypes = {
394
416
  */
395
417
  leftOverflowButtonProps: PropTypes__default["default"].object,
396
418
  /**
397
- * Specify whether or not to use the light component variant
419
+ * Specify whether to use the light component variant
398
420
  */
399
421
  light: deprecate["default"](PropTypes__default["default"].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.'),
400
422
  /**
@@ -408,53 +430,60 @@ TabList.propTypes = {
408
430
  */
409
431
  scrollDebounceWait: PropTypes__default["default"].number,
410
432
  /**
411
- * Choose whether or not to automatically scroll to newly selected tabs
412
- * on component rerender
433
+ * Choose whether to automatically scroll
434
+ * to newly selected tabs on component rerender
413
435
  */
414
436
  scrollIntoView: PropTypes__default["default"].bool
415
437
  };
416
438
 
417
439
  /**
418
- * Helper function to setup the behavior when a button is "long pressed". This
419
- * function will take a ref to the tablist, a direction, and a setter for
420
- * scrollLeft and will update the scroll position within a
421
- * requestAnimationFrame.
422
- *
423
- * It returns a cleanup function to be run when the long press is
424
- * deactivated
440
+ * Helper function to set up the behavior when a button is "long pressed".
441
+ * This function will take a ref to the tablist, a direction, and a setter
442
+ * for scrollLeft and will update the scroll position within a requestAnimationFrame.
425
443
  *
426
- * @param {RefObject} ref
427
- * @param {'forward' | 'backward'} direction
428
- * @param {Function} setScrollLeft
429
- * @returns {Function}
444
+ * It returns a cleanup function to be run
445
+ * when the long press is deactivated
430
446
  */
431
447
  function createLongPressBehavior(ref, direction, setScrollLeft) {
432
- // We manually override the scroll behavior to be "auto". If it is set as
433
- // smooth, this animation does not update correctly
434
- let defaultScrollBehavior = ref.current.style['scroll-behavior'];
435
- ref.current.style['scroll-behavior'] = 'auto';
448
+ const node = ref.current;
449
+ if (!node) {
450
+ return () => {};
451
+ }
452
+
453
+ // We manually override the scroll behavior to be "auto".
454
+ // If it is set as smooth, this animation does not update correctly
455
+ const defaultScrollBehavior = node?.style['scroll-behavior'];
456
+ node.style['scroll-behavior'] = 'auto';
436
457
  const scrollDelta = direction === 'forward' ? 5 : -5;
437
458
  let frameId = null;
438
459
  function tick() {
439
- ref.current.scrollLeft = ref.current.scrollLeft + scrollDelta;
460
+ if (!node) {
461
+ return;
462
+ }
463
+ node.scrollLeft = node.scrollLeft + scrollDelta;
440
464
  frameId = requestAnimationFrame(tick);
441
465
  }
442
466
  frameId = requestAnimationFrame(tick);
443
467
  return () => {
444
468
  // Restore the previous scroll behavior
445
- ref.current.style['scroll-behavior'] = defaultScrollBehavior;
469
+ node.style['scroll-behavior'] = defaultScrollBehavior;
446
470
 
447
471
  // Make sure that our `scrollLeft` value is in sync with the existing
448
472
  // `ref` after our requestAnimationFrame loop above
449
- setScrollLeft(ref.current.scrollLeft);
473
+ setScrollLeft(node.scrollLeft);
450
474
  if (frameId) {
451
475
  cancelAnimationFrame(frameId);
452
476
  }
453
477
  };
454
478
  }
455
- const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5, forwardRef) {
479
+
480
+ /**
481
+ * Tab
482
+ */
483
+
484
+ const Tab = /*#__PURE__*/React.forwardRef(function Tab(_ref5, forwardRef) {
456
485
  let {
457
- as: BaseComponent = 'button',
486
+ as = 'button',
458
487
  children,
459
488
  className: customClassName,
460
489
  disabled,
@@ -483,20 +512,21 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
483
512
  const [ignoreHover, setIgnoreHover] = React.useState(false);
484
513
  const id = `${baseId}-tab-${index}`;
485
514
  const panelId = `${baseId}-tabpanel-${index}`;
486
- const className = cx__default["default"](`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, customClassName, {
515
+ const className = cx__default["default"](`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, {
487
516
  [`${prefix}--tabs__nav-item--selected`]: selectedIndex === index,
488
517
  [`${prefix}--tabs__nav-item--disabled`]: disabled,
489
518
  [`${prefix}--tabs__nav-item--hover-off`]: ignoreHover
490
- });
519
+ }, customClassName);
520
+ const BaseComponent = as;
491
521
  const onDismissIconMouseEnter = evt => {
492
- if (contained) {
522
+ if (contained && tabRef.current) {
493
523
  evt.stopPropagation();
494
524
  setIgnoreHover(true);
495
525
  tabRef.current.classList.add(`${prefix}--tabs__nav-item--hover-off`);
496
526
  }
497
527
  };
498
528
  const onDismissIconMouseLeave = () => {
499
- if (contained) {
529
+ if (contained && tabRef.current) {
500
530
  tabRef.current.classList.remove(`${prefix}--tabs__nav-item--hover-off`);
501
531
  setIgnoreHover(false);
502
532
  }
@@ -528,7 +558,7 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
528
558
  title: "Close tab",
529
559
  ref: dismissIconRef
530
560
  }, _Close || (_Close = /*#__PURE__*/React__default["default"].createElement(iconsReact.Close, null)));
531
- const hasIcon = Icon || dismissable;
561
+ const hasIcon = Icon ?? dismissable;
532
562
  return /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({}, rest, {
533
563
  "aria-controls": panelId,
534
564
  "aria-disabled": disabled,
@@ -543,9 +573,7 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
543
573
  return;
544
574
  }
545
575
  setSelectedIndex(index);
546
- if (onClick) {
547
- onClick(evt);
548
- }
576
+ onClick?.(evt);
549
577
  },
550
578
  onKeyDown: handleKeyDown,
551
579
  tabIndex: selectedIndex === index ? '0' : '-1',
@@ -562,7 +590,7 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
562
590
  className: cx__default["default"](`${prefix}--tabs__nav-item--icon`, {
563
591
  [`${prefix}--visually-hidden`]: !hasIcon
564
592
  })
565
- }, DismissIcon, !dismissable && hasIcon && /*#__PURE__*/React__default["default"].createElement(Icon, {
593
+ }, DismissIcon, !dismissable && Icon && /*#__PURE__*/React__default["default"].createElement(Icon, {
566
594
  size: 16
567
595
  }))), hasSecondaryLabel && /*#__PURE__*/React__default["default"].createElement("div", {
568
596
  className: `${prefix}--tabs__nav-item-secondary-label`
@@ -572,9 +600,10 @@ Tab.propTypes = {
572
600
  /**
573
601
  * Provide a custom element to render instead of the default button
574
602
  */
603
+ // @ts-expect-error: Invalid prop type derivation
575
604
  as: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].elementType]),
576
605
  /**
577
- * Provide child elements to be rendered inside of `Tab`.
606
+ * Provide child elements to be rendered inside `Tab`.
578
607
  */
579
608
  children: PropTypes__default["default"].node,
580
609
  /**
@@ -603,6 +632,7 @@ Tab.propTypes = {
603
632
  * Optional prop to render an icon next to the label.
604
633
  * Can be a React component class
605
634
  */
635
+ // @ts-expect-error: Invalid prop type derivation
606
636
  renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
607
637
  /*
608
638
  * An optional label to render under the primary tab label.
@@ -610,6 +640,11 @@ Tab.propTypes = {
610
640
  **/
611
641
  secondaryLabel: PropTypes__default["default"].string
612
642
  };
643
+
644
+ /**
645
+ * IconTab
646
+ */
647
+
613
648
  const IconTab = /*#__PURE__*/React__default["default"].forwardRef(function IconTab(_ref6, ref) {
614
649
  let {
615
650
  children,
@@ -636,7 +671,7 @@ const IconTab = /*#__PURE__*/React__default["default"].forwardRef(function IconT
636
671
  });
637
672
  IconTab.propTypes = {
638
673
  /**
639
- * Provide an icon to be rendered inside of `IconTab` as the visual label for Tab.
674
+ * Provide an icon to be rendered inside `IconTab` as the visual label for Tab.
640
675
  */
641
676
  children: PropTypes__default["default"].node,
642
677
  /**
@@ -652,7 +687,7 @@ IconTab.propTypes = {
652
687
  */
653
688
  enterDelayMs: PropTypes__default["default"].number,
654
689
  /**
655
- * Provide the label to be rendered inside of the Tooltip. The label will use
690
+ * Provide the label to be rendered inside the Tooltip. The label will use
656
691
  * `aria-labelledby` and will fully describe the child node that is provided.
657
692
  * This means that if you have text in the child node it will not be
658
693
  * announced to the screen reader.
@@ -663,6 +698,11 @@ IconTab.propTypes = {
663
698
  */
664
699
  leaveDelayMs: PropTypes__default["default"].number
665
700
  };
701
+
702
+ /**
703
+ * TabPanel
704
+ */
705
+
666
706
  const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabPanel(_ref7, forwardRef) {
667
707
  let {
668
708
  children,
@@ -672,7 +712,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
672
712
  const prefix = usePrefix.usePrefix();
673
713
  const panel = React.useRef(null);
674
714
  const ref = useMergedRefs.useMergedRefs([forwardRef, panel]);
675
- const [tabIndex, setTabIndex] = React.useState('0');
715
+ const [tabIndex, setTabIndex] = React.useState(0);
676
716
  const [interactiveContent, setInteractiveContent] = React.useState(false);
677
717
  const {
678
718
  selectedIndex,
@@ -691,26 +731,24 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
691
731
  const content = useNoInteractiveChildren.getInteractiveContent(panel.current);
692
732
  if (content) {
693
733
  setInteractiveContent(true);
694
- setTabIndex('-1');
734
+ setTabIndex(-1);
695
735
  }
696
736
  });
697
737
 
698
738
  // tabindex should only be 0 if no interactive content in children
699
739
  React.useEffect(() => {
700
- if (!panel.current) {
740
+ const node = panel.current;
741
+ if (!node) {
701
742
  return;
702
743
  }
703
- const {
704
- current: node
705
- } = panel;
706
744
  function callback() {
707
745
  const content = useNoInteractiveChildren.getInteractiveContent(node);
708
746
  if (content) {
709
747
  setInteractiveContent(true);
710
- setTabIndex('-1');
748
+ setTabIndex(-1);
711
749
  } else {
712
750
  setInteractiveContent(false);
713
- setTabIndex('0');
751
+ setTabIndex(0);
714
752
  }
715
753
  }
716
754
  const observer = new MutationObserver(callback);
@@ -718,9 +756,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
718
756
  childList: true,
719
757
  subtree: true
720
758
  });
721
- return () => {
722
- observer.disconnect(node);
723
- };
759
+ return () => observer.disconnect();
724
760
  }, []);
725
761
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
726
762
  "aria-labelledby": tabId,
@@ -734,7 +770,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
734
770
  });
735
771
  TabPanel.propTypes = {
736
772
  /**
737
- * Provide child elements to be rendered inside of `TabPanel`.
773
+ * Provide child elements to be rendered inside `TabPanel`.
738
774
  */
739
775
  children: PropTypes__default["default"].node,
740
776
  /**
@@ -742,6 +778,11 @@ TabPanel.propTypes = {
742
778
  */
743
779
  className: PropTypes__default["default"].string
744
780
  };
781
+
782
+ /**
783
+ * TabPanels
784
+ */
785
+
745
786
  function TabPanels(_ref8) {
746
787
  let {
747
788
  children
@@ -754,7 +795,7 @@ function TabPanels(_ref8) {
754
795
  }
755
796
  TabPanels.propTypes = {
756
797
  /**
757
- * Provide child elements to be rendered inside of `TabPanels`.
798
+ * Provide child elements to be rendered inside `TabPanels`.
758
799
  */
759
800
  children: PropTypes__default["default"].node
760
801
  };
@@ -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';
@@ -11,6 +11,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var React = require('react');
13
13
 
14
+ /**
15
+ * @param {React.RefObject<HTMLElement>} ref
16
+ *
17
+ * @param {{
18
+ * onPress?(state: { longPress: boolean }): void,
19
+ * onPressIn?(): void,
20
+ * onPressOut?(): void,
21
+ * onLongPress?(): void,
22
+ * delayLongPressMs?: number,
23
+ * }} options
24
+ */
14
25
  function usePressable(ref) {
15
26
  let {
16
27
  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;
@@ -70,12 +70,12 @@ const ControlledPasswordInput = /*#__PURE__*/React__default["default"].forwardRe
70
70
  id,
71
71
  onChange: evt => {
72
72
  if (!other.disabled) {
73
- onChange(evt);
73
+ onChange?.(evt);
74
74
  }
75
75
  },
76
76
  onClick: evt => {
77
77
  if (!other.disabled) {
78
- onClick(evt);
78
+ onClick?.(evt);
79
79
  }
80
80
  },
81
81
  placeholder,
@@ -114,7 +114,7 @@ const ControlledPasswordInput = /*#__PURE__*/React__default["default"].forwardRe
114
114
  invalid,
115
115
  sharedTextInputProps,
116
116
  invalidId: errorId,
117
- hasHelper: !error && helperText,
117
+ hasHelper: !error && helperText ? true : false,
118
118
  helperId
119
119
  }), {
120
120
  "data-toggle-password-visibility": type === 'password'
@@ -231,8 +231,7 @@ ControlledPasswordInput.defaultProps = {
231
231
  invalid: false,
232
232
  invalidText: '',
233
233
  helperText: '',
234
- size: ''
234
+ size: undefined
235
235
  };
236
- var ControlledPasswordInput$1 = ControlledPasswordInput;
237
236
 
238
- exports["default"] = ControlledPasswordInput$1;
237
+ exports["default"] = ControlledPasswordInput;