@elliemae/ds-tabs 2.2.0-next.5 → 2.2.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.
@@ -11,7 +11,6 @@ var useTabBar = require('./useTabBar.js');
11
11
  var styles = require('./styles.js');
12
12
  var DSTabsCTX = require('../../DSTabsCTX.js');
13
13
  var useKeyboardNavigation = require('../../utils/hooks/useKeyboardNavigation.js');
14
- var helpers = require('../../utils/helpers.js');
15
14
  var constants = require('../../utils/constants.js');
16
15
  var useTabsCallbacks = require('../../utils/hooks/useTabsCallbacks.js');
17
16
  var DSTabsDatatestid = require('../../DSTabsDatatestid.js');
@@ -29,7 +28,6 @@ const TabBar = () => {
29
28
  focusableTabsRef,
30
29
  tabsListRef,
31
30
  tabsRefAsArray,
32
- carouselOnlyListRef,
33
31
  actualActiveTab,
34
32
  props: {
35
33
  type,
@@ -115,12 +113,6 @@ const TabBar = () => {
115
113
 
116
114
  if (onClick && !disabled) onClick(tabId, e);
117
115
  },
118
- onFocus: e => {
119
- if (withCarousel) helpers.centerTab({
120
- e,
121
- listRef: carouselOnlyListRef
122
- });
123
- },
124
116
  onKeyDown: e => {
125
117
  if (e.key === 'Enter') e.stopPropagation();
126
118
  if (!disabled) handleOnKeyDown(e);
@@ -130,7 +122,7 @@ const TabBar = () => {
130
122
  children: [title, required && (_StyledRequiredMark || (_StyledRequiredMark = /*#__PURE__*/_jsx__default["default"](styles.StyledRequiredMark, {}, void 0, "\u25CF")))]
131
123
  }, tabId);
132
124
  });
133
- }, [tabs, actualActiveTab, isDSMobile, fixedTabsHeaders, type, withCarousel, showSeparator, tabsRefAsArray, focusableTabsRef, tabsRef, firstSubtabInternalRef, lastTabInternalRef, handleOnTabChange, updateIndicatorStyle, carouselOnlyListRef, handleOnKeyDown]);
125
+ }, [tabs, actualActiveTab, isDSMobile, fixedTabsHeaders, type, withCarousel, showSeparator, tabsRefAsArray, focusableTabsRef, tabsRef, firstSubtabInternalRef, lastTabInternalRef, handleOnTabChange, updateIndicatorStyle, handleOnKeyDown]);
134
126
 
135
127
  if (type === constants.TabTypes.SUBTABS && !isDSMobile) {
136
128
  return /*#__PURE__*/jsxRuntime.jsx(styles.StyledSubTabsList, {
@@ -66,6 +66,15 @@ const useTabBar = () => {
66
66
  });
67
67
  }
68
68
  }, [fixedTabsHeaders, isDSMobile, tabsListRef]);
