@elliemae/ds-tabs 2.0.0-alpha.1 → 2.0.0-alpha.13

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 (106) hide show
  1. package/cjs/DSTabs.js +29 -107
  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} +19 -28
  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 -197
  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 -114
  86. package/cjs/TabsPanels.js +0 -82
  87. package/cjs/package.json +0 -7
  88. package/cjs/useResize.js +0 -24
  89. package/esm/Carousel.js +0 -186
  90. package/esm/DSTab.js +0 -33
  91. package/esm/SubTabBar.js +0 -39
  92. package/esm/TabBar.js +0 -399
  93. package/esm/TabTypes.js +0 -7
  94. package/esm/TabsImpl.js +0 -107
  95. package/esm/TabsPanels.js +0 -72
  96. package/esm/package.json +0 -7
  97. package/esm/useResize.js +0 -20
  98. package/types/Carousel.d.ts +0 -16
  99. package/types/DSTab.d.ts +0 -22
  100. package/types/PanelContainer.d.ts +0 -20
  101. package/types/SubTabBar.d.ts +0 -23
  102. package/types/TabBar.d.ts +0 -30
  103. package/types/TabTypes.d.ts +0 -5
  104. package/types/TabsImpl.d.ts +0 -37
  105. package/types/TabsPanels.d.ts +0 -5
  106. 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: `${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="${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 : clientWidth + 2;
339
- return {
340
- height: clientHeight,
341
- left: `${Math.floor(leftOff)}px`,
342
- // using left and top for ie compatibility
343
- top: `${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,114 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _jsx = require('@babel/runtime/helpers/jsx');
5
- var React = require('react');
6
- var dsClassnames = require('@elliemae/ds-classnames');
7
- var TabsPanels = require('./TabsPanels.js');
8
- var TabBar = require('./TabBar.js');
9
- var SubTabBar = require('./SubTabBar.js');
10
- var TabTypes = require('./TabTypes.js');
11
- var jsxRuntime = require('react/jsx-runtime');
12
-
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
16
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
17
-
18
- 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; }
19
-
20
- 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; }
21
- const blockName = 'tabs';
22
- const StyledTabsContainer = dsClassnames.aggregatedClasses('div')(blockName);
23
- const StyledTabBarContainer = dsClassnames.aggregatedClasses('div')(blockName, 'tab-bar-container');
24
- const TabBarComponentsByType = {
25
- [TabTypes.TabTypes.NORMAL]: TabBar,
26
- [TabTypes.TabTypes.SUBTABS]: SubTabBar
27
- };
28
-
29
- const TabsImpl = props => {
30
- var _tabs$, _tabs$$props, _TabsPanels, _StyledTabBarContaine;
31
-
32
- const {
33
- animated,
34
- children: tabs,
35
- type,
36
- tabBarExtraContent,
37
- onTabChange,
38
- enableMouseEvents,
39
- innerRef,
40
- onlyRenderActiveTab,
41
- containerProps,
42
- allowTextSelection,
43
- tabsListAriaLabel,
44
- activeTab,
45
- firstSubtabRef,
46
- lastTabRef,
47
- withCarousel,
48
- flexibleTabsHeaders,
49
- fixedTabsHeaders,
50
- isDSMobile
51
- } = props;
52
- 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));
53
- const firstTabRefByParent = React.useRef(null);
54
- const lastTabRefByParent = React.useRef(null);
55
- React.useEffect(() => {
56
- if (activeTab) {
57
- setActualActiveTab(activeTab);
58
- }
59
- }, [activeTab]);
60
- const handleTabClick = React.useCallback(tab => {
61
- setActualActiveTab(tab);
62
- onTabChange(tab);
63
- }, [onTabChange]);
64
- const handleDownArrow = React.useCallback(e => {
65
- var _firstTabRefByParent$;
66
-
67
- e.preventDefault();
68
- e.stopPropagation();
69
- if (firstTabRefByParent !== null && firstTabRefByParent !== void 0 && firstTabRefByParent.current) (_firstTabRefByParent$ = firstTabRefByParent.current) === null || _firstTabRefByParent$ === void 0 ? void 0 : _firstTabRefByParent$.focus();
70
- }, [firstTabRefByParent]);
71
- const handleUpArrow = React.useCallback(e => {
72
- var _lastTabRef$current;
73
-
74
- e.preventDefault();
75
- e.stopPropagation();
76
- if (lastTabRef !== null && lastTabRef !== void 0 && lastTabRef.current) (_lastTabRef$current = lastTabRef.current) === null || _lastTabRef$current === void 0 ? void 0 : _lastTabRef$current.focus();
77
- }, [lastTabRef]);
78
- const PureTabBarComponent = React.useMemo(() => {
79
- const TabBarComponent = TabBarComponentsByType[type] || TabBar;
80
- return /*#__PURE__*/_jsx__default['default'](TabBarComponent, {
81
- withCarousel: withCarousel,
82
- activeTab: actualActiveTab,
83
- onTabClick: handleTabClick,
84
- tabs: tabs,
85
- firstSubtabRef: firstSubtabRef,
86
- lastTabRef: lastTabRefByParent,
87
- handleDownArrow: handleDownArrow,
88
- handleUpArrow: handleUpArrow,
89
- isDSMobile: isDSMobile,
90
- flexibleTabsHeaders: flexibleTabsHeaders,
91
- fixedTabsHeaders: fixedTabsHeaders
92
- });
93
- }, [type, withCarousel, actualActiveTab, handleTabClick, tabs, firstSubtabRef, lastTabRefByParent, handleDownArrow, handleUpArrow, isDSMobile]);
94
- const PureTabsPanels = React.useMemo(() => _TabsPanels || (_TabsPanels = /*#__PURE__*/_jsx__default['default'](TabsPanels, {
95
- activeTab: actualActiveTab,
96
- allowTextSelection: allowTextSelection,
97
- animated: animated,
98
- enableMouseEvents: enableMouseEvents,
99
- onlyRenderActiveTab: onlyRenderActiveTab,
100
- onTabChange: handleTabClick,
101
- tabsComponents: tabs,
102
- lastTabRef: lastTabRefByParent,
103
- firstTabRefByParent: firstTabRefByParent
104
- })), [actualActiveTab, allowTextSelection, animated, enableMouseEvents, onlyRenderActiveTab, handleTabClick, tabs, lastTabRefByParent, firstTabRefByParent]);
105
- const PureTabsImpl = React.useMemo(() => /*#__PURE__*/jsxRuntime.jsxs(StyledTabsContainer, _objectSpread(_objectSpread({}, containerProps), {}, {
106
- "aria-label": tabsListAriaLabel,
107
- innerRef: innerRef,
108
- role: "tablist",
109
- children: [_StyledTabBarContaine || (_StyledTabBarContaine = /*#__PURE__*/_jsx__default['default'](StyledTabBarContainer, {}, void 0, PureTabBarComponent, tabBarExtraContent)), PureTabsPanels]
110
- })), [containerProps, tabsListAriaLabel, innerRef, PureTabBarComponent, tabBarExtraContent, PureTabsPanels]);
111
- return PureTabsImpl;
112
- };
113
-
114
- module.exports = TabsImpl;
package/cjs/TabsPanels.js DELETED
@@ -1,82 +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 memoizeOne = require('memoize-one');
7
- var dsClassnames = require('@elliemae/ds-classnames');
8
- var SwipeableViews = require('react-swipeable-views');
9
- var PanelContainer = require('./PanelContainer.js');
10
-
11
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
-
13
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
14
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
15
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
- var memoizeOne__default = /*#__PURE__*/_interopDefaultLegacy(memoizeOne);
17
- var SwipeableViews__default = /*#__PURE__*/_interopDefaultLegacy(SwipeableViews);
18
-
19
- const blockName = 'tabs-panels';
20
- const Panels = dsClassnames.aggregatedClasses('div')(blockName);
21
-
22
- const getIndexById = (children, activeId) => children && children.findIndex(item => item.props.tabId === activeId);
23
-
24
- const getIdByIndex = (children, index) => children && children[index].props.tabId;
25
-
26
- class TabsPanels extends React.Component {
27
- constructor(...args) {
28
- super(...args);
29
-
30
- _defineProperty__default['default'](this, "renderPanels", memoizeOne__default['default']((activeTab, tabsComponents) => {
31
- const {
32
- animated,
33
- onlyRenderActiveTab,
34
- allowTextSelection
35
- } = this.props;
36
- return React__default['default'].Children.map(tabsComponents, tab => {
37
- const {
38
- tabId: panelId,
39
- style,
40
- children: content
41
- } = tab.props;
42
- const isActive = activeTab === panelId;
43
- const shouldRender = !onlyRenderActiveTab || isActive;
44
- return /*#__PURE__*/_jsx__default['default'](PanelContainer, {
45
- "aria-labelledby": `${panelId}-label`,
46
- lastTabRef: this.props.lastTabRef,
47
- firstSubtabRef: this.props.firstTabRefByParent,
48
- classProps: {
49
- isActive
50
- },
51
- "data-panel-id": panelId,
52
- hidden: !animated && !isActive,
53
- onMouseDown: e => {
54
- const role = e.target.getAttribute('role');
55
- if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
56
- },
57
- role: "tabpanel",
58
- style: style
59
- }, panelId, shouldRender && content);
60
- }, null);
61
- }));
62
- }
63
-
64
- render() {
65
- const {
66
- activeTab,
67
- tabsComponents,
68
- animated,
69
- onTabChange,
70
- enableMouseEvents
71
- } = this.props;
72
- const panels = animated ? /*#__PURE__*/_jsx__default['default'](SwipeableViews__default['default'], {
73
- enableMouseEvents: enableMouseEvents,
74
- index: getIndexById(tabsComponents, activeTab),
75
- onChangeIndex: index => onTabChange(getIdByIndex(tabsComponents, index))
76
- }, void 0, this.renderPanels(activeTab, tabsComponents)) : this.renderPanels(activeTab, tabsComponents);
77
- return /*#__PURE__*/_jsx__default['default'](Panels, {}, void 0, panels);
78
- }
79
-
80
- }
81
-
82
- module.exports = TabsPanels;
package/cjs/package.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "sideEffects": [
4
- "*.css",
5
- "*.scss"
6
- ]
7
- }
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;