@elliemae/ds-tabs 2.0.0-rc.9 → 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 +91 -35
  52. package/types/DSTabs.d.ts +6 -165
  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 -51
  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/DSTabs.js CHANGED
@@ -3,123 +3,42 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _jsx = require('@babel/runtime/helpers/jsx');
6
- require('react');
7
6
  var reactDesc = require('react-desc');
8
- var TabTypes = require('./TabTypes.js');
9
- var TabsImpl = require('./TabsImpl.js');
10
- var DSTab = require('./DSTab.js');
7
+ var propTypes = require('./propTypes.js');
8
+ var DSTabsCTX = require('./DSTabsCTX.js');
9
+ var TabsContent = require('./parts/tabsContent/TabsContent.js');
10
+ var useTabs = require('./config/useTabs.js');
11
+ var useCrossRef = require('./config/useCrossRef.js');
12
+ var constants = require('./utils/constants.js');
11
13
 
12
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
15
 
14
16
  var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
15
17
 
16
- const DSTabs = _ref => {
17
- let {
18
- containerProps = {},
19
- innerRef,
20
- animated = true,
21
- enableMouseEvents = false,
22
- allowTextSelection = false,
23
- onTabChange = () => null,
24
- tabsListAriaLabel = 'Tab list',
25
- type = TabTypes.TabTypes.NORMAL,
26
- tabBarExtraContent = undefined,
27
- children: tabs,
28
- onlyRenderActiveTab = false,
29
- activeTab,
30
- withCarousel = false,
31
- firstSubtabRef,
32
- lastTabRef,
33
- flexibleTabsHeaders,
34
- fixedTabsHeaders,
35
- isDSMobile = false
36
- } = _ref;
37
- return /*#__PURE__*/_jsx__default["default"](TabsImpl, {
38
- activeTab: activeTab,
39
- firstSubtabRef: firstSubtabRef,
40
- lastTabRef: lastTabRef,
41
- allowTextSelection: allowTextSelection,
42
- animated: animated,
43
- containerProps: containerProps,
44
- enableMouseEvents: enableMouseEvents,
45
- innerRef: innerRef,
46
- onlyRenderActiveTab: onlyRenderActiveTab,
47
- onTabChange: onTabChange,
48
- tabBarExtraContent: tabBarExtraContent,
49
- tabsListAriaLabel: tabsListAriaLabel,
50
- type: type,
51
- withCarousel: withCarousel,
52
- flexibleTabsHeaders: flexibleTabsHeaders,
53
- fixedTabsHeaders: fixedTabsHeaders,
54
- isDSMobile: isDSMobile
55
- }, void 0, tabs);
18
+ var _TabsContent, _TabsContent2;
19
+
20
+ const DSTabs = props => {
21
+ const ctx = useTabs.useTabs(props);
22
+ const crossRefsCtx = useCrossRef.useCrossRef();
23
+ const {
24
+ type
25
+ } = props;
26
+
27
+ if (type === constants.TabTypes.SUBTABS) {
28
+ return /*#__PURE__*/_jsx__default["default"](DSTabsCTX.DSTabsContext.Provider, {
29
+ value: ctx
30
+ }, void 0, _TabsContent || (_TabsContent = /*#__PURE__*/_jsx__default["default"](TabsContent.TabsContent, {})));
31
+ }
32
+
33
+ return /*#__PURE__*/_jsx__default["default"](DSTabsCTX.DSTabsCrossRefContext.Provider, {
34
+ value: crossRefsCtx
35
+ }, void 0, /*#__PURE__*/_jsx__default["default"](DSTabsCTX.DSTabsContext.Provider, {
36
+ value: ctx
37
+ }, void 0, _TabsContent2 || (_TabsContent2 = /*#__PURE__*/_jsx__default["default"](TabsContent.TabsContent, {}))));
56
38
  };
57
39
 
58
- const props = {
59
- /** Whether the tab transition should animate or not */
60
- animated: reactDesc.PropTypes.bool.description('Whether the tab transition should animate or not'),
61
-
62
- /** Enables tab transition with mouse drag events */
63
- enableMouseEvents: reactDesc.PropTypes.bool.description('Enables tab transition with mouse drag events'),
64
-
65
- /** Allow text selection when mouse drag events are active */
66
- allowTextSelection: reactDesc.PropTypes.bool.description('Allow text selection when mouse drag events are active'),
67
-
68
- /** Handler when a user clicks on a different tab */
69
- onTabChange: reactDesc.PropTypes.func.description('Handler when a user clicks on a different tab'),
70
-
71
- /** Tab type */
72
- type: reactDesc.PropTypes.oneOf(['normal', 'subtabs']).description('Tab type'),
73
-
74
- /** Extra content next to the tabs pills */
75
- tabBarExtraContent: reactDesc.PropTypes.element.description('Extra content next to the tabs pills'),
76
-
77
- /** Only renders the active tab in the DOM */
78
- onlyRenderActiveTab: reactDesc.PropTypes.bool.description('Only renders the active tab in the DOM'),
79
-
80
- /** Mobile only flexible tabs mode */
81
- flexibleTabsHeaders: reactDesc.PropTypes.bool.description('Mobile only flexible tabs mode'),
82
-
83
- /** Mobile only fixed tabs mode */
84
- fixedTabsHeaders: reactDesc.PropTypes.bool.description('Mobile only fixed tabs mode'),
85
-
86
- /** Whether or not it's a ds-tab from DSMobile tabs */
87
- isDSMobile: reactDesc.PropTypes.bool.description("Whether or not it's a ds-tab from DSMobile tabs"),
88
-
89
- /** Activate carousel behavior */
90
- withCarousel: reactDesc.PropTypes.bool.description('Activate carousel behavior'),
91
-
92
- /** The active tabId */
93
- activeTab: reactDesc.PropTypes.string.description('The active tabId'),
94
-
95
- /** tabs children */
96
- children: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.shape({
97
- type: reactDesc.PropTypes.instanceOf([reactDesc.PropTypes.instanceOf(DSTab.DSTab), reactDesc.PropTypes.array])
98
- })).isRequired.description('tabs children'),
99
-
100
- /** Aria label for the list */
101
- tabsListAriaLabel: reactDesc.PropTypes.string.description('Aria label for the list'),
102
-
103
- /** Additional properties for the container */
104
- containerProps: reactDesc.PropTypes.object.description('Additional properties for the container'),
105
-
106
- /** REF */
107
- innerRef: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.func, reactDesc.PropTypes.shape({
108
- current: reactDesc.PropTypes.any
109
- })]).description('REF'),
110
-
111
- /** internal ref to handle keyboard a11y behavior */
112
- firstSubtabRef: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.func, reactDesc.PropTypes.shape({
113
- current: reactDesc.PropTypes.any
114
- })]).description('internal ref to handle keyboard a11y behavior'),
115
-
116
- /** internal ref to handle keyboard a11y behavior */
117
- lastTabRef: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.func, reactDesc.PropTypes.shape({
118
- current: reactDesc.PropTypes.any
119
- })]).description('internal ref to handle keyboard a11y behavior')
120
- };
121
40
  const DSTabsWithSchema = reactDesc.describe(DSTabs);
