@elliemae/ds-tabs 2.0.0-alpha.11 → 2.0.0-alpha.12

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