@elliemae/ds-tabs 2.0.0-rc.1 → 2.0.0-rc.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 (105) hide show
  1. package/cjs/DSTabs.js +27 -108
  2. package/cjs/DSTabsCTX.js +30 -0
  3. package/cjs/DSTabsDatatestid.js +18 -0
  4. package/cjs/DSTabsTypes.js +2 -0
  5. package/cjs/config/useCrossRef.js +17 -0
  6. package/cjs/config/useTabs.js +51 -0
  7. package/cjs/defaultProps.js +27 -0
  8. package/cjs/{PanelContainer.js → exportsRelated/DSTab.js} +14 -30
  9. package/cjs/index.js +5 -5
  10. package/cjs/parts/carousel/Carousel.js +71 -0
  11. package/cjs/parts/carousel/styles.js +60 -0
  12. package/cjs/parts/carousel/useCarousel.js +91 -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 +30 -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/{useResize.js → utils/hooks/useResize.js} +8 -4
  26. package/cjs/utils/hooks/useTabsCallbacks.js +59 -0
  27. package/esm/DSTabs.js +29 -110
  28. package/esm/DSTabsCTX.js +25 -0
  29. package/esm/DSTabsDatatestid.js +14 -0
  30. package/esm/DSTabsTypes.js +1 -0
  31. package/esm/config/useCrossRef.js +13 -0
  32. package/esm/config/useTabs.js +47 -0
  33. package/esm/defaultProps.js +23 -0
  34. package/esm/{PanelContainer.js → exportsRelated/DSTab.js} +7 -26
  35. package/esm/index.js +4 -3
  36. package/esm/parts/carousel/Carousel.js +63 -0
  37. package/esm/parts/carousel/styles.js +49 -0
  38. package/esm/parts/carousel/useCarousel.js +87 -0
  39. package/esm/parts/carousel/useCarouselCallbacks.js +68 -0
  40. package/esm/parts/tabBar/TabBar.js +151 -0
  41. package/esm/parts/tabBar/styles.js +185 -0
  42. package/esm/parts/tabBar/useTabBar.js +90 -0
  43. package/esm/parts/tabsContent/TabsContent.js +40 -0
  44. package/esm/parts/tabsContent/styles.js +7 -0
  45. package/esm/parts/tabsPanel/TabsPanels.js +67 -0
  46. package/esm/parts/tabsPanel/styles.js +22 -0
  47. package/esm/propTypes.js +28 -0
  48. package/esm/utils/constants.js +21 -0
  49. package/esm/utils/helpers.js +37 -0
  50. package/esm/utils/hooks/useKeyboardNavigation.js +57 -0
  51. package/esm/{useResize.js → utils/hooks/useResize.js} +9 -5
  52. package/esm/utils/hooks/useTabsCallbacks.js +55 -0
  53. package/package.json +103 -36
  54. package/types/DSTabs.d.ts +10 -60
  55. package/types/DSTabsCTX.d.ts +4 -0
  56. package/types/DSTabsDatatestid.d.ts +12 -0
  57. package/types/DSTabsTypes.d.ts +202 -0
  58. package/types/config/useCrossRef.d.ts +2 -0
  59. package/types/config/useTabs.d.ts +2 -0
  60. package/types/defaultProps.d.ts +2 -0
  61. package/types/exportsRelated/DSTab.d.ts +14 -0
  62. package/types/index.d.ts +4 -3
  63. package/types/parts/carousel/Carousel.d.ts +3 -0
  64. package/types/parts/carousel/styles.d.ts +9 -0
  65. package/types/parts/carousel/useCarousel.d.ts +2 -0
  66. package/types/parts/carousel/useCarouselCallbacks.d.ts +2 -0
  67. package/types/parts/tabBar/TabBar.d.ts +2 -0
  68. package/types/parts/tabBar/styles.d.ts +7 -0
  69. package/types/parts/tabBar/useTabBar.d.ts +2 -0
  70. package/types/parts/tabsContent/TabsContent.d.ts +2 -0
  71. package/types/parts/tabsContent/styles.d.ts +1 -0
  72. package/types/parts/tabsPanel/TabsPanels.d.ts +2 -0
  73. package/types/parts/tabsPanel/styles.d.ts +2 -0
  74. package/types/propTypes.d.ts +54 -0
  75. package/types/tests/{DSTabs.events.test.d.ts → DSTabs.callbacks.test.d.ts} +0 -0
  76. package/types/tests/DSTabs.func.test.d.ts +1 -0
  77. package/types/tests/DSTabs.keyboard.test.d.ts +1 -0
  78. package/types/utils/constants.d.ts +19 -0
  79. package/types/utils/helpers.d.ts +8 -0
  80. package/types/utils/hooks/useKeyboardNavigation.d.ts +2 -0
  81. package/types/utils/hooks/useResize.d.ts +2 -0
  82. package/types/utils/hooks/useTabsCallbacks.d.ts +2 -0
  83. package/cjs/Carousel.js +0 -205
  84. package/cjs/DSTab.js +0 -46
  85. package/cjs/SubTabBar.js +0 -54
  86. package/cjs/TabBar.js +0 -421
  87. package/cjs/TabTypes.js +0 -15
  88. package/cjs/TabsImpl.js +0 -120
  89. package/cjs/TabsPanels.js +0 -85
  90. package/esm/Carousel.js +0 -196
  91. package/esm/DSTab.js +0 -36
  92. package/esm/SubTabBar.js +0 -48
  93. package/esm/TabBar.js +0 -410
  94. package/esm/TabTypes.js +0 -10
  95. package/esm/TabsImpl.js +0 -113
  96. package/esm/TabsPanels.js +0 -75
  97. package/types/Carousel.d.ts +0 -16
  98. package/types/DSTab.d.ts +0 -22
  99. package/types/PanelContainer.d.ts +0 -20
  100. package/types/SubTabBar.d.ts +0 -23
  101. package/types/TabBar.d.ts +0 -30
  102. package/types/TabTypes.d.ts +0 -5
  103. package/types/TabsImpl.d.ts +0 -37
  104. package/types/TabsPanels.d.ts +0 -5
  105. package/types/useResize.d.ts +0 -1
