@elliemae/ds-tabs 2.0.0-rc.6 → 2.0.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 (104) hide show
  1. package/cjs/DSTabs.js +27 -108
  2. package/cjs/DSTabsCTX.js +30 -0
  3. package/cjs/DSTabsDatatestid.js +18 -0
  4. package/cjs/DSTabsTypes.js +2 -0
  5. package/cjs/config/useCrossRef.js +17 -0
  6. package/cjs/config/useTabs.js +51 -0
  7. package/cjs/defaultProps.js +27 -0
  8. package/cjs/{PanelContainer.js → exportsRelated/DSTab.js} +14 -30
  9. package/cjs/index.js +5 -5
  10. package/cjs/parts/carousel/Carousel.js +71 -0
  11. package/cjs/parts/carousel/styles.js +60 -0
  12. package/cjs/parts/carousel/useCarousel.js +78 -0
  13. package/cjs/parts/carousel/useCarouselCallbacks.js +72 -0
  14. package/cjs/parts/tabBar/TabBar.js +160 -0
  15. package/cjs/parts/tabBar/styles.js +199 -0
  16. package/cjs/parts/tabBar/useTabBar.js +98 -0
  17. package/cjs/parts/tabsContent/TabsContent.js +49 -0
  18. package/cjs/parts/tabsContent/styles.js +15 -0
  19. package/cjs/parts/tabsPanel/TabsPanels.js +77 -0
  20. package/cjs/parts/tabsPanel/styles.js +25 -0
  21. package/cjs/propTypes.js +33 -0
  22. package/cjs/utils/constants.js +29 -0
  23. package/cjs/utils/helpers.js +47 -0
  24. package/cjs/utils/hooks/useKeyboardNavigation.js +61 -0
  25. package/cjs/utils/hooks/useTabsCallbacks.js +59 -0
  26. package/esm/DSTabs.js +29 -110
  27. package/esm/DSTabsCTX.js +25 -0
  28. package/esm/DSTabsDatatestid.js +14 -0
  29. package/esm/DSTabsTypes.js +1 -0
  30. package/esm/config/useCrossRef.js +13 -0
  31. package/esm/config/useTabs.js +47 -0
  32. package/esm/defaultProps.js +23 -0
  33. package/esm/{PanelContainer.js → exportsRelated/DSTab.js} +7 -26
  34. package/esm/index.js +4 -3
  35. package/esm/parts/carousel/Carousel.js +63 -0
  36. package/esm/parts/carousel/styles.js +49 -0
  37. package/esm/parts/carousel/useCarousel.js +70 -0
  38. package/esm/parts/carousel/useCarouselCallbacks.js +68 -0
  39. package/esm/parts/tabBar/TabBar.js +151 -0
  40. package/esm/parts/tabBar/styles.js +185 -0
  41. package/esm/parts/tabBar/useTabBar.js +90 -0
  42. package/esm/parts/tabsContent/TabsContent.js +40 -0
  43. package/esm/parts/tabsContent/styles.js +7 -0
  44. package/esm/parts/tabsPanel/TabsPanels.js +67 -0
  45. package/esm/parts/tabsPanel/styles.js +17 -0
  46. package/esm/propTypes.js +28 -0
  47. package/esm/utils/constants.js +21 -0
  48. package/esm/utils/helpers.js +37 -0
  49. package/esm/utils/hooks/useKeyboardNavigation.js +57 -0
  50. package/esm/utils/hooks/useTabsCallbacks.js +55 -0
  51. package/package.json +99 -36
  52. package/types/DSTabs.d.ts +10 -60
  53. package/types/DSTabsCTX.d.ts +4 -0
  54. package/types/DSTabsDatatestid.d.ts +12 -0
  55. package/types/DSTabsTypes.d.ts +202 -0
  56. package/types/config/useCrossRef.d.ts +2 -0
  57. package/types/config/useTabs.d.ts +2 -0
  58. package/types/defaultProps.d.ts +2 -0
  59. package/types/exportsRelated/DSTab.d.ts +14 -0
  60. package/types/index.d.ts +4 -3
  61. package/types/parts/carousel/Carousel.d.ts +3 -0
  62. package/types/parts/carousel/styles.d.ts +9 -0
  63. package/types/parts/carousel/useCarousel.d.ts +2 -0
  64. package/types/parts/carousel/useCarouselCallbacks.d.ts +2 -0
  65. package/types/parts/tabBar/TabBar.d.ts +2 -0
  66. package/types/parts/tabBar/styles.d.ts +7 -0
  67. package/types/parts/tabBar/useTabBar.d.ts +2 -0
  68. package/types/parts/tabsContent/TabsContent.d.ts +2 -0
  69. package/types/parts/tabsContent/styles.d.ts +1 -0
  70. package/types/parts/tabsPanel/TabsPanels.d.ts +2 -0
  71. package/types/parts/tabsPanel/styles.d.ts +2 -0
  72. package/types/propTypes.d.ts +54 -0
  73. package/types/tests/{DSTabs.events.test.d.ts → DSTabs.callbacks.test.d.ts} +0 -0
  74. package/types/tests/DSTabs.func.test.d.ts +1 -0
  75. package/types/tests/DSTabs.keyboard.test.d.ts +1 -0
  76. package/types/utils/constants.d.ts +19 -0
  77. package/types/utils/helpers.d.ts +8 -0
  78. package/types/utils/hooks/useKeyboardNavigation.d.ts +2 -0
  79. package/types/utils/hooks/useTabsCallbacks.d.ts +2 -0
  80. package/cjs/Carousel.js +0 -205
  81. package/cjs/DSTab.js +0 -46
  82. package/cjs/SubTabBar.js +0 -54
  83. package/cjs/TabBar.js +0 -421
  84. package/cjs/TabTypes.js +0 -15
  85. package/cjs/TabsImpl.js +0 -120
  86. package/cjs/TabsPanels.js +0 -85
  87. package/cjs/useResize.js +0 -24
  88. package/esm/Carousel.js +0 -196
  89. package/esm/DSTab.js +0 -36
  90. package/esm/SubTabBar.js +0 -48
  91. package/esm/TabBar.js +0 -410
  92. package/esm/TabTypes.js +0 -10
  93. package/esm/TabsImpl.js +0 -113
  94. package/esm/TabsPanels.js +0 -75
  95. package/esm/useResize.js +0 -20
  96. package/types/Carousel.d.ts +0 -16
  97. package/types/DSTab.d.ts +0 -22
  98. package/types/PanelContainer.d.ts +0 -20
  99. package/types/SubTabBar.d.ts +0 -23
  100. package/types/TabBar.d.ts +0 -30
  101. package/types/TabTypes.d.ts +0 -5
  102. package/types/TabsImpl.d.ts +0 -37
  103. package/types/TabsPanels.d.ts +0 -5
  104. package/types/useResize.d.ts +0 -1
