@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
@@ -7,10 +7,12 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import { ChevronLeft, ChevronRight, Close } from '@carbon/icons-react';
10
+ import { breakpoints } from '@carbon/layout';
10
11
  import cx from 'classnames';
11
12
  import debounce from 'lodash.debounce';
12
13
  import PropTypes from 'prop-types';
13
- import React__default, { useState, useRef, useCallback, useEffect } from 'react';
14
+ import React__default, { useState, useRef, useCallback, useEffect, forwardRef } from 'react';
15
+ import { isElement } from 'react-is';
14
16
  import '../Tooltip/DefinitionTooltip.js';
15
17
  import { Tooltip } from '../Tooltip/Tooltip.js';
16
18
  import { useControllableState } from '../../internal/useControllableState.js';
@@ -23,19 +25,39 @@ import { usePrefix } from '../../internal/usePrefix.js';
23
25
  import { usePressable } from './usePressable.js';
24
26
  import deprecate from '../../prop-types/deprecate.js';
25
27
  import { useEvent } from '../../internal/useEvent.js';
28
+ import { useMatchMedia } from '../../internal/useMatchMedia.js';
26
29
  import { matches, match } from '../../internal/keyboard/match.js';
27
30
  import { ArrowRight, ArrowLeft, Home, End, Delete } from '../../internal/keyboard/keys.js';
28
31
 
29
32
  var _ChevronLeft, _ChevronRight, _Close;
30
33
 
31
34
  // Used to manage the overall state of the Tabs
32
- const TabsContext = /*#__PURE__*/React__default.createContext();
35
+
36
+ const TabsContext = /*#__PURE__*/React__default.createContext({
37
+ baseId: '',
38
+ activeIndex: 0,
39
+ defaultSelectedIndex: 0,
40
+ dismissable: false,
41
+ onTabCloseRequest() {},
42
+ setActiveIndex() {},
43
+ selectedIndex: 0,
44
+ setSelectedIndex() {}
45
+ });
33
46
 
34
47
  // Used to keep track of position in a tablist
35
- const TabContext = /*#__PURE__*/React__default.createContext();
48
+ const TabContext = /*#__PURE__*/React__default.createContext({
49
+ index: 0,
50
+ hasSecondaryLabel: false
51
+ });
52
+ const lgMediaQuery = `(min-width: ${breakpoints.lg.width})`;
36
53
 
37
54
  // Used to keep track of position in a list of tab panels
