@carbon/react 1.16.0-rc.0 → 1.17.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 (73) hide show
  1. package/es/components/Checkbox/Checkbox.Skeleton.d.ts +18 -0
  2. package/es/components/Checkbox/Checkbox.Skeleton.js +1 -2
  3. package/es/components/Checkbox/Checkbox.d.ts +47 -0
  4. package/es/components/Checkbox/Checkbox.js +6 -7
  5. package/es/components/Checkbox/index.d.ts +10 -0
  6. package/es/components/Checkbox/index.js +10 -0
  7. package/es/components/CodeSnippet/CodeSnippet.js +0 -1
  8. package/es/components/DataTable/TableToolbarSearch.js +1 -1
  9. package/es/components/ExpandableSearch/ExpandableSearch.js +1 -1
  10. package/es/components/Grid/Grid.js +0 -5
  11. package/es/components/NumberInput/NumberInput.js +45 -1
  12. package/es/components/ProgressIndicator/ProgressIndicator.Skeleton.js +10 -4
  13. package/es/components/Search/Search.js +160 -184
  14. package/es/components/Search/index.js +2 -8
  15. package/es/components/Tab/index.js +1 -1
  16. package/es/components/Tabs/Tabs.Skeleton.js +6 -6
  17. package/es/components/Tabs/Tabs.js +582 -508
  18. package/es/components/Tabs/index.js +2 -12
  19. package/es/components/Tabs/{next/usePressable.js → usePressable.js} +1 -1
  20. package/es/components/Text/Text.d.ts +33 -0
  21. package/es/components/Text/Text.js +8 -5
  22. package/es/components/Text/TextDirection.d.ts +35 -0
  23. package/es/components/Text/TextDirectionContext.js +2 -0
  24. package/es/components/Text/createTextComponent.d.ts +18 -0
  25. package/es/components/Text/index.d.ts +18 -0
  26. package/es/components/Text/index.js +2 -0
  27. package/es/components/TextInput/TextInput.js +1 -1
  28. package/es/components/Tile/Tile.js +339 -502
  29. package/es/index.js +6 -6
  30. package/es/internal/useNormalizedInputProps.js +13 -17
  31. package/es/internal/usePrefix.d.ts +9 -0
  32. package/lib/components/Checkbox/Checkbox.Skeleton.d.ts +18 -0
  33. package/lib/components/Checkbox/Checkbox.Skeleton.js +1 -2
  34. package/lib/components/Checkbox/Checkbox.d.ts +47 -0
  35. package/lib/components/Checkbox/Checkbox.js +6 -7
  36. package/lib/components/Checkbox/index.d.ts +10 -0
  37. package/lib/components/Checkbox/index.js +18 -0
  38. package/lib/components/CodeSnippet/CodeSnippet.js +0 -1
  39. package/lib/components/DataTable/TableToolbarSearch.js +2 -2
  40. package/lib/components/ExpandableSearch/ExpandableSearch.js +3 -3
  41. package/lib/components/Grid/Grid.js +0 -5
  42. package/lib/components/NumberInput/NumberInput.js +45 -1
  43. package/lib/components/ProgressIndicator/ProgressIndicator.Skeleton.js +9 -3
  44. package/lib/components/Search/Search.js +159 -183
  45. package/lib/components/Search/index.js +2 -25
  46. package/lib/components/Tab/index.js +1 -1
  47. package/lib/components/Tabs/Tabs.Skeleton.js +6 -6
  48. package/lib/components/Tabs/Tabs.js +586 -507
  49. package/lib/components/Tabs/index.js +7 -33
  50. package/lib/components/Tabs/{next/usePressable.js → usePressable.js} +1 -1
  51. package/lib/components/Text/Text.d.ts +33 -0
  52. package/lib/components/Text/Text.js +8 -5
  53. package/lib/components/Text/TextDirection.d.ts +35 -0
  54. package/lib/components/Text/TextDirectionContext.js +2 -0
  55. package/lib/components/Text/createTextComponent.d.ts +18 -0
  56. package/lib/components/Text/index.d.ts +18 -0
  57. package/lib/components/Text/index.js +4 -0
  58. package/lib/components/TextInput/TextInput.js +1 -1
  59. package/lib/components/Tile/Tile.js +336 -499
  60. package/lib/index.js +71 -71
  61. package/lib/internal/useNormalizedInputProps.js +12 -16
  62. package/lib/internal/usePrefix.d.ts +9 -0
  63. package/package.json +8 -4
  64. package/es/components/Search/next/Search.js +0 -265
  65. package/es/components/Tabs/next/Tabs.Skeleton.js +0 -53
  66. package/es/components/Tabs/next/Tabs.js +0 -692
  67. package/es/components/Tile/index.js +0 -19
  68. package/es/components/Tile/next/Tile.js +0 -604
  69. package/lib/components/Search/next/Search.js +0 -275
  70. package/lib/components/Tabs/next/Tabs.Skeleton.js +0 -63
  71. package/lib/components/Tabs/next/Tabs.js +0 -708
  72. package/lib/components/Tile/index.js +0 -48
  73. package/lib/components/Tile/next/Tile.js +0 -619
