@carbon/react 1.31.3 → 1.32.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 (190) 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 +311 -0
  73. package/es/components/Tabs/Tabs.js +151 -97
  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/HeaderPanel.js +61 -5
  86. package/es/components/UIShell/SideNav.d.ts +1 -1
  87. package/es/components/UIShell/Switcher.js +45 -5
  88. package/es/components/UIShell/SwitcherItem.js +45 -6
  89. package/es/index.js +16 -16
  90. package/es/internal/keyboard/match.js +2 -2
  91. package/es/internal/useControllableState.js +2 -2
  92. package/es/internal/useMatchMedia.js +44 -0
  93. package/es/internal/wrapFocus.js +6 -6
  94. package/es/prop-types/requiredIfGivenPropIsTruthy.js +1 -1
  95. package/es/prop-types/types.js +3 -0
  96. package/lib/components/Accordion/Accordion.Skeleton.d.ts +64 -0
  97. package/lib/components/Accordion/Accordion.Skeleton.js +3 -3
  98. package/lib/components/Accordion/Accordion.d.ts +65 -0
  99. package/lib/components/Accordion/Accordion.js +5 -6
  100. package/lib/components/Accordion/AccordionItem.d.ts +105 -0
  101. package/lib/components/Accordion/AccordionItem.js +11 -8
  102. package/lib/components/Accordion/AccordionProvider.d.ts +20 -0
  103. package/lib/components/Accordion/AccordionProvider.js +34 -0
  104. package/lib/components/Accordion/index.d.ts +11 -0
  105. package/lib/components/Button/Button.Skeleton.d.ts +28 -0
  106. package/lib/components/Button/Button.Skeleton.js +5 -3
  107. package/lib/components/Button/Button.d.ts +72 -0
  108. package/lib/components/Button/Button.js +18 -11
  109. package/lib/components/Button/index.d.ts +11 -0
  110. package/lib/components/Button/index.js +6 -0
  111. package/lib/components/ButtonSet/ButtonSet.d.ts +17 -0
  112. package/lib/components/ButtonSet/ButtonSet.js +1 -2
  113. package/lib/components/ButtonSet/index.d.ts +9 -0
  114. package/lib/components/CodeSnippet/CodeSnippet.js +1 -0
  115. package/lib/components/ComboButton/index.js +1 -0
  116. package/lib/components/ComposedModal/ComposedModal.d.ts +70 -0
  117. package/lib/components/ComposedModal/ComposedModal.js +58 -67
  118. package/lib/components/ComposedModal/ModalFooter.d.ts +71 -0
  119. package/lib/components/ComposedModal/ModalFooter.js +22 -19
  120. package/lib/components/ComposedModal/ModalHeader.d.ts +58 -0
  121. package/lib/components/ComposedModal/ModalHeader.js +8 -25
  122. package/lib/components/ComposedModal/index.d.ts +9 -0
  123. package/lib/components/ContainedList/ContainedList.js +12 -1
  124. package/lib/components/ContentSwitcher/ContentSwitcher.d.ts +109 -0
  125. package/lib/components/ContentSwitcher/ContentSwitcher.js +14 -6
  126. package/lib/components/DangerButton/DangerButton.d.ts +9 -0
  127. package/lib/components/DangerButton/DangerButton.js +2 -2
  128. package/lib/components/DangerButton/index.d.ts +9 -0
  129. package/lib/components/DataTable/TableBatchAction.js +1 -0
  130. package/lib/components/DataTable/TableBatchActions.js +1 -0
  131. package/lib/components/DataTable/TableBody.d.ts +29 -0
  132. package/lib/components/DataTable/TableBody.js +3 -4
  133. package/lib/components/DataTable/TableContainer.d.ts +51 -0
  134. package/lib/components/DataTable/TableContainer.js +3 -4
  135. package/lib/components/DataTable/TableExpandHeader.d.ts +86 -0
  136. package/lib/components/DataTable/TableExpandHeader.js +4 -5
  137. package/lib/components/DatePicker/plugins/fixEventsPlugin.js +12 -16
  138. package/lib/components/Dropdown/Dropdown.js +1 -0
  139. package/lib/components/FluidTextInput/FluidTextInput.js +1 -0
  140. package/lib/components/FormGroup/FormGroup.d.ts +80 -0
  141. package/lib/components/IconButton/index.js +3 -2
  142. package/lib/components/Layout/index.d.ts +74 -0
  143. package/lib/components/Layout/index.js +14 -5
  144. package/lib/components/Link/Link.d.ts +2 -2
  145. package/lib/components/Link/Link.js +2 -1
  146. package/lib/components/MenuButton/index.js +1 -0
  147. package/lib/components/Modal/Modal.js +1 -0
  148. package/lib/components/ModalWrapper/ModalWrapper.js +1 -0
  149. package/lib/components/Notification/Notification.d.ts +531 -0
  150. package/lib/components/Notification/Notification.js +40 -6
  151. package/lib/components/Notification/index.d.ts +7 -0
  152. package/lib/components/PrimaryButton/PrimaryButton.js +1 -0
  153. package/lib/components/SecondaryButton/SecondaryButton.js +1 -0
  154. package/lib/components/Select/Select.d.ts +1 -1
  155. package/lib/components/SkeletonText/SkeletonText.d.ts +61 -0
  156. package/lib/components/SkeletonText/SkeletonText.js +15 -17
  157. package/lib/components/SkeletonText/index.d.ts +9 -0
  158. package/lib/components/Switch/Switch.d.ts +56 -0
  159. package/lib/components/Switch/Switch.js +4 -4
  160. package/lib/components/Tab/index.d.ts +9 -0
  161. package/lib/components/TabContent/TabContent.d.ts +40 -0
  162. package/lib/components/TabContent/TabContent.js +6 -12
  163. package/lib/components/TabContent/index.d.ts +10 -0
  164. package/lib/components/Tabs/Tabs.Skeleton.d.ts +33 -0
  165. package/lib/components/Tabs/Tabs.Skeleton.js +2 -2
  166. package/lib/components/Tabs/Tabs.d.ts +311 -0
  167. package/lib/components/Tabs/Tabs.js +150 -96
  168. package/lib/components/Tabs/index.d.ts +10 -0
  169. package/lib/components/Tabs/usePressable.js +11 -0
  170. package/lib/components/TextInput/ControlledPasswordInput.d.ts +90 -0
  171. package/lib/components/TextInput/ControlledPasswordInput.js +5 -6
  172. package/lib/components/Tile/Tile.d.ts +153 -0
  173. package/lib/components/Tile/Tile.js +62 -74
  174. package/lib/components/Tile/index.d.ts +7 -0
  175. package/lib/components/Toggle/Toggle.Skeleton.d.ts +3 -47
  176. package/lib/components/Toggle/Toggle.Skeleton.js +22 -62
  177. package/lib/components/Toggle/Toggle.js +1 -1
  178. package/lib/components/UIShell/HeaderGlobalAction.js +1 -0
  179. package/lib/components/UIShell/HeaderPanel.js +60 -4
  180. package/lib/components/UIShell/SideNav.d.ts +1 -1
  181. package/lib/components/UIShell/Switcher.js +44 -4
  182. package/lib/components/UIShell/SwitcherItem.js +45 -6
  183. package/lib/index.js +51 -47
  184. package/lib/internal/keyboard/match.js +2 -2
  185. package/lib/internal/useControllableState.js +2 -2
  186. package/lib/internal/useMatchMedia.js +48 -0
  187. package/lib/internal/wrapFocus.js +6 -6
  188. package/lib/prop-types/requiredIfGivenPropIsTruthy.js +1 -1
  189. package/lib/prop-types/types.js +3 -0
  190. package/package.json +4 -3