122
- DSTabsWithSchema.propTypes = props;
41
+ DSTabsWithSchema.propTypes = propTypes.tabsPropTypes;
123
42
 
124
43
  exports.DSTabs = DSTabs;
125
44
  exports.DSTabsWithSchema = DSTabsWithSchema;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var defaultProps = require('./defaultProps.js');
7
+
8
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
9
+ const noop = () => {};
10
+
11
+ const defaultContext = {
12
+ props: defaultProps.tabsDefaultProps,
13
+ tabsRef: /*#__PURE__*/React.createRef(),
14
+ tabsListRef: /*#__PURE__*/React.createRef(),
15
+ carouselOnlyListRef: /*#__PURE__*/React.createRef(),
16
+ focusableTabsRef: /*#__PURE__*/React.createRef(),
17
+ tabsRefAsArray: /*#__PURE__*/React.createRef(),
18
+ actualActiveTabRef: /*#__PURE__*/React.createRef(),
19
+ setInternalActiveTab: noop,
20
+ actualActiveTab: ''
21
+ };
22
+ const defaultCrossRefsContext = {
23
+ lastTabInternalRef: /*#__PURE__*/React.createRef(),
24
+ firstSubtabInternalRef: /*#__PURE__*/React.createRef()
25
+ };
26
+ const DSTabsContext = /*#__PURE__*/React.createContext(defaultContext);
27
+ const DSTabsCrossRefContext = /*#__PURE__*/React.createContext(defaultCrossRefsContext);
28
+
29
+ exports.DSTabsContext = DSTabsContext;
30
+ exports.DSTabsCrossRefContext = DSTabsCrossRefContext;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const DSTabsDatatestid = {
6
+ TABS_CONTAINER: 'ds-tabs-container',
7
+ TAB_BUTTON: 'ds-tabs-tab-button',
8
+ SUBTAB_BUTTON: 'ds-tabs-subtab-button',
9
+ TAB_PANEL: 'ds-tabs-tab-panel',
10
+ SUB_TAB_LIST: 'subtabs-list',
11
+ TAB_LIST: 'tab-list',
12
+ CAROUSEL: {
13
+ BUTTON_RIGHT: 'chevron-right',
14
+ BUTTON_LEFT: 'chevron-left'
15
+ }
16
+ };
17
+
18
+ exports.DSTabsDatatestid = DSTabsDatatestid;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ const useCrossRef = () => {
8
+ const firstSubtabInternalRef = React.useRef();
9
+ const lastTabInternalRef = React.useRef();
10
+ const ctx = React.useMemo(() => ({
11
+ firstSubtabInternalRef,
12
+ lastTabInternalRef
13
+ }), []);
14
+ return ctx;
15
+ };
16
+
17
+ exports.useCrossRef = useCrossRef;
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/web.dom-collections.iterator.js');
6
+ require('core-js/modules/esnext.async-iterator.find.js');
7
+ require('core-js/modules/esnext.iterator.constructor.js');
8
+ require('core-js/modules/esnext.iterator.find.js');
9
+ var React = require('react');
10
+ var dsPropsHelpers = require('@elliemae/ds-props-helpers');
11
+ var defaultProps = require('../defaultProps.js');
12
+
13
+ const useTabs = props => {
14
+ var _children$, _children$$props;
15
+
16
+ const propsWithDefaults = dsPropsHelpers.useMemoMergePropsWithDefault(props, defaultProps.tabsDefaultProps);
17
+ const {
18
+ activeTab,
19
+ children
20
+ } = propsWithDefaults;
21
+ const tabsRef = React.useRef({});
22
+ const tabsRefAsArray = React.useRef([]);
23
+ const focusableTabsRef = React.useRef([]);
24
+ const carouselOnlyListRef = React.useRef(null);
25
+ const tabsListRef = React.useRef(null);
26
+ const actualActiveTabRef = React.useRef(null);
27
+ const [internalActiveTab, setInternalActiveTab] = React.useState(children === null || children === void 0 ? void 0 : (_children$ = children[0]) === null || _children$ === void 0 ? void 0 : (_children$$props = _children$.props) === null || _children$$props === void 0 ? void 0 : _children$$props.tabId);
28
+ const actualActiveTab = React.useMemo(() => {
29
+ if (activeTab !== undefined) return activeTab;
30
+ return internalActiveTab;
31
+ }, [activeTab, internalActiveTab]);
32
+ React.useEffect(() => {
33
+ var _focusableTabsRef$cur;
34
+
35
+ actualActiveTabRef.current = (_focusableTabsRef$cur = focusableTabsRef.current.find(el => el.dataset.tabId === internalActiveTab)) !== null && _focusableTabsRef$cur !== void 0 ? _focusableTabsRef$cur : null;
36
+ }, [internalActiveTab]);
37
+ const ctx = React.useMemo(() => ({
38
+ props: propsWithDefaults,
39
+ tabsRef,
40
+ focusableTabsRef,
41
+ tabsListRef,
42
+ tabsRefAsArray,
43
+ setInternalActiveTab,
44
+ actualActiveTab,
45
+ actualActiveTabRef,
46
+ carouselOnlyListRef
47
+ }), [actualActiveTab, propsWithDefaults]);
48
+ return ctx;
49
+ };
50
+
51
+ exports.useTabs = useTabs;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants = require('./utils/constants.js');
6
+
7
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
8
+ const noop = () => {};
9
+
10
+ const tabsDefaultProps = {
11
+ containerProps: {},
12
+ animated: true,
13
+ enableMouseEvents: false,
14
+ allowTextSelection: false,
15
+ onTabChange: noop,
16
+ tabsListAriaLabel: 'Tab list',
17
+ type: constants.TabTypes.NORMAL,
18
+ onlyRenderActiveTab: false,
19
+ withCarousel: false,
20
+ isDSMobile: false,
21
+ showSelectionIndicator: true,
22
+ children: [],
23
+ fixedTabsHeaders: false,
24
+ showSeparator: true
25
+ };
26
+
27
+ exports.tabsDefaultProps = tabsDefaultProps;
@@ -1,48 +1,32 @@
1
1
  'use strict';