package/cjs/Carousel.js DELETED
@@ -1,205 +0,0 @@
1
- 'use strict';
2
-
3
- var _jsx = require('@babel/runtime/helpers/jsx');
4
- require('core-js/modules/web.dom-collections.iterator.js');
5
- require('core-js/modules/esnext.async-iterator.reduce.js');
6
- require('core-js/modules/esnext.iterator.constructor.js');
7
- require('core-js/modules/esnext.iterator.reduce.js');
8
- require('core-js/modules/esnext.async-iterator.map.js');
9
- require('core-js/modules/esnext.iterator.map.js');
10
- var React = require('react');
11
- var dsIcons = require('@elliemae/ds-icons');
12
- var styled = require('styled-components');
13
- var DSButton = require('@elliemae/ds-button');
14
- var useResize = require('./useResize.js');
15
- var jsxRuntime = require('react/jsx-runtime');
16
-
17
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
-
19
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
20
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
- var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
22
- var DSButton__default = /*#__PURE__*/_interopDefaultLegacy(DSButton);
23
-
24
- const CarouselBtn = /*#__PURE__*/styled__default["default"](DSButton__default["default"]).withConfig({
25
- componentId: "sc-1317h31-0"
26
- })(["position:absolute;z-index:1;margin:0;&:focus{& span{background-color:", ";background-size:90%;border-radius:2px;border-color:transparent;}}&&{width:16px;height:calc(100% - 2px);@media (min-width:", "){height:calc(100% - 4px);&:focus{& span{background-color:unset;}}}}", " && .em-ds-icon{height:16px;width:16px;}"], props => props.theme.colors.brand[200], _ref => {
27
- let {
28
- theme
29
- } = _ref;
30
- return theme.breakpoints.medium;
31
- }, props => props.right ? 'right: 0;' : 'left: 0;');
32
- const CarouselWrapper = /*#__PURE__*/styled__default["default"].span.withConfig({
33
- componentId: "sc-1317h31-1"
34
- })(["position:relative;padding:0 16px;width:100%;"]);
35
- const ChildrenWrap = /*#__PURE__*/styled__default["default"].div.withConfig({
36
- componentId: "sc-1317h31-2"
37
- })(["display:flex;flex-wrap:nowrap;flex:1;overflow:hidden;"]);
38
-
39
- function isVisibleElement(el, container) {
40
- const rect = el.getBoundingClientRect();
41
- const cRect = container.getBoundingClientRect();
42
- const elemLeft = rect.left + 3;
43
- const elemRight = rect.right - 3; // Only completely visible elements return true:
44
-
45
- const isVisible = elemLeft >= cRect.left && elemRight <= cRect.right;
46
- return isVisible;
47
- }
48
-
49
- const Carousel = _ref2 => {
50
- let {
51
- children,
52
- onScroll
53
- } = _ref2;
54
- const itemsRef = React.useRef([]);
55
- const wrapRef = React.useRef(null);
56
- const leftRef = React.useRef(null);
57
- const rightRef = React.useRef(null);
58
-
59
- const shouldShowLeft = () => children && children[0] && wrapRef.current && itemsRef.current[0] && !isVisibleElement(itemsRef.current[0], wrapRef.current);
60
-
61
- const shouldShowRight = () => children && children[children.length - 1] && wrapRef.current && itemsRef.current[children.length - 1] && !isVisibleElement(itemsRef.current[children.length - 1], wrapRef.current);
62
-
63
- const [{
64
- right,
65
- left,
66
- CHEVRON_FOCUS_FLAG
67
- }, setShow] = React.useState({
68
- right: false,
69
- left: false,
70
- CHEVRON_FOCUS_FLAG: false // flag to replace lack of callback in useState hook
71
-
72
- });
73
-
74
- const recalcChevrons = () => setShow({
75
- right: shouldShowRight(),
76
- left: shouldShowLeft()
77
- });
78
-
79
- React.useEffect(() => {
80
- recalcChevrons();
81
- }, []);
82
- React.useEffect(() => {
83
- if (CHEVRON_FOCUS_FLAG) {
84
- // focus opposite chevron when current one hides
85
- if (!left && right && rightRef.current) {
86
- rightRef.current.focus();
87
- } else if (!right && left && leftRef.current) {
88
- leftRef.current.focus();
89
- }
90
-
91
- setShow({
92
- right,
93
- left,
94
- CHEVRON_FOCUS_FLAG: false
95
- });
96
- }
97
- }, [CHEVRON_FOCUS_FLAG]);
98
- useResize.useResize(wrapRef, recalcChevrons);
99
-
100
- const getVisibleItemsOffset = () => itemsRef.current.reduce((acc, c) => {
101
- if (isVisibleElement(c, wrapRef.current)) {
102
- const styles = window.getComputedStyle(c);
103
- const width = c.offsetWidth;
104
- const margin = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
105
- return acc + (width + margin);
106
- }
107
-
108
- return acc;
109
- }, 0);
110
-
111
- const rightClick = () => {
112
- wrapRef.current.scrollLeft += getVisibleItemsOffset();
113
- };
114
-
115
- const leftClick = () => {
116
- wrapRef.current.scrollLeft -= getVisibleItemsOffset();
117
- };
118
-
119
- const handleScroll = e => {
120
- // forces render when element.scrollTop is changed (out of react flow)
121
- setShow({
122
- right: shouldShowRight(),
123
- left: shouldShowLeft(),
124
- // to trigger focus logic at effect above
125
- CHEVRON_FOCUS_FLAG: true
126
- });
127
- onScroll(e);
128
- };
129
-
130
- const handleClick = function (e) {
131
- let onClick = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
132
- const tabListDomEl = wrapRef.current;
133
- const el = e.target;
134
- const rect = el.getBoundingClientRect();
135
- const cRect = tabListDomEl.getBoundingClientRect();
136
-
137
- if (!isVisibleElement(el, tabListDomEl)) {
138
- const containerWidth = cRect.width;
139
- const halfContainer = containerWidth / 2;
140
- const elementScrollPosition = rect.left - cRect.left;
141
- const positionInContainer = elementScrollPosition % containerWidth;
142
- const width = el.offsetWidth; // align to right
143
-
144
- if (positionInContainer > halfContainer) {
145
- wrapRef.current.scrollLeft += width + positionInContainer - containerWidth;
146
- } else {
147
- // align left
148
- wrapRef.current.scrollLeft += positionInContainer;
149
- }
150
-
151
- recalcChevrons();
152
- }
153
-
154
- onClick(e);
155
- };
156
-
157
- return /*#__PURE__*/_jsx__default["default"](CarouselWrapper, {}, void 0, left && /*#__PURE__*/_jsx__default["default"](CarouselBtn, {
158
- "data-testid": "chevron-left",
159
- buttonType: "link",
160
- innerRef: leftRef,
161
- size: "s",
162
- icon: /*#__PURE__*/_jsx__default["default"](dsIcons.ChevronLeft, {
163
- size: "s",
164
- color: ['brand-primary', '600']
165
- }),
166
- onClick: leftClick,
167
- tabIndex: -1
168
- }), right && /*#__PURE__*/_jsx__default["default"](CarouselBtn, {
169
- "data-testid": "chevron-right",
170
- innerRef: rightRef,
171
- right: true,
172
- size: "s",
173
- buttonType: "link",
174
- icon: /*#__PURE__*/_jsx__default["default"](dsIcons.ChevronRight, {
175
- size: "s",
176
- color: ['brand-primary', '600']
177
- }),
178
- onClick: rightClick,
179
- tabIndex: -1
180
- }), /*#__PURE__*/jsxRuntime.jsx(ChildrenWrap, {
181
- onScroll: handleScroll,
182
- ref: wrapRef,
183
- children: React__default["default"].Children.map(children, (child, idx) => /*#__PURE__*/React__default["default"].cloneElement(child, {
184
- onClick: e => {
185
- var _child$props;
186
-
187
- return handleClick(e, (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.onClick);
188
- },
189
- key: 'carousel'.concat(idx),
190
- ref: el => {
191
- itemsRef.current[idx] = el; // keep old refs
192
-
193
- if (typeof child.ref === 'function') {
194
- child.ref(el);
195
- }
196
- }
197
- }))
198
- }));
199
- };
200
-
201
- Carousel.defaultProps = {
202
- onScroll: () => null
203
- };
204
-
205
- module.exports = Carousel;
package/cjs/DSTab.js DELETED
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _jsx = require('@babel/runtime/helpers/jsx');
6
- require('react');
7
- var reactDesc = require('react-desc');
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 DSTab = _ref => {
14
- let {
15
- tabId = '',
16
- title = '',
17
- required = false
18
- } = _ref;
19
- return /*#__PURE__*/_jsx__default["default"]("div", {
20
- "aria-labelledby": "".concat(tabId, "-label"),
21
- tabId: tabId,
22
- title: title,
23
- required: required
24
- });
25
- };
26
-
27
- DSTab.displayName = 'DSTab';
28
- const props = {
29
- /** unique id for tab */
30
- tabId: reactDesc.PropTypes.string.description('unique id for tab'),
31
-
32
- /** tab title */
33
- title: reactDesc.PropTypes.string.description('tab title'),
34
-
35
- /** Show a required mark next to the title */
36
- required: reactDesc.PropTypes.bool.description('Show a required mark next to the title'),
37
-
38
- /** Whether or not it's a ds-tab from DSMobile tabs */
39
- isDSMobile: reactDesc.PropTypes.bool.description("Whether or not it's a ds-tab from DSMobile tabs")
40
- };
41
- const DSTabWithSchema = reactDesc.describe(DSTab);
42
- DSTabWithSchema.propTypes = props;
43
-
44
- exports.DSTab = DSTab;
45
- exports.DSTabWithSchema = DSTabWithSchema;
46
- exports["default"] = DSTab;
package/cjs/SubTabBar.js DELETED
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- var _jsx = require('@babel/runtime/helpers/jsx');
4
- require('react');
5
- var dsClassnames = require('@elliemae/ds-classnames');
6
- var TabBar = require('./TabBar.js');
7
- var Carousel = require('./Carousel.js');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
12
-
13
- const blockName = 'tabs-tab-bar';
14
- const SubTabList = dsClassnames.aggregatedClasses('div')(blockName, 'subtabs-list', _ref => {
15
- let {
16
- withCarousel
17
- } = _ref;
18
- return {
19
- carousel: withCarousel
20
- };
21
- });
22
-
23
- const SubTabBar = _ref2 => {
24
- let {
25
- withCarousel,
26
- tabs = [],
27
- activeTab = '',
28
- onTabClick = () => null,
29
- firstSubtabRef,
30
- handleUpArrow
31
- } = _ref2;
32
- return /*#__PURE__*/_jsx__default["default"](TabBar, {
33
- activeTab: activeTab,
34
- onTabClick: onTabClick,
35
- handleUpArrow: handleUpArrow,
36
- firstSubtabRef: firstSubtabRef,
37
- renderCustomTabBar: _ref3 => {
38
- let {
39
- tabsComponents,
40
- innerRef
41
- } = _ref3;
42
- return /*#__PURE__*/_jsx__default["default"](SubTabList, {
43
- withCarousel: withCarousel,
44
- innerRef: innerRef,
45
- "data-testid": "subtabs-list"
46
- }, void 0, withCarousel ? /*#__PURE__*/_jsx__default["default"](Carousel, {}, void 0, tabsComponents) : tabsComponents);
47
- },
48
- showSelectionIndicator: false,
49
- showSeparator: true,
50
- tabs: tabs
51
- });
52
- };
53
-
54
- module.exports = SubTabBar;