@@ -11,10 +11,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
13
13
  var iconsReact = require('@carbon/icons-react');
14
+ var layout = require('@carbon/layout');
14
15
  var cx = require('classnames');
15
16
  var debounce = require('lodash.debounce');
16
17
  var PropTypes = require('prop-types');
17
18
  var React = require('react');
19
+ var reactIs = require('react-is');
18
20
  require('../Tooltip/DefinitionTooltip.js');
19
21
  var Tooltip = require('../Tooltip/Tooltip.js');
20
22
  var useControllableState = require('../../internal/useControllableState.js');
@@ -27,6 +29,7 @@ var usePrefix = require('../../internal/usePrefix.js');
27
29
  var usePressable = require('./usePressable.js');
28
30
  var deprecate = require('../../prop-types/deprecate.js');
29
31
  var useEvent = require('../../internal/useEvent.js');
32
+ var useMatchMedia = require('../../internal/useMatchMedia.js');
30
33
  var match = require('../../internal/keyboard/match.js');
31
34
  var keys = require('../../internal/keyboard/keys.js');
32
35
 
@@ -40,13 +43,32 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
40
43
  var _ChevronLeft, _ChevronRight, _Close;
41
44
 
42
45
  // Used to manage the overall state of the Tabs
43
- const TabsContext = /*#__PURE__*/React__default["default"].createContext();
46
+
47
+ const TabsContext = /*#__PURE__*/React__default["default"].createContext({
48
+ baseId: '',
49
+ activeIndex: 0,
50
+ defaultSelectedIndex: 0,
51
+ dismissable: false,
52
+ onTabCloseRequest() {},
53
+ setActiveIndex() {},
54
+ selectedIndex: 0,
55
+ setSelectedIndex() {}
56
+ });
44
57
 