2
2
 
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
- require('core-js/modules/esnext.async-iterator.map.js');
6
- require('core-js/modules/esnext.iterator.map.js');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
7
5
  require('core-js/modules/esnext.async-iterator.filter.js');
8
6
  require('core-js/modules/esnext.iterator.constructor.js');
9
7
  require('core-js/modules/esnext.iterator.filter.js');
10
8
  require('core-js/modules/esnext.async-iterator.for-each.js');
11
9
  require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
12
11
  var React = require('react');
13
- var dsClassnames = require('@elliemae/ds-classnames');
12
+ var reactDesc = require('react-desc');
13
+ var propTypes = require('../propTypes.js');
14
14
  var jsxRuntime = require('react/jsx-runtime');
15
15
 
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
17
 
18
18
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
19
- var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
20
19
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
20
 
22
- const _excluded = ["children", "lastTabRef", "firstSubtabRef"];
23
-
24
21
  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; }
25
22
 
26
23
  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; }
27
- const blockName = 'tabs-panels';
28
- const PC = dsClassnames.aggregatedClasses('div')(blockName, 'panel');
29
-
30
- const PanelContainer = _ref => {
31
- let {
32
- children,
33
- lastTabRef,
34
- firstSubtabRef
35
- } = _ref,
36
- rest = _objectWithoutProperties__default["default"](_ref, _excluded);
37
-
38
- // inject ref to handle focus on first subtab child
39
- const child = React__default["default"].Children.map(children, (c, i) => i === 0 && c ? /*#__PURE__*/React__default["default"].cloneElement(c, {
40
- firstSubtabRef,
41
- lastTabRef
42
- }) : c);
43
- return /*#__PURE__*/jsxRuntime.jsx(PC, _objectSpread(_objectSpread({}, rest), {}, {
44
- children: child
45
- }));
46
- };
47
-
48
- module.exports = PanelContainer;
24
+
25
+ const DSTab = props => /*#__PURE__*/jsxRuntime.jsx(React__default["default"].Fragment, _objectSpread({}, props));
26
+
27
+ const DSTabWithSchema = reactDesc.describe(DSTab);
28
+ DSTabWithSchema.propTypes = propTypes.tabPropTypes;
29
+
30
+ exports.DSTab = DSTab;
31
+ exports.DSTabWithSchema = DSTabWithSchema;
32
+ exports["default"] = DSTab;
package/cjs/index.js CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var DSTab = require('./DSTab.js');
5
+ var DSTab = require('./exportsRelated/DSTab.js');
6
6
  var DSTabs = require('./DSTabs.js');
