@zohodesk/components 1.0.0-temp-262 → 1.0.0-temp-262.2
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 +6 -0
- package/es/v1/Tab/Tab.js +55 -12
- package/es/v1/Tab/TabList.js +11 -3
- package/es/v1/Tab/__tests__/Tab.spec.js +487 -22
- package/es/v1/Tab/__tests__/__snapshots__/Tab.spec.js.snap +692 -443
- package/es/v1/Tab/constants/index.js +7 -0
- package/es/v1/Tab/constants/presets.js +25 -10
- package/es/v1/Tab/css/Tab_v1.module.css +316 -284
- package/es/v1/Tab/css/tab.cva.js +101 -50
- package/es/v1/Tab/index.js +1 -1
- package/es/v1/Tab/props/propTypes.js +11 -0
- package/lib/v1/Tab/Tab.js +54 -10
- package/lib/v1/Tab/TabList.js +14 -3
- package/lib/v1/Tab/__tests__/Tab.spec.js +541 -34
- package/lib/v1/Tab/__tests__/__snapshots__/Tab.spec.js.snap +692 -443
- package/lib/v1/Tab/constants/index.js +6 -2
- package/lib/v1/Tab/constants/presets.js +42 -8
- package/lib/v1/Tab/css/Tab_v1.module.css +316 -284
- package/lib/v1/Tab/css/tab.cva.js +67 -39
- package/lib/v1/Tab/index.js +18 -0
- package/lib/v1/Tab/props/propTypes.js +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- **v1 Tab** - `Tab` (and data-driven `TabList` items) accept `renderAction`: an interactive node rendered beside the `role="tab"` button instead of inside it. The `tab` slot then styles a wrapper (`data-selected` / `data-disabled`) that also carries `customId`, `testId`, `dataSelectorId` and `tourId`; new `tabTrigger` / `tabAction` slots. Not shown in the overflow menu.
|
|
6
|
+
- **v1 Tab** - Data-driven `TabList` items accept a per-item `customClass`.
|
|
7
|
+
- **v1 Tab** - A data-driven `TabList` no longer clips its overflow when `customProps.popup.isAbsolutePositioningNeeded` is `true`, so the inline more menu is no longer hidden.
|
|
8
|
+
|
|
3
9
|
## 1.6.34
|
|
4
10
|
|
|
5
11
|
- **CheckBox** - Fixed the CSS Utility class ordering to resolve the position property conflict between the disabled and tick classes.
|
package/es/v1/Tab/Tab.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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
2
|
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { Tab as TabCore } from "./core";
|
|
4
|
+
import { Tab as TabCore, useTabsData } from "./core";
|
|
5
5
|
import mergeProps from '@zohodesk/utils/es/mergeProps';
|
|
6
6
|
import renderNode, { isRenderable } from '@zohodesk/utils/es/renderNode';
|
|
7
7
|
import FlexContainer from '@zohodesk/layout/es/Flex/FlexContainer';
|
|
@@ -9,7 +9,7 @@ import FlexItem from '@zohodesk/layout/es/Flex/FlexItem';
|
|
|
9
9
|
import Icon from '@zohodesk/icons/es/Icon';
|
|
10
10
|
import Typography from "../../Typography/Typography";
|
|
11
11
|
import { useTabsStyle } from "./context";
|
|
12
|
-
import { ICON_PLACEMENT_DIRECTION, ICON_PLACEMENT_TEXT_ALIGN, LABEL_STYLE, SIZE, SIZE_TEXT_SIZE, TEXT_TRANSFORM, TEXT_TRUNCATE } from "./constants";
|
|
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
13
|
import { Tab_defaultProps } from "./props/defaultProps";
|
|
14
14
|
import { Tab_propTypes } from "./props/propTypes";
|
|
15
15
|
|
|
@@ -30,6 +30,7 @@ const Tab = props => {
|
|
|
30
30
|
renderIcon,
|
|
31
31
|
renderBefore,
|
|
32
32
|
renderAfter,
|
|
33
|
+
renderAction,
|
|
33
34
|
onClick,
|
|
34
35
|
getRef,
|
|
35
36
|
customClass,
|
|
@@ -54,23 +55,31 @@ const Tab = props => {
|
|
|
54
55
|
getClasses,
|
|
55
56
|
iconPlacement,
|
|
56
57
|
labelStyle,
|
|
58
|
+
orientation,
|
|
57
59
|
size,
|
|
58
60
|
hasScroll,
|
|
59
61
|
hasOverflow,
|
|
60
62
|
textTransform: textTransformFromGroup,
|
|
61
63
|
textTruncate: textTruncateFromGroup
|
|
62
64
|
} = useTabsStyle('Tab');
|
|
65
|
+
const {
|
|
66
|
+
selectedValue
|
|
67
|
+
} = useTabsData('Tab');
|
|
63
68
|
const textTransform = textTransformFromGroup || TEXT_TRANSFORM.CAPITAL;
|
|
64
69
|
const textTruncate = textTruncateFromGroup || TEXT_TRUNCATE.CLAMP;
|
|
65
70
|
const isTextOnly = labelStyle === LABEL_STYLE.TEXT;
|
|
66
71
|
const isIconMode = labelStyle === LABEL_STYLE.ICON;
|
|
67
72
|
const hasText = !isIconMode && !!text;
|
|
68
73
|
const showIcon = !isTextOnly;
|
|
74
|
+
const textAlign = isTextOnly ? TEXT_ONLY_TEXT_ALIGN : ICON_PLACEMENT_TEXT_ALIGN[iconPlacement];
|
|
75
|
+
const hasIconAndText = !isTextOnly && !isIconMode;
|
|
76
|
+
const justifyContent = orientation === ORIENTATION.VERTICAL && hasIconAndText ? ICON_PLACEMENT_JUSTIFY[iconPlacement] : 'center';
|
|
69
77
|
const resolvedTextSize = SIZE_TEXT_SIZE[size] || SIZE_TEXT_SIZE[SIZE.MEDIUM];
|
|
70
78
|
const canShrink = !hasOverflow && !hasScroll;
|
|
71
79
|
const styleOverrides = {
|
|
72
80
|
labelStyle,
|
|
73
81
|
canShrink,
|
|
82
|
+
isDisabled,
|
|
74
83
|
customClass
|
|
75
84
|
};
|
|
76
85
|
const accessibleName = ariaLabel || (isIconMode ? text : undefined);
|
|
@@ -80,30 +89,33 @@ const Tab = props => {
|
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
const classes = getClasses(styleOverrides);
|
|
83
|
-
const isAnchor = !!href;
|
|
92
|
+
const isAnchor = !!href; // With an action the visual tab becomes a wrapper around the role="tab"
|
|
93
|
+
// trigger, so an interactive action never nests inside the <button>.
|
|
94
|
+
|
|
95
|
+
const hasAction = isRenderable(renderAction);
|
|
84
96
|
const elementProps = mergeProps({
|
|
85
|
-
className: classes.tab,
|
|
97
|
+
className: hasAction ? classes.tabTrigger : classes.tab,
|
|
86
98
|
href: isAnchor && !isDisabled ? href : undefined,
|
|
87
99
|
target: isAnchor ? target : undefined,
|
|
88
100
|
rel: isAnchor ? rel : undefined,
|
|
89
|
-
'data-tour': tourId,
|
|
101
|
+
'data-tour': hasAction ? undefined : tourId,
|
|
90
102
|
'aria-label': accessibleName,
|
|
91
103
|
'data-title': title
|
|
92
104
|
}, {
|
|
93
105
|
onClick
|
|
94
106
|
}, tabAttributes, a11yAttributes);
|
|
95
|
-
|
|
107
|
+
const trigger = /*#__PURE__*/React.createElement(TabCore, _extends({
|
|
96
108
|
value: value,
|
|
97
109
|
isDisabled: isDisabled,
|
|
98
110
|
isAnchor: isAnchor,
|
|
99
111
|
getRef: getRef,
|
|
100
112
|
displayMode: "inlineFlex",
|
|
101
113
|
alignItems: "center",
|
|
102
|
-
justifyContent:
|
|
114
|
+
justifyContent: justifyContent
|
|
103
115
|
}, elementProps, {
|
|
104
|
-
customId: customId,
|
|
105
|
-
testId: testId,
|
|
106
|
-
"data-selector-id": dataSelectorId
|
|
116
|
+
customId: hasAction ? undefined : customId,
|
|
117
|
+
testId: hasAction ? undefined : testId,
|
|
118
|
+
"data-selector-id": hasAction ? undefined : dataSelectorId
|
|
107
119
|
}), ({
|
|
108
120
|
isSelected
|
|
109
121
|
}) => {
|
|
@@ -121,7 +133,7 @@ const Tab = props => {
|
|
|
121
133
|
display: "flex",
|
|
122
134
|
direction: ICON_PLACEMENT_DIRECTION[iconPlacement],
|
|
123
135
|
alignItems: "center",
|
|
124
|
-
justifyContent:
|
|
136
|
+
justifyContent: justifyContent,
|
|
125
137
|
customClass: classes.content,
|
|
126
138
|
customAttributes: contentAttributes
|
|
127
139
|
}, icon ? /*#__PURE__*/React.createElement(FlexItem, {
|
|
@@ -136,12 +148,43 @@ const Tab = props => {
|
|
|
136
148
|
$flag_dotted: textTruncate === TEXT_TRUNCATE.ELLIPSIS,
|
|
137
149
|
$ui_wordBreak: textTruncate === TEXT_TRUNCATE.CLAMP ? 'breakWord' : undefined,
|
|
138
150
|
$ui_transform: textTransform,
|
|
139
|
-
$ui_textAlign:
|
|
151
|
+
$ui_textAlign: textAlign,
|
|
140
152
|
$ui_className: classes.tabText,
|
|
141
153
|
$i18n_dataTitle: title || text,
|
|
142
154
|
$tagAttributes_container: tabTextAttributes
|
|
143
155
|
}), text) : null, children, isRenderable(renderAfter) ? renderNode(renderAfter, slot) : null);
|
|
144
156
|
});
|
|
157
|
+
|
|
158
|
+
if (!hasAction) {
|
|
159
|
+
return trigger;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const isSelected = value === selectedValue;
|
|
163
|
+
const actionSlot = {
|
|
164
|
+
value,
|
|
165
|
+
isSelected,
|
|
166
|
+
isDisabled
|
|
167
|
+
};
|
|
168
|
+
return /*#__PURE__*/React.createElement(FlexContainer, {
|
|
169
|
+
as: "span",
|
|
170
|
+
display: "inlineFlex",
|
|
171
|
+
alignItems: "center",
|
|
172
|
+
justifyContent: justifyContent,
|
|
173
|
+
customClass: classes.tab,
|
|
174
|
+
customId: customId,
|
|
175
|
+
testId: testId,
|
|
176
|
+
customAttributes: {
|
|
177
|
+
role: 'presentation',
|
|
178
|
+
'data-selected': String(isSelected),
|
|
179
|
+
'data-disabled': String(!!isDisabled),
|
|
180
|
+
'data-tour': tourId,
|
|
181
|
+
'data-selector-id': dataSelectorId
|
|
182
|
+
}
|
|
183
|
+
}, trigger, /*#__PURE__*/React.createElement(FlexItem, {
|
|
184
|
+
as: "span",
|
|
185
|
+
shrink: "0",
|
|
186
|
+
customClass: classes.tabAction
|
|
187
|
+
}, renderNode(renderAction, actionSlot)));
|
|
145
188
|
};
|
|
146
189
|
|
|
147
190
|
export default Tab;
|
package/es/v1/Tab/TabList.js
CHANGED
|
@@ -64,9 +64,15 @@ const TabList = props => {
|
|
|
64
64
|
});
|
|
65
65
|
const styleValue = useMemo(() => ({ ...styleContext,
|
|
66
66
|
hasOverflow: isDataDriven
|
|
67
|
-
}), [styleContext, isDataDriven]);
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
}), [styleContext, isDataDriven]); // An inline (absolutely positioned) more menu renders inside the list, so
|
|
68
|
+
// clipping the list would hide it; a portalled menu escapes the clip.
|
|
69
|
+
|
|
70
|
+
const isMoreMenuInline = !!popupOptions.isAbsolutePositioningNeeded;
|
|
71
|
+
const scroll = hasScroll ? orientation === ORIENTATION.VERTICAL ? 'vertical' : 'horizontal' : isDataDriven && !isMoreMenuInline ? 'hidden' : undefined;
|
|
72
|
+
|
|
73
|
+
const getClassSignature = itemClass => itemClass ? Object.keys(itemClass).map(slot => `${slot}:${itemClass[slot] || ''}`).join(',') : '';
|
|
74
|
+
|
|
75
|
+
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}|${item.renderAction ? 1 : 0}|${getClassSignature(item.customClass)}`).join('\u0000');
|
|
70
76
|
const dataList = useMemo(() => items || DUMMY_ARRAY, [itemsSignature]);
|
|
71
77
|
const {
|
|
72
78
|
parentRef,
|
|
@@ -121,6 +127,8 @@ const TabList = props => {
|
|
|
121
127
|
renderIcon: item.renderIcon,
|
|
122
128
|
renderBefore: item.renderBefore,
|
|
123
129
|
renderAfter: item.renderAfter,
|
|
130
|
+
renderAction: item.renderAction,
|
|
131
|
+
customClass: item.customClass,
|
|
124
132
|
customId: item.customId,
|
|
125
133
|
testId: item.testId,
|
|
126
134
|
dataSelectorId: item.dataSelectorId
|