@elliemae/ds-tabs 1.60.0 → 2.0.0-alpha.12

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 (130) hide show
  1. package/cjs/DSTabs.js +29 -150
  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/exportsRelated/DSTab.js +32 -0
  9. package/cjs/index.js +5 -35
  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 +31 -152
  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/exportsRelated/DSTab.js +21 -0
  34. package/esm/index.js +4 -33
  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 +134 -18
  52. package/types/DSTabs.d.ts +14 -0
  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 +5 -0
  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.callbacks.test.d.ts +1 -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/tests/DSTabs.test.d.ts +1 -0
  77. package/types/utils/constants.d.ts +19 -0
  78. package/types/utils/helpers.d.ts +8 -0
  79. package/types/utils/hooks/useKeyboardNavigation.d.ts +2 -0
  80. package/types/utils/hooks/useTabsCallbacks.d.ts +2 -0
  81. package/Carousel/package.json +0 -10
  82. package/DSTab/package.json +0 -10
  83. package/DSTabs/package.json +0 -10
  84. package/PanelContainer/package.json +0 -10
  85. package/SubTabBar/package.json +0 -10
  86. package/TabBar/package.json +0 -10
  87. package/TabTypes/package.json +0 -10
  88. package/TabsImpl/package.json +0 -10
  89. package/TabsPanels/package.json +0 -10
  90. package/cjs/Carousel.js +0 -219
  91. package/cjs/Carousel.js.map +0 -1
  92. package/cjs/DSTab.js +0 -50
  93. package/cjs/DSTab.js.map +0 -1
  94. package/cjs/DSTabs.js.map +0 -1
  95. package/cjs/PanelContainer.js +0 -45
  96. package/cjs/PanelContainer.js.map +0 -1
  97. package/cjs/SubTabBar.js +0 -81
  98. package/cjs/SubTabBar.js.map +0 -1
  99. package/cjs/TabBar.js +0 -480
  100. package/cjs/TabBar.js.map +0 -1
  101. package/cjs/TabTypes.js +0 -17
  102. package/cjs/TabTypes.js.map +0 -1
  103. package/cjs/TabsImpl.js +0 -173
  104. package/cjs/TabsImpl.js.map +0 -1
  105. package/cjs/TabsPanels.js +0 -116
  106. package/cjs/TabsPanels.js.map +0 -1
  107. package/cjs/index.js.map +0 -1
  108. package/cjs/useResize.js +0 -25
  109. package/cjs/useResize.js.map +0 -1
  110. package/esm/Carousel.js +0 -209
  111. package/esm/Carousel.js.map +0 -1
  112. package/esm/DSTab.js +0 -40
  113. package/esm/DSTab.js.map +0 -1
  114. package/esm/DSTabs.js.map +0 -1
  115. package/esm/PanelContainer.js +0 -37
  116. package/esm/PanelContainer.js.map +0 -1
  117. package/esm/SubTabBar.js +0 -74
  118. package/esm/SubTabBar.js.map +0 -1
  119. package/esm/TabBar.js +0 -464
  120. package/esm/TabBar.js.map +0 -1
  121. package/esm/TabTypes.js +0 -12
  122. package/esm/TabTypes.js.map +0 -1
  123. package/esm/TabsImpl.js +0 -163
  124. package/esm/TabsImpl.js.map +0 -1
  125. package/esm/TabsPanels.js +0 -103
  126. package/esm/TabsPanels.js.map +0 -1
  127. package/esm/index.js.map +0 -1
  128. package/esm/useResize.js +0 -21
  129. package/esm/useResize.js.map +0 -1
  130. package/useResize/package.json +0 -10
