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