@elliemae/ds-tabs 2.0.0-alpha.1 → 2.0.0-alpha.13

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 (106) hide show
  1. package/cjs/DSTabs.js +29 -107
  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} +19 -28
  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 -197
  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 -114
  86. package/cjs/TabsPanels.js +0 -82
  87. package/cjs/package.json +0 -7
  88. package/cjs/useResize.js +0 -24
  89. package/esm/Carousel.js +0 -186
  90. package/esm/DSTab.js +0 -33
  91. package/esm/SubTabBar.js +0 -39
  92. package/esm/TabBar.js +0 -399
  93. package/esm/TabTypes.js +0 -7
  94. package/esm/TabsImpl.js +0 -107
  95. package/esm/TabsPanels.js +0 -72
  96. package/esm/package.json +0 -7
  97. package/esm/useResize.js +0 -20
  98. package/types/Carousel.d.ts +0 -16
  99. package/types/DSTab.d.ts +0 -22
  100. package/types/PanelContainer.d.ts +0 -20
  101. package/types/SubTabBar.d.ts +0 -23
  102. package/types/TabBar.d.ts +0 -30
  103. package/types/TabTypes.d.ts +0 -5
  104. package/types/TabsImpl.d.ts +0 -37
  105. package/types/TabsPanels.d.ts +0 -5
  106. package/types/useResize.d.ts +0 -1