@@ -0,0 +1,40 @@
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 { useContext } from 'react';
9
+ import { TabsPanels } from '../tabsPanel/TabsPanels.js';
10
+ import { TabBar } from '../tabBar/TabBar.js';
11
+ import { StyledTabBarContainer } from './styles.js';
12
+ import { DSTabsContext } from '../../DSTabsCTX.js';
13
+ import { DSTabsDatatestid } from '../../DSTabsDatatestid.js';
14
+ import { jsxs } from 'react/jsx-runtime';
15
+
16
+ var _TabBar, _TabsPanels;
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
+ const TabsContent = () => {
22
+ const {
23
+ props: {
24
+ containerProps,
25
+ innerRef,
26
+ tabsListAriaLabel,
27
+ tabBarExtraContent
28
+ }
29
+ } = useContext(DSTabsContext);
30
+ return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({}, containerProps), {}, {
31
+ ref: innerRef,
32
+ "data-testid": DSTabsDatatestid.TABS_CONTAINER,
33
+ children: [/*#__PURE__*/_jsx(StyledTabBarContainer, {
34
+ "aria-label": tabsListAriaLabel,
35
+ role: "tablist"
36
+ }, void 0, _TabBar || (_TabBar = /*#__PURE__*/_jsx(TabBar, {})), tabBarExtraContent), _TabsPanels || (_TabsPanels = /*#__PURE__*/_jsx(TabsPanels, {}))]
37
+ }));
38
+ };
39
+
40
+ export { TabsContent };
@@ -0,0 +1,7 @@
1
+ import styled from 'styled-components';
2
+
3
+ const StyledTabBarContainer = /*#__PURE__*/styled.div.withConfig({
4
+ componentId: "sc-vm3k1y-0"
5
+ })(["display:flex;overflow-x:hidden;"]);
6
+
7
+ export { StyledTabBarContainer };
@@ -0,0 +1,67 @@
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'core-js/modules/esnext.async-iterator.map.js';
3
+ import 'core-js/modules/esnext.iterator.map.js';
4
+ import React, { useContext, useCallback, useMemo } from 'react';
5
+ import SwipeableViews from 'react-swipeable-views';
6
+ import { getIdByIndex, getIndexById } from '../../utils/helpers.js';
7
+ import { StyledPanelContainer } from './styles.js';
8
+ import { DSTabsContext } from '../../DSTabsCTX.js';
9
+ import { useTabsCallbacks } from '../../utils/hooks/useTabsCallbacks.js';
10
+ import { jsx, Fragment } from 'react/jsx-runtime';
11
+
12
+ const TabsPanels = () => {
13
+ const {
14
+ actualActiveTab,
15
+ focusableTabsRef,
16
+ props: {
17
+ animated,
18
+ enableMouseEvents,
19
+ onlyRenderActiveTab,
20
+ children: tabs,
21
+ isDSMobile
22
+ }
23
+ } = useContext(DSTabsContext);
24
+ const {
25
+ handleOnTabChange,
26
+ handleOnMouseDown
27
+ } = useTabsCallbacks();
28
+ const handleOnChangeIndex = useCallback(index => {
29
+ handleOnTabChange(getIdByIndex(tabs, index));
30
+ if (focusableTabsRef.current) focusableTabsRef.current[index].click();
31
+ }, [focusableTabsRef, handleOnTabChange, tabs]);
32
+ const panels = useMemo(() => React.Children.map(tabs, tab => {
33
+ const {
34
+ tabId: panelId = '',
35
+ style,
36
+ children: content
37
+ } = tab.props;
38
+ const isActive = actualActiveTab === panelId;
39
+ const shouldRender = !onlyRenderActiveTab || isActive;
40
+ return shouldRender && /*#__PURE__*/_jsx(StyledPanelContainer, {
41
+ id: panelId,
42
+ "aria-labelledby": "".concat(panelId, "-label"),
43
+ "aria-hidden": !isActive,
44
+ "data-panel-id": panelId,
45
+ "data-testid": "ds-tabs-tab-panel",
46
+ hidden: !isActive,
47
+ onMouseDown: handleOnMouseDown,
48
+ role: "tabpanel",
49
+ style: style,
50
+ isDSMobile: isDSMobile
51
+ }, panelId, content);
52
+ }), [actualActiveTab, handleOnMouseDown, isDSMobile, onlyRenderActiveTab, tabs]);
53
+
54
+ if (animated) {
55
+ return /*#__PURE__*/_jsx(SwipeableViews, {
56
+ enableMouseEvents: enableMouseEvents,
57
+ index: getIndexById(tabs, actualActiveTab),
58
+ onChangeIndex: handleOnChangeIndex
59
+ }, void 0, panels);
60
+ }
61
+
62
+ return /*#__PURE__*/jsx(Fragment, {
63
+ children: panels
64
+ });
65
+ };
66
+
67
+ export { TabsPanels };
@@ -0,0 +1,17 @@
1
+ import styled from 'styled-components';
2
+
3
+ const StyledPanelContainer = /*#__PURE__*/styled.div.withConfig({
4
+ componentId: "sc-oxw5jq-0"
5
+ })(["padding-top:8px;&:focus{outline:none;}", " ", ""], _ref => {
6
+ let {
7
+ hidden
8
+ } = _ref;
9
+ return hidden ? 'visibility: hidden;' : '';
10
+ }, _ref2 => {
11
+ let {
12
+ isDSMobile
13
+ } = _ref2;
14
+ return isDSMobile ? "padding-top: 0;" : "";
15
+ });
16
+
17
+ export { StyledPanelContainer };
@@ -0,0 +1,28 @@
1
+ import { PropTypes } from 'react-desc';
2
+ import { TabTypesValuesAsArray } from './utils/constants.js';
3
+
4
+ const tabPropTypes = {
5
+ tabId: PropTypes.string.description('Unique Tab id.').defaultValue(''),
6
+ title: PropTypes.string.description('Tab title.').defaultValue(''),
7
+ required: PropTypes.bool.description('Show a required mark next to the title.').defaultValue(false),
8
+ disabled: PropTypes.bool.description('Disables Tab.').defaultValue(false)
9
+ };
10
+ const tabsPropTypes = {
11
+ animated: PropTypes.bool.description('Whether the Tab transition should animate or not.').defaultValue(true),
12
+ enableMouseEvents: PropTypes.bool.description('Enables Tab transition with mouse drag events.').defaultValue(false),
13
+ allowTextSelection: PropTypes.bool.description('Allows text selection when mouse drag events are active.').defaultValue(false),
14
+ onTabChange: PropTypes.func.description('Handler when a user clicks on a different Tab.').defaultValue('() => {}'),
15
+ type: PropTypes.oneOf(TabTypesValuesAsArray).description('Tab type.').defaultValue(TabTypesValuesAsArray[0]),
16
+ tabBarExtraContent: PropTypes.element.description('Extra content next to the Tab Bar.').defaultValue(undefined),
17
+ onlyRenderActiveTab: PropTypes.bool.description('Only renders the active Tab in the DOM.').defaultValue(false),
18
+ withCarousel: PropTypes.bool.description('Activate carousel behavior.').defaultValue(false),
19
+ activeTab: PropTypes.string.description('Passing a value makes DSTabs a controlled component.').defaultValue('First DSTab children.'),
20
+ children: PropTypes.node.description('Use DSTab component as children.').isRequired,
21
+ tabsListAriaLabel: PropTypes.string.description('Aria label for the list.').defaultValue('Tab list.'),
22
+ containerProps: PropTypes.object.description('Additional properties for the container.').defaultValue({}),
23
+ innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
24
+ current: PropTypes.any
25
+ })]).description('Ref to the container.').defaultValue(undefined)
26
+ };
27
+
28
+ export { tabPropTypes, tabsPropTypes };
@@ -0,0 +1,21 @@
1
+ const TabTypes = {
2
+ NORMAL: 'normal',
3
+ NORMAL_SMALL: 'normal_small',
4
+ SUBTABS: 'subtabs'
5
+ };
6
+ const TabTypesValuesAsArray = Object.values(TabTypes);
7
+ const MOBILE_GRADIENT_WIDTH = 24;
8
+ const defaultIndicatorStyles = {
9
+ left: '0px',
10
+ width: '0px',
11
+ backgroundWithTransparentAndWhite: '',
12
+ backgroundWithTransparent: ''
13
+ };
14
+ const gradientOffsetsAccordingType = {
15
+ normal_small: 14,
16
+ normal: 16,
17
+ subtabs: 16,
18
+ fixedTabsHeaders: 0
19
+ };
20
+
21
+ export { MOBILE_GRADIENT_WIDTH, TabTypes, TabTypesValuesAsArray, defaultIndicatorStyles, gradientOffsetsAccordingType };
@@ -0,0 +1,37 @@
1
+ import { MOBILE_GRADIENT_WIDTH } from './constants.js';
2
+
3
+ const isElementVisible = (tab, tabList) => {
4
+ const tabDimensions = tab.getBoundingClientRect();
5
+ const tabListDimensions = tabList.getBoundingClientRect();
6
+ return tabDimensions.left <= tabListDimensions.left ? tabListDimensions.left - tabDimensions.left <= tabDimensions.width : tabDimensions.right - tabListDimensions.right <= tabDimensions.width;
7
+ };
8
+ const isElementVisibleCarousel = function (tab, tabContainer) {
9
+ let firstOrLastItem = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
10
+
11
+ if (tab && tabContainer) {
12
+ const tabDimensions = tab.getBoundingClientRect();
13
+ const tabContainerDimensions = tabContainer.getBoundingClientRect();
14
+ const offset = firstOrLastItem ? 16 : 32;
15
+ const tabDimensionsLeft = Math.floor(tabDimensions.left - offset);
16
+ const tabDimensionsRight = Math.floor(tabDimensions.right + offset);
17
+ const tabContainerDimensionsLeft = Math.floor(tabContainerDimensions.left);
18
+ const tabContainerDimensionsRight = Math.floor(tabContainerDimensions.right);
19
+ return tabDimensionsLeft >= tabContainerDimensionsLeft && tabDimensionsRight <= tabContainerDimensionsRight;
20
+ }
21
+
22
+ return false;
23
+ };
24
+ const getVisibleDimensions = (node, referenceNode) => {
25
+ const nodeDimensions = node.getBoundingClientRect();
26
+ const referenceNodeDimensions = referenceNode.getBoundingClientRect();
27
+ return {
28
+ width: Math.min(node.clientWidth, referenceNodeDimensions.left + referenceNode.clientWidth - nodeDimensions.left, node.clientWidth - (referenceNodeDimensions.left - nodeDimensions.left)),
29
+ height: Math.min(node.clientHeight, referenceNodeDimensions.top + referenceNode.clientHeight - nodeDimensions.top, node.clientHeight - (referenceNodeDimensions.top - nodeDimensions.top))
30
+ };
31
+ };
32
+ const getIndexById = (children, activeId) => children && children.findIndex(item => item.props.tabId === activeId);
33
+ const getIdByIndex = (children, index) => children && children[index].props.tabId || '';
34
+ const shouldHaveLeftGradient = scrollLeft => Math.abs(scrollLeft) > MOBILE_GRADIENT_WIDTH;
35
+ const shouldHaveRightGradient = (scrollLeft, clientWidth, scrollWidth) => Math.abs(scrollLeft) <= scrollWidth - (clientWidth + MOBILE_GRADIENT_WIDTH);
36
+
37
+ export { getIdByIndex, getIndexById, getVisibleDimensions, isElementVisible, isElementVisibleCarousel, shouldHaveLeftGradient, shouldHaveRightGradient };
@@ -0,0 +1,57 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { DSTabsContext, DSTabsCrossRefContext } from '../../DSTabsCTX.js';
3
+
4
+ /* eslint-disable max-statements */
5
+ const useKeyboardNavigation = () => {
6
+ const {
7
+ focusableTabsRef
8
+ } = useContext(DSTabsContext);
9
+ const {
10
+ firstSubtabInternalRef,
11
+ lastTabInternalRef
12
+ } = useContext(DSTabsCrossRefContext);
13
+ const handleOnKeyDown = useCallback(e => {
14
+ if (e.key === 'ArrowRight' && focusableTabsRef.current) {
15
+ var _focusableTabsRef$cur, _focusableTabsRef$cur2;
16
+
17
+ e.preventDefault();
18
+ e.stopPropagation();
19
+ const nextTab = focusableTabsRef.current[(focusableTabsRef === null || focusableTabsRef === void 0 ? void 0 : (_focusableTabsRef$cur = focusableTabsRef.current) === null || _focusableTabsRef$cur === void 0 ? void 0 : (_focusableTabsRef$cur2 = _focusableTabsRef$cur.indexOf) === null || _focusableTabsRef$cur2 === void 0 ? void 0 : _focusableTabsRef$cur2.call(_focusableTabsRef$cur, e.target)) + 1];
20
+ if (nextTab) nextTab.focus();
21
+ if (!nextTab) return;
22
+ }
23
+
24
+ if (e.key === 'ArrowLeft' && focusableTabsRef.current) {
25
+ var _focusableTabsRef$cur3, _focusableTabsRef$cur4;
26
+
27
+ e.preventDefault();
28
+ e.stopPropagation();
29
+ const prevTab = focusableTabsRef.current[(focusableTabsRef === null || focusableTabsRef === void 0 ? void 0 : (_focusableTabsRef$cur3 = focusableTabsRef.current) === null || _focusableTabsRef$cur3 === void 0 ? void 0 : (_focusableTabsRef$cur4 = _focusableTabsRef$cur3.indexOf) === null || _focusableTabsRef$cur4 === void 0 ? void 0 : _focusableTabsRef$cur4.call(_focusableTabsRef$cur3, e.target)) - 1];
30
+ if (prevTab) prevTab.focus();
31
+ if (!prevTab) return;
32
+ }
33
+
34
+ if (e.key === 'ArrowDown') {
35
+ var _firstSubtabInternalR;
36
+
37
+ e.preventDefault();
38
+ e.stopPropagation();
39
+ const canFocusCrossTabs = (firstSubtabInternalRef === null || firstSubtabInternalRef === void 0 ? void 0 : firstSubtabInternalRef.current) && (lastTabInternalRef === null || lastTabInternalRef === void 0 ? void 0 : lastTabInternalRef.current);
40
+ if (canFocusCrossTabs) (_firstSubtabInternalR = firstSubtabInternalRef.current) === null || _firstSubtabInternalR === void 0 ? void 0 : _firstSubtabInternalR.focus();
41
+ }
42
+
43
+ if (e.key === 'ArrowUp') {
44
+ var _lastTabInternalRef$c;
45
+
46
+ e.preventDefault();
47
+ e.stopPropagation();
48
+ const canFocusCrossTabs = (firstSubtabInternalRef === null || firstSubtabInternalRef === void 0 ? void 0 : firstSubtabInternalRef.current) && (lastTabInternalRef === null || lastTabInternalRef === void 0 ? void 0 : lastTabInternalRef.current);
49
+ if (canFocusCrossTabs) (_lastTabInternalRef$c = lastTabInternalRef.current) === null || _lastTabInternalRef$c === void 0 ? void 0 : _lastTabInternalRef$c.focus();
50
+ }
51
+ }, [firstSubtabInternalRef, lastTabInternalRef, focusableTabsRef]);
52
+ return {
53
+ handleOnKeyDown
54
+ };
55
+ };
56
+
57
+ export { useKeyboardNavigation };
@@ -0,0 +1,55 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { DSTabsContext } from '../../DSTabsCTX.js';
3
+
4
+ const useTabsCallbacks = () => {
5
+ const {
6
+ setInternalActiveTab,
7
+ tabsListRef,
8
+ props: {
9
+ onTabChange,
10
+ isDSMobile,
11
+ allowTextSelection,
12
+ fixedTabsHeaders
13
+ }
14
+ } = useContext(DSTabsContext);
15
+ const centerTabWhenTabChangeMobile = useCallback(e => {
16
+ if (tabsListRef.current) {
17
+ const {
18
+ offsetLeft
19
+ } = e === null || e === void 0 ? void 0 : e.target;
20
+ const {
21
+ width: tabWidth
22
+ } = (e === null || e === void 0 ? void 0 : e.target).getBoundingClientRect();
23
+ const {
24
+ width: listWidth
25
+ } = tabsListRef.current.getBoundingClientRect();
26
+ const extraSideSpace = listWidth - tabWidth;
27
+ const leftOffsetToCenter = extraSideSpace > 0 ? extraSideSpace / 2 : 0;
28
+ const centeredLeftOffset = offsetLeft > leftOffsetToCenter ? offsetLeft - leftOffsetToCenter : 0;
29
+ tabsListRef.current.scrollTo({
30
+ top: 0,
31
+ left: centeredLeftOffset,
32
+ behavior: 'smooth'
33
+ });
34
+ e === null || e === void 0 ? void 0 : e.preventDefault();
35
+ }
36
+ }, [tabsListRef]);
37
+ const handleOnTabChange = useCallback((tabId, e) => {
38
+ setInternalActiveTab(tabId);
39
+ onTabChange(tabId, e);
40
+
41
+ if (isDSMobile && !fixedTabsHeaders && e) {
42
+ centerTabWhenTabChangeMobile(e);
43
+ }
44
+ }, [centerTabWhenTabChangeMobile, fixedTabsHeaders, isDSMobile, onTabChange, setInternalActiveTab]);
45
+ const handleOnMouseDown = useCallback(e => {
46
+ const role = e.target.getAttribute('role');
47
+ if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
48
+ }, [allowTextSelection]);
49
+ return {
50
+ handleOnTabChange,
51
+ handleOnMouseDown
52
+ };
53
+ };
54
+
55
+ export { useTabsCallbacks };
package/package.json CHANGED
@@ -1,14 +1,126 @@
1
1
  {
2
2
  "name": "@elliemae/ds-tabs",
3
- "version": "1.60.0",
3
+ "version": "2.0.0-alpha.12",
4
4
  "license": "MIT",
5
- "description": "Ellie Mae - Dim Sum - Tabs",
6
- "module": "esm/index.js",
7
- "main": "cjs/index.js",
5
+ "description": "ICE MT - Dimsum - Tabs",
6
+ "module": "./esm/index.js",
7
+ "main": "./cjs/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./esm/index.js",
12
+ "require": "./cjs/index.js"
13
+ },
14
+ "./utils/hooks/useTabsCallbacks": {
15
+ "import": "./esm/utils/hooks/useTabsCallbacks.js",
16
+ "require": "./cjs/utils/hooks/useTabsCallbacks.js"
17
+ },
18
+ "./utils/hooks/useKeyboardNavigation": {
19
+ "import": "./esm/utils/hooks/useKeyboardNavigation.js",
20
+ "require": "./cjs/utils/hooks/useKeyboardNavigation.js"
21
+ },
22
+ "./utils/helpers": {
23
+ "import": "./esm/utils/helpers.js",
24
+ "require": "./cjs/utils/helpers.js"
25
+ },
26
+ "./utils/constants": {
27
+ "import": "./esm/utils/constants.js",
28
+ "require": "./cjs/utils/constants.js"
29
+ },
30
+ "./propTypes": {
31
+ "import": "./esm/propTypes.js",
32
+ "require": "./cjs/propTypes.js"
33
+ },
34
+ "./parts/tabsPanel/TabsPanels": {
35
+ "import": "./esm/parts/tabsPanel/TabsPanels.js",
36
+ "require": "./cjs/parts/tabsPanel/TabsPanels.js"
37
+ },
38
+ "./parts/tabsPanel/styles": {
39
+ "import": "./esm/parts/tabsPanel/styles.js",
40
+ "require": "./cjs/parts/tabsPanel/styles.js"
41
+ },
42
+ "./parts/tabsContent/TabsContent": {
43
+ "import": "./esm/parts/tabsContent/TabsContent.js",
44
+ "require": "./cjs/parts/tabsContent/TabsContent.js"
45
+ },
46
+ "./parts/tabsContent/styles": {
47
+ "import": "./esm/parts/tabsContent/styles.js",
48
+ "require": "./cjs/parts/tabsContent/styles.js"
49
+ },
50
+ "./parts/tabBar/useTabBar": {
51
+ "import": "./esm/parts/tabBar/useTabBar.js",
52
+ "require": "./cjs/parts/tabBar/useTabBar.js"
53
+ },
54
+ "./parts/tabBar/TabBar": {
55
+ "import": "./esm/parts/tabBar/TabBar.js",
56
+ "require": "./cjs/parts/tabBar/TabBar.js"
57
+ },
58
+ "./parts/tabBar/styles": {
59
+ "import": "./esm/parts/tabBar/styles.js",
60
+ "require": "./cjs/parts/tabBar/styles.js"
61
+ },
62
+ "./parts/carousel/useCarouselCallbacks": {
63
+ "import": "./esm/parts/carousel/useCarouselCallbacks.js",
64
+ "require": "./cjs/parts/carousel/useCarouselCallbacks.js"
65
+ },
66
+ "./parts/carousel/useCarousel": {
67
+ "import": "./esm/parts/carousel/useCarousel.js",
68
+ "require": "./cjs/parts/carousel/useCarousel.js"
69
+ },
70
+ "./parts/carousel/styles": {
71
+ "import": "./esm/parts/carousel/styles.js",
72
+ "require": "./cjs/parts/carousel/styles.js"
73
+ },
74
+ "./parts/carousel/Carousel": {
75
+ "import": "./esm/parts/carousel/Carousel.js",
76
+ "require": "./cjs/parts/carousel/Carousel.js"
77
+ },
78
+ "./exportsRelated/DSTab": {
79
+ "import": "./esm/exportsRelated/DSTab.js",
80
+ "require": "./cjs/exportsRelated/DSTab.js"
81
+ },
82
+ "./DSTabsTypes": {
83
+ "import": "./esm/DSTabsTypes.js",
84
+ "require": "./cjs/DSTabsTypes.js"
85
+ },
86
+ "./DSTabsDatatestid": {
87
+ "import": "./esm/DSTabsDatatestid.js",
88
+ "require": "./cjs/DSTabsDatatestid.js"
89
+ },
90
+ "./DSTabsCTX": {
91
+ "import": "./esm/DSTabsCTX.js",
92
+ "require": "./cjs/DSTabsCTX.js"
93
+ },
94
+ "./DSTabs": {
95
+ "import": "./esm/DSTabs.js",
96
+ "require": "./cjs/DSTabs.js"
97
+ },
98
+ "./defaultProps": {
99
+ "import": "./esm/defaultProps.js",
100
+ "require": "./cjs/defaultProps.js"
101
+ },
102
+ "./config/useTabs": {
103
+ "import": "./esm/config/useTabs.js",
104
+ "require": "./cjs/config/useTabs.js"
105
+ },
106
+ "./config/useCrossRef": {
107
+ "import": "./esm/config/useCrossRef.js",
108
+ "require": "./cjs/config/useCrossRef.js"
109
+ }
110
+ },
8
111
  "sideEffects": [
9
112
  "*.css",
10
113
  "*.scss"
11
114
  ],