38
- const TabPanelContext = /*#__PURE__*/React__default.createContext();
55
+ const TabPanelContext = /*#__PURE__*/React__default.createContext(0);
56
+
57
+ /**
58
+ * Tabs
59
+ */
60
+
39
61
  function Tabs(_ref) {
40
62
  let {
41
63
  children,
@@ -52,13 +74,9 @@ function Tabs(_ref) {
52
74
  const [selectedIndex, setSelectedIndex] = useControllableState({
53
75
  value: controlledSelectedIndex,
54
76
  defaultValue: defaultSelectedIndex,
55
- onChange: value => {
56
- if (onChange) {
57
- onChange({
58
- selectedIndex: value
59
- });
60
- }
61
- }
77
+ onChange: value => onChange?.({
78
+ selectedIndex: value
79
+ })
62
80
  });
63
81
  const value = {
64
82
  baseId,
@@ -76,7 +94,7 @@ function Tabs(_ref) {
76
94
  }
77
95
  Tabs.propTypes = {
78
96
  /**
79
- * Provide child elements to be rendered inside of the `Tabs`.
97
+ * Provide child elements to be rendered inside the `Tabs`.
80
98
  * These elements should render either `TabsList` or `TabsPanels`
81
99
  */
82
100
  children: PropTypes.node,
@@ -112,24 +130,28 @@ Tabs.propTypes = {
112
130
  };
113
131
 
114
132
  /**
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}
133
+ * Get the next index for a given keyboard event
134
+ * given a count of the total items and the current index
121
135
  */
122
136
  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;
137
+ switch (true) {
138
+ case match(event, ArrowRight):
139
+ return (index + 1) % total;
140
+ case match(event, ArrowLeft):
141
+ return (total + index - 1) % total;
142
+ case match(event, Home):
143
+ return 0;
144
+ case match(event, End):
145
+ return total - 1;
146
+ default:
147
+ return index;
131
148
  }
132
149
  }
150
+
151
+ /**
152
+ * TabList
153
+ */
154
+
133
155
  function TabList(_ref2) {
134
156
  let {
135
157
  activation = 'automatic',
@@ -137,6 +159,7 @@ function TabList(_ref2) {
137
159
  children,
138
160
  className: customClassName,
139
161
  contained = false,
162
+ fullWidth = false,
140
163
  iconSize,
141
164
  leftOverflowButtonProps,
142
165
  light,
@@ -157,7 +180,23 @@ function TabList(_ref2) {
157
180
  const previousButton = useRef(null);
158
181
  const nextButton = useRef(null);
159
182
  const [isScrollable, setIsScrollable] = useState(false);
160
- const [scrollLeft, setScrollLeft] = useState(null);
183
+ const [scrollLeft, setScrollLeft] = useState(0);
184
+ let hasSecondaryLabelTabs = false;
185
+ if (contained) {
186
+ hasSecondaryLabelTabs = React__default.Children.toArray(children).some(child => {
187
+ return isElement(child) && !!child.props.secondaryLabel;
188
+ });
189
+ }
190
+ const isLg = useMatchMedia(lgMediaQuery);
191
+ const distributeWidth = fullWidth && contained && isLg && React__default.Children.toArray(children).length < 9;
192
+ const className = cx(`${prefix}--tabs`, {
193
+ [`${prefix}--tabs--contained`]: contained,
194
+ [`${prefix}--tabs--light`]: light,
195
+ [`${prefix}--tabs__icon--default`]: iconSize === 'default',
196
+ [`${prefix}--tabs__icon--lg`]: iconSize === 'lg',
197
+ [`${prefix}--tabs--tall`]: hasSecondaryLabelTabs,
198
+ [`${prefix}--tabs--full-width`]: distributeWidth
199
+ }, customClassName);
161
200
 
162
201
  // Previous Button
163
202
  // VISIBLE IF:
@@ -169,14 +208,6 @@ function TabList(_ref2) {
169
208
  // SCROLLABLE
170
209
  // AND SCROLL_LEFT + CLIENT_WIDTH < SCROLL_WIDTH
171
210
  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
211
  const isPreviousButtonVisible = ref.current ? isScrollable && scrollLeft > 0 : false;
181
212
  const previousButtonClasses = cx(`${prefix}--tab--overflow-nav-button`, `${prefix}--tab--overflow-nav-button--previous`, {
182
213
  [`${prefix}--tab--overflow-nav-button--hidden`]: !isPreviousButtonVisible
@@ -193,9 +224,7 @@ function TabList(_ref2) {
193
224
  function onKeyDown(event) {
194
225
  if (matches(event, [ArrowRight, ArrowLeft, Home, End])) {
195
226
  event.preventDefault();
196
- const activeTabs = tabs.current.filter(tab => {
197
- return !tab.disabled;
198
- });
227
+ const activeTabs = tabs.current.filter(tab => !tab.disabled);
199
228
  const currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
200
229
  const nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
201
230
  if (activation === 'automatic') {
@@ -203,7 +232,7 @@ function TabList(_ref2) {
203
232
  } else if (activation === 'manual') {
204
233
  setActiveIndex(nextIndex);
205
234
  }
206
- tabs.current[nextIndex].focus();
235
+ tabs.current[nextIndex]?.focus();
207
236
  }
208
237
  }
209
238
  useEffectOnce(() => {
@@ -253,12 +282,12 @@ function TabList(_ref2) {
253
282
 
254
283
  // updates scroll location for all scroll behavior.
255
284
  useIsomorphicEffect(() => {
256
- if (scrollLeft !== null) {
285
+ if (scrollLeft !== null && ref.current) {
257
286
  ref.current.scrollLeft = scrollLeft;
258
287
  }
259
288
  }, [scrollLeft]);
260
289
  useIsomorphicEffect(() => {
261
- if (!isScrollable) {
290
+ if (!isScrollable || !ref.current) {
262
291
  return;
263
292
  }
264
293
  const tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
@@ -292,7 +321,7 @@ function TabList(_ref2) {
292
321
  let {
293
322
  longPress
294
323
  } = _ref3;
295
- if (!longPress) {
324
+ if (!longPress && ref.current) {
296
325
  setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
297
326
  }
298
327
  },
@@ -305,7 +334,7 @@ function TabList(_ref2) {
305
334
  let {
306
335
  longPress
307
336
  } = _ref4;
308
- if (!longPress) {
337
+ if (!longPress && ref.current) {
309
338
  setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
310
339
  }
311
340
  },
@@ -317,7 +346,7 @@ function TabList(_ref2) {
317
346
  className: className
318
347
  }, /*#__PURE__*/React__default.createElement("button", _extends({
319
348
  "aria-hidden": "true",
320
- tabIndex: "-1",
349
+ tabIndex: -1,
321
350
  "aria-label": "Scroll left",
322
351
  ref: previousButton,
323
352
  className: previousButtonClasses,
@@ -330,7 +359,7 @@ function TabList(_ref2) {
330
359
  onScroll: debouncedOnScroll,
331
360
  onKeyDown: onKeyDown
332
361
  }), React__default.Children.map(children, (child, index) => {
333
- return /*#__PURE__*/React__default.createElement(TabContext.Provider, {
362
+ return !isElement(child) ? null : /*#__PURE__*/React__default.createElement(TabContext.Provider, {
334
363
  value: {
335
364
  index,
336
365
  hasSecondaryLabel: hasSecondaryLabelTabs,
@@ -343,7 +372,7 @@ function TabList(_ref2) {
343
372
  }));
344
373
  })), /*#__PURE__*/React__default.createElement("button", _extends({
345
374
  "aria-hidden": "true",
346
- tabIndex: "-1",
375
+ tabIndex: -1,
347
376
  "aria-label": "Scroll right",
348
377
  ref: nextButton,
349
378
  className: nextButtonClasses,
@@ -362,7 +391,7 @@ TabList.propTypes = {
362
391
  */
363
392
  'aria-label': PropTypes.string.isRequired,
364
393
  /**
365
- * Provide child elements to be rendered inside of `ContentTabs`.
394
+ * Provide child elements to be rendered inside `ContentTabs`.
366
395
  * These elements should render a `ContentTab`
367
396
  */
368
397
  children: PropTypes.node,
@@ -374,6 +403,10 @@ TabList.propTypes = {
374
403
  * Specify whether component is contained type
375
404
  */
376
405
  contained: PropTypes.bool,
406
+ /**
407
+ * 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
408
+ */
409
+ fullWidth: PropTypes.bool,
377
410
  /**
378
411
  * If using `IconTab`, specify the size of the icon being used.
379
412
  */
@@ -383,7 +416,7 @@ TabList.propTypes = {
383
416
  */
384
417
  leftOverflowButtonProps: PropTypes.object,
385
418
  /**
386
- * Specify whether or not to use the light component variant
419
+ * Specify whether to use the light component variant
387
420
  */
388
421
  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
422
  /**
@@ -397,53 +430,60 @@ TabList.propTypes = {
397
430
  */
398
431
  scrollDebounceWait: PropTypes.number,
399
432
  /**
400
- * Choose whether or not to automatically scroll to newly selected tabs
401
- * on component rerender
433
+ * Choose whether to automatically scroll
434
+ * to newly selected tabs on component rerender
402
435
  */
403
436
  scrollIntoView: PropTypes.bool
404
437
  };
405
438
 
406
439
  /**
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
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.
414
443
  *
415
- * @param {RefObject} ref
416
- * @param {'forward' | 'backward'} direction
417
- * @param {Function} setScrollLeft
418
- * @returns {Function}
444
+ * It returns a cleanup function to be run
445
+ * when the long press is deactivated
419
446
  */
420
447
  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';
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';
425
457
  const scrollDelta = direction === 'forward' ? 5 : -5;
426
458
  let frameId = null;
427
459
  function tick() {
428
- ref.current.scrollLeft = ref.current.scrollLeft + scrollDelta;
460
+ if (!node) {
461
+ return;
462
+ }
463
+ node.scrollLeft = node.scrollLeft + scrollDelta;
429
464
  frameId = requestAnimationFrame(tick);
430
465
  }
431
466
  frameId = requestAnimationFrame(tick);
432
467
  return () => {
433
468
  // Restore the previous scroll behavior
434
- ref.current.style['scroll-behavior'] = defaultScrollBehavior;
469
+ node.style['scroll-behavior'] = defaultScrollBehavior;
435
470
 
436
471
  // Make sure that our `scrollLeft` value is in sync with the existing
437
472
  // `ref` after our requestAnimationFrame loop above
438
- setScrollLeft(ref.current.scrollLeft);
473
+ setScrollLeft(node.scrollLeft);
439
474
  if (frameId) {
440
475
  cancelAnimationFrame(frameId);
441
476
  }
442
477
  };
443
478
  }
444
- const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRef) {
479
+
480
+ /**
481
+ * Tab
482
+ */
483
+
484
+ const Tab = /*#__PURE__*/forwardRef(function Tab(_ref5, forwardRef) {
445
485
  let {
446
- as: BaseComponent = 'button',
486
+ as = 'button',
447
487
  children,
448
488
  className: customClassName,
449
489
  disabled,
@@ -472,20 +512,21 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
472
512
  const [ignoreHover, setIgnoreHover] = useState(false);
473
513
  const id = `${baseId}-tab-${index}`;
474
514
  const panelId = `${baseId}-tabpanel-${index}`;
475
- const className = cx(`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, customClassName, {
515
+ const className = cx(`${prefix}--tabs__nav-item`, `${prefix}--tabs__nav-link`, {
476
516
  [`${prefix}--tabs__nav-item--selected`]: selectedIndex === index,
477
517
  [`${prefix}--tabs__nav-item--disabled`]: disabled,
478
518
  [`${prefix}--tabs__nav-item--hover-off`]: ignoreHover
479
- });
519
+ }, customClassName);
520
+ const BaseComponent = as;
480
521
  const onDismissIconMouseEnter = evt => {
481
- if (contained) {
522
+ if (contained && tabRef.current) {
482
523
  evt.stopPropagation();
483
524
  setIgnoreHover(true);
484
525
  tabRef.current.classList.add(`${prefix}--tabs__nav-item--hover-off`);
485
526
  }
486
527
  };
487
528
  const onDismissIconMouseLeave = () => {
488
- if (contained) {
529
+ if (contained && tabRef.current) {
489
530
  tabRef.current.classList.remove(`${prefix}--tabs__nav-item--hover-off`);
490
531
  setIgnoreHover(false);
491
532
  }
@@ -517,7 +558,7 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
517
558
  title: "Close tab",
518
559
  ref: dismissIconRef
519
560
  }, _Close || (_Close = /*#__PURE__*/React__default.createElement(Close, null)));
520
- const hasIcon = Icon || dismissable;
561
+ const hasIcon = Icon ?? dismissable;
521
562
  return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
522
563
  "aria-controls": panelId,
523
564
  "aria-disabled": disabled,
@@ -532,9 +573,7 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
532
573
  return;
533
574
  }
534
575
  setSelectedIndex(index);
535
- if (onClick) {
536
- onClick(evt);
537
- }
576
+ onClick?.(evt);
538
577
  },
539
578
  onKeyDown: handleKeyDown,
540
579
  tabIndex: selectedIndex === index ? '0' : '-1',
@@ -546,24 +585,27 @@ const Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, forwardRe
546
585
  }, /*#__PURE__*/React__default.createElement(Icon, {
547
586
  size: 16
548
587
  })), /*#__PURE__*/React__default.createElement("span", {
549
- className: `${prefix}--tabs__nav-item-label`
588
+ className: `${prefix}--tabs__nav-item-label`,
589
+ title: children
550
590
  }, children), /*#__PURE__*/React__default.createElement("div", {
551
591
  className: cx(`${prefix}--tabs__nav-item--icon`, {
552
592
  [`${prefix}--visually-hidden`]: !hasIcon
553
593
  })
554
- }, DismissIcon, !dismissable && hasIcon && /*#__PURE__*/React__default.createElement(Icon, {
594
+ }, DismissIcon, !dismissable && Icon && /*#__PURE__*/React__default.createElement(Icon, {
555
595
  size: 16
556
596
  }))), hasSecondaryLabel && /*#__PURE__*/React__default.createElement("div", {
557
- className: `${prefix}--tabs__nav-item-secondary-label`
597
+ className: `${prefix}--tabs__nav-item-secondary-label`,
598
+ title: secondaryLabel
558
599
  }, secondaryLabel));
559
600
  });
560
601
  Tab.propTypes = {
561
602
  /**
562
603
  * Provide a custom element to render instead of the default button
563
604
  */
605
+ // @ts-expect-error: Invalid prop type derivation
564
606
  as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
565
607
  /**
566
- * Provide child elements to be rendered inside of `Tab`.
608
+ * Provide child elements to be rendered inside `Tab`.
567
609
  */
568
610
  children: PropTypes.node,
569
611
  /**
@@ -592,6 +634,7 @@ Tab.propTypes = {
592
634
  * Optional prop to render an icon next to the label.
593
635
  * Can be a React component class
594
636
  */
637
+ // @ts-expect-error: Invalid prop type derivation
595
638
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
596
639
  /*
597
640
  * An optional label to render under the primary tab label.
@@ -599,6 +642,11 @@ Tab.propTypes = {
599
642
  **/
600
643
  secondaryLabel: PropTypes.string
601
644
  };
645
+
646
+ /**
647
+ * IconTab
648
+ */
649
+
602
650
  const IconTab = /*#__PURE__*/React__default.forwardRef(function IconTab(_ref6, ref) {
603
651
  let {
604
652
  children,
@@ -625,7 +673,7 @@ const IconTab = /*#__PURE__*/React__default.forwardRef(function IconTab(_ref6, r
625
673
  });
626
674
  IconTab.propTypes = {
627
675
  /**
628
- * Provide an icon to be rendered inside of `IconTab` as the visual label for Tab.
676
+ * Provide an icon to be rendered inside `IconTab` as the visual label for Tab.
629
677
  */
630
678
  children: PropTypes.node,
631
679
  /**
@@ -641,7 +689,7 @@ IconTab.propTypes = {
641
689
  */
642
690
  enterDelayMs: PropTypes.number,
643
691
  /**
644
- * Provide the label to be rendered inside of the Tooltip. The label will use
692
+ * Provide the label to be rendered inside the Tooltip. The label will use
645
693
  * `aria-labelledby` and will fully describe the child node that is provided.
646
694
  * This means that if you have text in the child node it will not be
647
695
  * announced to the screen reader.
@@ -652,6 +700,11 @@ IconTab.propTypes = {
652
700
  */
653
701
  leaveDelayMs: PropTypes.number
654
702
  };
703
+
704
+ /**
705
+ * TabPanel
706
+ */
707
+
655
708
  const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7, forwardRef) {
656
709
  let {
657
710
  children,
@@ -661,7 +714,7 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
661
714
  const prefix = usePrefix();
662
715
  const panel = useRef(null);
663
716
  const ref = useMergedRefs([forwardRef, panel]);
664
- const [tabIndex, setTabIndex] = useState('0');
717
+ const [tabIndex, setTabIndex] = useState(0);
665
718
  const [interactiveContent, setInteractiveContent] = useState(false);
666
719
  const {
667
720
  selectedIndex,
@@ -680,26 +733,24 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
680
733
  const content = getInteractiveContent(panel.current);
681
734
  if (content) {
682
735
  setInteractiveContent(true);
683
- setTabIndex('-1');
736
+ setTabIndex(-1);
684
737
  }
685
738
  });
686
739
 
687
740
  // tabindex should only be 0 if no interactive content in children
688
741
  useEffect(() => {
689
- if (!panel.current) {
742
+ const node = panel.current;
743
+ if (!node) {
690
744
  return;
691
745
  }
692
- const {
693
- current: node
694
- } = panel;
695
746
  function callback() {
696
747
  const content = getInteractiveContent(node);
697
748
  if (content) {
698
749
  setInteractiveContent(true);
699
- setTabIndex('-1');
750
+ setTabIndex(-1);
700
751
  } else {
701
752
  setInteractiveContent(false);
702
- setTabIndex('0');
753
+ setTabIndex(0);
703
754
  }
704
755
  }
705
756
  const observer = new MutationObserver(callback);
@@ -707,9 +758,7 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
707
758
  childList: true,
708
759
  subtree: true
709
760
  });
710
- return () => {
711
- observer.disconnect(node);
712
- };
761
+ return () => observer.disconnect();
713
762
  }, []);
714
763
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
715
764
  "aria-labelledby": tabId,
@@ -723,7 +772,7 @@ const TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7,
723
772
  });
724
773
  TabPanel.propTypes = {
725
774
  /**
726
- * Provide child elements to be rendered inside of `TabPanel`.
775
+ * Provide child elements to be rendered inside `TabPanel`.
727
776
  */
728
777
  children: PropTypes.node,
729
778
  /**
@@ -731,6 +780,11 @@ TabPanel.propTypes = {
731
780
  */
732
781
  className: PropTypes.string
733
782
  };
783
+
784
+ /**
785
+ * TabPanels
786
+ */
787
+
734
788
  function TabPanels(_ref8) {
735
789
  let {
736
790
  children
@@ -743,7 +797,7 @@ function TabPanels(_ref8) {
743
797
  }
744
798
  TabPanels.propTypes = {
745
799
  /**
746
- * Provide child elements to be rendered inside of `TabPanels`.
800
+ * Provide child elements to be rendered inside `TabPanels`.
747
801
  */
748
802
  children: PropTypes.node
749
803
  };
@@ -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;