@@ -1,692 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
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
-
8
- import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
- import { ChevronLeft, ChevronRight } from '@carbon/icons-react';
10
- import cx from 'classnames';
11
- import debounce from 'lodash.debounce';
12
- import PropTypes from 'prop-types';
13
- import React__default, { useRef, useState, useCallback, useEffect } from 'react';
14
- import { Tooltip } from '../../Tooltip/next/Tooltip.js';
15
- import { useControllableState } from '../../../internal/useControllableState.js';
16
- import { useEffectOnce } from '../../../internal/useEffectOnce.js';
17
- import { useId } from '../../../internal/useId.js';
18
- import useIsomorphicEffect from '../../../internal/useIsomorphicEffect.js';
19
- import { useMergedRefs } from '../../../internal/useMergedRefs.js';
20
- import { getInteractiveContent } from '../../../internal/useNoInteractiveChildren.js';
21
- import { usePrefix } from '../../../internal/usePrefix.js';
22
- import { usePressable } from './usePressable.js';
23
- import { matches, match } from '../../../internal/keyboard/match.js';
24
- import { ArrowRight, ArrowLeft, Home, End } from '../../../internal/keyboard/keys.js';
25
-
26
- var _ChevronLeft, _ChevronRight;
27
-
28
- var _excluded = ["activation", "aria-label", "children", "className", "contained", "iconSize", "leftOverflowButtonProps", "light", "rightOverflowButtonProps", "scrollDebounceWait", "scrollIntoView"],
29
- _excluded2 = ["as", "children", "className", "disabled", "onClick", "onKeyDown"],
30
- _excluded3 = ["children", "className", "defaultOpen", "enterDelayMs", "leaveDelayMs", "label"],
31
- _excluded4 = ["children", "className"];
32
-
33
- var TabsContext = /*#__PURE__*/React__default.createContext(); // Used to keep track of position in a tablist
34
-
35
- var TabContext = /*#__PURE__*/React__default.createContext(); // Used to keep track of position in a list of tab panels
36
-
37
- var TabPanelContext = /*#__PURE__*/React__default.createContext();
38
-
39
- function Tabs(_ref) {
40
- var children = _ref.children,
41
- _ref$defaultSelectedI = _ref.defaultSelectedIndex,
42
- defaultSelectedIndex = _ref$defaultSelectedI === void 0 ? 0 : _ref$defaultSelectedI,
43
- _onChange = _ref.onChange,
44
- controlledSelectedIndex = _ref.selectedIndex;
45
- var baseId = useId('ccs'); // The active index is used to track the element which has focus in our tablist
46
-
47
- var _useState = useState(defaultSelectedIndex),
48
- _useState2 = _slicedToArray(_useState, 2),
49
- activeIndex = _useState2[0],
50
- setActiveIndex = _useState2[1]; // The selected index is used for the tab/panel pairing which is "visible"
51
-
52
-
53
- var _useControllableState = useControllableState({
54
- value: controlledSelectedIndex,
55
- defaultValue: defaultSelectedIndex,
56
- onChange: function onChange(value) {
57
- if (_onChange) {
58
- _onChange({
59
- selectedIndex: value
60
- });
61
- }
62
- }
63
- }),
64
- _useControllableState2 = _slicedToArray(_useControllableState, 2),
65
- selectedIndex = _useControllableState2[0],
66
- setSelectedIndex = _useControllableState2[1];
67
-
68
- var value = {
69
- baseId: baseId,
70
- activeIndex: activeIndex,
71
- defaultSelectedIndex: defaultSelectedIndex,
72
- setActiveIndex: setActiveIndex,
73
- selectedIndex: selectedIndex,
74
- setSelectedIndex: setSelectedIndex
75
- };
76
- return /*#__PURE__*/React__default.createElement(TabsContext.Provider, {
77
- value: value
78
- }, children);
79
- }
80
-
81
- Tabs.propTypes = {
82
- /**
83
- * Provide child elements to be rendered inside of the `Tabs`.
84
- * These elements should render either `TabsList` or `TabsPanels`
85
- */
86
- children: PropTypes.node,
87
-
88
- /**
89
- * Specify which content tab should be initially selected when the component
90
- * is first rendered
91
- */
92
- defaultSelectedIndex: PropTypes.number,
93
-
94
- /**
95
- * Provide an optional function which is called whenever the state of the
96
- * `Tabs` changes
97
- */
98
- onChange: PropTypes.func,
99
-
100
- /**
101
- * Control which content panel is currently selected. This puts the component
102
- * in a controlled mode and should be used along with `onChange`
103
- */
104
- selectedIndex: PropTypes.number
105
- };
106
- /**
107
- * Get the next index for a given keyboard event given a count of the total
108
- * items and the current index
109
- * @param {Event} event
110
- * @param {number} total
111
- * @param {number} index
112
- * @returns {number}
113
- */
114
-
115
- function getNextIndex(event, total, index) {
116
- if (match(event, ArrowRight)) {
117
- return (index + 1) % total;
118
- } else if (match(event, ArrowLeft)) {
119
- return (total + index - 1) % total;
120
- } else if (match(event, Home)) {
121
- return 0;
122
- } else if (match(event, End)) {
123
- return total - 1;
124
- }
125
- }
126
-
127
- function TabList(_ref2) {
128
- var _cx;
129
-
130
- var _ref2$activation = _ref2.activation,
131
- activation = _ref2$activation === void 0 ? 'automatic' : _ref2$activation,
132
- label = _ref2['aria-label'],
133
- children = _ref2.children,
134
- customClassName = _ref2.className,
135
- _ref2$contained = _ref2.contained,
136
- contained = _ref2$contained === void 0 ? false : _ref2$contained,
137
- iconSize = _ref2.iconSize,
138
- leftOverflowButtonProps = _ref2.leftOverflowButtonProps,
139
- light = _ref2.light,
140
- rightOverflowButtonProps = _ref2.rightOverflowButtonProps,
141
- _ref2$scrollDebounceW = _ref2.scrollDebounceWait,
142
- scrollDebounceWait = _ref2$scrollDebounceW === void 0 ? 200 : _ref2$scrollDebounceW,
143
- scrollIntoView = _ref2.scrollIntoView,
144
- rest = _objectWithoutProperties(_ref2, _excluded);
145
-
146
- var _React$useContext = React__default.useContext(TabsContext),
147
- activeIndex = _React$useContext.activeIndex,
148
- selectedIndex = _React$useContext.selectedIndex,
149
- setSelectedIndex = _React$useContext.setSelectedIndex,
150
- setActiveIndex = _React$useContext.setActiveIndex;
151
-
152
- var prefix = usePrefix();
153
- var ref = useRef(null);
154
- var previousButton = useRef(null);
155
- var nextButton = useRef(null);
156
-
157
- var _useState3 = useState(false),
158
- _useState4 = _slicedToArray(_useState3, 2),
159
- isScrollable = _useState4[0],
160
- setIsScrollable = _useState4[1];
161
-
162
- var _useState5 = useState(null),
163
- _useState6 = _slicedToArray(_useState5, 2),
164
- scrollLeft = _useState6[0],
165
- setScrollLeft = _useState6[1];
166
-
167
- var className = cx("".concat(prefix, "--tabs"), customClassName, (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--tabs--contained"), contained), _defineProperty(_cx, "".concat(prefix, "--tabs--light"), light), _defineProperty(_cx, "".concat(prefix, "--tabs__icon--default"), iconSize === 'default'), _defineProperty(_cx, "".concat(prefix, "--tabs__icon--lg"), iconSize === 'lg'), _cx)); // Previous Button
168
- // VISIBLE IF:
169
- // SCROLLABLE
170
- // AND SCROLL_LEFT > 0
171
-
172
- var buttonWidth = 44;
173
- var isPreviousButtonVisible = ref.current ? isScrollable && scrollLeft > 0 : false; // Next Button
174
- // VISIBLE IF:
175
- // SCROLLABLE
176
- // AND SCROLL_LEFT + CLIENT_WIDTH < SCROLL_WIDTH
177
-
178
- var isNextButtonVisible = ref.current ? scrollLeft + buttonWidth + ref.current.clientWidth < ref.current.scrollWidth : false;
179
- var previousButtonClasses = cx("".concat(prefix, "--tab--overflow-nav-button"), "".concat(prefix, "--tab--overflow-nav-button--previous"), _defineProperty({}, "".concat(prefix, "--tab--overflow-nav-button--hidden"), !isPreviousButtonVisible));
180
- var nextButtonClasses = cx("".concat(prefix, "--tab--overflow-nav-button"), "".concat(prefix, "--tab--overflow-nav-button--next"), _defineProperty({}, "".concat(prefix, "--tab--overflow-nav-button--hidden"), !isNextButtonVisible));
181
- var tabs = useRef([]);
182
- var debouncedOnScroll = useCallback(function () {
183
- return debounce(function (event) {
184
- setScrollLeft(event.target.scrollLeft);
185
- }, scrollDebounceWait);
186
- }, [scrollDebounceWait]);
187
-
188
- function onKeyDown(event) {
189
- if (matches(event, [ArrowRight, ArrowLeft, Home, End])) {
190
- event.preventDefault();
191
- var activeTabs = tabs.current.filter(function (tab) {
192
- return !tab.disabled;
193
- });
194
- var currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
195
- var nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
196
-
197
- if (activation === 'automatic') {
198
- setSelectedIndex(nextIndex);
199
- } else if (activation === 'manual') {
200
- setActiveIndex(nextIndex);
201
- }
202
-
203
- tabs.current[nextIndex].focus();
204
- }
205
- }
206
-
207
- useEffectOnce(function () {
208
- var tab = tabs.current[selectedIndex];
209
-
210
- if (scrollIntoView && tab) {
211
- tab.scrollIntoView({
212
- block: 'nearest',
213
- inline: 'nearest'
214
- });
215
- }
216
- });
217
- useEffectOnce(function () {
218
- if (tabs.current[selectedIndex].disabled) {
219
- var activeTabs = tabs.current.filter(function (tab) {
220
- return !tab.disabled;
221
- });
222
-
223
- if (activeTabs.length > 0) {
224
- var tab = activeTabs[0];
225
- setSelectedIndex(tabs.current.indexOf(tab));
226
- }
227
- }
228
- });
229
- useIsomorphicEffect(function () {
230
- if (ref.current) {
231
- setIsScrollable(ref.current.scrollWidth > ref.current.clientWidth);
232
- }
233
-
234
- function handler() {
235
- if (ref.current) {
236
- setIsScrollable(ref.current.scrollWidth > ref.current.clientWidth);
237
- }
238
- }
239
-
240
- var debouncedHandler = debounce(handler, 200);
241
- window.addEventListener('resize', debouncedHandler);
242
- return function () {
243
- debouncedHandler.cancel();
244
- window.removeEventListener('resize', debouncedHandler);
245
- };
246
- }, []); // updates scroll location for all scroll behavior.
247
-
248
- useIsomorphicEffect(function () {
249
- if (scrollLeft !== null) {
250
- ref.current.scrollLeft = scrollLeft;
251
- }
252
- }, [scrollLeft]);
253
- useIsomorphicEffect(function () {
254
- if (!isScrollable) {
255
- return;
256
- }
257
-
258
- var tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
259
-
260
- if (tab) {
261
- // The width of the "scroll buttons"
262
- // The start and end position of the selected tab
263
- var _tab$getBoundingClien = tab.getBoundingClientRect(),
264
- tabWidth = _tab$getBoundingClien.width;
265
-
266
- var start = tab.offsetLeft;
267
- var end = tab.offsetLeft + tabWidth; // The start and end of the visible area for the tabs
268
-
269
- var visibleStart = ref.current.scrollLeft + buttonWidth;
270
- var visibleEnd = ref.current.scrollLeft + ref.current.clientWidth - buttonWidth; // The beginning of the tab is clipped and not visible
271
-
272
- if (start < visibleStart) {
273
- setScrollLeft(start - buttonWidth);
274
- } // The end of teh tab is clipped and not visible
275
-
276
-
277
- if (end > visibleEnd) {
278
- setScrollLeft(end + buttonWidth - ref.current.clientWidth);
279
- }
280
- }
281
- }, [activation, activeIndex, selectedIndex, isScrollable]);
282
- usePressable(previousButton, {
283
- onPress: function onPress(_ref3) {
284
- var longPress = _ref3.longPress;
285
-
286
- if (!longPress) {
287
- setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
288
- }
289
- },
290
- onLongPress: function onLongPress() {
291
- return createLongPressBehavior(ref, 'backward', setScrollLeft);
292
- }
293
- });
294
- usePressable(nextButton, {
295
- onPress: function onPress(_ref4) {
296
- var longPress = _ref4.longPress;
297
-
298
- if (!longPress) {
299
- setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
300
- }
301
- },
302
- onLongPress: function onLongPress() {
303
- return createLongPressBehavior(ref, 'forward', setScrollLeft);
304
- }
305
- });
306
- return /*#__PURE__*/React__default.createElement("div", {
307
- className: className
308
- }, /*#__PURE__*/React__default.createElement("button", _extends({
309
- "aria-hidden": "true",
310
- "aria-label": "Scroll left",
311
- ref: previousButton,
312
- className: previousButtonClasses,
313
- type: "button"
314
- }, leftOverflowButtonProps), _ChevronLeft || (_ChevronLeft = /*#__PURE__*/React__default.createElement(ChevronLeft, null))), /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
315
- "aria-label": label,
316
- ref: ref,
317
- role: "tablist",
318
- className: "".concat(prefix, "--tab--list"),
319
- onScroll: debouncedOnScroll,
320
- onKeyDown: onKeyDown
321
- }), React__default.Children.map(children, function (child, index) {
322
- return /*#__PURE__*/React__default.createElement(TabContext.Provider, {
323
- value: index
324
- }, /*#__PURE__*/React__default.cloneElement(child, {
325
- ref: function ref(node) {
326
- tabs.current[index] = node;
327
- }
328
- }));
329
- })), /*#__PURE__*/React__default.createElement("button", _extends({
330
- "aria-hidden": "true",
331
- "aria-label": "Scroll right",
332
- ref: nextButton,
333
- className: nextButtonClasses,
334
- type: "button"
335
- }, rightOverflowButtonProps), _ChevronRight || (_ChevronRight = /*#__PURE__*/React__default.createElement(ChevronRight, null))));
336
- }
337
-
338
- TabList.propTypes = {
339
- /**
340
- * Specify whether the content tab should be activated automatically or
341
- * manually
342
- */
343
- activation: PropTypes.oneOf(['automatic', 'manual']),
344
-
345
- /**
346
- * Provide an accessible label to be read when a user interacts with this
347
- * component
348
- */
349
- 'aria-label': PropTypes.string.isRequired,
350
-
351
- /**
352
- * Provide child elements to be rendered inside of `ContentTabs`.
353
- * These elements should render a `ContentTab`
354
- */
355
- children: PropTypes.node,
356
-
357
- /**
358
- * Specify an optional className to be added to the container node
359
- */
360
- className: PropTypes.string,
361
-
362
- /**
363
- * Specify whether component is contained type
364
- */
365
- contained: PropTypes.bool,
366
-
367
- /**
368
- * If using `IconTab`, specify the size of the icon being used.
369
- */
370
- iconSize: PropTypes.oneOf(['default', 'lg']),
371
-
372
- /**
373
- * Provide the props that describe the left overflow button
374
- */
375
- leftOverflowButtonProps: PropTypes.object,
376
-
377
- /**
378
- * Specify whether or not to use the light component variant
379
- */
380
- light: PropTypes.bool,
381
-
382
- /**
383
- * Provide the props that describe the right overflow button
384
- */
385
- rightOverflowButtonProps: PropTypes.object,
386
-
387
- /**
388
- * Optionally provide a delay (in milliseconds) passed to the lodash
389
- * debounce of the onScroll handler. This will impact the responsiveness
390
- * of scroll arrow buttons rendering when scrolling to the first or last tab.
391
- */
392
- scrollDebounceWait: PropTypes.number,
393
-
394
- /**
395
- * Choose whether or not to automatically scroll to newly selected tabs
396
- * on component rerender
397
- */
398
- scrollIntoView: PropTypes.bool
399
- };
400
- /**
401
- * Helper function to setup the behavior when a button is "long pressed". This
402
- * function will take a ref to the tablist, a direction, and a setter for
403
- * scrollLeft and will update the scroll position within a
404
- * requestAnimationFrame.
405
- *
406
- * It returns a cleanup function to be run when the long press is
407
- * deactivated
408
- *
409
- * @param {RefObject} ref
410
- * @param {'forward' | 'backward'} direction
411
- * @param {Function} setScrollLeft
412
- * @returns {Function}
413
- */
414
-
415
- function createLongPressBehavior(ref, direction, setScrollLeft) {
416
- // We manually override the scroll behavior to be "auto". If it is set as
417
- // smooth, this animation does not update correctly
418
- var defaultScrollBehavior = ref.current.style['scroll-behavior'];
419
- ref.current.style['scroll-behavior'] = 'auto';
420
- var scrollDelta = direction === 'forward' ? 5 : -5;
421
- var frameId = null;
422
-
423
- function tick() {
424
- ref.current.scrollLeft = ref.current.scrollLeft + scrollDelta;
425
- frameId = requestAnimationFrame(tick);
426
- }
427
-
428
- frameId = requestAnimationFrame(tick);
429
- return function () {
430
- // Restore the previous scroll behavior
431
- ref.current.style['scroll-behavior'] = defaultScrollBehavior; // Make sure that our `scrollLeft` value is in sync with the existing
432
- // `ref` after our requestAnimationFrame loop above
433
-
434
- setScrollLeft(ref.current.scrollLeft);
435
-
436
- if (frameId) {
437
- cancelAnimationFrame(frameId);
438
- }
439
- };
440
- }
441
-
442
- var Tab = /*#__PURE__*/React__default.forwardRef(function Tab(_ref5, ref) {
443
- var _cx4;
444
-
445
- var _ref5$as = _ref5.as,
446
- BaseComponent = _ref5$as === void 0 ? 'button' : _ref5$as,
447
- children = _ref5.children,
448
- customClassName = _ref5.className,
449
- disabled = _ref5.disabled,
450
- _onClick = _ref5.onClick,
451
- onKeyDown = _ref5.onKeyDown,
452
- rest = _objectWithoutProperties(_ref5, _excluded2);
453
-
454
- var prefix = usePrefix();
455
-
456
- var _React$useContext2 = React__default.useContext(TabsContext),
457
- selectedIndex = _React$useContext2.selectedIndex,
458
- setSelectedIndex = _React$useContext2.setSelectedIndex,
459
- baseId = _React$useContext2.baseId;
460
-
461
- var index = React__default.useContext(TabContext);
462
- var id = "".concat(baseId, "-tab-").concat(index);
463
- var panelId = "".concat(baseId, "-tabpanel-").concat(index);
464
- var className = cx("".concat(prefix, "--tabs__nav-item"), "".concat(prefix, "--tabs__nav-link"), customClassName, (_cx4 = {}, _defineProperty(_cx4, "".concat(prefix, "--tabs__nav-item--selected"), selectedIndex === index), _defineProperty(_cx4, "".concat(prefix, "--tabs__nav-item--disabled"), disabled), _cx4));
465
- return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
466
- "aria-controls": panelId,
467
- "aria-disabled": disabled,
468
- "aria-selected": selectedIndex === index,
469
- ref: ref,
470
- id: id,
471
- role: "tab",
472
- className: className,
473
- disabled: disabled,
474
- onClick: function onClick(evt) {
475
- if (disabled) {
476
- return;
477
- }
478
-
479
- setSelectedIndex(index);
480
-
481
- if (_onClick) {
482
- _onClick(evt);
483
- }
484
- },
485
- onKeyDown: onKeyDown,
486
- tabIndex: selectedIndex === index ? '0' : '-1',
487
- type: "button"
488
- }), children);
489
- });
490
- Tab.propTypes = {
491
- /**
492
- * Provide a custom element to render instead of the default button
493
- */
494
- as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
495
-
496
- /**
497
- * Provide child elements to be rendered inside of `Tab`.
498
- */
499
- children: PropTypes.node,
500
-
501
- /**
502
- * Specify an optional className to be added to your Tab
503
- */
504
- className: PropTypes.string,
505
-
506
- /**
507
- * Whether your Tab is disabled.
508
- */
509
- disabled: PropTypes.bool,
510
-
511
- /**
512
- * Provide a handler that is invoked when a user clicks on the control
513
- */
514
- onClick: PropTypes.func,
515
-
516
- /**
517
- * Provide a handler that is invoked on the key down event for the control
518
- */
519
- onKeyDown: PropTypes.func,
520
-
521
- /*
522
- * An optional parameter to allow overriding the anchor rendering.
523
- * Useful for using Tab along with react-router or other client
524
- * side router libraries.
525
- **/
526
- renderButton: PropTypes.func
527
- };
528
- var IconTab = /*#__PURE__*/React__default.forwardRef(function IconTab(_ref6, ref) {
529
- var children = _ref6.children,
530
- customClassName = _ref6.className,
531
- _ref6$defaultOpen = _ref6.defaultOpen,
532
- defaultOpen = _ref6$defaultOpen === void 0 ? false : _ref6$defaultOpen,
533
- enterDelayMs = _ref6.enterDelayMs,
534
- leaveDelayMs = _ref6.leaveDelayMs,
535
- label = _ref6.label,
536
- rest = _objectWithoutProperties(_ref6, _excluded3);
537
-
538
- var prefix = usePrefix();
539
- var classNames = cx("".concat(prefix, "--tabs__nav-item--icon"), customClassName);
540
- return /*#__PURE__*/React__default.createElement(Tooltip, {
541
- align: "bottom",
542
- defaultOpen: defaultOpen,
543
- className: "".concat(prefix, "--icon-tooltip"),
544
- enterDelayMs: enterDelayMs,
545
- label: label,
546
- leaveDelayMs: leaveDelayMs
547
- }, /*#__PURE__*/React__default.createElement(Tab, _extends({
548
- className: classNames,
549
- ref: ref
550
- }, rest), children));
551
- });
552
- IconTab.propTypes = {
553
- /**
554
- * Provide an icon to be rendered inside of `IconTab` as the visual label for Tab.
555
- */
556
- children: PropTypes.node,
557
-
558
- /**
559
- * Specify an optional className to be added to your Tab
560
- */
561
- className: PropTypes.string,
562
-
563
- /**
564
- * Specify whether the tooltip for the icon should be open when it first renders
565
- */
566
- defaultOpen: PropTypes.bool,
567
-
568
- /**
569
- * Specify the duration in milliseconds to delay before displaying the tooltip for the icon.
570
- */
571
- enterDelayMs: PropTypes.number,
572
-
573
- /**
574
- * Provide the label to be rendered inside of the Tooltip. The label will use
575
- * `aria-labelledby` and will fully describe the child node that is provided.
576
- * This means that if you have text in the child node it will not be
577
- * announced to the screen reader.
578
- */
579
- label: PropTypes.node.isRequired,
580
-
581
- /**
582
- * Specify the duration in milliseconds to delay before hiding the tooltip
583
- */
584
- leaveDelayMs: PropTypes.number
585
- };
586
- var TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7, forwardRef) {
587
- var children = _ref7.children,
588
- customClassName = _ref7.className,
589
- rest = _objectWithoutProperties(_ref7, _excluded4);
590
-
591
- var prefix = usePrefix();
592
- var panel = useRef(null);
593
- var ref = useMergedRefs([forwardRef, panel]);
594
-
595
- var _useState7 = useState('0'),
596
- _useState8 = _slicedToArray(_useState7, 2),
597
- tabIndex = _useState8[0],
598
- setTabIndex = _useState8[1];
599
-
600
- var _useState9 = useState(false),
601
- _useState10 = _slicedToArray(_useState9, 2),
602
- interactiveContent = _useState10[0],
603
- setInteractiveContent = _useState10[1];
604
-
605
- var _React$useContext3 = React__default.useContext(TabsContext),
606
- selectedIndex = _React$useContext3.selectedIndex,
607
- baseId = _React$useContext3.baseId;
608
-
609
- var index = React__default.useContext(TabPanelContext);
610
- var id = "".concat(baseId, "-tabpanel-").concat(index);
611
- var tabId = "".concat(baseId, "-tab-").concat(index);
612
- var className = cx("".concat(prefix, "--tab-content"), customClassName, _defineProperty({}, "".concat(prefix, "--tab-content--interactive"), interactiveContent));
613
- useEffectOnce(function () {
614
- if (!panel.current) {
615
- return;
616
- }
617
-
618
- var content = getInteractiveContent(panel.current);
619
-
620
- if (content) {
621
- setInteractiveContent(true);
622
- setTabIndex('-1');
623
- }
624
- }); // tabindex should only be 0 if no interactive content in children
625
-
626
- useEffect(function () {
627
- if (!panel.current) {
628
- return;
629
- }
630
-
631
- var node = panel.current;
632
-
633
- function callback() {
634
- var content = getInteractiveContent(node);
635
-
636
- if (content) {
637
- setInteractiveContent(true);
638
- setTabIndex('-1');
639
- } else {
640
- setInteractiveContent(false);
641
- setTabIndex('0');
642
- }
643
- }
644
-
645
- var observer = new MutationObserver(callback);
646
- observer.observe(node, {
647
- childList: true,
648
- subtree: true
649
- });
650
- return function () {
651
- observer.disconnect(node);
652
- };
653
- }, []);
654
- return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
655
- "aria-labelledby": tabId,
656
- id: id,
657
- className: className,
658
- ref: ref,
659
- role: "tabpanel",
660
- tabIndex: tabIndex,
661
- hidden: selectedIndex !== index
662
- }), children);
663
- });
664
- TabPanel.propTypes = {
665
- /**
666
- * Provide child elements to be rendered inside of `TabPanel`.
667
- */
668
- children: PropTypes.node,
669
-
670
- /**
671
- * Specify an optional className to be added to TabPanel.
672
- */
673
- className: PropTypes.string
674
- };
675
-
676
- function TabPanels(_ref8) {
677
- var children = _ref8.children;
678
- return React__default.Children.map(children, function (child, index) {
679
- return /*#__PURE__*/React__default.createElement(TabPanelContext.Provider, {
680
- value: index
681
- }, child);
682
- });
683
- }
684
-
685
- TabPanels.propTypes = {
686
- /**
687
- * Provide child elements to be rendered inside of `TabPanels`.
688
- */
689
- children: PropTypes.node
690
- };
691
-
692
- export { IconTab, Tab, TabList, TabPanel, TabPanels, Tabs };