115
+ "repository": {
116
+ "type": "git",
117
+ "url": "https://git.elliemae.io/platform-ui/dimsum.git"
118
+ },
119
+ "engines": {
120
+ "npm": ">=7",
121
+ "node": ">=14"
122
+ },
123
+ "author": "ICE MT",
12
124
  "scripts": {
13
125
  "dev": "cross-env NODE_ENV=development && node ../../scripts/build/build.js -w",
14
126
  "prebuild": "exit 0",
@@ -16,27 +128,31 @@
16
128
  "build": "node ../../scripts/build/build.js"
17
129
  },
18
130
  "dependencies": {
19
- "@elliemae/ds-button": "1.60.0",
20
- "@elliemae/ds-classnames": "1.60.0",
21
- "@elliemae/ds-form": "1.60.0",
22
- "@elliemae/ds-icons": "1.60.0",
23
- "memoize-one": "~5.1.1",
131
+ "@elliemae/ds-button": "2.0.0-alpha.12",
132
+ "@elliemae/ds-icon": "2.0.0-alpha.12",
133
+ "@elliemae/ds-icons": "2.0.0-alpha.12",
134
+ "@elliemae/ds-props-helpers": "2.0.0-alpha.12",
135
+ "@elliemae/ds-system": "2.0.0-alpha.12",
136
+ "@react-hook/resize-observer": "~1.2.5",
24
137
  "prop-types": "~15.7.2",
25
- "react-desc": "^4.1.2",
26
- "react-swipeable-views": "~0.13.9",
27
- "resize-observer": "~1.0.0"
138
+ "react-desc": "~4.1.3",
139
+ "react-swipeable-views": "~0.13.9"
28
140
  },
