@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.
- package/es/components/Checkbox/Checkbox.Skeleton.d.ts +18 -0
- package/es/components/Checkbox/Checkbox.Skeleton.js +1 -2
- package/es/components/Checkbox/Checkbox.d.ts +47 -0
- package/es/components/Checkbox/Checkbox.js +6 -7
- package/es/components/Checkbox/index.d.ts +10 -0
- package/es/components/Checkbox/index.js +10 -0
- package/es/components/CodeSnippet/CodeSnippet.js +0 -1
- package/es/components/DataTable/TableToolbarSearch.js +1 -1
- package/es/components/ExpandableSearch/ExpandableSearch.js +1 -1
- package/es/components/Grid/Grid.js +0 -5
- package/es/components/NumberInput/NumberInput.js +45 -1
- package/es/components/ProgressIndicator/ProgressIndicator.Skeleton.js +10 -4
- package/es/components/Search/Search.js +160 -184
- package/es/components/Search/index.js +2 -8
- package/es/components/Tab/index.js +1 -1
- package/es/components/Tabs/Tabs.Skeleton.js +6 -6
- package/es/components/Tabs/Tabs.js +582 -508
- package/es/components/Tabs/index.js +2 -12
- package/es/components/Tabs/{next/usePressable.js → usePressable.js} +1 -1
- package/es/components/Text/Text.d.ts +33 -0
- package/es/components/Text/Text.js +8 -5
- package/es/components/Text/TextDirection.d.ts +35 -0
- package/es/components/Text/TextDirectionContext.js +2 -0
- package/es/components/Text/createTextComponent.d.ts +18 -0
- package/es/components/Text/index.d.ts +18 -0
- package/es/components/Text/index.js +2 -0
- package/es/components/TextInput/TextInput.js +1 -1
- package/es/components/Tile/Tile.js +339 -502
- package/es/index.js +6 -6
- package/es/internal/useNormalizedInputProps.js +13 -17
- package/es/internal/usePrefix.d.ts +9 -0
- package/lib/components/Checkbox/Checkbox.Skeleton.d.ts +18 -0
- package/lib/components/Checkbox/Checkbox.Skeleton.js +1 -2
- package/lib/components/Checkbox/Checkbox.d.ts +47 -0
- package/lib/components/Checkbox/Checkbox.js +6 -7
- package/lib/components/Checkbox/index.d.ts +10 -0
- package/lib/components/Checkbox/index.js +18 -0
- package/lib/components/CodeSnippet/CodeSnippet.js +0 -1
- package/lib/components/DataTable/TableToolbarSearch.js +2 -2
- package/lib/components/ExpandableSearch/ExpandableSearch.js +3 -3
- package/lib/components/Grid/Grid.js +0 -5
- package/lib/components/NumberInput/NumberInput.js +45 -1
- package/lib/components/ProgressIndicator/ProgressIndicator.Skeleton.js +9 -3
- package/lib/components/Search/Search.js +159 -183
- package/lib/components/Search/index.js +2 -25
- package/lib/components/Tab/index.js +1 -1
- package/lib/components/Tabs/Tabs.Skeleton.js +6 -6
- package/lib/components/Tabs/Tabs.js +586 -507
- package/lib/components/Tabs/index.js +7 -33
- package/lib/components/Tabs/{next/usePressable.js → usePressable.js} +1 -1
- package/lib/components/Text/Text.d.ts +33 -0
- package/lib/components/Text/Text.js +8 -5
- package/lib/components/Text/TextDirection.d.ts +35 -0
- package/lib/components/Text/TextDirectionContext.js +2 -0
- package/lib/components/Text/createTextComponent.d.ts +18 -0
- package/lib/components/Text/index.d.ts +18 -0
- package/lib/components/Text/index.js +4 -0
- package/lib/components/TextInput/TextInput.js +1 -1
- package/lib/components/Tile/Tile.js +336 -499
- package/lib/index.js +71 -71
- package/lib/internal/useNormalizedInputProps.js +12 -16
- package/lib/internal/usePrefix.d.ts +9 -0
- package/package.json +8 -4
- package/es/components/Search/next/Search.js +0 -265
- package/es/components/Tabs/next/Tabs.Skeleton.js +0 -53
- package/es/components/Tabs/next/Tabs.js +0 -692
- package/es/components/Tile/index.js +0 -19
- package/es/components/Tile/next/Tile.js +0 -604
- package/lib/components/Search/next/Search.js +0 -275
- package/lib/components/Tabs/next/Tabs.Skeleton.js +0 -63
- package/lib/components/Tabs/next/Tabs.js +0 -708
- package/lib/components/Tile/index.js +0 -48
- package/lib/components/Tile/next/Tile.js +0 -619
|
@@ -1,708 +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
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
-
|
|
12
|
-
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
-
var iconsReact = require('@carbon/icons-react');
|
|
14
|
-
var cx = require('classnames');
|
|
15
|
-
var debounce = require('lodash.debounce');
|
|
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');
|
|
25
|
-
var usePrefix = require('../../../internal/usePrefix.js');
|
|
26
|
-
var usePressable = require('./usePressable.js');
|
|
27
|
-
var match = require('../../../internal/keyboard/match.js');
|
|
28
|
-
var keys = require('../../../internal/keyboard/keys.js');
|
|
29
|
-
|
|
30
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
31
|
-
|
|
32
|
-
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
33
|
-
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
34
|
-
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
35
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
36
|
-
|
|
37
|
-
var _ChevronLeft, _ChevronRight;
|
|
38
|
-
|
|
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"];
|
|
43
|
-
|
|
44
|
-
var TabsContext = /*#__PURE__*/React__default["default"].createContext(); // Used to keep track of position in a tablist
|
|
45
|
-
|
|
46
|
-
var TabContext = /*#__PURE__*/React__default["default"].createContext(); // Used to keep track of position in a list of tab panels
|
|
47
|
-
|
|
48
|
-
var TabPanelContext = /*#__PURE__*/React__default["default"].createContext();
|
|
49
|
-
|
|
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
|
|
57
|
-
|
|
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"
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
});
|
|
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,
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Specify which content tab should be initially selected when the component
|
|
101
|
-
* is first rendered
|
|
102
|
-
*/
|
|
103
|
-
defaultSelectedIndex: PropTypes__default["default"].number,
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Provide an optional function which is called whenever the state of the
|
|
107
|
-
* `Tabs` changes
|
|
108
|
-
*/
|
|
109
|
-
onChange: PropTypes__default["default"].func,
|
|
110
|
-
|
|
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
|
-
*/
|
|
125
|
-
|
|
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)]);
|
|
207
|
-
|
|
208
|
-
if (activation === 'automatic') {
|
|
209
|
-
setSelectedIndex(nextIndex);
|
|
210
|
-
} else if (activation === 'manual') {
|
|
211
|
-
setActiveIndex(nextIndex);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
tabs.current[nextIndex].focus();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
useEffectOnce.useEffectOnce(function () {
|
|
219
|
-
var tab = tabs.current[selectedIndex];
|
|
220
|
-
|
|
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;
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
if (activeTabs.length > 0) {
|
|
235
|
-
var tab = activeTabs[0];
|
|
236
|
-
setSelectedIndex(tabs.current.indexOf(tab));
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
useIsomorphicEffect["default"](function () {
|
|
241
|
-
if (ref.current) {
|
|
242
|
-
setIsScrollable(ref.current.scrollWidth > ref.current.clientWidth);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function handler() {
|
|
246
|
-
if (ref.current) {
|
|
247
|
-
setIsScrollable(ref.current.scrollWidth > ref.current.clientWidth);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
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
|
-
}
|
|
268
|
-
|
|
269
|
-
var tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
|
|
270
|
-
|
|
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;
|
|
276
|
-
|
|
277
|
-
var start = tab.offsetLeft;
|
|
278
|
-
var end = tab.offsetLeft + tabWidth; // The start and end of the visible area for the tabs
|
|
279
|
-
|
|
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
|
|
282
|
-
|
|
283
|
-
if (start < visibleStart) {
|
|
284
|
-
setScrollLeft(start - buttonWidth);
|
|
285
|
-
} // The end of teh tab is clipped and not visible
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (end > visibleEnd) {
|
|
289
|
-
setScrollLeft(end + buttonWidth - ref.current.clientWidth);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}, [activation, activeIndex, selectedIndex, isScrollable]);
|
|
293
|
-
usePressable.usePressable(previousButton, {
|
|
294
|
-
onPress: function onPress(_ref3) {
|
|
295
|
-
var longPress = _ref3.longPress;
|
|
296
|
-
|
|
297
|
-
if (!longPress) {
|
|
298
|
-
setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
|
|
299
|
-
}
|
|
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;
|
|
308
|
-
|
|
309
|
-
if (!longPress) {
|
|
310
|
-
setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
|
|
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']),
|
|
355
|
-
|
|
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,
|
|
361
|
-
|
|
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,
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Specify an optional className to be added to the container node
|
|
370
|
-
*/
|
|
371
|
-
className: PropTypes__default["default"].string,
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Specify whether component is contained type
|
|
375
|
-
*/
|
|
376
|
-
contained: PropTypes__default["default"].bool,
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* If using `IconTab`, specify the size of the icon being used.
|
|
380
|
-
*/
|
|
381
|
-
iconSize: PropTypes__default["default"].oneOf(['default', 'lg']),
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Provide the props that describe the left overflow button
|
|
385
|
-
*/
|
|
386
|
-
leftOverflowButtonProps: PropTypes__default["default"].object,
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Specify whether or not to use the light component variant
|
|
390
|
-
*/
|
|
391
|
-
light: PropTypes__default["default"].bool,
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Provide the props that describe the right overflow button
|
|
395
|
-
*/
|
|
396
|
-
rightOverflowButtonProps: PropTypes__default["default"].object,
|
|
397
|
-
|
|
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,
|
|
404
|
-
|
|
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
|
-
*/
|
|
425
|
-
|
|
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
|
-
}
|
|
438
|
-
|
|
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
|
|
444
|
-
|
|
445
|
-
setScrollLeft(ref.current.scrollLeft);
|
|
446
|
-
|
|
447
|
-
if (frameId) {
|
|
448
|
-
cancelAnimationFrame(frameId);
|
|
449
|
-
}
|
|
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;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
setSelectedIndex(index);
|
|
491
|
-
|
|
492
|
-
if (_onClick) {
|
|
493
|
-
_onClick(evt);
|
|
494
|
-
}
|
|
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]),
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Provide child elements to be rendered inside of `Tab`.
|
|
509
|
-
*/
|
|
510
|
-
children: PropTypes__default["default"].node,
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Specify an optional className to be added to your Tab
|
|
514
|
-
*/
|
|
515
|
-
className: PropTypes__default["default"].string,
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Whether your Tab is disabled.
|
|
519
|
-
*/
|
|
520
|
-
disabled: PropTypes__default["default"].bool,
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Provide a handler that is invoked when a user clicks on the control
|
|
524
|
-
*/
|
|
525
|
-
onClick: PropTypes__default["default"].func,
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Provide a handler that is invoked on the key down event for the control
|
|
529
|
-
*/
|
|
530
|
-
onKeyDown: PropTypes__default["default"].func,
|
|
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 = {
|
|
564
|
-
/**
|
|
565
|
-
* Provide an icon to be rendered inside of `IconTab` as the visual label for Tab.
|
|
566
|
-
*/
|
|
567
|
-
children: PropTypes__default["default"].node,
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Specify an optional className to be added to your Tab
|
|
571
|
-
*/
|
|
572
|
-
className: PropTypes__default["default"].string,
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Specify whether the tooltip for the icon should be open when it first renders
|
|
576
|
-
*/
|
|
577
|
-
defaultOpen: PropTypes__default["default"].bool,
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Specify the duration in milliseconds to delay before displaying the tooltip for the icon.
|
|
581
|
-
*/
|
|
582
|
-
enterDelayMs: PropTypes__default["default"].number,
|
|
583
|
-
|
|
584
|
-
/**
|
|
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
|
-
*/
|
|
590
|
-
label: PropTypes__default["default"].node.isRequired,
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Specify the duration in milliseconds to delay before hiding the tooltip
|
|
594
|
-
*/
|
|
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
|
-
}
|
|
628
|
-
|
|
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);
|
|
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 = {
|
|
676
|
-
/**
|
|
677
|
-
* Provide child elements to be rendered inside of `TabPanel`.
|
|
678
|
-
*/
|
|
679
|
-
children: PropTypes__default["default"].node,
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Specify an optional className to be added to TabPanel.
|
|
683
|
-
*/
|
|
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 = {
|
|
697
|
-
/**
|
|
698
|
-
* Provide child elements to be rendered inside of `TabPanels`.
|
|
699
|
-
*/
|
|
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;
|