@zohodesk/components 1.6.34 → 1.6.35
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.
- package/CHANGELOG.md +4 -0
- package/assets/Appearance/dark/mode/Component_v1_DarkMode.module.css +20 -0
- package/assets/Appearance/dark/themes/blue/blue_componentsCTA_DarkModifyCategory.module.css +2 -0
- package/assets/Appearance/dark/themes/green/green_componentsCTA_DarkModifyCategory.module.css +2 -0
- package/assets/Appearance/dark/themes/orange/orange_componentsCTA_DarkModifyCategory.module.css +2 -0
- package/assets/Appearance/dark/themes/red/red_componentsCTA_DarkModifyCategory.module.css +2 -0
- package/assets/Appearance/dark/themes/yellow/yellow_componentsCTA_DarkModifyCategory.module.css +2 -0
- package/assets/Appearance/light/mode/Component_v1_LightMode.module.css +20 -0
- package/assets/Appearance/light/themes/blue/blue_componentsCTA_LightModifyCategory.module.css +2 -0
- package/assets/Appearance/light/themes/green/green_componentsCTA_LightModifyCategory.module.css +2 -0
- package/assets/Appearance/light/themes/orange/orange_componentsCTA_LightModifyCategory.module.css +2 -0
- package/assets/Appearance/light/themes/red/red_componentsCTA_LightModifyCategory.module.css +2 -0
- package/assets/Appearance/light/themes/yellow/yellow_componentsCTA_LightModifyCategory.module.css +2 -0
- package/assets/Appearance/pureDark/mode/Component_v1_PureDarkMode.module.css +20 -0
- package/assets/Appearance/pureDark/themes/blue/blue_componentsCTA_PureDarkModifyCategory.module.css +2 -0
- package/assets/Appearance/pureDark/themes/green/green_componentsCTA_PureDarkModifyCategory.module.css +2 -0
- package/assets/Appearance/pureDark/themes/orange/orange_componentsCTA_PureDarkModifyCategory.module.css +2 -0
- package/assets/Appearance/pureDark/themes/red/red_componentsCTA_PureDarkModifyCategory.module.css +2 -0
- package/assets/Appearance/pureDark/themes/yellow/yellow_componentsCTA_PureDarkModifyCategory.module.css +2 -0
- package/cbt.config.js +1 -0
- package/es/DateTime/__tests__/__snapshots__/DateTime.spec.js.snap +497 -497
- package/es/index.d.ts +39 -0
- package/es/index.js +12 -12
- package/es/v1/Tab/Tab.js +159 -0
- package/es/v1/Tab/TabList.js +153 -0
- package/es/v1/Tab/TabMoreMenu.js +245 -0
- package/es/v1/Tab/TabPanel.js +51 -0
- package/es/v1/Tab/Tabs.js +125 -0
- package/es/v1/Tab/__tests__/Tab.spec.js +1082 -0
- package/es/v1/Tab/__tests__/__snapshots__/Tab.spec.js.snap +4933 -0
- package/es/v1/Tab/constants/index.js +112 -0
- package/es/v1/Tab/constants/presets.js +36 -0
- package/es/v1/Tab/context.js +19 -0
- package/es/v1/Tab/core/Tab.js +60 -0
- package/es/v1/Tab/core/TabList.js +51 -0
- package/es/v1/Tab/core/TabListFocusScope.js +18 -0
- package/es/v1/Tab/core/TabPanel.js +54 -0
- package/es/v1/Tab/core/Tabs.js +45 -0
- package/es/v1/Tab/core/index.js +6 -0
- package/es/v1/Tab/css/Tab_v1.module.css +335 -0
- package/es/v1/Tab/css/cssJSLogic.js +1 -0
- package/es/v1/Tab/css/tab.cva.js +205 -0
- package/es/v1/Tab/index.js +8 -0
- package/es/v1/Tab/props/defaultProps.js +55 -0
- package/es/v1/Tab/props/propTypes.js +221 -0
- package/es/v1/Tab/utils/pinSelectedTab.js +44 -0
- package/lib/DateTime/__tests__/__snapshots__/DateTime.spec.js.snap +497 -497
- package/lib/index.d.ts +39 -0
- package/lib/index.js +270 -173
- package/lib/v1/Tab/Tab.js +180 -0
- package/lib/v1/Tab/TabList.js +191 -0
- package/lib/v1/Tab/TabMoreMenu.js +284 -0
- package/lib/v1/Tab/TabPanel.js +64 -0
- package/lib/v1/Tab/Tabs.js +151 -0
- package/lib/v1/Tab/__tests__/Tab.spec.js +1174 -0
- package/lib/v1/Tab/__tests__/__snapshots__/Tab.spec.js.snap +4933 -0
- package/lib/v1/Tab/constants/index.js +113 -0
- package/lib/v1/Tab/constants/presets.js +64 -0
- package/lib/v1/Tab/context.js +30 -0
- package/lib/v1/Tab/core/Tab.js +89 -0
- package/lib/v1/Tab/core/TabList.js +82 -0
- package/lib/v1/Tab/core/TabListFocusScope.js +28 -0
- package/lib/v1/Tab/core/TabPanel.js +85 -0
- package/lib/v1/Tab/core/Tabs.js +63 -0
- package/lib/v1/Tab/core/index.js +109 -0
- package/lib/v1/Tab/css/Tab_v1.module.css +335 -0
- package/lib/v1/Tab/css/cssJSLogic.js +25 -0
- package/lib/v1/Tab/css/tab.cva.js +192 -0
- package/lib/v1/Tab/index.js +159 -0
- package/lib/v1/Tab/props/defaultProps.js +69 -0
- package/lib/v1/Tab/props/propTypes.js +246 -0
- package/lib/v1/Tab/utils/pinSelectedTab.js +59 -0
- package/package.json +13 -11
- package/tsconfig.jest.json +5 -0
- package/tsconfig.json +9 -0
- package/ut.config.js +2 -1
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { Accordion, AccordionItem } from './Accordion';
|
|
2
|
+
export { default as Animation } from './Animation/Animation';
|
|
3
|
+
export { default as AppContainer } from './AppContainer/AppContainer';
|
|
4
|
+
export { default as Avatar } from './Avatar/Avatar';
|
|
5
|
+
export { default as AvatarTeam } from './AvatarTeam/AvatarTeam';
|
|
6
|
+
export { default as Button } from './Button/Button';
|
|
7
|
+
export { default as Buttongroup } from './Buttongroup/Buttongroup';
|
|
8
|
+
export { Card, CardContent, CardFooter, CardHeader } from './Card';
|
|
9
|
+
export { default as CheckBox } from './CheckBox/CheckBox';
|
|
10
|
+
export { DateWidget } from './DateTime';
|
|
11
|
+
export { default as DropBox } from './DropBox/DropBox';
|
|
12
|
+
export { DropDown, DropDownHeading, DropDownItem, DropDownItemContainer, DropDownSearch, DropDownSeparator, DropDownTarget } from './DropDown';
|
|
13
|
+
export { default as Heading } from './Heading/Heading';
|
|
14
|
+
export { default as Label } from './Label/Label';
|
|
15
|
+
export { Box, Container } from './Layout';
|
|
16
|
+
export { ListContainer, ListItem, ListItemWithAvatar, ListItemWithCheckBox, ListItemWithIcon, ListItemWithRadio } from './ListItem';
|
|
17
|
+
export { default as Modal } from './Modal/Modal';
|
|
18
|
+
export { AdvancedGroupMultiSelect, AdvancedMultiSelect, MultiSelect, MultiSelectWithAvatar } from './MultiSelect';
|
|
19
|
+
export * as PopOver from './PopOver';
|
|
20
|
+
export { default as Popup } from './Popup/Popup';
|
|
21
|
+
export * as Providers from './Provider';
|
|
22
|
+
export { default as Radio } from './Radio/Radio';
|
|
23
|
+
export { CustomResponsiveReceiver, CustomResponsiveSender, ResizeComponent, ResponsiveReceiver, ResponsiveSender, useCustomResponsiveReceiver, useResponsiveReceiver } from './Responsive';
|
|
24
|
+
export { default as ResponsiveDropBox } from './ResponsiveDropBox/ResponsiveDropBox';
|
|
25
|
+
export { default as Ribbon } from './Ribbon/Ribbon';
|
|
26
|
+
export { default as RippleEffect } from './RippleEffect/RippleEffect';
|
|
27
|
+
export { GroupSelect, Select, SelectWithAvatar, SelectWithIcon } from './Select';
|
|
28
|
+
export { default as Stencils } from './Stencils/Stencils';
|
|
29
|
+
export { default as Switch } from './Switch/Switch';
|
|
30
|
+
export { Tab, TabContent, TabContentWrapper, TabWrapper, Tabs } from './Tab';
|
|
31
|
+
export { default as Tag } from './Tag/Tag';
|
|
32
|
+
export { default as Textarea } from './Textarea/Textarea';
|
|
33
|
+
export { default as TextBox } from './TextBox/TextBox';
|
|
34
|
+
export { default as TextBoxIcon } from './TextBoxIcon/TextBoxIcon';
|
|
35
|
+
export { default as Tooltip } from './Tooltip/Tooltip';
|
|
36
|
+
export * as utils from './utils';
|
|
37
|
+
export { VelocityAnimation, VelocityAnimationGroup } from './VelocityAnimation';
|
|
38
|
+
export { SemanticButton } from './semantic';
|
|
39
|
+
export { default as Typography } from './Typography/Typography';
|
package/es/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { Accordion, AccordionItem } from "./Accordion";
|
|
2
2
|
export { default as Animation } from "./Animation/Animation";
|
|
3
3
|
export { default as AppContainer } from "./AppContainer/AppContainer";
|
|
4
4
|
export { default as Avatar } from "./Avatar/Avatar";
|
|
5
5
|
export { default as AvatarTeam } from "./AvatarTeam/AvatarTeam";
|
|
6
6
|
export { default as Button } from "./Button/Button";
|
|
7
7
|
export { default as Buttongroup } from "./Buttongroup/Buttongroup";
|
|
8
|
-
export
|
|
8
|
+
export { Card, CardContent, CardFooter, CardHeader } from "./Card";
|
|
9
9
|
export { default as CheckBox } from "./CheckBox/CheckBox";
|
|
10
|
-
export
|
|
10
|
+
export { DateWidget } from "./DateTime";
|
|
11
11
|
export { default as DropBox } from "./DropBox/DropBox";
|
|
12
|
-
export
|
|
12
|
+
export { DropDown, DropDownHeading, DropDownItem, DropDownItemContainer, DropDownSearch, DropDownSeparator, DropDownTarget } from "./DropDown";
|
|
13
13
|
export { default as Heading } from "./Heading/Heading";
|
|
14
14
|
export { default as Label } from "./Label/Label";
|
|
15
|
-
export
|
|
16
|
-
export
|
|
15
|
+
export { Box, Container } from "./Layout";
|
|
16
|
+
export { ListContainer, ListItem, ListItemWithAvatar, ListItemWithCheckBox, ListItemWithIcon, ListItemWithRadio } from "./ListItem";
|
|
17
17
|
export { default as Modal } from "./Modal/Modal";
|
|
18
|
-
export
|
|
18
|
+
export { AdvancedGroupMultiSelect, AdvancedMultiSelect, MultiSelect, MultiSelectWithAvatar } from "./MultiSelect";
|
|
19
19
|
import * as _PopOver from "./PopOver";
|
|
20
20
|
export { _PopOver as PopOver };
|
|
21
21
|
export { default as Popup } from "./Popup/Popup";
|
|
22
22
|
import * as _Providers from "./Provider";
|
|
23
23
|
export { _Providers as Providers };
|
|
24
24
|
export { default as Radio } from "./Radio/Radio";
|
|
25
|
-
export
|
|
25
|
+
export { CustomResponsiveReceiver, CustomResponsiveSender, ResizeComponent, ResponsiveReceiver, ResponsiveSender, useCustomResponsiveReceiver, useResponsiveReceiver } from "./Responsive";
|
|
26
26
|
export { default as ResponsiveDropBox } from "./ResponsiveDropBox/ResponsiveDropBox";
|
|
27
27
|
export { default as Ribbon } from "./Ribbon/Ribbon";
|
|
28
28
|
export { default as RippleEffect } from "./RippleEffect/RippleEffect";
|
|
29
|
-
export
|
|
29
|
+
export { GroupSelect, Select, SelectWithAvatar, SelectWithIcon } from "./Select";
|
|
30
30
|
export { default as Stencils } from "./Stencils/Stencils";
|
|
31
31
|
export { default as Switch } from "./Switch/Switch";
|
|
32
|
-
export
|
|
32
|
+
export { Tab, TabContent, TabContentWrapper, TabWrapper, Tabs } from "./Tab";
|
|
33
33
|
export { default as Tag } from "./Tag/Tag";
|
|
34
34
|
export { default as Textarea } from "./Textarea/Textarea";
|
|
35
35
|
export { default as TextBox } from "./TextBox/TextBox";
|
|
@@ -37,6 +37,6 @@ export { default as TextBoxIcon } from "./TextBoxIcon/TextBoxIcon";
|
|
|
37
37
|
export { default as Tooltip } from "./Tooltip/Tooltip";
|
|
38
38
|
import * as _utils from "./utils";
|
|
39
39
|
export { _utils as utils };
|
|
40
|
-
export
|
|
41
|
-
export
|
|
40
|
+
export { VelocityAnimation, VelocityAnimationGroup } from "./VelocityAnimation";
|
|
41
|
+
export { SemanticButton } from "./semantic";
|
|
42
42
|
export { default as Typography } from "./Typography/Typography";
|
package/es/v1/Tab/Tab.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Tab as TabCore } from "./core";
|
|
5
|
+
import mergeProps from '@zohodesk/utils/es/mergeProps';
|
|
6
|
+
import renderNode, { isRenderable } from '@zohodesk/utils/es/renderNode';
|
|
7
|
+
import FlexContainer from '@zohodesk/layout/es/Flex/FlexContainer';
|
|
8
|
+
import FlexItem from '@zohodesk/layout/es/Flex/FlexItem';
|
|
9
|
+
import Icon from '@zohodesk/icons/es/Icon';
|
|
10
|
+
import Typography from "../../Typography/Typography";
|
|
11
|
+
import { useTabsStyle } from "./context";
|
|
12
|
+
import { ICON_PLACEMENT_DIRECTION, ICON_PLACEMENT_JUSTIFY, ICON_PLACEMENT_TEXT_ALIGN, LABEL_STYLE, ORIENTATION, SIZE, SIZE_TEXT_SIZE, TEXT_ONLY_TEXT_ALIGN, TEXT_TRANSFORM, TEXT_TRUNCATE } from "./constants";
|
|
13
|
+
import { Tab_defaultProps } from "./props/defaultProps";
|
|
14
|
+
import { Tab_propTypes } from "./props/propTypes";
|
|
15
|
+
|
|
16
|
+
const Tab = props => {
|
|
17
|
+
const {
|
|
18
|
+
value,
|
|
19
|
+
text,
|
|
20
|
+
children,
|
|
21
|
+
isDisabled,
|
|
22
|
+
ariaLabel,
|
|
23
|
+
title,
|
|
24
|
+
iconName,
|
|
25
|
+
iconSize,
|
|
26
|
+
tourId,
|
|
27
|
+
tagName,
|
|
28
|
+
isAnchor: isAnchorFromProps,
|
|
29
|
+
href,
|
|
30
|
+
target,
|
|
31
|
+
rel,
|
|
32
|
+
renderIcon,
|
|
33
|
+
renderBefore,
|
|
34
|
+
renderAfter,
|
|
35
|
+
onClick,
|
|
36
|
+
getRef,
|
|
37
|
+
customClass,
|
|
38
|
+
customProps,
|
|
39
|
+
customAttributes,
|
|
40
|
+
a11yAttributes,
|
|
41
|
+
customId,
|
|
42
|
+
testId,
|
|
43
|
+
dataSelectorId
|
|
44
|
+
} = props;
|
|
45
|
+
const {
|
|
46
|
+
text: textProps,
|
|
47
|
+
icon: iconProps
|
|
48
|
+
} = customProps;
|
|
49
|
+
const {
|
|
50
|
+
tab: tabAttributes,
|
|
51
|
+
content: contentAttributes,
|
|
52
|
+
iconBox: iconBoxAttributes,
|
|
53
|
+
tabText: tabTextAttributes
|
|
54
|
+
} = customAttributes;
|
|
55
|
+
const {
|
|
56
|
+
getClasses,
|
|
57
|
+
iconPlacement,
|
|
58
|
+
labelStyle,
|
|
59
|
+
orientation,
|
|
60
|
+
size,
|
|
61
|
+
hasScroll,
|
|
62
|
+
hasOverflow,
|
|
63
|
+
textTransform: textTransformFromGroup,
|
|
64
|
+
textTruncate: textTruncateFromGroup
|
|
65
|
+
} = useTabsStyle('Tab');
|
|
66
|
+
const textTransform = textTransformFromGroup || TEXT_TRANSFORM.CAPITAL;
|
|
67
|
+
const textTruncate = textTruncateFromGroup || TEXT_TRUNCATE.CLAMP;
|
|
68
|
+
const isTextOnly = labelStyle === LABEL_STYLE.TEXT;
|
|
69
|
+
const isIconMode = labelStyle === LABEL_STYLE.ICON;
|
|
70
|
+
const hasText = !isIconMode && !!text;
|
|
71
|
+
const showIcon = !isTextOnly;
|
|
72
|
+
const textAlign = isTextOnly ? TEXT_ONLY_TEXT_ALIGN : ICON_PLACEMENT_TEXT_ALIGN[iconPlacement];
|
|
73
|
+
const hasIconAndText = !isTextOnly && !isIconMode;
|
|
74
|
+
const justifyContent = orientation === ORIENTATION.VERTICAL && hasIconAndText ? ICON_PLACEMENT_JUSTIFY[iconPlacement] : 'center';
|
|
75
|
+
const resolvedTextSize = SIZE_TEXT_SIZE[size] || SIZE_TEXT_SIZE[SIZE.MEDIUM];
|
|
76
|
+
const canShrink = !hasOverflow && !hasScroll;
|
|
77
|
+
const styleOverrides = {
|
|
78
|
+
labelStyle,
|
|
79
|
+
canShrink,
|
|
80
|
+
isDisabled,
|
|
81
|
+
customClass
|
|
82
|
+
};
|
|
83
|
+
const accessibleName = ariaLabel || (isIconMode ? text : undefined);
|
|
84
|
+
|
|
85
|
+
if (process.env.NODE_ENV !== 'production' && !hasText && !accessibleName && !children) {
|
|
86
|
+
console.warn(`<Tab value="${value}" /> renders no label and has no ariaLabel, so it has no accessible name. Icon-only tabs must pass ariaLabel or text.`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const classes = getClasses(styleOverrides);
|
|
90
|
+
const isAnchor = isAnchorFromProps ?? !!href;
|
|
91
|
+
const elementProps = mergeProps({
|
|
92
|
+
className: classes.tab,
|
|
93
|
+
href: isAnchor && !isDisabled ? href : undefined,
|
|
94
|
+
target: isAnchor ? target : undefined,
|
|
95
|
+
rel: isAnchor ? rel : undefined,
|
|
96
|
+
'data-tour': tourId,
|
|
97
|
+
'aria-label': accessibleName,
|
|
98
|
+
'data-title': title
|
|
99
|
+
}, {
|
|
100
|
+
onClick
|
|
101
|
+
}, tabAttributes);
|
|
102
|
+
return /*#__PURE__*/React.createElement(TabCore, _extends({
|
|
103
|
+
value: value,
|
|
104
|
+
isDisabled: isDisabled,
|
|
105
|
+
isAnchor: isAnchor,
|
|
106
|
+
tagName: tagName,
|
|
107
|
+
a11yAttributes: a11yAttributes,
|
|
108
|
+
getRef: getRef,
|
|
109
|
+
displayMode: "inlineFlex",
|
|
110
|
+
alignItems: "center",
|
|
111
|
+
justifyContent: justifyContent
|
|
112
|
+
}, elementProps, {
|
|
113
|
+
customId: customId,
|
|
114
|
+
testId: testId,
|
|
115
|
+
"data-selector-id": dataSelectorId
|
|
116
|
+
}), ({
|
|
117
|
+
isSelected
|
|
118
|
+
}) => {
|
|
119
|
+
const slot = {
|
|
120
|
+
value,
|
|
121
|
+
isSelected,
|
|
122
|
+
isDisabled
|
|
123
|
+
};
|
|
124
|
+
const icon = !showIcon ? null : isRenderable(renderIcon) ? renderNode(renderIcon, slot) : iconName ? /*#__PURE__*/React.createElement(Icon, _extends({}, iconProps, {
|
|
125
|
+
name: iconName,
|
|
126
|
+
size: iconSize
|
|
127
|
+
})) : null;
|
|
128
|
+
return /*#__PURE__*/React.createElement(FlexContainer, {
|
|
129
|
+
as: "span",
|
|
130
|
+
display: "flex",
|
|
131
|
+
direction: ICON_PLACEMENT_DIRECTION[iconPlacement],
|
|
132
|
+
alignItems: "center",
|
|
133
|
+
justifyContent: justifyContent,
|
|
134
|
+
customClass: classes.content,
|
|
135
|
+
customAttributes: contentAttributes
|
|
136
|
+
}, icon ? /*#__PURE__*/React.createElement(FlexItem, {
|
|
137
|
+
as: "span",
|
|
138
|
+
shrink: "0",
|
|
139
|
+
customClass: classes.iconBox,
|
|
140
|
+
customAttributes: iconBoxAttributes
|
|
141
|
+
}, icon) : null, isRenderable(renderBefore) ? renderNode(renderBefore, slot) : null, hasText ? /*#__PURE__*/React.createElement(Typography, _extends({}, textProps, {
|
|
142
|
+
$ui_size: resolvedTextSize,
|
|
143
|
+
$ui_lineHeight: "1.3",
|
|
144
|
+
$ui_lineClamp: textTruncate === TEXT_TRUNCATE.CLAMP ? '2' : undefined,
|
|
145
|
+
$flag_dotted: textTruncate === TEXT_TRUNCATE.ELLIPSIS,
|
|
146
|
+
$ui_wordBreak: textTruncate === TEXT_TRUNCATE.CLAMP ? 'breakWord' : undefined,
|
|
147
|
+
$ui_transform: textTransform,
|
|
148
|
+
$ui_textAlign: textAlign,
|
|
149
|
+
$ui_className: classes.tabText,
|
|
150
|
+
$i18n_dataTitle: title || text,
|
|
151
|
+
$tagAttributes_container: tabTextAttributes
|
|
152
|
+
}), text) : null, children, isRenderable(renderAfter) ? renderNode(renderAfter, slot) : null);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export default Tab;
|
|
157
|
+
Tab.displayName = 'Tab';
|
|
158
|
+
Tab.defaultProps = Tab_defaultProps;
|
|
159
|
+
Tab.propTypes = Tab_propTypes;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import { TabList as TabListCore, useTabsData, useTabsActions } from "./core";
|
|
5
|
+
import useAdaptiveRenderer from '@zohodesk/hooks/es/adaptiveRenderer/useAdaptiveRenderer';
|
|
6
|
+
import { DUMMY_ARRAY } from '@zohodesk/dotkit/es/utils/constants';
|
|
7
|
+
import Tab from "./Tab";
|
|
8
|
+
import TabMoreMenu from "./TabMoreMenu";
|
|
9
|
+
import TabsStyleContext, { useTabsStyle } from "./context";
|
|
10
|
+
import pinSelectedTab from "./utils/pinSelectedTab";
|
|
11
|
+
import { ORIENTATION, ORIENTATION_DIRECTION, MORE_MENU_DEFAULTS, POPUP_OPTIONS_DEFAULTS } from "./constants";
|
|
12
|
+
import { TabList_defaultProps } from "./props/defaultProps";
|
|
13
|
+
import { TabList_propTypes } from "./props/propTypes";
|
|
14
|
+
|
|
15
|
+
const TabList = props => {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
items,
|
|
19
|
+
ariaLabel,
|
|
20
|
+
ariaLabelledBy,
|
|
21
|
+
minVisibleTabs,
|
|
22
|
+
moreMenu,
|
|
23
|
+
customProps,
|
|
24
|
+
customClass,
|
|
25
|
+
customAttributes,
|
|
26
|
+
a11yAttributes,
|
|
27
|
+
customId,
|
|
28
|
+
testId,
|
|
29
|
+
dataSelectorId
|
|
30
|
+
} = props;
|
|
31
|
+
const resolvedMoreMenu = { ...MORE_MENU_DEFAULTS,
|
|
32
|
+
...moreMenu
|
|
33
|
+
};
|
|
34
|
+
const {
|
|
35
|
+
list: listAttributes
|
|
36
|
+
} = customAttributes;
|
|
37
|
+
const {
|
|
38
|
+
focusScopeProps,
|
|
39
|
+
popup: popupProps
|
|
40
|
+
} = customProps; // Popup HOC reads its options off TabMoreMenu's own props, falling back to its static
|
|
41
|
+
// Popup(TabMoreMenu) config when unset - so these must be forwarded top-level, not nested.
|
|
42
|
+
|
|
43
|
+
const popupOptions = { ...POPUP_OPTIONS_DEFAULTS,
|
|
44
|
+
...popupProps
|
|
45
|
+
};
|
|
46
|
+
const styleContext = useTabsStyle('TabList');
|
|
47
|
+
const {
|
|
48
|
+
getClasses,
|
|
49
|
+
orientation,
|
|
50
|
+
position,
|
|
51
|
+
labelStyle,
|
|
52
|
+
hasScroll
|
|
53
|
+
} = styleContext;
|
|
54
|
+
const {
|
|
55
|
+
selectedValue
|
|
56
|
+
} = useTabsData('TabList');
|
|
57
|
+
const {
|
|
58
|
+
selectTab
|
|
59
|
+
} = useTabsActions('TabList');
|
|
60
|
+
const isDataDriven = Array.isArray(items);
|
|
61
|
+
const classes = getClasses({
|
|
62
|
+
hasOverflow: isDataDriven,
|
|
63
|
+
customClass
|
|
64
|
+
});
|
|
65
|
+
const styleValue = useMemo(() => ({ ...styleContext,
|
|
66
|
+
hasOverflow: isDataDriven
|
|
67
|
+
}), [styleContext, isDataDriven]);
|
|
68
|
+
const isMoreMenuInline = !!popupOptions.isAbsolutePositioningNeeded;
|
|
69
|
+
const scroll = hasScroll ? orientation === ORIENTATION.VERTICAL ? 'vertical' : 'horizontal' : isDataDriven && !isMoreMenuInline ? 'hidden' : undefined;
|
|
70
|
+
|
|
71
|
+
const getClassSignature = itemClass => itemClass ? Object.keys(itemClass).map(slot => `${slot}:${itemClass[slot] || ''}`).join(',') : '';
|
|
72
|
+
|
|
73
|
+
const itemsSignature = `${labelStyle || ''}\u0001${position || ''}\u0001` + (items || DUMMY_ARRAY).map(item => `${item.value}|${item.text || ''}|${item.iconName || ''}|${item.isDisabled ? 1 : 0}|${item.renderBefore ? 1 : 0}|${item.renderAfter ? 1 : 0}|${getClassSignature(item.customClass)}`).join('\u0000');
|
|
74
|
+
const dataList = useMemo(() => items || DUMMY_ARRAY, [itemsSignature]);
|
|
75
|
+
const {
|
|
76
|
+
parentRef,
|
|
77
|
+
moreElementRef,
|
|
78
|
+
isMoreVisible,
|
|
79
|
+
leftElements,
|
|
80
|
+
remainingElements
|
|
81
|
+
} = useAdaptiveRenderer({
|
|
82
|
+
dataList,
|
|
83
|
+
minimumLeftVisible: minVisibleTabs,
|
|
84
|
+
storeChildrenWidth: false,
|
|
85
|
+
axis: orientation === ORIENTATION.VERTICAL ? 'block' : 'inline'
|
|
86
|
+
});
|
|
87
|
+
const {
|
|
88
|
+
visible,
|
|
89
|
+
overflow
|
|
90
|
+
} = pinSelectedTab({
|
|
91
|
+
dataList,
|
|
92
|
+
visible: leftElements,
|
|
93
|
+
overflow: remainingElements,
|
|
94
|
+
selectedValue
|
|
95
|
+
});
|
|
96
|
+
return /*#__PURE__*/React.createElement(TabListCore, _extends({
|
|
97
|
+
ariaLabel: ariaLabel,
|
|
98
|
+
ariaLabelledBy: ariaLabelledBy,
|
|
99
|
+
getRef: isDataDriven ? parentRef : null,
|
|
100
|
+
focusScopeProps: focusScopeProps,
|
|
101
|
+
displayMode: "flex",
|
|
102
|
+
direction: ORIENTATION_DIRECTION[orientation],
|
|
103
|
+
alignItems: "stretch",
|
|
104
|
+
scroll: scroll
|
|
105
|
+
}, listAttributes, a11yAttributes, {
|
|
106
|
+
className: classes.list,
|
|
107
|
+
customId: customId,
|
|
108
|
+
testId: testId,
|
|
109
|
+
"data-selector-id": dataSelectorId
|
|
110
|
+
}), /*#__PURE__*/React.createElement(TabsStyleContext.Provider, {
|
|
111
|
+
value: styleValue
|
|
112
|
+
}, isDataDriven ? visible.map(item => /*#__PURE__*/React.createElement(Tab, {
|
|
113
|
+
key: item.value,
|
|
114
|
+
value: item.value,
|
|
115
|
+
text: item.text,
|
|
116
|
+
iconName: item.iconName,
|
|
117
|
+
iconSize: item.iconSize,
|
|
118
|
+
isDisabled: item.isDisabled,
|
|
119
|
+
ariaLabel: item.ariaLabel,
|
|
120
|
+
title: item.title,
|
|
121
|
+
tourId: item.tourId,
|
|
122
|
+
tagName: item.tagName,
|
|
123
|
+
isAnchor: item.isAnchor,
|
|
124
|
+
a11yAttributes: item.a11yAttributes,
|
|
125
|
+
href: item.href,
|
|
126
|
+
target: item.target,
|
|
127
|
+
rel: item.rel,
|
|
128
|
+
renderIcon: item.renderIcon,
|
|
129
|
+
renderBefore: item.renderBefore,
|
|
130
|
+
renderAfter: item.renderAfter,
|
|
131
|
+
customClass: item.customClass,
|
|
132
|
+
customId: item.customId,
|
|
133
|
+
testId: item.testId,
|
|
134
|
+
dataSelectorId: item.dataSelectorId
|
|
135
|
+
})) : children, isDataDriven && isMoreVisible ? /*#__PURE__*/React.createElement(TabMoreMenu, _extends({
|
|
136
|
+
items: overflow,
|
|
137
|
+
classes: classes,
|
|
138
|
+
moreMenu: resolvedMoreMenu,
|
|
139
|
+
moreRef: moreElementRef,
|
|
140
|
+
onSelect: selectTab,
|
|
141
|
+
selectedValue: selectedValue,
|
|
142
|
+
customProps: customProps,
|
|
143
|
+
customId: `${customId}_more`,
|
|
144
|
+
testId: `${testId}_more`
|
|
145
|
+
}, popupOptions, {
|
|
146
|
+
dataSelectorId: dataSelectorId ? `${dataSelectorId}_more` : undefined
|
|
147
|
+
})) : null, isDataDriven ? children : null));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default TabList;
|
|
151
|
+
TabList.displayName = 'TabList';
|
|
152
|
+
TabList.defaultProps = TabList_defaultProps;
|
|
153
|
+
TabList.propTypes = TabList_propTypes;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { cn } from "@dot-system/css-utility";
|
|
2
|
+
|
|
3
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
|
|
5
|
+
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import renderNode, { isRenderable } from '@zohodesk/utils/es/renderNode';
|
|
7
|
+
import EmptySearch from '@zohodesk/svg/es/emptystate/version3/EmptySearch';
|
|
8
|
+
import Icon from '@zohodesk/icons/es/Icon';
|
|
9
|
+
import Popup from "../../Popup/Popup";
|
|
10
|
+
import ResponsiveDropBox from "../../ResponsiveDropBox/ResponsiveDropBox";
|
|
11
|
+
import ListItem from "../../ListItem/ListItem";
|
|
12
|
+
import TextBoxIcon from "../../TextBoxIcon/TextBoxIcon";
|
|
13
|
+
import { ResponsiveReceiver } from "../../Responsive/CustomResponsive";
|
|
14
|
+
import { TabMoreMenu_defaultProps } from "./props/defaultProps";
|
|
15
|
+
import { TabMoreMenu_propTypes } from "./props/propTypes";
|
|
16
|
+
|
|
17
|
+
function TabMoreMenu(props) {
|
|
18
|
+
const {
|
|
19
|
+
items,
|
|
20
|
+
classes,
|
|
21
|
+
moreMenu,
|
|
22
|
+
onSelect,
|
|
23
|
+
selectedValue,
|
|
24
|
+
moreRef,
|
|
25
|
+
customProps,
|
|
26
|
+
customId,
|
|
27
|
+
testId,
|
|
28
|
+
dataSelectorId,
|
|
29
|
+
|
|
30
|
+
/* Popup HOC passthrough, authored via TabList's customProps.popup */
|
|
31
|
+
isAbsolutePositioningNeeded,
|
|
32
|
+
isOutsideScrollBlocked,
|
|
33
|
+
isArrow,
|
|
34
|
+
|
|
35
|
+
/* injected by Popup() */
|
|
36
|
+
isPopupOpen,
|
|
37
|
+
isPopupReady,
|
|
38
|
+
position,
|
|
39
|
+
togglePopup,
|
|
40
|
+
closePopupOnly,
|
|
41
|
+
getTargetRef,
|
|
42
|
+
getContainerRef,
|
|
43
|
+
removeClose
|
|
44
|
+
} = props;
|
|
45
|
+
const {
|
|
46
|
+
DropBoxProps,
|
|
47
|
+
ListItemProps,
|
|
48
|
+
TextBoxIconProps,
|
|
49
|
+
focusScopeProps
|
|
50
|
+
} = customProps;
|
|
51
|
+
const {
|
|
52
|
+
iconName,
|
|
53
|
+
iconSize,
|
|
54
|
+
ariaLabel,
|
|
55
|
+
searchThreshold,
|
|
56
|
+
searchPlaceholder,
|
|
57
|
+
searchErrorText,
|
|
58
|
+
searchBoxSize,
|
|
59
|
+
renderTarget,
|
|
60
|
+
onScroll,
|
|
61
|
+
defaultPosition,
|
|
62
|
+
positionsOffset,
|
|
63
|
+
targetOffset
|
|
64
|
+
} = moreMenu;
|
|
65
|
+
const [searchValue, setSearchValue] = useState('');
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
setSearchValue('');
|
|
68
|
+
}, [isPopupOpen]);
|
|
69
|
+
|
|
70
|
+
const handleToggle = event => {
|
|
71
|
+
removeClose && removeClose(event);
|
|
72
|
+
togglePopup(event, defaultPosition);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleSelect = (value, _label, _index, event) => {
|
|
76
|
+
const target = event && event.target;
|
|
77
|
+
const isModified = event && (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
78
|
+
|
|
79
|
+
if (isModified && target && target.closest && target.closest('a')) {
|
|
80
|
+
event.stopPropagation();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
event && event.preventDefault();
|
|
85
|
+
onSelect(value, event);
|
|
86
|
+
closePopupOnly();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleSearchChange = value => {
|
|
90
|
+
setSearchValue(value || '');
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const handleSearchClear = () => {
|
|
94
|
+
setSearchValue('');
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const hasSearch = items.length > searchThreshold;
|
|
98
|
+
const query = searchValue.trim().toLowerCase();
|
|
99
|
+
const visibleItems = hasSearch && query ? items.filter(item => {
|
|
100
|
+
const label = item.text || item.title || item.ariaLabel || '';
|
|
101
|
+
return label.toLowerCase().includes(query);
|
|
102
|
+
}) : items;
|
|
103
|
+
const targetSlot = {
|
|
104
|
+
isOpen: !!isPopupOpen,
|
|
105
|
+
hiddenCount: items.length
|
|
106
|
+
};
|
|
107
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
108
|
+
ref: moreRef,
|
|
109
|
+
className: cn(classes.moreWrapper)
|
|
110
|
+
}, isRenderable(renderTarget) ? /*#__PURE__*/React.createElement("span", {
|
|
111
|
+
ref: getTargetRef,
|
|
112
|
+
role: "button",
|
|
113
|
+
tabIndex: 0,
|
|
114
|
+
"aria-haspopup": "menu",
|
|
115
|
+
"aria-expanded": !!isPopupOpen,
|
|
116
|
+
"aria-label": ariaLabel,
|
|
117
|
+
className: cn(classes.more),
|
|
118
|
+
onClick: handleToggle,
|
|
119
|
+
"data-id": customId,
|
|
120
|
+
"data-test-id": testId,
|
|
121
|
+
"data-selector-id": dataSelectorId
|
|
122
|
+
}, renderNode(renderTarget, targetSlot)) : /*#__PURE__*/React.createElement("button", {
|
|
123
|
+
ref: getTargetRef,
|
|
124
|
+
type: "button",
|
|
125
|
+
className: cn(classes.more),
|
|
126
|
+
"aria-haspopup": "menu",
|
|
127
|
+
"aria-expanded": !!isPopupOpen,
|
|
128
|
+
"aria-label": ariaLabel,
|
|
129
|
+
onClick: handleToggle,
|
|
130
|
+
"data-id": customId,
|
|
131
|
+
"data-test-id": testId,
|
|
132
|
+
"data-selector-id": dataSelectorId
|
|
133
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
134
|
+
name: iconName,
|
|
135
|
+
size: iconSize
|
|
136
|
+
})), isPopupOpen ? /*#__PURE__*/React.createElement(ResponsiveReceiver, {
|
|
137
|
+
query: responsiveQuery,
|
|
138
|
+
responsiveId: "Helmet"
|
|
139
|
+
}, ({
|
|
140
|
+
tabletMode
|
|
141
|
+
}) => /*#__PURE__*/React.createElement(ResponsiveDropBox, _extends({
|
|
142
|
+
isActive: isPopupReady,
|
|
143
|
+
isAnimate: true,
|
|
144
|
+
size: "medium",
|
|
145
|
+
boxPosition: position,
|
|
146
|
+
getRef: getContainerRef,
|
|
147
|
+
isBoxPaddingNeed: false,
|
|
148
|
+
isArrow: isArrow,
|
|
149
|
+
isAbsolutePositioningNeeded: isAbsolutePositioningNeeded,
|
|
150
|
+
isRestrictScroll: isOutsideScrollBlocked,
|
|
151
|
+
positionsOffset: positionsOffset,
|
|
152
|
+
targetOffset: targetOffset,
|
|
153
|
+
isResponsivePadding: true,
|
|
154
|
+
needFocusScope: true,
|
|
155
|
+
customClass: {
|
|
156
|
+
customDropBoxWrap: classes.moreBox
|
|
157
|
+
},
|
|
158
|
+
customProps: {
|
|
159
|
+
focusScopeProps
|
|
160
|
+
},
|
|
161
|
+
onClick: removeClose,
|
|
162
|
+
onClose: handleToggle,
|
|
163
|
+
dataId: `${customId}_dropbox`
|
|
164
|
+
}, DropBoxProps), /*#__PURE__*/React.createElement(React.Fragment, null, hasSearch ? /*#__PURE__*/React.createElement("div", {
|
|
165
|
+
className: cn(classes.search)
|
|
166
|
+
}, /*#__PURE__*/React.createElement(TextBoxIcon, _extends({
|
|
167
|
+
placeHolder: searchPlaceholder,
|
|
168
|
+
onChange: handleSearchChange,
|
|
169
|
+
value: searchValue,
|
|
170
|
+
onClear: handleSearchClear,
|
|
171
|
+
size: searchBoxSize,
|
|
172
|
+
customProps: {
|
|
173
|
+
TextBoxProps: {
|
|
174
|
+
'data-a11y-autofocus': true
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
dataId: `${customId}_search`,
|
|
178
|
+
autoComplete: false,
|
|
179
|
+
name: "search"
|
|
180
|
+
}, TextBoxIconProps))) : null, /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
role: "menu",
|
|
182
|
+
"aria-label": ariaLabel,
|
|
183
|
+
className: cn(tabletMode ? classes.moreListWrapper : `${classes.moreListWrapper} ${classes.moreMenuHeight}`),
|
|
184
|
+
onScroll: onScroll
|
|
185
|
+
}, !visibleItems.length ? /*#__PURE__*/React.createElement("div", {
|
|
186
|
+
className: cn(classes.emptyStateContainer)
|
|
187
|
+
}, /*#__PURE__*/React.createElement(EmptySearch, {
|
|
188
|
+
size: "small"
|
|
189
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
190
|
+
className: cn(classes.emptyStateTitle)
|
|
191
|
+
}, searchErrorText)) : null, visibleItems.map((item, index) => {
|
|
192
|
+
const icon = item.iconName ? /*#__PURE__*/React.createElement("span", {
|
|
193
|
+
className: cn(classes.moreItemIcon)
|
|
194
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
195
|
+
name: item.iconName,
|
|
196
|
+
size: item.iconSize || iconSize,
|
|
197
|
+
"aria-hidden": true
|
|
198
|
+
})) : null;
|
|
199
|
+
const slot = {
|
|
200
|
+
value: item.value,
|
|
201
|
+
isSelected: item.value === selectedValue,
|
|
202
|
+
isDisabled: !!item.isDisabled
|
|
203
|
+
};
|
|
204
|
+
const hasBefore = isRenderable(item.renderBefore);
|
|
205
|
+
const renderBeforeChildren = hasBefore || icon ? () => /*#__PURE__*/React.createElement(React.Fragment, null, icon, hasBefore ? renderNode(item.renderBefore, slot) : null) : null;
|
|
206
|
+
const renderAfter = isRenderable(item.renderAfter) ? () => renderNode(item.renderAfter, slot) : null;
|
|
207
|
+
return /*#__PURE__*/React.createElement(ListItem, _extends({
|
|
208
|
+
key: item.value,
|
|
209
|
+
id: item.value,
|
|
210
|
+
index: index,
|
|
211
|
+
value: item.text || item.ariaLabel,
|
|
212
|
+
title: item.title || item.text,
|
|
213
|
+
onClick: handleSelect,
|
|
214
|
+
isLink: !!item.href,
|
|
215
|
+
href: item.isDisabled ? undefined : item.href,
|
|
216
|
+
target: item.target === '_blank' ? 'blank' : 'self',
|
|
217
|
+
autoHover: true,
|
|
218
|
+
isDisabled: item.isDisabled,
|
|
219
|
+
a11y: {
|
|
220
|
+
role: 'menuitem'
|
|
221
|
+
},
|
|
222
|
+
customClass: {
|
|
223
|
+
customListItem: classes.moreItem
|
|
224
|
+
},
|
|
225
|
+
dataId: `${customId}_item`,
|
|
226
|
+
renderBeforeChildren: renderBeforeChildren,
|
|
227
|
+
renderValueRightPlaceholderNode: renderAfter
|
|
228
|
+
}, ListItemProps));
|
|
229
|
+
}))))) : null);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function responsiveQuery({
|
|
233
|
+
mediaQueryOR
|
|
234
|
+
}) {
|
|
235
|
+
return {
|
|
236
|
+
tabletMode: mediaQueryOR([{
|
|
237
|
+
maxWidth: 700
|
|
238
|
+
}])
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
TabMoreMenu.displayName = 'TabMoreMenu';
|
|
243
|
+
TabMoreMenu.defaultProps = TabMoreMenu_defaultProps;
|
|
244
|
+
TabMoreMenu.propTypes = TabMoreMenu_propTypes;
|
|
245
|
+
export default Popup(TabMoreMenu);
|