69
+ React.useEffect(() => {
70
+ if (showSelectionIndicator) {
71
+ updateIndicatorStyle();
72
+ }
73
+
74
+ if (isDSMobile && !fixedTabsHeaders) {
75
+ updateMobileGradients();
76
+ }
77
+ }, [updateIndicatorStyle, showSelectionIndicator, actualActiveTab, updateMobileGradients, isDSMobile, fixedTabsHeaders]);
69
78
  React.useLayoutEffect(() => {
70
79
  if (showSelectionIndicator) {
71
80
  updateIndicatorStyle();
@@ -74,7 +83,7 @@ const useTabBar = () => {
74
83
  if (isDSMobile && !fixedTabsHeaders) {
75
84
  updateMobileGradients();
76
85
  }
77
- }, [updateMobileGradients, showSelectionIndicator, updateIndicatorStyle, isDSMobile, fixedTabsHeaders, actualActiveTab]);
86
+ }, [updateMobileGradients, showSelectionIndicator, updateIndicatorStyle, isDSMobile, fixedTabsHeaders]);
78
87
  return {
79
88
  updateIndicatorStyle,
80
89
  setIndicatorStyle,
@@ -25,33 +25,6 @@ const isElementVisibleCarousel = function (tab, tabContainer) {
25
25
 
26
26
  return false;
27
27
  };
28
- const centerTab = _ref => {
29
- let {
30
- e,
31
- listRef
32
- } = _ref;
33
-
34
- if (listRef.current) {
35
- const {
36
- offsetLeft
37
- } = e === null || e === void 0 ? void 0 : e.target;
38
- const {
39
- width: tabWidth
40
- } = (e === null || e === void 0 ? void 0 : e.target).getBoundingClientRect();
41
- const {
42
- width: listWidth
43
- } = listRef.current.getBoundingClientRect();
44
- const extraSideSpace = listWidth - tabWidth;
45
- const leftOffsetToCenter = extraSideSpace > 0 ? extraSideSpace / 2 : 0;
46
- const centeredLeftOffset = offsetLeft > leftOffsetToCenter ? offsetLeft - leftOffsetToCenter : 0;
47
- listRef.current.scrollTo({
48
- top: 0,
49
- left: centeredLeftOffset,
50
- behavior: 'smooth'
51
- });
52
- e === null || e === void 0 ? void 0 : e.preventDefault();
53
- }
54
- };
55
28
  const getVisibleDimensions = (node, referenceNode) => {
56
29
  const nodeDimensions = node.getBoundingClientRect();
57
30
  const referenceNodeDimensions = referenceNode.getBoundingClientRect();
@@ -65,7 +38,6 @@ const getIdByIndex = (children, index) => children && children[index].props.tabI
65
38
  const shouldHaveLeftGradient = scrollLeft => Math.abs(scrollLeft) > constants.MOBILE_GRADIENT_WIDTH;
66
39
  const shouldHaveRightGradient = (scrollLeft, clientWidth, scrollWidth) => Math.abs(scrollLeft) <= scrollWidth - (clientWidth + constants.MOBILE_GRADIENT_WIDTH);
67
40
 
68
- exports.centerTab = centerTab;
69
41
  exports.getIdByIndex = getIdByIndex;
70
42
  exports.getIndexById = getIndexById;
71
43
  exports.getVisibleDimensions = getVisibleDimensions;
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var helpers = require('../helpers.js');
7
6
  var DSTabsCTX = require('../../DSTabsCTX.js');
8
7
 
9
8
  const useTabsCallbacks = () => {
@@ -17,17 +16,36 @@ const useTabsCallbacks = () => {
17
16
  fixedTabsHeaders
18
17
  }
19
18
  } = React.useContext(DSTabsCTX.DSTabsContext);
19
+ const centerTabWhenTabChangeMobile = React.useCallback(e => {
20
+ if (tabsListRef.current) {
21
+ const {
22
+ offsetLeft
23
+ } = e === null || e === void 0 ? void 0 : e.target;
24
+ const {
25
+ width: tabWidth
26
+ } = (e === null || e === void 0 ? void 0 : e.target).getBoundingClientRect();
27
+ const {
28
+ width: listWidth
29
+ } = tabsListRef.current.getBoundingClientRect();
30
+ const extraSideSpace = listWidth - tabWidth;
31
+ const leftOffsetToCenter = extraSideSpace > 0 ? extraSideSpace / 2 : 0;
32
+ const centeredLeftOffset = offsetLeft > leftOffsetToCenter ? offsetLeft - leftOffsetToCenter : 0;
33
+ tabsListRef.current.scrollTo({
34
+ top: 0,
35
+ left: centeredLeftOffset,
36
+ behavior: 'smooth'
37
+ });
38
+ e === null || e === void 0 ? void 0 : e.preventDefault();
39
+ }
40
+ }, [tabsListRef]);
20
41
  const handleOnTabChange = React.useCallback((tabId, e) => {
21
42
  setInternalActiveTab(tabId);
22
43
  onTabChange(tabId, e);
23
44
 
24
45
  if (isDSMobile && !fixedTabsHeaders && e) {
25
- helpers.centerTab({
26
- e,
27
- listRef: tabsListRef
28
- });
46
+ centerTabWhenTabChangeMobile(e);
29
47
  }
30
- }, [fixedTabsHeaders, isDSMobile, onTabChange, setInternalActiveTab, tabsListRef]);
48
+ }, [centerTabWhenTabChangeMobile, fixedTabsHeaders, isDSMobile, onTabChange, setInternalActiveTab]);
31
49
  const handleOnMouseDown = React.useCallback(e => {
32
50
  const role = e.target.getAttribute('role');
33
51
  if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
@@ -7,7 +7,6 @@ import { useTabBar } from './useTabBar.js';
7
7
  import { StyledTabButton, StyledRequiredMark, StyledSubTabsList, StyledTabList, StyledTabWrapper, StyledSelectionIndicator } from './styles.js';
8
8
  import { DSTabsContext, DSTabsCrossRefContext } from '../../DSTabsCTX.js';
9
9
  import { useKeyboardNavigation } from '../../utils/hooks/useKeyboardNavigation.js';
10
- import { centerTab } from '../../utils/helpers.js';
11
10
  import { TabTypes } from '../../utils/constants.js';
12
11
  import { useTabsCallbacks } from '../../utils/hooks/useTabsCallbacks.js';
13
12
  import { DSTabsDatatestid } from '../../DSTabsDatatestid.js';
@@ -20,7 +19,6 @@ const TabBar = () => {
20
19
  focusableTabsRef,
21
20
  tabsListRef,
22
21
  tabsRefAsArray,
23
- carouselOnlyListRef,
24
22
  actualActiveTab,
25
23
  props: {
26
24
  type,
@@ -106,12 +104,6 @@ const TabBar = () => {
106
104
 
107
105
  if (onClick && !disabled) onClick(tabId, e);
108
106
  },
109
- onFocus: e => {
110
- if (withCarousel) centerTab({
111
- e,
112
- listRef: carouselOnlyListRef
113
- });
114
- },
115
107
  onKeyDown: e => {
116
108
  if (e.key === 'Enter') e.stopPropagation();
117
109
  if (!disabled) handleOnKeyDown(e);
@@ -121,7 +113,7 @@ const TabBar = () => {
121
113
  children: [title, required && (_StyledRequiredMark || (_StyledRequiredMark = /*#__PURE__*/_jsx(StyledRequiredMark, {}, void 0, "\u25CF")))]
122
114
  }, tabId);
123
115
  });
124
- }, [tabs, actualActiveTab, isDSMobile, fixedTabsHeaders, type, withCarousel, showSeparator, tabsRefAsArray, focusableTabsRef, tabsRef, firstSubtabInternalRef, lastTabInternalRef, handleOnTabChange, updateIndicatorStyle, carouselOnlyListRef, handleOnKeyDown]);
116
+ }, [tabs, actualActiveTab, isDSMobile, fixedTabsHeaders, type, withCarousel, showSeparator, tabsRefAsArray, focusableTabsRef, tabsRef, firstSubtabInternalRef, lastTabInternalRef, handleOnTabChange, updateIndicatorStyle, handleOnKeyDown]);
125
117
 