7
- var TabTypes = require('./TabTypes.js');
7
+ var constants = require('./utils/constants.js');
8
+ var DSTabsDatatestid = require('./DSTabsDatatestid.js');
8
9
 
9
10
 
10
11
 
@@ -12,6 +13,5 @@ exports.DSTab = DSTab.DSTab;
12
13
  exports.DSTabWithSchema = DSTab.DSTabWithSchema;
13
14
  exports.DSTabs = DSTabs.DSTabs;
14
15
  exports.DSTabsWithSchema = DSTabs.DSTabsWithSchema;
15
- exports["default"] = DSTabs.DSTabs;
16
- exports.TabTypes = TabTypes.TabTypes;
17
- exports.getTabTypes = TabTypes.getTabTypes;
16
+ exports.TabTypes = constants.TabTypes;
17
+ exports.DSTabsDatatestid = DSTabsDatatestid.DSTabsDatatestid;
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _jsx = require('@babel/runtime/helpers/jsx');
6
+ var React = require('react');
7
+ var dsIcon = require('@elliemae/ds-icon');
8
+ var dsButton = require('@elliemae/ds-button');
9
+ var dsIcons = require('@elliemae/ds-icons');
10
+ var styles = require('./styles.js');
11
+ var useCarousel = require('./useCarousel.js');
12
+ var DSTabsCTX = require('../../DSTabsCTX.js');
13
+ var DSTabsDatatestid = require('../../DSTabsDatatestid.js');
14
+ var jsxRuntime = require('react/jsx-runtime');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
+
18
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
19
+
20
+ const Carousel = _ref => {
21
+ let {
22
+ children,
23
+ updateIndicatorStyle
24
+ } = _ref;
25
+ const {
26
+ showChevrons,
27
+ leftButtonOnClick,
28
+ rightButtonOnClick,
29
+ handleOnClick,
30
+ handleOnScroll
31
+ } = useCarousel.useCarousel({
32
+ updateIndicatorStyle
33
+ });
34
+ const {
35
+ carouselOnlyListRef,
36
+ props: {
37
+ type
38
+ }
39
+ } = React.useContext(DSTabsCTX.DSTabsContext);
40
+ return /*#__PURE__*/_jsx__default["default"](styles.StyledCarouselWrapper, {}, void 0, showChevrons.left && /*#__PURE__*/_jsx__default["default"](styles.StyledCarouselButtonWrapper, {
41
+ tabType: type
42
+ }, void 0, /*#__PURE__*/_jsx__default["default"](styles.StyledCarouselBtn, {
43
+ size: "s",
44
+ onClick: leftButtonOnClick,
45
+ tabIndex: -1,
46
+ "data-testid": DSTabsDatatestid.DSTabsDatatestid.CAROUSEL.BUTTON_LEFT,
47
+ buttonType: dsButton.BUTTON_TYPES.ICON
48
+ }, void 0, /*#__PURE__*/_jsx__default["default"](dsIcons.ChevronLeft, {
49
+ size: dsIcon.DSIconSizes.S,
50
+ color: dsIcon.DSIconColors.PRIMARY
51
+ }))), showChevrons.right && /*#__PURE__*/_jsx__default["default"](styles.StyledCarouselButtonWrapper, {
52
+ tabType: type,
53
+ right: showChevrons.right
54
+ }, void 0, /*#__PURE__*/_jsx__default["default"](styles.StyledCarouselBtn, {
55
+ size: "s",
56
+ onClick: rightButtonOnClick,
57
+ tabIndex: -1,
58
+ "data-testid": DSTabsDatatestid.DSTabsDatatestid.CAROUSEL.BUTTON_RIGHT,
59
+ buttonType: dsButton.BUTTON_TYPES.ICON
60
+ }, void 0, /*#__PURE__*/_jsx__default["default"](dsIcons.ChevronRight, {
61
+ size: dsIcon.DSIconSizes.S,
62
+ color: dsIcon.DSIconColors.PRIMARY
63
+ }))), /*#__PURE__*/jsxRuntime.jsx(styles.StyledChildrenWrap, {
64
+ ref: carouselOnlyListRef,
65
+ onClick: handleOnClick,
66
+ onScroll: handleOnScroll,
67
+ children: children
68
+ }));
69
+ };
70
+
71
+ exports.Carousel = Carousel;
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var styled = require('styled-components');
6
+ var dsButton = require('@elliemae/ds-button');
7
+ var constants = require('../../utils/constants.js');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
12
+
13
+ const StyledCarouselBtn = /*#__PURE__*/styled__default["default"](dsButton.DSButtonV2).withConfig({
14
+ componentId: "sc-prv5a7-0"
15
+ })(["margin:0;min-width:", ";width:", ";&:hover:not(:disabled){background-color:transparent;}background-color:transparent;border-radius:0px;"], _ref => {
16
+ let {
17
+ theme
18
+ } = _ref;
19
+ return theme.space.xs;
20
+ }, _ref2 => {
21
+ let {
22
+ theme
23
+ } = _ref2;
24
+ return theme.space.xs;
25
+ });
26
+ const StyledCarouselWrapper = /*#__PURE__*/styled__default["default"].span.withConfig({
27
+ componentId: "sc-prv5a7-1"
28
+ })(["position:relative;width:100%;display:flex;"]);
29
+ const StyledChildrenWrap = /*#__PURE__*/styled__default["default"].div.withConfig({
30
+ componentId: "sc-prv5a7-2"
31
+ })(["display:flex;flex-wrap:nowrap;flex:1;overflow-x:hidden;"]);
32
+ const StyledCarouselButtonWrapper = /*#__PURE__*/styled__default["default"].div.withConfig({
33
+ componentId: "sc-prv5a7-3"
34
+ })(["max-width:16px;position:absolute;z-index:200;", " width:16px;height:", ";padding-top:", ";background-color:white;", ";"], _ref3 => {
35
+ let {
36
+ right
37
+ } = _ref3;
38
+ return right ? 'right: 0;' : "left: 0;";
39
+ }, _ref4 => {
40
+ let {
41
+ tabType
42
+ } = _ref4;
43
+ return tabType === constants.TabTypes.NORMAL ? '32px' : '22px';
44
+ }, _ref5 => {
45
+ let {
46
+ tabType
47
+ } = _ref5;
48
+ return tabType === constants.TabTypes.NORMAL ? '5px' : '0px';
49
+ }, _ref6 => {
50
+ let {
51
+ theme,
52
+ tabType
53
+ } = _ref6;
54
+ return tabType === constants.TabTypes.NORMAL ? "\n border-bottom: 1px solid ".concat(theme.colors.neutral[200], ";") : "";
55
+ });
56
+
57
+ exports.StyledCarouselBtn = StyledCarouselBtn;
58
+ exports.StyledCarouselButtonWrapper = StyledCarouselButtonWrapper;
59
+ exports.StyledCarouselWrapper = StyledCarouselWrapper;
60
+ exports.StyledChildrenWrap = StyledChildrenWrap;
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/web.dom-collections.iterator.js');
6
+ require('core-js/modules/esnext.async-iterator.reduce.js');
7
+ require('core-js/modules/esnext.iterator.constructor.js');
8
+ require('core-js/modules/esnext.iterator.reduce.js');
9
+ var React = require('react');
10
+ var useResizeObserver = require('@react-hook/resize-observer');
11
+ var DSTabsCTX = require('../../DSTabsCTX.js');
12
+ var helpers = require('../../utils/helpers.js');
13
+ var useCarouselCallbacks = require('./useCarouselCallbacks.js');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var useResizeObserver__default = /*#__PURE__*/_interopDefaultLegacy(useResizeObserver);
18
+
19
+ const useCarousel = _ref => {
20
+ let {
21
+ updateIndicatorStyle
22
+ } = _ref;
23
+ const {
24
+ carouselOnlyListRef
25
+ } = React.useContext(DSTabsCTX.DSTabsContext);
26
+ const [showChevrons, setShowChevrons] = React.useState({
27
+ right: false,
28
+ left: false
29
+ });
30
+ const {
31
+ tabsRefAsArray
32
+ } = React.useContext(DSTabsCTX.DSTabsContext);
33
+ const shouldShowLeft = React.useCallback(() => carouselOnlyListRef.current ? carouselOnlyListRef.current.scrollLeft > 0 : false, [carouselOnlyListRef]);
34
+ const shouldShowRight = React.useCallback(() => carouselOnlyListRef.current ? carouselOnlyListRef.current.scrollLeft < carouselOnlyListRef.current.scrollWidth - carouselOnlyListRef.current.clientWidth : false, [carouselOnlyListRef]);
35
+ const recalcChevrons = React.useCallback(() => {
36
+ setShowChevrons({
37
+ right: shouldShowRight(),
38
+ left: shouldShowLeft()
39
+ });
40
+ }, [shouldShowLeft, shouldShowRight]);
41
+ const getVisibleItemsOffset = React.useCallback(() => {
42
+ if (tabsRefAsArray.current) {
43
+ const scroll = tabsRefAsArray.current.reduce((acc, c) => {
44
+ if (helpers.isElementVisibleCarousel(c, carouselOnlyListRef.current)) {
45
+ const styles = window.getComputedStyle(c);
46
+ const width = c.clientWidth;
47
+ const margin = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
48
+ return acc + (width + margin);
49
+ }
50
+
51
+ return acc;
52
+ }, 0);
53
+ return scroll - 16;
54
+ }
55
+
56
+ return 0;
57
+ }, [tabsRefAsArray, carouselOnlyListRef]);
58
+ useResizeObserver__default["default"](carouselOnlyListRef, recalcChevrons);
59
+ const {
60
+ leftButtonOnClick,
61
+ rightButtonOnClick,
62
+ handleOnClick,
63
+ handleOnScroll
64
+ } = useCarouselCallbacks.useCarouselCallbacks({
65
+ getVisibleItemsOffset,
66
+ recalcChevrons,
67
+ updateIndicatorStyle
68
+ });
69
+ return {
70
+ showChevrons,
71
+ leftButtonOnClick,
72
+ rightButtonOnClick,
73
+ handleOnClick,
74
+ handleOnScroll
75
+ };
76
+ };
77
+
78
+ exports.useCarousel = useCarousel;
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var helpers = require('../../utils/helpers.js');
7
+ var DSTabsCTX = require('../../DSTabsCTX.js');
8
+
9
+ /* eslint-disable max-statements */
10
+ const useCarouselCallbacks = _ref => {
11
+ let {
12
+ getVisibleItemsOffset,
13
+ updateIndicatorStyle,
14
+ recalcChevrons
15
+ } = _ref;
16
+ const {
17
+ focusableTabsRef,
18
+ carouselOnlyListRef
19
+ } = React.useContext(DSTabsCTX.DSTabsContext);
20
+ const rightButtonOnClick = React.useCallback(() => {
21
+ if (carouselOnlyListRef.current) {
22
+ carouselOnlyListRef.current.scrollLeft += getVisibleItemsOffset();
23
+ }
24
+ }, [getVisibleItemsOffset, carouselOnlyListRef]);
25
+ const leftButtonOnClick = React.useCallback(() => {
26
+ if (carouselOnlyListRef.current) {
27
+ carouselOnlyListRef.current.scrollLeft -= getVisibleItemsOffset();
28
+ }
29
+ }, [getVisibleItemsOffset, carouselOnlyListRef]);
30
+ const handleOnScroll = React.useCallback(() => {
31
+ recalcChevrons();
32
+ if (updateIndicatorStyle) updateIndicatorStyle();
33
+ }, [recalcChevrons, updateIndicatorStyle]);
34
+ const handleOnClick = React.useCallback(_ref2 => {
35
+ let {
36
+ target
37
+ } = _ref2;
38
+
39
+ if (focusableTabsRef.current && target.getAttribute('role') === 'tab') {
40
+ const tabList = carouselOnlyListRef.current;
41
+ const tabButton = target;
42
+ const tabButtonDimensions = tabButton.getBoundingClientRect();
43
+ const tabListDimensions = tabList === null || tabList === void 0 ? void 0 : tabList.getBoundingClientRect();
44
+ const tabButtonIndex = tabButton.dataset.index;
45
+ const lastItemIndex = focusableTabsRef.current.length.toString();
46
+ const magicNumber = 34;
47
+ const firstOrLastItem = tabButtonIndex === '0' || tabButtonIndex === lastItemIndex;
48
+
49
+ if (!helpers.isElementVisibleCarousel(tabButton, tabList, firstOrLastItem) && tabListDimensions && carouselOnlyListRef.current) {
50
+ const containerWidth = tabListDimensions.width;
51
+ const halfContainer = containerWidth / 2;
52
+ const elementScrollPosition = tabButtonDimensions.left - tabListDimensions.left;
53
+ const positionInContainer = elementScrollPosition % containerWidth;
54
+ const width = tabButton.offsetWidth + magicNumber;
55
+
56
+ if (positionInContainer > halfContainer) {
57
+ carouselOnlyListRef.current.scrollLeft += width + positionInContainer - containerWidth;
58
+ } else {
59
+ carouselOnlyListRef.current.scrollLeft += positionInContainer - magicNumber;
60
+ }
61
+ }
62
+ }
63
+ }, [focusableTabsRef, carouselOnlyListRef]);
64
+ return {
65
+ handleOnClick,
66
+ rightButtonOnClick,
67
+ leftButtonOnClick,
68
+ handleOnScroll
69
+ };
70
+ };
71
+
72
+ exports.useCarouselCallbacks = useCarouselCallbacks;