package/cjs/SubTabBar.js DELETED
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- var _jsx = require('@babel/runtime/helpers/jsx');
4
- require('react');
5
- var dsClassnames = require('@elliemae/ds-classnames');
6
- var TabBar = require('./TabBar.js');
7
- var Carousel = require('./Carousel.js');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
12
-
13
- const blockName = 'tabs-tab-bar';
14
- const SubTabList = dsClassnames.aggregatedClasses('div')(blockName, 'subtabs-list', _ref => {
15
- let {
16
- withCarousel
17
- } = _ref;
18
- return {
19
- carousel: withCarousel
20
- };
21
- });
22
-
23
- const SubTabBar = _ref2 => {
24
- let {
25
- withCarousel,
26
- tabs = [],
27
- activeTab = '',
28
- onTabClick = () => null,
29
- firstSubtabRef,
30
- handleUpArrow
31
- } = _ref2;
32
- return /*#__PURE__*/_jsx__default["default"](TabBar, {
33
- activeTab: activeTab,
34
- onTabClick: onTabClick,
35
- handleUpArrow: handleUpArrow,
36
- firstSubtabRef: firstSubtabRef,
37
- renderCustomTabBar: _ref3 => {
38
- let {
39
- tabsComponents,
40
- innerRef
41
- } = _ref3;
42
- return /*#__PURE__*/_jsx__default["default"](SubTabList, {
43
- withCarousel: withCarousel,
44
- innerRef: innerRef,
45
- "data-testid": "subtabs-list"
46
- }, void 0, withCarousel ? /*#__PURE__*/_jsx__default["default"](Carousel, {}, void 0, tabsComponents) : tabsComponents);
47
- },
48
- showSelectionIndicator: false,
49
- showSeparator: true,
50
- tabs: tabs
51
- });
52
- };
53
-
54
- module.exports = SubTabBar;
package/cjs/TabBar.js DELETED
@@ -1,421 +0,0 @@
1
- 'use strict';
2
-
3
- var _jsx = require('@babel/runtime/helpers/jsx');
4
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- require('core-js/modules/esnext.async-iterator.map.js');
6
- require('core-js/modules/esnext.iterator.map.js');
7
- var React = require('react');
8
- var lodash = require('lodash');
9
- var dsClassnames = require('@elliemae/ds-classnames');
10
- var RequiredMark = require('@elliemae/ds-form/RequiredMark');
11
- var memoizeOne = require('memoize-one');
12
- var resizeObserver = require('resize-observer');
13
- var styled = require('styled-components');
14
- var Carousel = require('./Carousel.js');
15
- var jsxRuntime = require('react/jsx-runtime');
16
-
17
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
-
19
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
20
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
21
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
22
- var RequiredMark__default = /*#__PURE__*/_interopDefaultLegacy(RequiredMark);
23
- var memoizeOne__default = /*#__PURE__*/_interopDefaultLegacy(memoizeOne);
24
- var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
25
-
26
- const blockName = 'tabs-tab-bar';
27
- const gradientWidth = 24;
28
- const StyledTabWrapper = /*#__PURE__*/styled__default["default"].div.withConfig({
29
- componentId: "sc-7sdovg-0"
30
- })(["display:flex;flex:1;flex-wrap:nowrap;", ";"], _ref => {
31
- let {
32
- flexibleTabsHeaders
33
- } = _ref;
34
- return flexibleTabsHeaders ? '' : 'overflow-x: hidden';
35
- });
36
- const StyledTabList = dsClassnames.aggregatedClasses('div')(blockName, 'list', _ref2 => {
37
- let {
38
- withCarousel,
39
- flexibleTabsHeaders,
40
- fixedTabsHeaders,
41
- isDSMobile,
42
- withLeftGradients,
43
- withRightGradients
44
- } = _ref2;
45
- return {
46
- carousel: withCarousel,
47
- 'flexible-table-headers': isDSMobile && flexibleTabsHeaders,
48
- 'fixed-table-headers': isDSMobile && fixedTabsHeaders,
49
- 'left-gradients': isDSMobile && flexibleTabsHeaders && withLeftGradients,
50
- 'right-gradients': isDSMobile && flexibleTabsHeaders && withRightGradients
51
- };
52
- }, {
53
- propsToRemoveFromFinalElement: ['withCarousel', 'flexibleTabsHeaders', 'fixedTabsHeaders', 'withLeftGradients', 'withRightGradients', 'isDSMobile']
54
- });
55
- const TabContainer = dsClassnames.aggregatedClasses('button', {
56
- role: 'tab'
57
- })(blockName, 'tab', _ref3 => {
58
- let {
59
- isActive,
60
- showSeparator,
61
- disabled
62
- } = _ref3;
63
- return {
64
- active: isActive,
65
- separator: showSeparator,
66
- disabled
67
- };
68
- });
69
- const SelectionIndicator = dsClassnames.aggregatedClasses('div')(blockName, 'selection-indicator');
70
-
71
- class TabBar extends React.Component {
72
- constructor(_props) {
73
- super(_props);
74
-
75
- _defineProperty__default["default"](this, "handleTabClick", (tabId, e) => {
76
- const {
77
- tabListRef,
78
- props
79
- } = this;
80
- const {
81
- onTabClick,
82
- flexibleTabsHeaders,
83
- isDSMobile
84
- } = props;
85
-
86
- if (isDSMobile && flexibleTabsHeaders) {
87
- const tabListDomEl = tabListRef.current;
88
- const el = e.target;
89
- const {
90
- offsetLeft
91
- } = el;
92
- const {
93
- width: elWidth
94
- } = el.getBoundingClientRect();
95
- const {
96
- width: listWidth
97
- } = tabListDomEl.getBoundingClientRect();
98
- const extraSideSpace = listWidth - elWidth;
99
- const leftOffsetToCenter = extraSideSpace > 0 ? extraSideSpace / 2 : 0;
100
- const centeredLeftOffset = offsetLeft > leftOffsetToCenter ? offsetLeft - leftOffsetToCenter : 0;
101
- tabListDomEl.scrollTo({
102
- top: 0,
103
- left: centeredLeftOffset,
104
- behavior: 'smooth'
105
- });
106
- }
107
-
108
- e.preventDefault();
109
- onTabClick(tabId);
110
- });
111
-
112
- _defineProperty__default["default"](this, "handleKeyPress", (tabId, e, index) => {
113
- const {
114
- tabs,
115
- handleDownArrow,
116
- handleUpArrow // onTabClick,
117
-
118
- } = this.props;
119
-
120
- if (e.keyCode === 39) {
121
- var _this$tabsRef;
122
-
123
- const nextTab = tabs[index + 1];
124
- if (!nextTab && handleDownArrow) handleDownArrow(e);
125
- if (!nextTab) return; // const { props } = nextTab
126
- // onTabClick(props.tabId)
127
-
128
- (_this$tabsRef = this.tabsRef[index + 1]) === null || _this$tabsRef === void 0 ? void 0 : _this$tabsRef.focus();
129
- }
130
-
131
- if (e.keyCode === 37) {
132
- var _this$tabsRef2;
133
-
134
- const nextTab = tabs[index - 1];
135
- if (!nextTab && handleUpArrow) handleUpArrow(e);
136
- if (!nextTab) return; // const { props } = nextTab
137
- // onTabClick(props.tabId)
138
-
139
- (_this$tabsRef2 = this.tabsRef[index - 1]) === null || _this$tabsRef2 === void 0 ? void 0 : _this$tabsRef2.focus();
140
- }
141
-
142
- if (e.keyCode === 40 && handleDownArrow) {
143
- handleDownArrow(e);
144
- }
145
-
146
- if (e.keyCode === 38 && handleUpArrow) {
147
- handleUpArrow(e);
148
- }
149
- });
150
-
151
- _defineProperty__default["default"](this, "handleTabsHeadersHorizontalScroll", lodash.debounce(() => {
152
- const {
153
- tabListRef,
154
- props
155
- } = this;
156
- const {
157
- flexibleTabsHeaders,
158
- isDSMobile
159
- } = props;
160
-
161
- if (isDSMobile && flexibleTabsHeaders) {
162
- const tabListDomEl = tabListRef.current;
163
- const {
164
- scrollLeft,
165
- scrollWidth,
166
- clientWidth
167
- } = tabListDomEl;
168
- const withLeftGradients = this.shouldHaveLeftGradient(scrollLeft, gradientWidth);
169
- const withRightGradients = this.shouldHaveRightGradient(scrollLeft, gradientWidth, clientWidth, scrollWidth);
170
- this.setState({
171
- withLeftGradients,
172
- withRightGradients
173
- });
174
- }
175
- }, 50));
176
-
177
- _defineProperty__default["default"](this, "renderTabs", memoizeOne__default["default"]((activeTab, tabs) => {
178
- const {
179
- showSeparator
180
- } = this.props;
181
- return React__default["default"].Children.map(tabs, (tab, index) => {
182
- const {
183
- tabId,
184
- title,
185
- style,
186
- required,
187
- disabled
188
- } = tab.props;
189
- const isActive = activeTab === tabId;
190
- return [/*#__PURE__*/jsxRuntime.jsxs(TabContainer, {
191
- // eslint-disable-next-line no-return-assign
192
- ref: t => {
193
- this.tabsRef[index] = t;
194
-
195
- if (index === 0 && this.props.firstSubtabRef) {
196
- this.props.firstSubtabRef.current = t;
197
- }
198
-
199
- if (index === tabs.length - 1 && this.props.lastTabRef) {
200
- this.props.lastTabRef.current = t;
201
- }
202
- },
203
- "aria-controls": tabId,
204
- "aria-selected": isActive,
205
- "aria-disabled": !!disabled,
206
- classProps: {
207
- isActive,
208
- showSeparator,
209
- disabled
210
- },
211
- "data-tab-id": tabId,
212
- id: "".concat(tabId, "-label"),
213
- onClick: e => {
214
- if (!disabled) this.handleTabClick(tabId, e, index);
215
- },
216
- onKeyDown: e => {
217
- if (!disabled) this.handleKeyPress(tabId, e, index);
218
- },
219
- style: style,
220
- tabIndex: 0,
221
- children: [title, /*#__PURE__*/_jsx__default["default"](RequiredMark__default["default"], {
222
- required: required
223
- })]
224
- }, tabId)];
225
- }, null);
226
- }));
227
-
228
- this.tabListRef = /*#__PURE__*/React__default["default"].createRef();
229
- this.resizeObserver = new resizeObserver.ResizeObserver(() => this.setIndicatorStyle());
230
- this.state = {
231
- indicatorStyle: null,
232
- withLeftGradients: false,
233
- withRightGradients: false
234
- };
235
- this.setIndicatorStyle = this.setIndicatorStyle.bind(this);
236
- this.getIndicatorStyles = this.getIndicatorStyles.bind(this);
237
- this.handleGradients = this.handleGradients.bind(this);
238
- this.handleTabsHeadersHorizontalScroll = this.handleTabsHeadersHorizontalScroll.bind(this);
239
- this.tabsRef = {};
240
- this.setIndicatorStyle = this.setIndicatorStyle.bind(this);
241
- }
242
-
243
- componentDidMount() {
244
- const {
245
- showSelectionIndicator
246
- } = this.props;
247
- this.resizeObserver.observe(this.tabListRef.current);
248
-
249
- if (showSelectionIndicator) {
250
- this.setIndicatorStyle();
251
- }
252
-
253
- window.addEventListener('resize', this.handleGradients);
254
- window.addEventListener('orientationchange', this.handleGradients);
255
- this.handleGradients();
256
- }
257
-
258
- componentDidUpdate(prevProps) {
259
- const {
260
- activeTab,
261
- showSelectionIndicator
262
- } = this.props;
263
-
264
- if (showSelectionIndicator && prevProps.activeTab !== activeTab) {
265
- this.setIndicatorStyle(activeTab);
266
- }
267
- }
268
-
269
- componentWillUnmount() {
270
- this.resizeObserver.unobserve(this.tabListRef.current);
271
- window.removeEventListener('resize', this.handleGradients);
272
- window.removeEventListener('orientationchange', this.handleGradients);
273
- }
274
-
275
- handleGradients() {
276
- const {
277
- scrollLeft,
278
- scrollWidth,
279
- clientWidth
280
- } = this.tabListRef.current;
281
- const withLeftGradients = this.shouldHaveLeftGradient(scrollLeft, gradientWidth);
282
- const withRightGradients = this.shouldHaveRightGradient(scrollLeft, gradientWidth, clientWidth, scrollWidth);
283
- this.setState({
284
- withLeftGradients,
285
- withRightGradients
286
- });
287
- }
288
-
289
- shouldHaveLeftGradient(scrollLeft, gWidth) {
290
- return Math.abs(scrollLeft) > gWidth;
291
- } // eslint-disable-next-line max-params
292
-
293
-
294
- shouldHaveRightGradient(scrollLeft, gWidth, clientWidth, scrollWidth) {
295
- return Math.abs(scrollLeft) <= scrollWidth - (clientWidth + gWidth);
296
- }
297
-
298
- setIndicatorStyle() {
299
- const {
300
- activeTab
301
- } = this.props;
302
- setTimeout(() => this.setState({
303
- indicatorStyle: this.getIndicatorStyles(activeTab)
304
- }), 100);
305
- }
306
-
307
- getActiveTabElement(activeTab) {
308
- const tabListEl = this.tabListRef.current;
309
- const tabSelector = "[data-tab-id=\"".concat(activeTab, "\"]");
310
- return tabListEl && tabListEl.querySelector(tabSelector);
311
- }
312
-
313
- isElementVisible(el, holder) {
314
- const {
315
- left,
316
- right,
317
- width
318
- } = el.getBoundingClientRect();
319
- const holderRect = holder.getBoundingClientRect();
320
- return left <= holderRect.left ? holderRect.left - left <= width : right - holderRect.right <= width;
321
- }
322
-
323
- getVisibleDimensions(node, referenceNode) {
324
- const pos = node.getBoundingClientRect();
325
- const referencePos = referenceNode.getBoundingClientRect();
326
- return {
327
- width: Math.min(node.clientWidth, referencePos.left + referenceNode.clientWidth - pos.left, node.clientWidth - (referencePos.left - pos.left)),
328
- height: Math.min(node.clientHeight, referencePos.top + referenceNode.clientHeight - pos.top, node.clientHeight - (referencePos.top - pos.top))
329
- };
330
- }
331
-
332
- getIndicatorStyles(activeTab) {
333
- const tabListEl = this.tabListRef.current;
334
- const {
335
- withCarousel
336
- } = this.props;
337
- const activeTabEl = this.getActiveTabElement(activeTab);
338
- if (!activeTabEl || !this.isElementVisible(activeTabEl, tabListEl)) return null;
339
- const {
340
- clientHeight,
341
- clientWidth,
342
- offsetTop,
343
- offsetLeft
344
- } = activeTabEl;
345
- const {
346
- left
347
- } = activeTabEl.getBoundingClientRect();
348
- const leftOff = withCarousel ? Math.max(0, left - tabListEl.getBoundingClientRect().left) : offsetLeft;
349
- const width = withCarousel ? this.getVisibleDimensions(activeTabEl, tabListEl).width + 2 : clientWidth + 2;
350
- return {
351
- height: clientHeight,
352
- left: "".concat(Math.floor(leftOff), "px"),
353
- // using left and top for ie compatibility
354
- top: "".concat(Math.floor(offsetTop), "px"),
355
- width
356
- };
357
- }
358
-
359
- render() {
360
- const {
361
- id,
362
- tabs,
363
- activeTab,
364
- renderCustomTabBar,
365
- withCarousel,
366
- isDSMobile,
367
- flexibleTabsHeaders,
368
- fixedTabsHeaders
369
- } = this.props;
370
- const {
371
- indicatorStyle,
372
- withLeftGradients,
373
- withRightGradients
374
- } = this.state;
375
-
376
- if (renderCustomTabBar) {
377
- return renderCustomTabBar({
378
- innerRef: this.tabListRef,
379
- withCarousel,
380
- tabsComponents: this.renderTabs(activeTab, tabs)
381
- });
382
- }
383
-
384
- const shouldUseCarousel = !isDSMobile && withCarousel;
385
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
386
- children: /*#__PURE__*/_jsx__default["default"](StyledTabList, {
387
- withCarousel: withCarousel,
388
- "aria-label": id,
389
- innerRef: this.tabListRef,
390
- role: "tablist",
391
- "data-testid": "tab-list",
392
- isDSMobile: isDSMobile,
393
- flexibleTabsHeaders: flexibleTabsHeaders,
394
- withLeftGradients: withLeftGradients,
395
- withRightGradients: withRightGradients,
396
- fixedTabsHeaders: fixedTabsHeaders,
397
- onScroll: this.handleTabsHeadersHorizontalScroll,
398
- style: {
399
- width: '100%'
400
- }
401
- }, void 0, /*#__PURE__*/_jsx__default["default"](StyledTabWrapper, {
402
- isDSMobile: isDSMobile,
403
- flexibleTabsHeaders: flexibleTabsHeaders,
404
- fixedTabsHeaders: fixedTabsHeaders
405
- }, void 0, shouldUseCarousel ? /*#__PURE__*/_jsx__default["default"](Carousel, {
406
- onScroll: this.setIndicatorStyle
407
- }, void 0, this.renderTabs(activeTab, tabs)) : null, !shouldUseCarousel ? this.renderTabs(activeTab, tabs) : null, /*#__PURE__*/_jsx__default["default"](SelectionIndicator, {
408
- style: indicatorStyle
409
- })))
410
- });
411
- }
412
-
413
- }
414
-
415
- TabBar.defaultProps = {
416
- showSelectionIndicator: true,
417
- showSeparator: false,
418
- isDSMobile: false
419
- };
420
-
421
- module.exports = TabBar;
package/cjs/TabTypes.js DELETED
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('core-js/modules/esnext.async-iterator.map.js');
6
- require('core-js/modules/esnext.iterator.map.js');
7
-
8
- const TabTypes = {
9
- NORMAL: 'normal',
10
- SUBTABS: 'subtabs'
11
- };
12
- const getTabTypes = () => Object.keys(TabTypes).map(key => TabTypes[key]);
13
-
14
- exports.TabTypes = TabTypes;
15
- exports.getTabTypes = getTabTypes;
package/cjs/TabsImpl.js DELETED
@@ -1,120 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _jsx = require('@babel/runtime/helpers/jsx');
5
- require('core-js/modules/web.dom-collections.iterator.js');
6
- require('core-js/modules/esnext.async-iterator.filter.js');
7
- require('core-js/modules/esnext.iterator.constructor.js');
8
- require('core-js/modules/esnext.iterator.filter.js');
9
- require('core-js/modules/esnext.async-iterator.for-each.js');
10
- require('core-js/modules/esnext.iterator.for-each.js');
11
- var React = require('react');
12
- var dsClassnames = require('@elliemae/ds-classnames');
13
- var TabsPanels = require('./TabsPanels.js');
14
- var TabBar = require('./TabBar.js');
15
- var SubTabBar = require('./SubTabBar.js');
16
- var TabTypes = require('./TabTypes.js');
17
- var jsxRuntime = require('react/jsx-runtime');
18
-
19
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
-
21
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
22
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
23
-
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
25
-
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
- const blockName = 'tabs';
28
- const StyledTabsContainer = dsClassnames.aggregatedClasses('div')(blockName);
29
- const StyledTabBarContainer = dsClassnames.aggregatedClasses('div')(blockName, 'tab-bar-container');
30
- const TabBarComponentsByType = {
31
- [TabTypes.TabTypes.NORMAL]: TabBar,
32
- [TabTypes.TabTypes.SUBTABS]: SubTabBar
33
- };
34
-
35
- const TabsImpl = props => {
36
- var _tabs$, _tabs$$props, _TabsPanels, _StyledTabBarContaine;
37
-
38
- const {
39
- animated,
40
- children: tabs,
41
- type,
42
- tabBarExtraContent,
43
- onTabChange,
44
- enableMouseEvents,
45
- innerRef,
46
- onlyRenderActiveTab,
47
- containerProps,
48
- allowTextSelection,
49
- tabsListAriaLabel,
50
- activeTab,
51
- firstSubtabRef,
52
- lastTabRef,
53
- withCarousel,
54
- flexibleTabsHeaders,
55
- fixedTabsHeaders,
56
- isDSMobile
57
- } = props;
58
- const [actualActiveTab, setActualActiveTab] = React.useState(activeTab || (tabs === null || tabs === void 0 ? void 0 : (_tabs$ = tabs[0]) === null || _tabs$ === void 0 ? void 0 : (_tabs$$props = _tabs$.props) === null || _tabs$$props === void 0 ? void 0 : _tabs$$props.tabId));
59
- const firstTabRefByParent = React.useRef(null);
60
- const lastTabRefByParent = React.useRef(null);
61
- React.useEffect(() => {
62
- if (activeTab) {
63
- setActualActiveTab(activeTab);
64
- }
65
- }, [activeTab]);
66
- const handleTabClick = React.useCallback(tab => {
67
- setActualActiveTab(tab);
68
- onTabChange(tab);
69
- }, [onTabChange]);
70
- const handleDownArrow = React.useCallback(e => {
71
- var _firstTabRefByParent$;
72
-
73
- e.preventDefault();
74
- e.stopPropagation();
75
- if (firstTabRefByParent !== null && firstTabRefByParent !== void 0 && firstTabRefByParent.current) (_firstTabRefByParent$ = firstTabRefByParent.current) === null || _firstTabRefByParent$ === void 0 ? void 0 : _firstTabRefByParent$.focus();
76
- }, [firstTabRefByParent]);
77
- const handleUpArrow = React.useCallback(e => {
78
- var _lastTabRef$current;
79
-
80
- e.preventDefault();
81
- e.stopPropagation();
82
- if (lastTabRef !== null && lastTabRef !== void 0 && lastTabRef.current) (_lastTabRef$current = lastTabRef.current) === null || _lastTabRef$current === void 0 ? void 0 : _lastTabRef$current.focus();
83
- }, [lastTabRef]);
84
- const PureTabBarComponent = React.useMemo(() => {
85
- const TabBarComponent = TabBarComponentsByType[type] || TabBar;
86
- return /*#__PURE__*/_jsx__default["default"](TabBarComponent, {
87
- withCarousel: withCarousel,
88
- activeTab: actualActiveTab,
89
- onTabClick: handleTabClick,
90
- tabs: tabs,
91
- firstSubtabRef: firstSubtabRef,
92
- lastTabRef: lastTabRefByParent,
93
- handleDownArrow: handleDownArrow,
94
- handleUpArrow: handleUpArrow,
95
- isDSMobile: isDSMobile,
96
- flexibleTabsHeaders: flexibleTabsHeaders,
97
- fixedTabsHeaders: fixedTabsHeaders
98
- });
99
- }, [type, withCarousel, actualActiveTab, handleTabClick, tabs, firstSubtabRef, lastTabRefByParent, handleDownArrow, handleUpArrow, isDSMobile]);
100
- const PureTabsPanels = React.useMemo(() => _TabsPanels || (_TabsPanels = /*#__PURE__*/_jsx__default["default"](TabsPanels, {
101
- activeTab: actualActiveTab,
102
- allowTextSelection: allowTextSelection,
103
- animated: animated,
104
- enableMouseEvents: enableMouseEvents,
105
- onlyRenderActiveTab: onlyRenderActiveTab,
106
- onTabChange: handleTabClick,
107
- tabsComponents: tabs,
108
- lastTabRef: lastTabRefByParent,
109
- firstTabRefByParent: firstTabRefByParent
110
- })), [actualActiveTab, allowTextSelection, animated, enableMouseEvents, onlyRenderActiveTab, handleTabClick, tabs, lastTabRefByParent, firstTabRefByParent]);
111
- const PureTabsImpl = React.useMemo(() => /*#__PURE__*/jsxRuntime.jsxs(StyledTabsContainer, _objectSpread(_objectSpread({}, containerProps), {}, {
112
- "aria-label": tabsListAriaLabel,
113
- innerRef: innerRef,
114
- role: "tablist",
115
- children: [_StyledTabBarContaine || (_StyledTabBarContaine = /*#__PURE__*/_jsx__default["default"](StyledTabBarContainer, {}, void 0, PureTabBarComponent, tabBarExtraContent)), PureTabsPanels]
116
- })), [containerProps, tabsListAriaLabel, innerRef, PureTabBarComponent, tabBarExtraContent, PureTabsPanels]);
117
- return PureTabsImpl;
118
- };
119
-
120
- module.exports = TabsImpl;
package/cjs/TabsPanels.js DELETED
@@ -1,85 +0,0 @@
1
- 'use strict';
2
-
3
- var _jsx = require('@babel/runtime/helpers/jsx');
4
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- require('core-js/modules/web.dom-collections.iterator.js');
6
- require('core-js/modules/esnext.async-iterator.map.js');
7
- require('core-js/modules/esnext.iterator.map.js');
8
- var React = require('react');
9
- var memoizeOne = require('memoize-one');
10
- var dsClassnames = require('@elliemae/ds-classnames');
11
- var SwipeableViews = require('react-swipeable-views');
12
- var PanelContainer = require('./PanelContainer.js');
13
-
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
-
16
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
17
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
18
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
- var memoizeOne__default = /*#__PURE__*/_interopDefaultLegacy(memoizeOne);
20
- var SwipeableViews__default = /*#__PURE__*/_interopDefaultLegacy(SwipeableViews);
21
-
22
- const blockName = 'tabs-panels';
23
- const Panels = dsClassnames.aggregatedClasses('div')(blockName);
24
-
25
- const getIndexById = (children, activeId) => children && children.findIndex(item => item.props.tabId === activeId);
26
-
27
- const getIdByIndex = (children, index) => children && children[index].props.tabId;
28
-
29
- class TabsPanels extends React.Component {
30
- constructor() {
31
- super(...arguments);
32
-
33
- _defineProperty__default["default"](this, "renderPanels", memoizeOne__default["default"]((activeTab, tabsComponents) => {
34
- const {
35
- animated,
36
- onlyRenderActiveTab,
37
- allowTextSelection
38
- } = this.props;
39
- return React__default["default"].Children.map(tabsComponents, tab => {
40
- const {
41
- tabId: panelId,
42
- style,
43
- children: content
44
- } = tab.props;
45
- const isActive = activeTab === panelId;
46
- const shouldRender = !onlyRenderActiveTab || isActive;
47
- return /*#__PURE__*/_jsx__default["default"](PanelContainer, {
48
- "aria-labelledby": "".concat(panelId, "-label"),
49
- lastTabRef: this.props.lastTabRef,
50
- firstSubtabRef: this.props.firstTabRefByParent,
51
- classProps: {
52
- isActive
53
- },
54
- "data-panel-id": panelId,
55
- hidden: !animated && !isActive,
56
- onMouseDown: e => {
57
- const role = e.target.getAttribute('role');
58
- if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
59
- },
60
- role: "tabpanel",
61
- style: style
62
- }, panelId, shouldRender && content);
63
- }, null);
64
- }));
65
- }
66
-
67
- render() {
68
- const {
69
- activeTab,
70
- tabsComponents,
71
- animated,
72
- onTabChange,
73
- enableMouseEvents
74
- } = this.props;
75
- const panels = animated ? /*#__PURE__*/_jsx__default["default"](SwipeableViews__default["default"], {
76
- enableMouseEvents: enableMouseEvents,
77
- index: getIndexById(tabsComponents, activeTab),
78
- onChangeIndex: index => onTabChange(getIdByIndex(tabsComponents, index))
79
- }, void 0, this.renderPanels(activeTab, tabsComponents)) : this.renderPanels(activeTab, tabsComponents);
80
- return /*#__PURE__*/_jsx__default["default"](Panels, {}, void 0, panels);
81
- }
82
-
83
- }
84
-
85
- module.exports = TabsPanels;