126
118
  if (type === TabTypes.SUBTABS && !isDSMobile) {
127
119
  return /*#__PURE__*/jsx(StyledSubTabsList, {
@@ -1,5 +1,5 @@
1
1
  import 'core-js/modules/web.dom-collections.iterator.js';
2
- import { useContext, useState, useCallback, useLayoutEffect } from 'react';
2
+ import { useContext, useState, useCallback, useEffect, useLayoutEffect } from 'react';
3
3
  import useResizeObserver from '@react-hook/resize-observer';
4
4
  import { isElementVisible, shouldHaveLeftGradient, shouldHaveRightGradient } from '../../utils/helpers.js';
5
5
  import { DSTabsContext } from '../../DSTabsCTX.js';
@@ -58,6 +58,15 @@ const useTabBar = () => {
58
58
  });
59
59
  }
60
60
  }, [fixedTabsHeaders, isDSMobile, tabsListRef]);
61
+ useEffect(() => {
62
+ if (showSelectionIndicator) {
63
+ updateIndicatorStyle();
64
+ }
65
+
66
+ if (isDSMobile && !fixedTabsHeaders) {
67
+ updateMobileGradients();
68
+ }
69
+ }, [updateIndicatorStyle, showSelectionIndicator, actualActiveTab, updateMobileGradients, isDSMobile, fixedTabsHeaders]);
61
70
  useLayoutEffect(() => {
62
71
  if (showSelectionIndicator) {
63
72
  updateIndicatorStyle();
@@ -66,7 +75,7 @@ const useTabBar = () => {
66
75
  if (isDSMobile && !fixedTabsHeaders) {
67
76
  updateMobileGradients();
68
77
  }
69
- }, [updateMobileGradients, showSelectionIndicator, updateIndicatorStyle, isDSMobile, fixedTabsHeaders, actualActiveTab]);
78
+ }, [updateMobileGradients, showSelectionIndicator, updateIndicatorStyle, isDSMobile, fixedTabsHeaders]);
70
79
  return {
71
80
  updateIndicatorStyle,
72
81
  setIndicatorStyle,
@@ -21,33 +21,6 @@ const isElementVisibleCarousel = function (tab, tabContainer) {
21
21
 
22
22
  return false;
23
23
  };
24
- const centerTab = _ref => {
25
- let {
26
- e,
27
- listRef
28
- } = _ref;
29
-
30
- if (listRef.current) {
31
- const {
32
- offsetLeft
33
- } = e === null || e === void 0 ? void 0 : e.target;
34
- const {
35
- width: tabWidth
36
- } = (e === null || e === void 0 ? void 0 : e.target).getBoundingClientRect();
37
- const {
38
- width: listWidth
39
- } = listRef.current.getBoundingClientRect();
40
- const extraSideSpace = listWidth - tabWidth;
41
- const leftOffsetToCenter = extraSideSpace > 0 ? extraSideSpace / 2 : 0;
42
- const centeredLeftOffset = offsetLeft > leftOffsetToCenter ? offsetLeft - leftOffsetToCenter : 0;
43
- listRef.current.scrollTo({
44
- top: 0,
45
- left: centeredLeftOffset,
46
- behavior: 'smooth'
47
- });
48
- e === null || e === void 0 ? void 0 : e.preventDefault();
49
- }
50
- };
51
24
  const getVisibleDimensions = (node, referenceNode) => {
52
25
  const nodeDimensions = node.getBoundingClientRect();
53
26
  const referenceNodeDimensions = referenceNode.getBoundingClientRect();
@@ -61,4 +34,4 @@ const getIdByIndex = (children, index) => children && children[index].props.tabI
61
34
  const shouldHaveLeftGradient = scrollLeft => Math.abs(scrollLeft) > MOBILE_GRADIENT_WIDTH;
62
35
  const shouldHaveRightGradient = (scrollLeft, clientWidth, scrollWidth) => Math.abs(scrollLeft) <= scrollWidth - (clientWidth + MOBILE_GRADIENT_WIDTH);
63
36
 
64
- export { centerTab, getIdByIndex, getIndexById, getVisibleDimensions, isElementVisible, isElementVisibleCarousel, shouldHaveLeftGradient, shouldHaveRightGradient };
37
+ export { getIdByIndex, getIndexById, getVisibleDimensions, isElementVisible, isElementVisibleCarousel, shouldHaveLeftGradient, shouldHaveRightGradient };
@@ -1,5 +1,4 @@
1
1
  import { useContext, useCallback } from 'react';
2
- import { centerTab } from '../helpers.js';
3
2
  import { DSTabsContext } from '../../DSTabsCTX.js';
4
3
 
5
4
  const useTabsCallbacks = () => {
@@ -13,17 +12,36 @@ const useTabsCallbacks = () => {
13
12
  fixedTabsHeaders
14
13
  }
15
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]);
16
37
  const handleOnTabChange = useCallback((tabId, e) => {
17
38
  setInternalActiveTab(tabId);
18
39
  onTabChange(tabId, e);
19
40
 
20
41
  if (isDSMobile && !fixedTabsHeaders && e) {
21
- centerTab({
22
- e,
23
- listRef: tabsListRef
24
- });
42
+ centerTabWhenTabChangeMobile(e);
25
43
  }
26
- }, [fixedTabsHeaders, isDSMobile, onTabChange, setInternalActiveTab, tabsListRef]);
44
+ }, [centerTabWhenTabChangeMobile, fixedTabsHeaders, isDSMobile, onTabChange, setInternalActiveTab]);
27
45
  const handleOnMouseDown = useCallback(e => {
28
46
  const role = e.target.getAttribute('role');
29
47
  if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-tabs",
3
- "version": "2.2.0-next.5",
3
+ "version": "2.2.0",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Tabs",
6
6
  "module": "./esm/index.js",
@@ -128,11 +128,11 @@
128
128
  "build": "node ../../scripts/build/build.js"
129
129
  },
130
130
  "dependencies": {
131
- "@elliemae/ds-button": "2.2.0-next.5",
132
- "@elliemae/ds-icon": "2.2.0-next.5",
133
- "@elliemae/ds-icons": "2.2.0-next.5",
134
- "@elliemae/ds-props-helpers": "2.2.0-next.5",
135
- "@elliemae/ds-system": "2.2.0-next.5",
131
+ "@elliemae/ds-button": "2.2.0",
132
+ "@elliemae/ds-icon": "2.2.0",
133
+ "@elliemae/ds-icons": "2.2.0",
134
+ "@elliemae/ds-props-helpers": "2.2.0",
135
+ "@elliemae/ds-system": "2.2.0",
136
136
  "@react-hook/resize-observer": "~1.2.5",
137
137
  "prop-types": "~15.7.2",
138
138
  "react-desc": "~4.1.3",
@@ -162,10 +162,6 @@ export interface VisibleDimensionsT {
162
162
  width: number;
163
163
  height: number;
164
164
  }
165
- export interface CenterTabPropsT {
166
- e?: React.MouseEvent | React.FocusEvent;
167
- listRef: React.MutableRefObject<HTMLDivElement | null>;
168
- }
169
165
  export interface StyledTabWrapperPropsT {
170
166
  isDSMobile: boolean;
171
167
  fixedTabsHeaders: boolean;
@@ -1,7 +1,6 @@
1
- import type { CenterTabPropsT, DSTabPropsWithDefaultT, VisibleDimensionsT } from '../DSTabsTypes';
1
+ import type { DSTabPropsWithDefaultT, VisibleDimensionsT } from '../DSTabsTypes';
2
2
  export declare const isElementVisible: (tab: HTMLElement, tabList: HTMLElement) => boolean;
3
3
  export declare const isElementVisibleCarousel: (tab: HTMLElement | null, tabContainer: HTMLDivElement | null, firstOrLastItem?: boolean) => boolean;
4
- export declare const centerTab: ({ e, listRef }: CenterTabPropsT) => void;
5
4
  export declare const getVisibleDimensions: (node: HTMLElement, referenceNode: HTMLElement) => VisibleDimensionsT;
6
5
  export declare const getIndexById: (children: React.ReactElement<DSTabPropsWithDefaultT>[], activeId?: string | undefined) => number;
7
6
  export declare const getIdByIndex: (children: React.ReactElement<DSTabPropsWithDefaultT>[], index: number) => string;