@elliemae/ds-tabs 2.0.0-alpha.11 → 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 (104) hide show
  1. package/cjs/DSTabs.js +28 -106
  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} +18 -27
  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 +30 -108
  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} +11 -23
  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 +100 -37
  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 -198
  81. package/cjs/DSTab.js +0 -43
  82. package/cjs/SubTabBar.js +0 -45
  83. package/cjs/TabBar.js +0 -410
  84. package/cjs/TabTypes.js +0 -12
  85. package/cjs/TabsImpl.js +0 -115
  86. package/cjs/TabsPanels.js +0 -83
  87. package/cjs/useResize.js +0 -24
  88. package/esm/Carousel.js +0 -187
  89. package/esm/DSTab.js +0 -33
  90. package/esm/SubTabBar.js +0 -39
  91. package/esm/TabBar.js +0 -399
  92. package/esm/TabTypes.js +0 -7
  93. package/esm/TabsImpl.js +0 -108
  94. package/esm/TabsPanels.js +0 -73
  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/esm/TabsImpl.js DELETED
@@ -1,108 +0,0 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import _jsx from '@babel/runtime/helpers/esm/jsx';
3
- import 'core-js/modules/web.dom-collections.iterator.js';
4
- import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
5
- import { aggregatedClasses } from '@elliemae/ds-classnames';
6
- import TabsPanels from './TabsPanels.js';
7
- import TabBar from './TabBar.js';
8
- import SubTabBar from './SubTabBar.js';
9
- import { TabTypes } from './TabTypes.js';
10
- import { jsxs } from 'react/jsx-runtime';
11
-
12
- 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; }
13
-
14
- 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; }
15
- const blockName = 'tabs';
16
- const StyledTabsContainer = aggregatedClasses('div')(blockName);
17
- const StyledTabBarContainer = aggregatedClasses('div')(blockName, 'tab-bar-container');
18
- const TabBarComponentsByType = {
19
- [TabTypes.NORMAL]: TabBar,
20
- [TabTypes.SUBTABS]: SubTabBar
21
- };
22
-
23
- const TabsImpl = props => {
24
- var _tabs$, _tabs$$props, _TabsPanels, _StyledTabBarContaine;
25
-
26
- const {
27
- animated,
28
- children: tabs,
29
- type,
30
- tabBarExtraContent,
31
- onTabChange,
32
- enableMouseEvents,
33
- innerRef,
34
- onlyRenderActiveTab,
35
- containerProps,
36
- allowTextSelection,
37
- tabsListAriaLabel,
38
- activeTab,
39
- firstSubtabRef,
40
- lastTabRef,
41
- withCarousel,
42
- flexibleTabsHeaders,
43
- fixedTabsHeaders,
44
- isDSMobile
45
- } = props;
46
- const [actualActiveTab, setActualActiveTab] = useState(activeTab || (tabs === null || tabs === void 0 ? void 0 : (_tabs$ = tabs[0]) === null || _tabs$ === void 0 ? void 0 : (_tabs$$props = _tabs$.props) === null || _tabs$$props === void 0 ? void 0 : _tabs$$props.tabId));
47
- const firstTabRefByParent = useRef(null);
48
- const lastTabRefByParent = useRef(null);
49
- useEffect(() => {
50
- if (activeTab) {
51
- setActualActiveTab(activeTab);
52
- }
53
- }, [activeTab]);
54
- const handleTabClick = useCallback(tab => {
55
- setActualActiveTab(tab);
56
- onTabChange(tab);
57
- }, [onTabChange]);
58
- const handleDownArrow = useCallback(e => {
59
- var _firstTabRefByParent$;
60
-
61
- e.preventDefault();
62
- e.stopPropagation();
63
- if (firstTabRefByParent !== null && firstTabRefByParent !== void 0 && firstTabRefByParent.current) (_firstTabRefByParent$ = firstTabRefByParent.current) === null || _firstTabRefByParent$ === void 0 ? void 0 : _firstTabRefByParent$.focus();
64
- }, [firstTabRefByParent]);
65
- const handleUpArrow = useCallback(e => {
66
- var _lastTabRef$current;
67
-
68
- e.preventDefault();
69
- e.stopPropagation();
70
- if (lastTabRef !== null && lastTabRef !== void 0 && lastTabRef.current) (_lastTabRef$current = lastTabRef.current) === null || _lastTabRef$current === void 0 ? void 0 : _lastTabRef$current.focus();
71
- }, [lastTabRef]);
72
- const PureTabBarComponent = useMemo(() => {
73
- const TabBarComponent = TabBarComponentsByType[type] || TabBar;
74
- return /*#__PURE__*/_jsx(TabBarComponent, {
75
- withCarousel: withCarousel,
76
- activeTab: actualActiveTab,
77
- onTabClick: handleTabClick,
78
- tabs: tabs,
79
- firstSubtabRef: firstSubtabRef,
80
- lastTabRef: lastTabRefByParent,
81
- handleDownArrow: handleDownArrow,
82
- handleUpArrow: handleUpArrow,
83
- isDSMobile: isDSMobile,
84
- flexibleTabsHeaders: flexibleTabsHeaders,
85
- fixedTabsHeaders: fixedTabsHeaders
86
- });
87
- }, [type, withCarousel, actualActiveTab, handleTabClick, tabs, firstSubtabRef, lastTabRefByParent, handleDownArrow, handleUpArrow, isDSMobile]);
88
- const PureTabsPanels = useMemo(() => _TabsPanels || (_TabsPanels = /*#__PURE__*/_jsx(TabsPanels, {
89
- activeTab: actualActiveTab,
90
- allowTextSelection: allowTextSelection,
91
- animated: animated,
92
- enableMouseEvents: enableMouseEvents,
93
- onlyRenderActiveTab: onlyRenderActiveTab,
94
- onTabChange: handleTabClick,
95
- tabsComponents: tabs,
96
- lastTabRef: lastTabRefByParent,
97
- firstTabRefByParent: firstTabRefByParent
98
- })), [actualActiveTab, allowTextSelection, animated, enableMouseEvents, onlyRenderActiveTab, handleTabClick, tabs, lastTabRefByParent, firstTabRefByParent]);
99
- const PureTabsImpl = useMemo(() => /*#__PURE__*/jsxs(StyledTabsContainer, _objectSpread(_objectSpread({}, containerProps), {}, {
100
- "aria-label": tabsListAriaLabel,
101
- innerRef: innerRef,
102
- role: "tablist",
103
- children: [_StyledTabBarContaine || (_StyledTabBarContaine = /*#__PURE__*/_jsx(StyledTabBarContainer, {}, void 0, PureTabBarComponent, tabBarExtraContent)), PureTabsPanels]
104
- })), [containerProps, tabsListAriaLabel, innerRef, PureTabBarComponent, tabBarExtraContent, PureTabsPanels]);
105
- return PureTabsImpl;
106
- };
107
-
108
- export { TabsImpl as default };
package/esm/TabsPanels.js DELETED
@@ -1,73 +0,0 @@
1
- import _jsx from '@babel/runtime/helpers/esm/jsx';
2
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
- import 'core-js/modules/web.dom-collections.iterator.js';
4
- import React, { Component } from 'react';
5
- import memoizeOne from 'memoize-one';
6
- import { aggregatedClasses } from '@elliemae/ds-classnames';
7
- import SwipeableViews from 'react-swipeable-views';
8
- import PanelContainer from './PanelContainer.js';
9
-
10
- const blockName = 'tabs-panels';
11
- const Panels = aggregatedClasses('div')(blockName);
12
-
13
- const getIndexById = (children, activeId) => children && children.findIndex(item => item.props.tabId === activeId);
14
-
15
- const getIdByIndex = (children, index) => children && children[index].props.tabId;
16
-
17
- class TabsPanels extends Component {
18
- constructor(...args) {
19
- super(...args);
20
-
21
- _defineProperty(this, "renderPanels", memoizeOne((activeTab, tabsComponents) => {
22
- const {
23
- animated,
24
- onlyRenderActiveTab,
25
- allowTextSelection
26
- } = this.props;
27
- return React.Children.map(tabsComponents, tab => {
28
- const {
29
- tabId: panelId,
30
- style,
31
- children: content
32
- } = tab.props;
33
- const isActive = activeTab === panelId;
34
- const shouldRender = !onlyRenderActiveTab || isActive;
35
- return /*#__PURE__*/_jsx(PanelContainer, {
36
- "aria-labelledby": "".concat(panelId, "-label"),
37
- lastTabRef: this.props.lastTabRef,
38
- firstSubtabRef: this.props.firstTabRefByParent,
39
- classProps: {
40
- isActive
41
- },
42
- "data-panel-id": panelId,
43
- hidden: !animated && !isActive,
44
- onMouseDown: e => {
45
- const role = e.target.getAttribute('role');
46
- if (role !== 'tabpanel' && allowTextSelection) e.stopPropagation();
47
- },
48
- role: "tabpanel",
49
- style: style
50
- }, panelId, shouldRender && content);
51
- }, null);
52
- }));
53
- }
54
-
55
- render() {
56
- const {
57
- activeTab,
58
- tabsComponents,
59
- animated,
60
- onTabChange,
61
- enableMouseEvents
62
- } = this.props;
63
- const panels = animated ? /*#__PURE__*/_jsx(SwipeableViews, {
64
- enableMouseEvents: enableMouseEvents,
65
- index: getIndexById(tabsComponents, activeTab),
66
- onChangeIndex: index => onTabChange(getIdByIndex(tabsComponents, index))
67
- }, void 0, this.renderPanels(activeTab, tabsComponents)) : this.renderPanels(activeTab, tabsComponents);
68
- return /*#__PURE__*/_jsx(Panels, {}, void 0, panels);
69
- }
70
-
71
- }
72
-
73
- export { TabsPanels as default };
package/esm/useResize.js DELETED
@@ -1,20 +0,0 @@
1
- import { useLayoutEffect } from 'react';
2
- import { debounce } from 'lodash';
3
-
4
- function useResize(ref, callback) {
5
- var _ref$current;
6
-
7
- const {
8
- right,
9
- left
10
- } = (ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect()) || {
11
- right: null,
12
- left: null
13
- };
14
- const handleResize = debounce(callback, 300);
15
- useLayoutEffect(() => {
16
- handleResize();
17
- }, [right, left]);
18
- }
19
-
20
- export { useResize };
@@ -1,16 +0,0 @@
1
- /// <reference types="react" />
2
- import PropTypes from 'prop-types';
3
- declare const Carousel: {
4
- ({ children, onScroll }: {
5
- children: any;
6
- onScroll: any;
7
- }): JSX.Element;
8
- defaultProps: {
9
- onScroll: () => null;
10
- };
11
- propTypes: {
12
- children: PropTypes.Validator<(PropTypes.ReactElementLike | null | undefined)[]>;
13
- onScroll: PropTypes.Requireable<(...args: any[]) => any>;
14
- };
15
- };
16
- export default Carousel;
package/types/DSTab.d.ts DELETED
@@ -1,22 +0,0 @@
1
- /// <reference types="react" />
2
- declare const DSTab: {
3
- ({ tabId, title, required }: {
4
- tabId?: string | undefined;
5
- title?: string | undefined;
6
- required?: boolean | undefined;
7
- }): JSX.Element;
8
- displayName: string;
9
- propTypes: {
10
- /** unique id for tab */
11
- tabId: any;
12
- /** tab title */
13
- title: any;
14
- /** Show a required mark next to the title */
15
- required: any;
16
- /** Whether or not it's a ds-tab from DSMobile tabs */
17
- isDSMobile: any;
18
- };
19
- };
20
- declare const DSTabWithSchema: any;
21
- export { DSTab, DSTabWithSchema };
22
- export default DSTab;
@@ -1,20 +0,0 @@
1
- /// <reference types="react" />
2
- import PropTypes from 'prop-types';
3
- declare const PanelContainer: {
4
- ({ children, lastTabRef, firstSubtabRef, ...rest }: {
5
- [x: string]: any;
6
- children: any;
7
- lastTabRef: any;
8
- firstSubtabRef: any;
9
- }): JSX.Element;
10
- propTypes: {
11
- children: PropTypes.Requireable<any>;
12
- firstSubtabRef: PropTypes.Requireable<((...args: any[]) => any) | PropTypes.InferProps<{
13
- current: PropTypes.Requireable<any>;
14
- }>>;
15
- lastTabRef: PropTypes.Requireable<((...args: any[]) => any) | PropTypes.InferProps<{
16
- current: PropTypes.Requireable<any>;
17
- }>>;
18
- };
19
- };
20
- export default PanelContainer;
@@ -1,23 +0,0 @@
1
- /// <reference types="react" />
2
- import PropTypes from 'prop-types';
3
- declare const SubTabBar: {
4
- ({ withCarousel, tabs, activeTab, onTabClick, firstSubtabRef, handleUpArrow, }: {
5
- withCarousel: any;
6
- tabs?: never[] | undefined;
7
- activeTab?: string | undefined;
8
- onTabClick?: (() => null) | undefined;
9
- firstSubtabRef: any;
10
- handleUpArrow: any;
11
- }): JSX.Element;
12
- propTypes: {
13
- tabs: PropTypes.Validator<(PropTypes.ReactElementLike | null | undefined)[]>;
14
- activeTab: PropTypes.Requireable<string>;
15
- onTabClick: PropTypes.Validator<(...args: any[]) => any>;
16
- withCarousel: PropTypes.Requireable<boolean>;
17
- handleUpArrow: PropTypes.Requireable<(...args: any[]) => any>;
18
- firstSubtabRef: PropTypes.Requireable<((...args: any[]) => any) | PropTypes.InferProps<{
19
- current: PropTypes.Requireable<any>;
20
- }>>;
21
- };
22
- };
23
- export default SubTabBar;
package/types/TabBar.d.ts DELETED
@@ -1,30 +0,0 @@
1
- /// <reference types="lodash" />
2
- import { Component } from 'react';
3
- declare class TabBar extends Component {
4
- constructor(props: any);
5
- componentDidMount(): void;
6
- componentDidUpdate(prevProps: any): void;
7
- componentWillUnmount(): void;
8
- handleGradients(): void;
9
- shouldHaveLeftGradient(scrollLeft: any, gWidth: any): boolean;
10
- shouldHaveRightGradient(scrollLeft: any, gWidth: any, clientWidth: any, scrollWidth: any): boolean;
11
- setIndicatorStyle(): void;
12
- getActiveTabElement(activeTab: any): any;
13
- isElementVisible(el: any, holder: any): boolean;
14
- getVisibleDimensions(node: any, referenceNode: any): {
15
- width: number;
16
- height: number;
17
- };
18
- getIndicatorStyles(activeTab: any): {
19
- height: any;
20
- left: string;
21
- top: string;
22
- width: any;
23
- } | null;
24
- handleTabClick: (tabId: any, e: any) => void;
25
- handleKeyPress: (tabId: any, e: any, index: any) => void;
26
- handleTabsHeadersHorizontalScroll: import("lodash").DebouncedFunc<() => void>;
27
- renderTabs: (this: any, activeTab: any, tabs: any) => any;
28
- render(): any;
29
- }
30
- export default TabBar;
@@ -1,5 +0,0 @@
1
- export declare const TabTypes: {
2
- NORMAL: string;
3
- SUBTABS: string;
4
- };
5
- export declare const getTabTypes: () => any[];
@@ -1,37 +0,0 @@
1
- /// <reference types="react" />
2
- import PropTypes from 'prop-types';
3
- declare const TabsImpl: {
4
- (props: any): JSX.Element;
5
- propTypes: {
6
- animated: PropTypes.Requireable<boolean>;
7
- enableMouseEvents: PropTypes.Requireable<boolean>;
8
- allowTextSelection: PropTypes.Requireable<boolean>;
9
- onTabChange: PropTypes.Requireable<(...args: any[]) => any>;
10
- type: PropTypes.Requireable<string>;
11
- tabBarExtraContent: PropTypes.Requireable<PropTypes.ReactElementLike>;
12
- onlyRenderActiveTab: PropTypes.Requireable<boolean>;
13
- withCarousel: PropTypes.Requireable<boolean>;
14
- activeTab: PropTypes.Requireable<string>;
15
- children: PropTypes.Validator<(PropTypes.InferProps<{
16
- type: PropTypes.Requireable<any>;
17
- }> | null | undefined)[]>;
18
- tabsListAriaLabel: PropTypes.Requireable<string>;
19
- containerProps: PropTypes.Requireable<object>;
20
- innerRef: PropTypes.Requireable<((...args: any[]) => any) | PropTypes.InferProps<{
21
- current: PropTypes.Requireable<any>;
22
- }>>;
23
- firstSubtabRef: PropTypes.Requireable<((...args: any[]) => any) | PropTypes.InferProps<{
24
- current: PropTypes.Requireable<any>;
25
- }>>;
26
- lastTabRef: PropTypes.Requireable<((...args: any[]) => any) | PropTypes.InferProps<{
27
- current: PropTypes.Requireable<any>;
28
- }>>;
29
- /** Whether or not it's a ds-tab from DSMobile tabs */
30
- isDSMobile: PropTypes.Requireable<boolean>;
31
- /** DSMobile only flexible tabs mode */
32
- flexibleTabsHeaders: PropTypes.Requireable<boolean>;
33
- /** DSMobile only fixed tabs mode */
34
- fixedTabsHeaders: PropTypes.Requireable<boolean>;
35
- };
36
- };
37
- export default TabsImpl;
@@ -1,5 +0,0 @@
1
- import { Component } from 'react';
2
- export default class TabsPanels extends Component {
3
- renderPanels: (this: any, activeTab: any, tabsComponents: any) => any;
4
- render(): JSX.Element;
5
- }
@@ -1 +0,0 @@
1
- export declare function useResize(ref: any, callback: any): void;