45
58
  // Used to keep track of position in a tablist
46
- const TabContext = /*#__PURE__*/React__default["default"].createContext();
59
+ const TabContext = /*#__PURE__*/React__default["default"].createContext({
60
+ index: 0,
61
+ hasSecondaryLabel: false
62
+ });
63
+ const lgMediaQuery = `(min-width: ${layout.breakpoints.lg.width})`;
47
64
 
48
65
  // Used to keep track of position in a list of tab panels
49
- const TabPanelContext = /*#__PURE__*/React__default["default"].createContext();
66
+ const TabPanelContext = /*#__PURE__*/React__default["default"].createContext(0);
67
+
68
+ /**
69
+ * Tabs
70
+ */
71
+
50
72
  function Tabs(_ref) {
51
73
  let {
52
74
  children,
@@ -63,13 +85,9 @@ function Tabs(_ref) {
63
85
  const [selectedIndex, setSelectedIndex] = useControllableState.useControllableState({
64
86
  value: controlledSelectedIndex,
65
87
  defaultValue: defaultSelectedIndex,
66
- onChange: value => {
67
- if (onChange) {
68
- onChange({
69
- selectedIndex: value
70
- });
71
- }
72
- }
88
+ onChange: value => onChange?.({
89
+ selectedIndex: value
90
+ })
73
91
  });
74
92
  const value = {
75
93
  baseId,
@@ -87,7 +105,7 @@ function Tabs(_ref) {
87
105
  }
88
106
  Tabs.propTypes = {
89
107
  /**
90
- * Provide child elements to be rendered inside of the `Tabs`.
108
+ * Provide child elements to be rendered inside the `Tabs`.
91
109
  * These elements should render either `TabsList` or `TabsPanels`
92
110
  */
93
111
  children: PropTypes__default["default"].node,
@@ -123,24 +141,28 @@ Tabs.propTypes = {
123
141
  };
124
142
 
125
143
  /**
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}
144
+ * Get the next index for a given keyboard event
145
+ * given a count of the total items and the current index
132
146
  */
133
147
  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;
148
+ switch (true) {
149
+ case match.match(event, keys.ArrowRight):
150
+ return (index + 1) % total;
151
+ case match.match(event, keys.ArrowLeft):
152
+ return (total + index - 1) % total;
153
+ case match.match(event, keys.Home):
154
+ return 0;
155
+ case match.match(event, keys.End):
156
+ return total - 1;
157
+ default:
158
+ return index;
142
159
  }
143
160
  }
161
+
162
+ /**
163
+ * TabList
164
+ */
165
+
144
166
  function TabList(_ref2) {
145
167
  let {
146
168
  activation = 'automatic',
@@ -148,6 +170,7 @@ function TabList(_ref2) {
148
170
  children,
149
171
  className: customClassName,
150
172
  contained = false,
173
+ fullWidth = false,
151
174
  iconSize,
152
175
  leftOverflowButtonProps,
153
176
  light,
@@ -168,7 +191,23 @@ function TabList(_ref2) {
168
191
  const previousButton = React.useRef(null);
169
192
  const nextButton = React.useRef(null);
170
193
  const [isScrollable, setIsScrollable] = React.useState(false);
171
- const [scrollLeft, setScrollLeft] = React.useState(null);
194
+ const [scrollLeft, setScrollLeft] = React.useState(0);
195
+ let hasSecondaryLabelTabs = false;
196
+ if (contained) {
197
+ hasSecondaryLabelTabs = React__default["default"].Children.toArray(children).some(child => {
198
+ return reactIs.isElement(child) && !!child.props.secondaryLabel;
199
+ });
200
+ }
201
+ const isLg = useMatchMedia.useMatchMedia(lgMediaQuery);
202
+ const distributeWidth = fullWidth && contained && isLg && React__default["default"].Children.toArray(children).length < 9;
203
+ const className = cx__default["default"](`${prefix}--tabs`, {
204
+ [`${prefix}--tabs--contained`]: contained,
205
+ [`${prefix}--tabs--light`]: light,
206
+ [`${prefix}--tabs__icon--default`]: iconSize === 'default',
207
+ [`${prefix}--tabs__icon--lg`]: iconSize === 'lg',
208
+ [`${prefix}--tabs--tall`]: hasSecondaryLabelTabs,
209
+ [`${prefix}--tabs--full-width`]: distributeWidth
210
+ }, customClassName);
172
211
 
173
212
  // Previous Button
174
213
  // VISIBLE IF:
@@ -180,14 +219,6 @@ function TabList(_ref2) {
180
219
  // SCROLLABLE
181
220
  // AND SCROLL_LEFT + CLIENT_WIDTH < SCROLL_WIDTH
182
221
  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
222
  const isPreviousButtonVisible = ref.current ? isScrollable && scrollLeft > 0 : false;
192
223
  const previousButtonClasses = cx__default["default"](`${prefix}--tab--overflow-nav-button`, `${prefix}--tab--overflow-nav-button--previous`, {
193
224
  [`${prefix}--tab--overflow-nav-button--hidden`]: !isPreviousButtonVisible
@@ -204,9 +235,7 @@ function TabList(_ref2) {
204
235
  function onKeyDown(event) {
205
236
  if (match.matches(event, [keys.ArrowRight, keys.ArrowLeft, keys.Home, keys.End])) {
206
237
  event.preventDefault();
207
- const activeTabs = tabs.current.filter(tab => {
208
- return !tab.disabled;
209
- });
238
+ const activeTabs = tabs.current.filter(tab => !tab.disabled);
210
239
  const currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
211
240
  const nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
212
241
  if (activation === 'automatic') {
@@ -214,7 +243,7 @@ function TabList(_ref2) {
214
243
  } else if (activation === 'manual') {
215
244
  setActiveIndex(nextIndex);
216
245
  }
217
- tabs.current[nextIndex].focus();
246
+ tabs.current[nextIndex]?.focus();
218
247
  }
219
248
  }
220
249
  useEffectOnce.useEffectOnce(() => {
@@ -264,12 +293,12 @@ function TabList(_ref2) {
264
293
 
265
294
  // updates scroll location for all scroll behavior.
266
295
  useIsomorphicEffect["default"](() => {
267
- if (scrollLeft !== null) {
296
+ if (scrollLeft !== null && ref.current) {
268
297
  ref.current.scrollLeft = scrollLeft;
269
298
  }
270
299
  }, [scrollLeft]);
271
300
  useIsomorphicEffect["default"](() => {
272
- if (!isScrollable) {
301
+ if (!isScrollable || !ref.current) {
273
302
  return;
274
303
  }
275
304
  const tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
@@ -303,7 +332,7 @@ function TabList(_ref2) {
303
332
  let {
304
333
  longPress
305
334
  } = _ref3;
306
- if (!longPress) {
335
+ if (!longPress && ref.current) {
307
336
  setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
308
337
  }
309
338
  },
@@ -316,7 +345,7 @@ function TabList(_ref2) {
316
345
  let {
317
346
  longPress
318
347
  } = _ref4;
319
- if (!longPress) {
348
+ if (!longPress && ref.current) {
320
349
  setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
321
350
  }
322
351
  },
@@ -328,7 +357,7 @@ function TabList(_ref2) {
328
357
  className: className
329
358
  }, /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({
330
359
  "aria-hidden": "true",
331
- tabIndex: "-1",
360
+ tabIndex: -1,
332
361
  "aria-label": "Scroll left",
333
362
  ref: previousButton,
334
363
  className: previousButtonClasses,
@@ -341,7 +370,7 @@ function TabList(_ref2) {
341
370
  onScroll: debouncedOnScroll,
342
371
  onKeyDown: onKeyDown
343
372
  }), React__default["default"].Children.map(children, (child, index) => {
344
- return /*#__PURE__*/React__default["default"].createElement(TabContext.Provider, {
373
+ return !reactIs.isElement(child) ? null : /*#__PURE__*/React__default["default"].createElement(TabContext.Provider, {
345
374
  value: {
346
375
  index,
347
376
  hasSecondaryLabel: hasSecondaryLabelTabs,
@@ -354,7 +383,7 @@ function TabList(_ref2) {
354
383
  }));
355
384
  })), /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({
356
385
  "aria-hidden": "true",
357
- tabIndex: "-1",
386
+ tabIndex: -1,
358
387
  "aria-label": "Scroll right",
359
388
  ref: nextButton,
360
389
  className: nextButtonClasses,
@@ -373,7 +402,7 @@ TabList.propTypes = {
373
402
  */
374
403
  'aria-label': PropTypes__default["default"].string.isRequired,
375
404
  /**
376
- * Provide child elements to be rendered inside of `ContentTabs`.
405
+ * Provide child elements to be rendered inside `ContentTabs`.
377
406
  * These elements should render a `ContentTab`
378
407
  */
379
408
  children: PropTypes__default["default"].node,
@@ -385,6 +414,10 @@ TabList.propTypes = {
385
414
  * Specify whether component is contained type
386
415
  */
387
416
  contained: PropTypes__default["default"].bool,
417
+ /**
418
+ * Used for tabs within a grid, this makes it so tabs span the full container width and have the same width. Only available on contained tabs with <9 children
419
+ */
420
+ fullWidth: PropTypes__default["default"].bool,
388
421
  /**
389
422
  * If using `IconTab`, specify the size of the icon being used.
390
423
  */
@@ -394,7 +427,7 @@ TabList.propTypes = {
394
427
  */
395
428
  leftOverflowButtonProps: PropTypes__default["default"].object,
396
429
  /**
397
- * Specify whether or not to use the light component variant
430
+ * Specify whether to use the light component variant
398
431
  */
399
432
  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
433
  /**
@@ -408,53 +441,60 @@ TabList.propTypes = {
408
441
  */
409
442
  scrollDebounceWait: PropTypes__default["default"].number,
410
443
  /**
411
- * Choose whether or not to automatically scroll to newly selected tabs
412
- * on component rerender
444
+ * Choose whether to automatically scroll
445
+ * to newly selected tabs on component rerender
413
446
  */
414
447
  scrollIntoView: PropTypes__default["default"].bool
415
448
  };
416
449
 
417
450
  /**
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
451
+ * Helper function to set up the behavior when a button is "long pressed".
452
+ * This function will take a ref to the tablist, a direction, and a setter
453
+ * for scrollLeft and will update the scroll position within a requestAnimationFrame.
425
454
  *
426
- * @param {RefObject} ref
427
- * @param {'forward' | 'backward'} direction
428
- * @param {Function} setScrollLeft
429
- * @returns {Function}
455
+ * It returns a cleanup function to be run
456
+ * when the long press is deactivated
430
457
  */
431
458
  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';
459
+ const node = ref.current;
460
+ if (!node) {
461
+ return () => {};
462
+ }
463
+
464
+ // We manually override the scroll behavior to be "auto".
465
+ // If it is set as smooth, this animation does not update correctly
466
+ const defaultScrollBehavior = node?.style['scroll-behavior'];
467
+ node.style['scroll-behavior'] = 'auto';
436
468
  const scrollDelta = direction === 'forward' ? 5 : -5;
437
469
  let frameId = null;
438
470
  function tick() {
439
- ref.current.scrollLeft = ref.current.scrollLeft + scrollDelta;
471
+ if (!node) {
472
+ return;
473
+ }
474
+ node.scrollLeft = node.scrollLeft + scrollDelta;
440
475
  frameId = requestAnimationFrame(tick);
441
476
  }
442
477
  frameId = requestAnimationFrame(tick);
443
478
  return () => {
444
479
  // Restore the previous scroll behavior
445
- ref.current.style['scroll-behavior'] = defaultScrollBehavior;
480
+ node.style['scroll-behavior'] = defaultScrollBehavior;
446
481
 
447
482
  // Make sure that our `scrollLeft` value is in sync with the existing
448
483
  // `ref` after our requestAnimationFrame loop above
449
- setScrollLeft(ref.current.scrollLeft);
484
+ setScrollLeft(node.scrollLeft);
450
485
  if (frameId) {
451
486
  cancelAnimationFrame(frameId);
452
487
  }
453
488
  };
454
489
  }
455
- const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5, forwardRef) {
490
+
491
+ /**
492
+ * Tab
493
+ */
494
+
495
+ const Tab = /*#__PURE__*/React.forwardRef(function Tab(_ref5, forwardRef) {
456
496
  let {
457
- as: BaseComponent = 'button',
497
+ as = 'button',
458
498
  children,
459
499
  className: customClassName,
460
500
  disabled,
@@ -483,20 +523,21 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
483
523
  const [ignoreHover, setIgnoreHover] = React.useState(false);
484
524
  const id = `${baseId}-tab-${index}`;
485
525
  const panelId = `${baseId}-tabpanel-${index}`;
486
- const className = cx__default["default"](`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, customClassName, {
526
+ const className = cx__default["default"](`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, {
487
527
  [`${prefix}--tabs__nav-item--selected`]: selectedIndex === index,
488
528
  [`${prefix}--tabs__nav-item--disabled`]: disabled,
489
529
  [`${prefix}--tabs__nav-item--hover-off`]: ignoreHover
490
- });
530
+ }, customClassName);
531
+ const BaseComponent = as;
491
532
  const onDismissIconMouseEnter = evt => {
492
- if (contained) {
533
+ if (contained && tabRef.current) {
493
534
  evt.stopPropagation();
494
535
  setIgnoreHover(true);
495
536
  tabRef.current.classList.add(`${prefix}--tabs__nav-item--hover-off`);
496
537
  }
497
538
  };
498
539
  const onDismissIconMouseLeave = () => {
499
- if (contained) {
540
+ if (contained && tabRef.current) {
500
541
  tabRef.current.classList.remove(`${prefix}--tabs__nav-item--hover-off`);
501
542
  setIgnoreHover(false);
502
543
  }
@@ -528,7 +569,7 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
528
569
  title: "Close tab",
529
570
  ref: dismissIconRef
530
571
  }, _Close || (_Close = /*#__PURE__*/React__default["default"].createElement(iconsReact.Close, null)));
531
- const hasIcon = Icon || dismissable;
572
+ const hasIcon = Icon ?? dismissable;
532
573
  return /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({}, rest, {
533
574
  "aria-controls": panelId,
534
575
  "aria-disabled": disabled,
@@ -543,9 +584,7 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
543
584
  return;
544
585
  }
545
586
  setSelectedIndex(index);
546
- if (onClick) {
547
- onClick(evt);
548
- }
587
+ onClick?.(evt);
549
588
  },
550
589
  onKeyDown: handleKeyDown,
551
590
  tabIndex: selectedIndex === index ? '0' : '-1',
@@ -557,24 +596,27 @@ const Tab = /*#__PURE__*/React__default["default"].forwardRef(function Tab(_ref5
557
596
  }, /*#__PURE__*/React__default["default"].createElement(Icon, {
558
597
  size: 16
559
598
  })), /*#__PURE__*/React__default["default"].createElement("span", {
560
- className: `${prefix}--tabs__nav-item-label`
599
+ className: `${prefix}--tabs__nav-item-label`,
600
+ title: children
561
601
  }, children), /*#__PURE__*/React__default["default"].createElement("div", {
562
602
  className: cx__default["default"](`${prefix}--tabs__nav-item--icon`, {
563
603
  [`${prefix}--visually-hidden`]: !hasIcon
564
604
  })
565
- }, DismissIcon, !dismissable && hasIcon && /*#__PURE__*/React__default["default"].createElement(Icon, {
605
+ }, DismissIcon, !dismissable && Icon && /*#__PURE__*/React__default["default"].createElement(Icon, {
566
606
  size: 16
567
607
  }))), hasSecondaryLabel && /*#__PURE__*/React__default["default"].createElement("div", {
568
- className: `${prefix}--tabs__nav-item-secondary-label`
608
+ className: `${prefix}--tabs__nav-item-secondary-label`,
609
+ title: secondaryLabel
569
610
  }, secondaryLabel));
570
611
  });
571
612
  Tab.propTypes = {
572
613
  /**
573
614
  * Provide a custom element to render instead of the default button
574
615
  */
616
+ // @ts-expect-error: Invalid prop type derivation
575
617
  as: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].elementType]),
576
618
  /**
577
- * Provide child elements to be rendered inside of `Tab`.
619
+ * Provide child elements to be rendered inside `Tab`.
578
620
  */
579
621
  children: PropTypes__default["default"].node,
580
622
  /**
@@ -603,6 +645,7 @@ Tab.propTypes = {
603
645
  * Optional prop to render an icon next to the label.
604
646
  * Can be a React component class
605
647
  */
648
+ // @ts-expect-error: Invalid prop type derivation
606
649
  renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
607
650
  /*
608
651
  * An optional label to render under the primary tab label.
@@ -610,6 +653,11 @@ Tab.propTypes = {
610
653
  **/
611
654
  secondaryLabel: PropTypes__default["default"].string
612
655
  };
656
+
657
+ /**
658
+ * IconTab
659
+ */
660
+
613
661
  const IconTab = /*#__PURE__*/React__default["default"].forwardRef(function IconTab(_ref6, ref) {
614
662
  let {
615
663
  children,
@@ -636,7 +684,7 @@ const IconTab = /*#__PURE__*/React__default["default"].forwardRef(function IconT
636
684
  });
637
685
  IconTab.propTypes = {
638
686
  /**
639
- * Provide an icon to be rendered inside of `IconTab` as the visual label for Tab.
687
+ * Provide an icon to be rendered inside `IconTab` as the visual label for Tab.
640
688
  */
641
689
  children: PropTypes__default["default"].node,
642
690
  /**
@@ -652,7 +700,7 @@ IconTab.propTypes = {
652
700
  */
653
701
  enterDelayMs: PropTypes__default["default"].number,
654
702
  /**
655
- * Provide the label to be rendered inside of the Tooltip. The label will use
703
+ * Provide the label to be rendered inside the Tooltip. The label will use
656
704
  * `aria-labelledby` and will fully describe the child node that is provided.
657
705
  * This means that if you have text in the child node it will not be
658
706
  * announced to the screen reader.
@@ -663,6 +711,11 @@ IconTab.propTypes = {
663
711
  */
664
712
  leaveDelayMs: PropTypes__default["default"].number
665
713
  };
714
+
715
+ /**
716
+ * TabPanel
717
+ */
718
+
666
719
  const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabPanel(_ref7, forwardRef) {
667
720
  let {
668
721
  children,
@@ -672,7 +725,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
672
725
  const prefix = usePrefix.usePrefix();
673
726
  const panel = React.useRef(null);
674
727
  const ref = useMergedRefs.useMergedRefs([forwardRef, panel]);
675
- const [tabIndex, setTabIndex] = React.useState('0');
728
+ const [tabIndex, setTabIndex] = React.useState(0);
676
729
  const [interactiveContent, setInteractiveContent] = React.useState(false);
677
730
  const {
678
731
  selectedIndex,
@@ -691,26 +744,24 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
691
744
  const content = useNoInteractiveChildren.getInteractiveContent(panel.current);
692
745
  if (content) {
693
746
  setInteractiveContent(true);
694
- setTabIndex('-1');
747
+ setTabIndex(-1);
695
748
  }
696
749
  });
697
750
 
698
751
  // tabindex should only be 0 if no interactive content in children
699
752
  React.useEffect(() => {
700
- if (!panel.current) {
753
+ const node = panel.current;
754
+ if (!node) {
701
755
  return;
702
756
  }
703
- const {
704
- current: node
705
- } = panel;
706
757
  function callback() {
707
758
  const content = useNoInteractiveChildren.getInteractiveContent(node);
708
759
  if (content) {
709
760
  setInteractiveContent(true);
710
- setTabIndex('-1');
761
+ setTabIndex(-1);
711
762
  } else {
712
763
  setInteractiveContent(false);
713
- setTabIndex('0');
764
+ setTabIndex(0);
714
765
  }
715
766
  }
716
767
  const observer = new MutationObserver(callback);
@@ -718,9 +769,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
718
769
  childList: true,
719
770
  subtree: true
720
771
  });
721
- return () => {
722
- observer.disconnect(node);
723
- };
772
+ return () => observer.disconnect();
724
773
  }, []);
725
774
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
726
775
  "aria-labelledby": tabId,
@@ -734,7 +783,7 @@ const TabPanel = /*#__PURE__*/React__default["default"].forwardRef(function TabP
734
783
  });
735
784
  TabPanel.propTypes = {
736
785
  /**
737
- * Provide child elements to be rendered inside of `TabPanel`.
786
+ * Provide child elements to be rendered inside `TabPanel`.
738
787
  */
739
788
  children: PropTypes__default["default"].node,
740
789
  /**
@@ -742,6 +791,11 @@ TabPanel.propTypes = {
742
791
  */
743
792
  className: PropTypes__default["default"].string
744
793
  };
794
+
795
+ /**
796
+ * TabPanels
797
+ */
798
+
745
799
  function TabPanels(_ref8) {
746
800
  let {
747
801
  children
@@ -754,7 +808,7 @@ function TabPanels(_ref8) {
754
808
  }
755
809
  TabPanels.propTypes = {
756
810
  /**
757
- * Provide child elements to be rendered inside of `TabPanels`.
811
+ * Provide child elements to be rendered inside `TabPanels`.
758
812
  */
759
813
  children: PropTypes__default["default"].node
760
814
  };
@@ -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;