@elliemae/ds-tabs 2.0.0-rc.9 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/DSTabs.js +27 -108
- package/cjs/DSTabsCTX.js +30 -0
- package/cjs/DSTabsDatatestid.js +18 -0
- package/cjs/DSTabsTypes.js +2 -0
- package/cjs/config/useCrossRef.js +17 -0
- package/cjs/config/useTabs.js +51 -0
- package/cjs/defaultProps.js +27 -0
- package/cjs/exportsRelated/DSTab.js +32 -0
- package/cjs/index.js +5 -5
- package/cjs/parts/carousel/Carousel.js +71 -0
- package/cjs/parts/carousel/styles.js +60 -0
- package/cjs/parts/carousel/useCarousel.js +78 -0
- package/cjs/parts/carousel/useCarouselCallbacks.js +72 -0
- package/cjs/parts/tabBar/TabBar.js +160 -0
- package/cjs/parts/tabBar/styles.js +199 -0
- package/cjs/parts/tabBar/useTabBar.js +98 -0
- package/cjs/parts/tabsContent/TabsContent.js +49 -0
- package/cjs/parts/tabsContent/styles.js +15 -0
- package/cjs/parts/tabsPanel/TabsPanels.js +77 -0
- package/cjs/parts/tabsPanel/styles.js +25 -0
- package/cjs/propTypes.js +33 -0
- package/cjs/utils/constants.js +29 -0
- package/cjs/utils/helpers.js +47 -0
- package/cjs/utils/hooks/useKeyboardNavigation.js +61 -0
- package/cjs/utils/hooks/useTabsCallbacks.js +59 -0
- package/esm/DSTabs.js +29 -110
- package/esm/DSTabsCTX.js +25 -0
- package/esm/DSTabsDatatestid.js +14 -0
- package/esm/DSTabsTypes.js +1 -0
- package/esm/config/useCrossRef.js +13 -0
- package/esm/config/useTabs.js +47 -0
- package/esm/defaultProps.js +23 -0
- package/esm/exportsRelated/DSTab.js +21 -0
- package/esm/index.js +4 -3
- package/esm/parts/carousel/Carousel.js +63 -0
- package/esm/parts/carousel/styles.js +49 -0
- package/esm/parts/carousel/useCarousel.js +70 -0
- package/esm/parts/carousel/useCarouselCallbacks.js +68 -0
- package/esm/parts/tabBar/TabBar.js +151 -0
- package/esm/parts/tabBar/styles.js +185 -0
- package/esm/parts/tabBar/useTabBar.js +90 -0
- package/esm/parts/tabsContent/TabsContent.js +40 -0
- package/esm/parts/tabsContent/styles.js +7 -0
- package/esm/parts/tabsPanel/TabsPanels.js +67 -0
- package/esm/parts/tabsPanel/styles.js +17 -0
- package/esm/propTypes.js +28 -0
- package/esm/utils/constants.js +21 -0
- package/esm/utils/helpers.js +37 -0
- package/esm/utils/hooks/useKeyboardNavigation.js +57 -0
- package/esm/utils/hooks/useTabsCallbacks.js +55 -0
- package/package.json +91 -35
- package/types/DSTabs.d.ts +6 -165
- package/types/DSTabsCTX.d.ts +4 -0
- package/types/DSTabsDatatestid.d.ts +12 -0
- package/types/DSTabsTypes.d.ts +202 -0
- package/types/config/useCrossRef.d.ts +2 -0
- package/types/config/useTabs.d.ts +2 -0
- package/types/defaultProps.d.ts +2 -0
- package/types/exportsRelated/DSTab.d.ts +14 -0
- package/types/index.d.ts +4 -3
- package/types/parts/carousel/Carousel.d.ts +3 -0
- package/types/parts/carousel/styles.d.ts +9 -0
- package/types/parts/carousel/useCarousel.d.ts +2 -0
- package/types/parts/carousel/useCarouselCallbacks.d.ts +2 -0
- package/types/parts/tabBar/TabBar.d.ts +2 -0
- package/types/parts/tabBar/styles.d.ts +7 -0
- package/types/parts/tabBar/useTabBar.d.ts +2 -0
- package/types/parts/tabsContent/TabsContent.d.ts +2 -0
- package/types/parts/tabsContent/styles.d.ts +1 -0
- package/types/parts/tabsPanel/TabsPanels.d.ts +2 -0
- package/types/parts/tabsPanel/styles.d.ts +2 -0
- package/types/propTypes.d.ts +54 -0
- package/types/tests/{DSTabs.events.test.d.ts → DSTabs.callbacks.test.d.ts} +0 -0
- package/types/tests/DSTabs.func.test.d.ts +1 -0
- package/types/tests/DSTabs.keyboard.test.d.ts +1 -0
- package/types/utils/constants.d.ts +19 -0
- package/types/utils/helpers.d.ts +8 -0
- package/types/utils/hooks/useKeyboardNavigation.d.ts +2 -0
- package/types/utils/hooks/useTabsCallbacks.d.ts +2 -0
- package/cjs/Carousel.js +0 -205
- package/cjs/DSTab.js +0 -46
- package/cjs/PanelContainer.js +0 -48
- package/cjs/SubTabBar.js +0 -54
- package/cjs/TabBar.js +0 -421
- package/cjs/TabTypes.js +0 -15
- package/cjs/TabsImpl.js +0 -120
- package/cjs/TabsPanels.js +0 -85
- package/cjs/useResize.js +0 -24
- package/esm/Carousel.js +0 -196
- package/esm/DSTab.js +0 -36
- package/esm/PanelContainer.js +0 -40
- package/esm/SubTabBar.js +0 -48
- package/esm/TabBar.js +0 -410
- package/esm/TabTypes.js +0 -10
- package/esm/TabsImpl.js +0 -113
- package/esm/TabsPanels.js +0 -75
- package/esm/useResize.js +0 -20
- package/types/Carousel.d.ts +0 -16
- package/types/DSTab.d.ts +0 -51
- package/types/PanelContainer.d.ts +0 -20
- package/types/SubTabBar.d.ts +0 -23
- package/types/TabBar.d.ts +0 -30
- package/types/TabTypes.d.ts +0 -5
- package/types/TabsImpl.d.ts +0 -37
- package/types/TabsPanels.d.ts +0 -5
- package/types/useResize.d.ts +0 -1
package/esm/TabBar.js
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
3
|
-
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
4
|
-
import 'core-js/modules/esnext.iterator.map.js';
|
|
5
|
-
import React, { Component } from 'react';
|
|
6
|
-
import { debounce } from 'lodash';
|
|
7
|
-
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
8
|
-
import RequiredMark from '@elliemae/ds-form/RequiredMark';
|
|
9
|
-
import memoizeOne from 'memoize-one';
|
|
10
|
-
import { ResizeObserver } from 'resize-observer';
|
|
11
|
-
import styled from 'styled-components';
|
|
12
|
-
import Carousel from './Carousel.js';
|
|
13
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
14
|
-
|
|
15
|
-
const blockName = 'tabs-tab-bar';
|
|
16
|
-
const gradientWidth = 24;
|
|
17
|
-
const StyledTabWrapper = /*#__PURE__*/styled.div.withConfig({
|
|
18
|
-
componentId: "sc-7sdovg-0"
|
|
19
|
-
})(["display:flex;flex:1;flex-wrap:nowrap;", ";"], _ref => {
|
|
20
|
-
let {
|
|
21
|
-
flexibleTabsHeaders
|
|
22
|
-
} = _ref;
|
|
23
|
-
return flexibleTabsHeaders ? '' : 'overflow-x: hidden';
|
|
24
|
-
});
|
|
25
|
-
const StyledTabList = aggregatedClasses('div')(blockName, 'list', _ref2 => {
|
|
26
|
-
let {
|
|
27
|
-
withCarousel,
|
|
28
|
-
flexibleTabsHeaders,
|
|
29
|
-
fixedTabsHeaders,
|
|
30
|
-
isDSMobile,
|
|
31
|
-
withLeftGradients,
|
|
32
|
-
withRightGradients
|
|
33
|
-
} = _ref2;
|
|
34
|
-
return {
|
|
35
|
-
carousel: withCarousel,
|
|
36
|
-
'flexible-table-headers': isDSMobile && flexibleTabsHeaders,
|
|
37
|
-
'fixed-table-headers': isDSMobile && fixedTabsHeaders,
|
|
38
|
-
'left-gradients': isDSMobile && flexibleTabsHeaders && withLeftGradients,
|
|
39
|
-
'right-gradients': isDSMobile && flexibleTabsHeaders && withRightGradients
|
|
40
|
-
};
|
|
41
|
-
}, {
|
|
42
|
-
propsToRemoveFromFinalElement: ['withCarousel', 'flexibleTabsHeaders', 'fixedTabsHeaders', 'withLeftGradients', 'withRightGradients', 'isDSMobile']
|
|
43
|
-
});
|
|
44
|
-
const TabContainer = aggregatedClasses('button', {
|
|
45
|
-
role: 'tab'
|
|
46
|
-
})(blockName, 'tab', _ref3 => {
|
|
47
|
-
let {
|
|
48
|
-
isActive,
|
|
49
|
-
showSeparator,
|
|
50
|
-
disabled
|
|
51
|
-
} = _ref3;
|
|
52
|
-
return {
|
|
53
|
-
active: isActive,
|
|
54
|
-
separator: showSeparator,
|
|
55
|
-
disabled
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
const SelectionIndicator = aggregatedClasses('div')(blockName, 'selection-indicator');
|
|
59
|
-
|
|
60
|
-
class TabBar extends Component {
|
|
61
|
-
constructor(_props) {
|
|
62
|
-
super(_props);
|
|
63
|
-
|
|
64
|
-
_defineProperty(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(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(this, "handleTabsHeadersHorizontalScroll", 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(this, "renderTabs", memoizeOne((activeTab, tabs) => {
|
|
167
|
-
const {
|
|
168
|
-
showSeparator
|
|
169
|
-
} = this.props;
|
|
170
|
-
return React.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__*/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(RequiredMark, {
|
|
211
|
-
required: required
|
|
212
|
-
})]
|
|
213
|
-
}, tabId)];
|
|
214
|
-
}, null);
|
|
215
|
-
}));
|
|
216
|
-
|
|
217
|
-
this.tabListRef = /*#__PURE__*/React.createRef();
|
|
218
|
-
this.resizeObserver = new 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__*/jsx(Fragment, {
|
|
375
|
-
children: /*#__PURE__*/_jsx(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(StyledTabWrapper, {
|
|
391
|
-
isDSMobile: isDSMobile,
|
|
392
|
-
flexibleTabsHeaders: flexibleTabsHeaders,
|
|
393
|
-
fixedTabsHeaders: fixedTabsHeaders
|
|
394
|
-
}, void 0, shouldUseCarousel ? /*#__PURE__*/_jsx(Carousel, {
|
|
395
|
-
onScroll: this.setIndicatorStyle
|
|
396
|
-
}, void 0, this.renderTabs(activeTab, tabs)) : null, !shouldUseCarousel ? this.renderTabs(activeTab, tabs) : null, /*#__PURE__*/_jsx(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
|
-
export { TabBar as default };
|
package/esm/TabTypes.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.map.js';
|
|
3
|
-
|
|
4
|
-
const TabTypes = {
|
|
5
|
-
NORMAL: 'normal',
|
|
6
|
-
SUBTABS: 'subtabs'
|
|
7
|
-
};
|
|
8
|
-
const getTabTypes = () => Object.keys(TabTypes).map(key => TabTypes[key]);
|
|
9
|
-
|
|
10
|
-
export { TabTypes, getTabTypes };
|
package/esm/TabsImpl.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
-
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
-
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
-
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
8
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
9
|
-
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
10
|
-
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
11
|
-
import TabsPanels from './TabsPanels.js';
|
|
12
|
-
import TabBar from './TabBar.js';
|
|
13
|
-
import SubTabBar from './SubTabBar.js';
|
|
14
|
-
import { TabTypes } from './TabTypes.js';
|
|
15
|
-
import { jsxs } from 'react/jsx-runtime';
|
|
16
|
-
|
|
17
|
-
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; }
|
|
18
|
-
|
|
19
|
-
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(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; }
|
|
20
|
-
const blockName = 'tabs';
|
|
21
|
-
const StyledTabsContainer = aggregatedClasses('div')(blockName);
|
|
22
|
-
const StyledTabBarContainer = aggregatedClasses('div')(blockName, 'tab-bar-container');
|
|
23
|
-
const TabBarComponentsByType = {
|
|
24
|
-
[TabTypes.NORMAL]: TabBar,
|
|
25
|
-
[TabTypes.SUBTABS]: SubTabBar
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const TabsImpl = props => {
|
|
29
|
-
var _tabs$, _tabs$$props, _TabsPanels, _StyledTabBarContaine;
|
|
30
|
-
|
|
31
|
-
const {
|
|
32
|
-
animated,
|
|
33
|
-
children: tabs,
|
|
34
|
-
type,
|
|
35
|
-
tabBarExtraContent,
|
|
36
|
-
onTabChange,
|
|
37
|
-
enableMouseEvents,
|
|
38
|
-
innerRef,
|
|
39
|
-
onlyRenderActiveTab,
|
|
40
|
-
containerProps,
|
|
41
|
-
allowTextSelection,
|
|
42
|
-
tabsListAriaLabel,
|
|
43
|
-
activeTab,
|
|
44
|
-
firstSubtabRef,
|
|
45
|
-
lastTabRef,
|
|
46
|
-
withCarousel,
|
|
47
|
-
flexibleTabsHeaders,
|
|
48
|
-
fixedTabsHeaders,
|
|
49
|
-
isDSMobile
|
|
50
|
-
} = props;
|
|
51
|
-
const [actualActiveTab, setActualActiveTab] = 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));
|
|
52
|
-
const firstTabRefByParent = useRef(null);
|
|
53
|
-
const lastTabRefByParent = useRef(null);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (activeTab) {
|
|
56
|
-
setActualActiveTab(activeTab);
|
|
57
|
-
}
|
|
58
|
-
}, [activeTab]);
|
|
59
|
-
const handleTabClick = useCallback(tab => {
|
|
60
|
-
setActualActiveTab(tab);
|
|
61
|
-
onTabChange(tab);
|
|
62
|
-
}, [onTabChange]);
|
|
63
|
-
const handleDownArrow = useCallback(e => {
|
|
64
|
-
var _firstTabRefByParent$;
|
|
65
|
-
|
|
66
|
-
e.preventDefault();
|
|
67
|
-
e.stopPropagation();
|
|
68
|
-
if (firstTabRefByParent !== null && firstTabRefByParent !== void 0 && firstTabRefByParent.current) (_firstTabRefByParent$ = firstTabRefByParent.current) === null || _firstTabRefByParent$ === void 0 ? void 0 : _firstTabRefByParent$.focus();
|
|
69
|
-
}, [firstTabRefByParent]);
|
|
70
|
-
const handleUpArrow = useCallback(e => {
|
|
71
|
-
var _lastTabRef$current;
|
|
72
|
-
|
|
73
|
-
e.preventDefault();
|
|
74
|
-
e.stopPropagation();
|
|
75
|
-
if (lastTabRef !== null && lastTabRef !== void 0 && lastTabRef.current) (_lastTabRef$current = lastTabRef.current) === null || _lastTabRef$current === void 0 ? void 0 : _lastTabRef$current.focus();
|
|
76
|
-
}, [lastTabRef]);
|
|
77
|
-
const PureTabBarComponent = useMemo(() => {
|
|
78
|
-
const TabBarComponent = TabBarComponentsByType[type] || TabBar;
|
|
79
|
-
return /*#__PURE__*/_jsx(TabBarComponent, {
|
|
80
|
-
withCarousel: withCarousel,
|
|
81
|
-
activeTab: actualActiveTab,
|
|
82
|
-
onTabClick: handleTabClick,
|
|
83
|
-
tabs: tabs,
|
|
84
|
-
firstSubtabRef: firstSubtabRef,
|
|
85
|
-
lastTabRef: lastTabRefByParent,
|
|
86
|
-
handleDownArrow: handleDownArrow,
|
|
87
|
-
handleUpArrow: handleUpArrow,
|
|
88
|
-
isDSMobile: isDSMobile,
|
|
89
|
-
flexibleTabsHeaders: flexibleTabsHeaders,
|
|
90
|
-
fixedTabsHeaders: fixedTabsHeaders
|
|
91
|
-
});
|
|
92
|
-
}, [type, withCarousel, actualActiveTab, handleTabClick, tabs, firstSubtabRef, lastTabRefByParent, handleDownArrow, handleUpArrow, isDSMobile]);
|
|
93
|
-
const PureTabsPanels = useMemo(() => _TabsPanels || (_TabsPanels = /*#__PURE__*/_jsx(TabsPanels, {
|
|
94
|
-
activeTab: actualActiveTab,
|
|
95
|
-
allowTextSelection: allowTextSelection,
|
|
96
|
-
animated: animated,
|
|
97
|
-
enableMouseEvents: enableMouseEvents,
|
|
98
|
-
onlyRenderActiveTab: onlyRenderActiveTab,
|
|
99
|
-
onTabChange: handleTabClick,
|
|
100
|
-
tabsComponents: tabs,
|
|
101
|
-
lastTabRef: lastTabRefByParent,
|
|
102
|
-
firstTabRefByParent: firstTabRefByParent
|
|
103
|
-
})), [actualActiveTab, allowTextSelection, animated, enableMouseEvents, onlyRenderActiveTab, handleTabClick, tabs, lastTabRefByParent, firstTabRefByParent]);
|
|
104
|
-
const PureTabsImpl = useMemo(() => /*#__PURE__*/jsxs(StyledTabsContainer, _objectSpread(_objectSpread({}, containerProps), {}, {
|
|
105
|
-
"aria-label": tabsListAriaLabel,
|
|
106
|
-
innerRef: innerRef,
|
|
107
|
-
role: "tablist",
|
|
108
|
-
children: [_StyledTabBarContaine || (_StyledTabBarContaine = /*#__PURE__*/_jsx(StyledTabBarContainer, {}, void 0, PureTabBarComponent, tabBarExtraContent)), PureTabsPanels]
|
|
109
|
-
})), [containerProps, tabsListAriaLabel, innerRef, PureTabBarComponent, tabBarExtraContent, PureTabsPanels]);
|
|
110
|
-
return PureTabsImpl;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export { TabsImpl as default };
|
package/esm/TabsPanels.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
3
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
4
|
-
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
5
|
-
import 'core-js/modules/esnext.iterator.map.js';
|
|
6
|
-
import React, { Component } from 'react';
|
|
7
|
-
import memoizeOne from 'memoize-one';
|
|
8
|
-
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
9
|
-
import SwipeableViews from 'react-swipeable-views';
|
|
10
|
-
import PanelContainer from './PanelContainer.js';
|
|
11
|
-
|
|
12
|
-
const blockName = 'tabs-panels';
|
|
13
|
-
const Panels = aggregatedClasses('div')(blockName);
|
|
14
|
-
|
|
15
|
-
const getIndexById = (children, activeId) => children && children.findIndex(item => item.props.tabId === activeId);
|
|
16
|
-
|
|
17
|
-
const getIdByIndex = (children, index) => children && children[index].props.tabId;
|
|
18
|
-
|
|
19
|
-
class TabsPanels extends Component {
|
|
20
|
-
constructor() {
|
|
21
|
-
super(...arguments);
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "renderPanels", memoizeOne((activeTab, tabsComponents) => {
|
|
24
|
-
const {
|
|
25
|
-
animated,
|
|
26
|
-
onlyRenderActiveTab,
|
|
27
|
-
allowTextSelection
|
|
28
|
-
} = this.props;
|
|
29
|
-
return React.Children.map(tabsComponents, tab => {
|
|
30
|
-
const {
|
|
31
|
-
tabId: panelId,
|
|
32
|
-
style,
|
|
33
|
-
children: content
|
|
34
|
-
} = tab.props;
|
|
35
|
-
const isActive = activeTab === panelId;
|
|
36
|
-
const shouldRender = !onlyRenderActiveTab || isActive;
|
|
37
|
-
return /*#__PURE__*/_jsx(PanelContainer, {
|
|
38
|
-
"aria-labelledby": "".concat(panelId, "-label"),
|
|
39
|
-
lastTabRef: this.props.lastTabRef,
|
|
40
|
-
firstSubtabRef: this.props.firstTabRefByParent,
|
|
41
|
-
classProps: {
|
|
42
|
-
isActive
|
|
43
|
-
},
|
|
44
|
-
"data-panel-id": panelId,
|
|
45
|
-
hidden: !animated && !isActive,
|
|
46
|
-
onMouseDown: e => {
|
|
47
|
-
const role = e.target.getAttribute('role');
|
|
48
|
-
if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
|
|
49
|
-
},
|
|
50
|
-
role: "tabpanel",
|
|
51
|
-
style: style
|
|
52
|
-
}, panelId, shouldRender && content);
|
|
53
|
-
}, null);
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
render() {
|
|
58
|
-
const {
|
|
59
|
-
activeTab,
|
|
60
|
-
tabsComponents,
|
|
61
|
-
animated,
|
|
62
|
-
onTabChange,
|
|
63
|
-
enableMouseEvents
|
|
64
|
-
} = this.props;
|
|
65
|
-
const panels = animated ? /*#__PURE__*/_jsx(SwipeableViews, {
|
|
66
|
-
enableMouseEvents: enableMouseEvents,
|
|
67
|
-
index: getIndexById(tabsComponents, activeTab),
|
|
68
|
-
onChangeIndex: index => onTabChange(getIdByIndex(tabsComponents, index))
|
|
69
|
-
}, void 0, this.renderPanels(activeTab, tabsComponents)) : this.renderPanels(activeTab, tabsComponents);
|
|
70
|
-
return /*#__PURE__*/_jsx(Panels, {}, void 0, panels);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { TabsPanels as default };
|
package/esm/useResize.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react';
|
|
2
|
-
import { debounce } from 'lodash';
|
|
3
|
-
|
|
4
|
-
function useResize(ref, callback) {
|
|
5
|
-
var _ref$current;
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
right,
|
|
9
|
-
left
|
|
10
|
-
} = (ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect()) || {
|
|
11
|
-
right: null,
|
|
12
|
-
left: null
|
|
13
|
-
};
|
|
14
|
-
const handleResize = debounce(callback, 300);
|
|
15
|
-
useLayoutEffect(() => {
|
|
16
|
-
handleResize();
|
|
17
|
-
}, [right, left]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { useResize };
|
package/types/Carousel.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
declare const Carousel: {
|
|
4
|
-
({ children, onScroll }: {
|
|
5
|
-
children: any;
|
|
6
|
-
onScroll: any;
|
|
7
|
-
}): JSX.Element;
|
|
8
|
-
defaultProps: {
|
|
9
|
-
onScroll: () => null;
|
|
10
|
-
};
|
|
11
|
-
propTypes: {
|
|
12
|
-
children: PropTypes.Validator<(PropTypes.ReactElementLike | null | undefined)[]>;
|
|
13
|
-
onScroll: PropTypes.Requireable<(...args: any[]) => any>;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export default Carousel;
|
package/types/DSTab.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
-
/// <reference types="react" />
|
|
3
|
-
declare const DSTab: {
|
|
4
|
-
({ tabId, title, required }: {
|
|
5
|
-
tabId?: string | undefined;
|
|
6
|
-
title?: string | undefined;
|
|
7
|
-
required?: boolean | undefined;
|
|
8
|
-
}): JSX.Element;
|
|
9
|
-
displayName: string;
|
|
10
|
-
propTypes: {
|
|
11
|
-
/** unique id for tab */
|
|
12
|
-
tabId: {
|
|
13
|
-
defaultValue<T = unknown>(arg: T): {
|
|
14
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
15
|
-
};
|
|
16
|
-
isRequired: import("react-desc").PropTypesDescValidator;
|
|
17
|
-
};
|
|
18
|
-
/** tab title */
|
|
19
|
-
title: {
|
|
20
|
-
defaultValue<T = unknown>(arg: T): {
|
|
21
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
22
|
-
};
|
|
23
|
-
isRequired: import("react-desc").PropTypesDescValidator;
|
|
24
|
-
};
|
|
25
|
-
/** Show a required mark next to the title */
|
|
26
|
-
required: {
|
|
27
|
-
defaultValue<T = unknown>(arg: T): {
|
|
28
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
29
|
-
};
|
|
30
|
-
isRequired: import("react-desc").PropTypesDescValidator;
|
|
31
|
-
};
|
|
32
|
-
/** Whether or not it's a ds-tab from DSMobile tabs */
|
|
33
|
-
isDSMobile: {
|
|
34
|
-
defaultValue<T = unknown>(arg: T): {
|
|
35
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
36
|
-
};
|
|
37
|
-
isRequired: import("react-desc").PropTypesDescValidator;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
declare const DSTabWithSchema: {
|
|
42
|
-
(props?: {
|
|
43
|
-
tabId?: string | undefined;
|
|
44
|
-
title?: string | undefined;
|
|
45
|
-
required?: boolean | undefined;
|
|
46
|
-
} | undefined): JSX.Element;
|
|
47
|
-
propTypes: unknown;
|
|
48
|
-
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
49
|
-
};
|
|
50
|
-
export { DSTab, DSTabWithSchema };
|
|
51
|
-
export default DSTab;
|