29
141
  "devDependencies": {
30
- "styled-components": "~5.3.0"
142
+ "@testing-library/jest-dom": "~5.15.0",
143
+ "@testing-library/react": "~12.1.2",
144
+ "@testing-library/user-event": "~13.5.0",
145
+ "styled-components": "~5.3.3"
31
146
  },
32
147
  "peerDependencies": {
33
- "lodash": "^4.17.20",
34
- "react": "^17.0.1",
35
- "react-dom": "^17.0.1",
36
- "styled-components": "^5.3.0"
148
+ "lodash": "^4.17.21",
149
+ "react": "^17.0.2",
150
+ "react-dom": "^17.0.2",
151
+ "styled-components": "^5.3.3"
37
152
  },
38
153
  "publishConfig": {
39
154
  "access": "public",
40
- "directory": "dist"
155
+ "directory": "dist",
156
+ "generateSubmodules": true
41
157
  }
42
158
  }
@@ -0,0 +1,14 @@
1
+ /// <reference path="../../../../shared/typings/react-desc.d.ts" />
2
+ import type { WeakValidationMap } from 'react';
3
+ import type { DSTabsPropsT } from './DSTabsTypes';
4
+ declare const DSTabs: {
5
+ (props: DSTabsPropsT): JSX.Element;
6
+ propTypes: WeakValidationMap<unknown>;
7
+ };
8
+ declare const DSTabsWithSchema: {
9
+ (props?: DSTabsPropsT | undefined): JSX.Element;
10
+ propTypes: unknown;
11
+ toTypescript: () => import("react-desc").TypescriptSchema;
12
+ };
13
+ export { DSTabs, DSTabsWithSchema };
14
+ export default DSTabs;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { DSTabsUseCrossRefContextT, DSTabsUseTabsContextT } from './DSTabsTypes';
3
+ export declare const DSTabsContext: import("react").Context<DSTabsUseTabsContextT>;
4
+ export declare const DSTabsCrossRefContext: import("react").Context<DSTabsUseCrossRefContextT>;
@@ -0,0 +1,12 @@
1
+ export declare const DSTabsDatatestid: {
2
+ TABS_CONTAINER: string;
3
+ TAB_BUTTON: string;
4
+ SUBTAB_BUTTON: string;
5
+ TAB_PANEL: string;
6
+ SUB_TAB_LIST: string;
7
+ TAB_LIST: string;
8
+ CAROUSEL: {
9
+ BUTTON_RIGHT: string;
10
+ BUTTON_LEFT: string;
11
+ };
12
+ };