@@ -0,0 +1,160 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _jsx = require('@babel/runtime/helpers/jsx');
6
+ require('core-js/modules/esnext.async-iterator.map.js');
7
+ require('core-js/modules/esnext.iterator.map.js');
8
+ var React = require('react');
9
+ var Carousel = require('../carousel/Carousel.js');
10
+ var useTabBar = require('./useTabBar.js');
11
+ var styles = require('./styles.js');
12
+ var DSTabsCTX = require('../../DSTabsCTX.js');
13
+ var useKeyboardNavigation = require('../../utils/hooks/useKeyboardNavigation.js');
14
+ var constants = require('../../utils/constants.js');
15
+ var useTabsCallbacks = require('../../utils/hooks/useTabsCallbacks.js');
16
+ var DSTabsDatatestid = require('../../DSTabsDatatestid.js');
17
+ var jsxRuntime = require('react/jsx-runtime');
18
+
19
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
+
21
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
22
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
23
+
24
+ var _StyledRequiredMark;
25
+ const TabBar = () => {
26
+ const {
27
+ tabsRef,
28
+ focusableTabsRef,
29
+ tabsListRef,
30
+ tabsRefAsArray,
31
+ actualActiveTab,
32
+ props: {
33
+ type,
34
+ fixedTabsHeaders,
35
+ withCarousel,
36
+ isDSMobile,
37
+ showSeparator,
38
+ children: tabs
39
+ }
40
+ } = React.useContext(DSTabsCTX.DSTabsContext);
41
+ const {
42
+ lastTabInternalRef,
43
+ firstSubtabInternalRef
44
+ } = React.useContext(DSTabsCTX.DSTabsCrossRefContext);
45
+ const {
46
+ handleOnTabChange
47
+ } = useTabsCallbacks.useTabsCallbacks();
48
+ const {
49
+ handleOnKeyDown
50
+ } = useKeyboardNavigation.useKeyboardNavigation();
51
+ const {
52
+ indicatorStyle,
53
+ mobileGradients,
54
+ updateMobileGradients,
55
+ updateIndicatorStyle
56
+ } = useTabBar.useTabBar();
57
+ const renderTabs = React.useMemo(() => {
58
+ const availableTabIndexes = [];
59
+ return React__default["default"].Children.map(tabs, (tab, index) => {
60
+ const {
61
+ tabId = '',
62
+ title = '',
63
+ style,
64
+ required = false,
65
+ disabled = false,
66
+ ref,
67
+ onClick,
68
+ onKeyDown
69
+ } = tab.props;
70
+ if (!disabled) availableTabIndexes.push(index);
71
+ return /*#__PURE__*/jsxRuntime.jsxs(styles.StyledTabButton, {
72
+ role: "tab",
73
+ ref: t => {
74
+ if (tabsRefAsArray.current && focusableTabsRef.current && tabsRef.current) {
75
+ tabsRefAsArray.current[index] = t;
76
+ if (!disabled && !focusableTabsRef.current.includes(t)) focusableTabsRef.current.push(t);
77
+ tabsRef.current[index] = t;
78
+
79
+ if (type === constants.TabTypes.SUBTABS && firstSubtabInternalRef && index === availableTabIndexes[0]) {
80
+ firstSubtabInternalRef.current = t;
81
+ }
82
+
83
+ if (type !== constants.TabTypes.SUBTABS && index === availableTabIndexes[availableTabIndexes.length - 1]) {
84
+ lastTabInternalRef.current = t;
85
+ }
86
+
87
+ if (ref) ref.current = t;
88
+ }
89
+ },
90
+ type: "button",
91
+ "aria-controls": tabId,
92
+ "aria-selected": actualActiveTab === tabId,
93
+ "aria-disabled": disabled,
94
+ "aria-labelledby": "".concat(tabId, "-label"),
95
+ isDSMobile: isDSMobile,
96
+ fixedTabsHeaders: fixedTabsHeaders,
97
+ tabType: type,
98
+ title: title,
99
+ "data-required": required,
100
+ "data-tab-id": tabId,
101
+ "data-index": index,
102
+ withCarousel: withCarousel,
103
+ isActive: actualActiveTab === tabId,
104
+ disabled: disabled,
105
+ showSeparator: showSeparator && type !== constants.TabTypes.NORMAL,
106
+ "data-testid": type === constants.TabTypes.NORMAL ? DSTabsDatatestid.DSTabsDatatestid.TAB_BUTTON : DSTabsDatatestid.DSTabsDatatestid.SUBTAB_BUTTON,
107
+ id: "".concat(tabId, "-label"),
108
+ onClick: e => {
109
+ if (!disabled) {
110
+ handleOnTabChange(tabId, e);
111
+ updateIndicatorStyle();
112
+ }
113
+
114
+ if (onClick && !disabled) onClick(tabId, e);
115
+ },
116
+ onKeyDown: e => {
117
+ if (e.key === 'Enter') e.stopPropagation();
118
+ if (!disabled) handleOnKeyDown(e);
119
+ if (onKeyDown && !disabled) onKeyDown(e);
120
+ },
121
+ style: style,
122
+ children: [title, required && (_StyledRequiredMark || (_StyledRequiredMark = /*#__PURE__*/_jsx__default["default"](styles.StyledRequiredMark, {}, void 0, "\u25CF")))]
123
+ }, tabId);
124
+ });
125
+ }, [tabs, actualActiveTab, isDSMobile, fixedTabsHeaders, type, withCarousel, showSeparator, tabsRefAsArray, focusableTabsRef, tabsRef, firstSubtabInternalRef, lastTabInternalRef, handleOnTabChange, updateIndicatorStyle, handleOnKeyDown]);
126
+
127
+ if (type === constants.TabTypes.SUBTABS && !isDSMobile) {
128
+ return /*#__PURE__*/jsxRuntime.jsx(styles.StyledSubTabsList, {
129
+ withCarousel: withCarousel,
130
+ "data-testid": DSTabsDatatestid.DSTabsDatatestid.SUB_TAB_LIST,
131
+ ref: tabsListRef,
132
+ role: "tablist",
133
+ children: withCarousel ? /*#__PURE__*/_jsx__default["default"](Carousel.Carousel, {}, void 0, renderTabs) : renderTabs
134
+ });
135
+ }
136
+
137
+ return /*#__PURE__*/jsxRuntime.jsxs(styles.StyledTabList, {
138
+ withCarousel: withCarousel,
139
+ ref: tabsListRef,
140
+ role: "tablist",
141
+ "data-testid": DSTabsDatatestid.DSTabsDatatestid.TAB_LIST,
142
+ isDSMobile: isDSMobile,
143
+ fixedTabsHeaders: fixedTabsHeaders,
144
+ mobileGradients: mobileGradients,
145
+ onScroll: updateMobileGradients,
146
+ indicatorStyle: indicatorStyle,
147
+ tabType: type,
148
+ children: [/*#__PURE__*/_jsx__default["default"](styles.StyledTabWrapper, {
149
+ isDSMobile: isDSMobile,
150
+ fixedTabsHeaders: fixedTabsHeaders
151
+ }, void 0, !isDSMobile && withCarousel ? /*#__PURE__*/_jsx__default["default"](Carousel.Carousel, {
152
+ updateIndicatorStyle: updateIndicatorStyle
153
+ }, void 0, renderTabs) : renderTabs), /*#__PURE__*/_jsx__default["default"](styles.StyledSelectionIndicator, {
154
+ isDSMobile: isDSMobile,
155
+ tabType: type
156
+ })]
157
+ });
158
+ };
159
+
160
+ exports.TabBar = TabBar;
@@ -0,0 +1,199 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
6
+ var styled = require('styled-components');
7
+ var dsSystem = require('@elliemae/ds-system');
8
+ var constants = require('../../utils/constants.js');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteral);
13
+ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
14
+
15
+ var _templateObject;
16
+ const StyledSelectionIndicator = /*#__PURE__*/styled__default["default"].div.withConfig({
17
+ componentId: "sc-3hla56-0"
18
+ })(["position:absolute;height:3px;top:", ";margin-top:", ";pointer-events:none;transition:200ms cubic-bezier(0.36,0,1,1);z-index:10;", ""], _ref => {
19
+ let {
20
+ tabType,
21
+ isDSMobile
22
+ } = _ref;
23
+ if (isDSMobile) return "34px";
24
+ if (tabType === constants.TabTypes.NORMAL_SMALL) return "15px";
25
+ return "25px";
26
+ }, _ref2 => {
27
+ let {
28
+ theme
29
+ } = _ref2;
30
+ return theme.space.xxxs;
31
+ }, _ref3 => {
32
+ let {
33
+ isDSMobile
34
+ } = _ref3;
35
+ return isDSMobile ? " \n margin-left: 0;\n margin-top: 3px;\n " : "";
36
+ });
37
+ const mobileGradientsSettings = dsSystem.css(_templateObject || (_templateObject = _taggedTemplateLiteral__default["default"](["\n ", "\n"])), _ref4 => {
38
+ let {
39
+ theme,
40
+ mobileGradients,
41
+ isDSMobile,
42
+ fixedTabsHeaders
43
+ } = _ref4;
44
+
45
+ if (isDSMobile && !fixedTabsHeaders) {
46
+ if (mobileGradients.right && mobileGradients.left) return "background: linear-gradient(90deg, rgba(238,238,238,0) 0%, ".concat(theme.colors.brand[200], " 20%, ").concat(theme.colors.brand[200], " 80%, rgba(238,238,238,0) 100%);");
47
+ if (mobileGradients.right) return "background: linear-gradient(90deg, ".concat(theme.colors.brand[200], " 0%, ").concat(theme.colors.brand[200], " 80%, rgba(238,238,238,0) 100%);");
48
+ if (mobileGradients.left) return "background: linear-gradient(90deg, rgba(238,238,238,0) 0%, ".concat(theme.colors.brand[200], " 20%, ").concat(theme.colors.brand[200], " 100%);");
49
+ }
50
+
51
+ return "";
52
+ });
53
+ const StyledTabWrapper = /*#__PURE__*/styled__default["default"].div.withConfig({
54
+ componentId: "sc-3hla56-1"
55
+ })(["display:flex;flex:1;flex-wrap:nowrap;", ""], _ref5 => {
56
+ let {
57
+ fixedTabsHeaders,
58
+ isDSMobile
59
+ } = _ref5;
60
+ return !fixedTabsHeaders && isDSMobile ? '' : 'overflow-x: hidden;';
61
+ });
62
+ const StyledTabButton = /*#__PURE__*/styled__default["default"].button.withConfig({
63
+ componentId: "sc-3hla56-2"
64
+ })(["position:relative;background-color:transparent;border:none;cursor:pointer;transition:100ms cubic-bezier(0,0,0.42,1);text-transform:", ";letter-spacing:0px;white-space:nowrap;padding:2px 0;margin-right:", ";margin-left:", ";color:", ";", " ", " ", " ", " ", " ", " ", ""], _ref6 => {
65
+ let {
66
+ tabType
67
+ } = _ref6;
68
+ return tabType === constants.TabTypes.SUBTABS ? "capitalize" : "uppercase";
69
+ }, _ref7 => {
70
+ let {
71
+ fixedTabsHeaders,
72
+ isDSMobile
73
+ } = _ref7;
74
+ if (fixedTabsHeaders) return '0px';
75
+ if (!fixedTabsHeaders && isDSMobile) return '14px';
76
+ return '16px';
77
+ }, _ref8 => {
78
+ let {
79
+ fixedTabsHeaders,
80
+ isDSMobile
81
+ } = _ref8;
82
+ if (fixedTabsHeaders) return '0px';
83
+ if (!fixedTabsHeaders && isDSMobile) return '14px';
84
+ return '16px';
85
+ }, _ref9 => {
86
+ let {
87
+ theme
88
+ } = _ref9;
89
+ return theme.colors.neutral[700];
90
+ }, dsSystem.onlySafariAndFirefox('-webkit-text-stroke: 0.4px transparent;'), _ref10 => {
91
+ let {
92
+ tabType
93
+ } = _ref10;
94
+ return tabType === constants.TabTypes.NORMAL ? "height: 32px;" : "height: 22px;";
95
+ }, _ref11 => {
96
+ let {
97
+ theme,
98
+ isActive,
99
+ disabled
100
+ } = _ref11;
101
+ return isActive && !disabled ? "\n font-weight: ".concat(theme.fontWeights.semibold, ";\n ").concat(dsSystem.safariAndFirefoxBold("#353C46"), "\n\n &:hover {\n ").concat(dsSystem.safariAndFirefoxBold("#1E79C2"), "\n }\n \n ") : "\n \n ";
102
+ }, _ref12 => {
103
+ let {
104
+ theme,
105
+ disabled
106
+ } = _ref12;
107
+ return disabled ? "\n color: ".concat(theme.colors.neutral[500], ";\n cursor: not-allowed;\n ") : "\n &:hover {\n color: ".concat(theme.colors.brand[600], ";\n }\n ");
108
+ }, _ref13 => {
109
+ let {
110
+ theme,
111
+ isDSMobile
112
+ } = _ref13;
113
+ return !isDSMobile ? "\n &:focus {\n outline: none;\n &:after {\n position: absolute;\n content: '';\n top: 0;\n left: -16px;\n width: calc(100% + 32px);\n height: 100%;\n z-index: 5;\n border-radius: 2px;\n border: 2px solid ".concat(theme.colors.brand[600], ";\n }\n }\n \n ") : "";
114
+ }, _ref14 => {
115
+ let {
116
+ theme,
117
+ showSeparator,
118
+ tabType
119
+ } = _ref14;
120
+ return showSeparator ? "\n &:not(:last-of-type):before\n {\n content: \"\";\n position: absolute;\n width: 1px;\n right: -17px;\n top: 50%;\n transform: translateY(-50%);\n height: ".concat(tabType === constants.TabTypes.NORMAL_SMALL ? "10px" : "16px", ";\n background-color: ").concat(theme.colors.neutral[400], ";\n }") : "";
121
+ }, _ref15 => {
122
+ let {
123
+ theme,
124
+ isActive,
125
+ disabled,
126
+ isDSMobile
127
+ } = _ref15;
128
+ return isDSMobile ? "\n height: 40px;\n color: ".concat(theme.colors.brand[600], ";\n font-weight: ").concat(theme.fontWeights.regular, ";\n padding: 0;\n font-size: 13px;\n line-height: 1.3;\n ").concat(dsSystem.onlySafariAndFirefox('-webkit-text-stroke: 0.4px transparent;'), " \n\n &:focus {\n font-weight: ").concat(theme.fontWeights.regular, ";\n font-size: 13px;\n ").concat(dsSystem.safariAndFirefoxBold('#006AA9'), "\n }\n\n ").concat(isActive ? "\n font-weight: ".concat(theme.fontWeights.regular, ";\n font-size: 13px;\n ").concat(dsSystem.safariAndFirefoxBold('#006AA9'), "\n ") : "", "\n\n ").concat(isActive && !disabled ? "\n font-size: 13px;\n color: ".concat(theme.colors.brand[700], ";\n line-height: 1.3;\n font-weight: ").concat(theme.fontWeights.regular, ";\n -webkit-font-smoothing: subpixel-antialiased; \n -webkit-text-stroke: 0.4px ").concat(theme.colors.brand[700], ";") : "", "\n\n ").concat(!disabled ? "\n &:hover,\n &:focus {\n outline: none;\n color: ".concat(theme.colors.brand[700], ";\n ").concat(dsSystem.safariAndFirefoxBold('#006AA9'), "\n }") : "", "\n\n ") : "";
129
+ });
130
+ const StyledSubTabsList = /*#__PURE__*/styled__default["default"].div.withConfig({
131
+ componentId: "sc-3hla56-3"
132
+ })(["position:relative;display:flex;flex-wrap:nowrap;flex:1;width:100%;", ""], _ref16 => {
133
+ let {
134
+ withCarousel
135
+ } = _ref16;
136
+ return withCarousel ? 'max-width: 100%;' : '';
137
+ });
138
+ const StyledTabList = /*#__PURE__*/styled__default["default"].div.withConfig({
139
+ componentId: "sc-3hla56-4"
140
+ })(["position:relative;display:flex;flex-wrap:nowrap;flex:1;width:100%;", " ", " ", "{padding-bottom:0;padding-top:0;}", " ", " ", " ", "{", "}&:not(:focus-within){", "{background:", ";}}&:focus-within{", "{background:", "}"], _ref17 => {
141
+ let {
142
+ withCarousel,
143
+ isDSMobile
144
+ } = _ref17;
145
+ return withCarousel && !isDSMobile ? "max-width: 100%;" : '';
146
+ }, _ref18 => {
147
+ let {
148
+ theme,
149
+ isDSMobile,
150
+ tabType
151
+ } = _ref18;
152
+ return tabType !== constants.TabTypes.NORMAL_SMALL ? "\n &:after {\n content: '';\n position: absolute;\n width: 100%;\n height: 100%;\n border-bottom-width: 1px;\n border-bottom-style: solid;\n border-bottom-color: ".concat(isDSMobile ? theme.colors.brand[200] : theme.colors.neutral[200], ";\n pointer-events: none;\n }\n ") : "";
153
+ }, StyledTabButton, _ref19 => {
154
+ let {
155
+ theme,
156
+ isDSMobile
157
+ } = _ref19;
158
+ return isDSMobile ? "border-bottom: 1px solid ".concat(theme.colors.brand[300], ";\n background: ").concat(theme.colors.brand[200], ";") : "";
159
+ }, mobileGradientsSettings, _ref20 => {
160
+ let {
161
+ isDSMobile,
162
+ fixedTabsHeaders
163
+ } = _ref20;
164
+ return isDSMobile ? "\n ".concat(!fixedTabsHeaders ? "\n z-index: 0;\n overflow-x: auto;\n overflow-y: hidden;\n scrollbar-width: thin;\n &::-webkit-scrollbar {\n display: none;\n }" : "\n display: flex;\n ".concat(StyledTabButton, " {\n flex: 1;\n overflow-x: hidden;\n }")) : "";
165
+ }, StyledSelectionIndicator, _ref21 => {
166
+ let {
167
+ indicatorStyle
168
+ } = _ref21;
169
+ return "\n width: ".concat(indicatorStyle.width, ";\n left: ").concat(indicatorStyle.left, ";\n ");
170
+ }, StyledSelectionIndicator, _ref22 => {
171
+ let {
172
+ theme,
173
+ indicatorStyle,
174
+ isDSMobile
175
+ } = _ref22;
176
+ return !isDSMobile ? indicatorStyle.backgroundWithTransparent : theme.colors.brand[600];
177
+ }, StyledSelectionIndicator, _ref23 => {
178
+ let {
179
+ theme,
180
+ indicatorStyle,
181
+ isDSMobile
182
+ } = _ref23;
183
+ return !isDSMobile ? indicatorStyle.backgroundWithTransparentAndWhite : theme.colors.brand[600];
184
+ });
185
+ const StyledRequiredMark = /*#__PURE__*/styled__default["default"].span.withConfig({
186
+ componentId: "sc-3hla56-5"
187
+ })(["color:", ";font-size:6px;margin-left:2px;position:absolute;top:5px;"], _ref24 => {
188
+ let {
189
+ theme
190
+ } = _ref24;
191
+ return theme.colors.danger[900];
192
+ });
193
+
194
+ exports.StyledRequiredMark = StyledRequiredMark;
195
+ exports.StyledSelectionIndicator = StyledSelectionIndicator;
196
+ exports.StyledSubTabsList = StyledSubTabsList;
197
+ exports.StyledTabButton = StyledTabButton;
198
+ exports.StyledTabList = StyledTabList;
199
+ exports.StyledTabWrapper = StyledTabWrapper;
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/web.dom-collections.iterator.js');
6
+ var React = require('react');
7
+ var useResizeObserver = require('@react-hook/resize-observer');
8
+ var helpers = require('../../utils/helpers.js');
9
+ var DSTabsCTX = require('../../DSTabsCTX.js');
10
+ var constants = require('../../utils/constants.js');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var useResizeObserver__default = /*#__PURE__*/_interopDefaultLegacy(useResizeObserver);
15
+
16
+ const useTabBar = () => {
17
+ const {
18
+ actualActiveTab,
19
+ actualActiveTabRef,
20
+ tabsListRef,
21
+ props: {
22
+ showSelectionIndicator,
23
+ isDSMobile,
24
+ fixedTabsHeaders
25
+ }
26
+ } = React.useContext(DSTabsCTX.DSTabsContext);
27
+ const [mobileGradients, setMobileGradients] = React.useState({
28
+ left: false,
29
+ right: false
30
+ });
31
+ const [indicatorStyle, setIndicatorStyle] = React.useState(constants.defaultIndicatorStyles);
32
+ const getIndicatorStyles = React.useCallback(() => {
33
+ if (tabsListRef.current) {
34
+ const tabList = tabsListRef.current;
35
+ const activeTabButton = actualActiveTabRef.current;
36
+ if (!activeTabButton || !helpers.isElementVisible(activeTabButton, tabList)) return constants.defaultIndicatorStyles; // The missingMargins are to make the selection indicator white marks work properly in desktop, we need
37
+ // the full width of the tab button with margins.
38
+
39
+ const missingMargins = isDSMobile ? 0 : 16;
40
+ const tabClientWidth = isDSMobile && !fixedTabsHeaders ? activeTabButton.clientWidth : activeTabButton.clientWidth + missingMargins * 2; // The reason why we use the tabList.scrollLeft is due to the centerOnTabChange (only in Mobile and FlexibleTabs)
41
+ // behavior that adds scroll to the tabList
42
+
43
+ const position = isDSMobile && !fixedTabsHeaders ? activeTabButton.getBoundingClientRect().left - tabList.getBoundingClientRect().left + tabList.scrollLeft : activeTabButton.getBoundingClientRect().left - tabList.getBoundingClientRect().left - missingMargins;
44
+ const backgroundWithTransparentAndWhite = "linear-gradient(to right, transparent 0px, transparent 12px, white 12px, white 16px, #1E79C2 16px, #1E79C2 ".concat(tabClientWidth - 16, "px,white ").concat(tabClientWidth - 16, "px,white ").concat(tabClientWidth - 12, "px,transparent ").concat(tabClientWidth - 12, "px,transparent ").concat(tabClientWidth, "px )");
45
+ const backgroundWithTransparent = "linear-gradient(to right, transparent 0px, transparent 16px, #1E79C2 16px, #1E79C2 ".concat(tabClientWidth - 16, "px,transparent ").concat(tabClientWidth - 16, "px,transparent ").concat(tabClientWidth, "px )");
46
+ return {
47
+ left: "".concat(position, "px"),
48
+ width: "".concat(tabClientWidth, "px"),
49
+ backgroundWithTransparentAndWhite,
50
+ backgroundWithTransparent
51
+ };
52
+ }
53
+
54
+ return constants.defaultIndicatorStyles;
55
+ }, [actualActiveTabRef, fixedTabsHeaders, isDSMobile, tabsListRef]);
56
+ const updateIndicatorStyle = React.useCallback(() => setTimeout(() => setIndicatorStyle(getIndicatorStyles()), 100), [getIndicatorStyles, setIndicatorStyle]);
57
+ useResizeObserver__default["default"](tabsListRef, updateIndicatorStyle);
58
+ const updateMobileGradients = React.useCallback(() => {
59
+ if (tabsListRef.current && isDSMobile && !fixedTabsHeaders) {
60
+ const {
61
+ scrollLeft,
62
+ scrollWidth,
63
+ clientWidth
64
+ } = tabsListRef.current;
65
+ setMobileGradients({
66
+ left: helpers.shouldHaveLeftGradient(scrollLeft),
67
+ right: helpers.shouldHaveRightGradient(scrollLeft, clientWidth, scrollWidth)
68
+ });
69
+ }
70
+ }, [fixedTabsHeaders, isDSMobile, tabsListRef]);
71
+ React.useEffect(() => {
72
+ if (showSelectionIndicator) {
73
+ updateIndicatorStyle();
74
+ }
75
+
76
+ if (isDSMobile && !fixedTabsHeaders) {
77
+ updateMobileGradients();
78
+ }
79
+ }, [updateIndicatorStyle, showSelectionIndicator, actualActiveTab, updateMobileGradients, isDSMobile, fixedTabsHeaders]);
80
+ React.useLayoutEffect(() => {
81
+ if (showSelectionIndicator) {
82
+ updateIndicatorStyle();
83
+ }
84
+
85
+ if (isDSMobile && !fixedTabsHeaders) {
86
+ updateMobileGradients();
87
+ }
88
+ }, [updateMobileGradients, showSelectionIndicator, updateIndicatorStyle, isDSMobile, fixedTabsHeaders]);
89
+ return {
90
+ updateIndicatorStyle,
91
+ setIndicatorStyle,
92
+ indicatorStyle,
93
+ mobileGradients,
94
+ updateMobileGradients
95
+ };
96
+ };
97
+
98
+ exports.useTabBar = useTabBar;
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
+ var _jsx = require('@babel/runtime/helpers/jsx');
12
+ var React = require('react');
13
+ var TabsPanels = require('../tabsPanel/TabsPanels.js');
14
+ var TabBar = require('../tabBar/TabBar.js');
15
+ var styles = require('./styles.js');
16
+ var DSTabsCTX = require('../../DSTabsCTX.js');
17
+ var DSTabsDatatestid = require('../../DSTabsDatatestid.js');
18
+ var jsxRuntime = require('react/jsx-runtime');
19
+
20
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
+
22
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
23
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
24
+
25
+ var _TabBar, _TabsPanels;
26
+
27
+ 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; }
28
+
29
+ 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; }
30
+ const TabsContent = () => {
31
+ const {
32
+ props: {
33
+ containerProps,
34
+ innerRef,
35
+ tabsListAriaLabel,
36
+ tabBarExtraContent
37
+ }
38
+ } = React.useContext(DSTabsCTX.DSTabsContext);
39
+ return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({}, containerProps), {}, {
40
+ ref: innerRef,
41
+ "data-testid": DSTabsDatatestid.DSTabsDatatestid.TABS_CONTAINER,
42
+ children: [/*#__PURE__*/_jsx__default["default"](styles.StyledTabBarContainer, {
43
+ "aria-label": tabsListAriaLabel,
44
+ role: "tablist"
45
+ }, void 0, _TabBar || (_TabBar = /*#__PURE__*/_jsx__default["default"](TabBar.TabBar, {})), tabBarExtraContent), _TabsPanels || (_TabsPanels = /*#__PURE__*/_jsx__default["default"](TabsPanels.TabsPanels, {}))]
46
+ }));
47
+ };
48
+
49
+ exports.TabsContent = TabsContent;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var styled = require('styled-components');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
10
+
11
+ const StyledTabBarContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
12
+ componentId: "sc-vm3k1y-0"
13
+ })(["display:flex;overflow-x:hidden;"]);
14
+
15
+ exports.StyledTabBarContainer = StyledTabBarContainer;
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _jsx = require('@babel/runtime/helpers/jsx');
6
+ require('core-js/modules/esnext.async-iterator.map.js');
7
+ require('core-js/modules/esnext.iterator.map.js');
8
+ var React = require('react');
9
+ var SwipeableViews = require('react-swipeable-views');
10
+ var helpers = require('../../utils/helpers.js');
11
+ var styles = require('./styles.js');
12
+ var DSTabsCTX = require('../../DSTabsCTX.js');
13
+ var useTabsCallbacks = require('../../utils/hooks/useTabsCallbacks.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
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
+ var SwipeableViews__default = /*#__PURE__*/_interopDefaultLegacy(SwipeableViews);
21
+
22
+ const TabsPanels = () => {
23
+ const {
24
+ actualActiveTab,
25
+ focusableTabsRef,
26
+ props: {
27
+ animated,
28
+ enableMouseEvents,
29
+ onlyRenderActiveTab,
30
+ children: tabs,
31
+ isDSMobile
32
+ }
33
+ } = React.useContext(DSTabsCTX.DSTabsContext);
34
+ const {
35
+ handleOnTabChange,
36
+ handleOnMouseDown
37
+ } = useTabsCallbacks.useTabsCallbacks();
38
+ const handleOnChangeIndex = React.useCallback(index => {
39
+ handleOnTabChange(helpers.getIdByIndex(tabs, index));
40
+ if (focusableTabsRef.current) focusableTabsRef.current[index].click();
41
+ }, [focusableTabsRef, handleOnTabChange, tabs]);
42
+ const panels = React.useMemo(() => React__default["default"].Children.map(tabs, tab => {
43
+ const {
44
+ tabId: panelId = '',
45
+ style,
46
+ children: content
47
+ } = tab.props;
48
+ const isActive = actualActiveTab === panelId;
49
+ const shouldRender = !onlyRenderActiveTab || isActive;
50
+ return shouldRender && /*#__PURE__*/_jsx__default["default"](styles.StyledPanelContainer, {
51
+ id: panelId,
52
+ "aria-labelledby": "".concat(panelId, "-label"),
53
+ "aria-hidden": !isActive,
54
+ "data-panel-id": panelId,
55
+ "data-testid": "ds-tabs-tab-panel",
56
+ hidden: !isActive,
57
+ onMouseDown: handleOnMouseDown,
58
+ role: "tabpanel",
59
+ style: style,
60
+ isDSMobile: isDSMobile
61
+ }, panelId, content);
62
+ }), [actualActiveTab, handleOnMouseDown, isDSMobile, onlyRenderActiveTab, tabs]);
63
+
64
+ if (animated) {
65
+ return /*#__PURE__*/_jsx__default["default"](SwipeableViews__default["default"], {
66
+ enableMouseEvents: enableMouseEvents,
67
+ index: helpers.getIndexById(tabs, actualActiveTab),
68
+ onChangeIndex: handleOnChangeIndex
69
+ }, void 0, panels);
70
+ }
71
+
72
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
73
+ children: panels
74
+ });
75
+ };
76
+
77
+ exports.TabsPanels = TabsPanels;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var styled = require('styled-components');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
10
+
11
+ const StyledPanelContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
12
+ componentId: "sc-oxw5jq-0"
13
+ })(["padding-top:8px;&:focus{outline:none;}", " ", ""], _ref => {
14
+ let {
15
+ hidden
16
+ } = _ref;
17
+ return hidden ? 'visibility: hidden;' : '';
18
+ }, _ref2 => {
19
+ let {
20
+ isDSMobile
21
+ } = _ref2;
22
+ return isDSMobile ? "padding-top: 0;" : "";
23
+ });
24
+
25
+ exports.StyledPanelContainer = StyledPanelContainer;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var reactDesc = require('react-desc');
6
+ var constants = require('./utils/constants.js');
7
+
8
+ const tabPropTypes = {
9
+ tabId: reactDesc.PropTypes.string.description('Unique Tab id.').defaultValue(''),
10
+ title: reactDesc.PropTypes.string.description('Tab title.').defaultValue(''),
11
+ required: reactDesc.PropTypes.bool.description('Show a required mark next to the title.').defaultValue(false),
12
+ disabled: reactDesc.PropTypes.bool.description('Disables Tab.').defaultValue(false)
13
+ };
14
+ const tabsPropTypes = {
15
+ animated: reactDesc.PropTypes.bool.description('Whether the Tab transition should animate or not.').defaultValue(true),
16
+ enableMouseEvents: reactDesc.PropTypes.bool.description('Enables Tab transition with mouse drag events.').defaultValue(false),
17
+ allowTextSelection: reactDesc.PropTypes.bool.description('Allows text selection when mouse drag events are active.').defaultValue(false),
18
+ onTabChange: reactDesc.PropTypes.func.description('Handler when a user clicks on a different Tab.').defaultValue('() => {}'),
19
+ type: reactDesc.PropTypes.oneOf(constants.TabTypesValuesAsArray).description('Tab type.').defaultValue(constants.TabTypesValuesAsArray[0]),
20
+ tabBarExtraContent: reactDesc.PropTypes.element.description('Extra content next to the Tab Bar.').defaultValue(undefined),
21
+ onlyRenderActiveTab: reactDesc.PropTypes.bool.description('Only renders the active Tab in the DOM.').defaultValue(false),
22
+ withCarousel: reactDesc.PropTypes.bool.description('Activate carousel behavior.').defaultValue(false),
23
+ activeTab: reactDesc.PropTypes.string.description('Passing a value makes DSTabs a controlled component.').defaultValue('First DSTab children.'),
24
+ children: reactDesc.PropTypes.node.description('Use DSTab component as children.').isRequired,
25
+ tabsListAriaLabel: reactDesc.PropTypes.string.description('Aria label for the list.').defaultValue('Tab list.'),
26
+ containerProps: reactDesc.PropTypes.object.description('Additional properties for the container.').defaultValue({}),
27
+ innerRef: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.func, reactDesc.PropTypes.shape({
28
+ current: reactDesc.PropTypes.any
29
+ })]).description('Ref to the container.').defaultValue(undefined)
30
+ };
31
+
32
+ exports.tabPropTypes = tabPropTypes;
33
+ exports.tabsPropTypes = tabsPropTypes;