@elliemae/ds-tabs 2.0.0-rc.6 → 2.0.0

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