@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.
@@ -1,69 +1,68 @@
1
1
  import { csv } from '@dot-system/css-utility';
2
2
  import style from "./Tab_v1.module.css";
3
- import { SIZE, VARIANT, ORIENTATION, POSITION } from "../constants";
3
+ import { SIZE, VARIANT, ORIENTATION, POSITION } from "../constants"; // css-utility's gap scale is arbitrary-value classes: .d-gap-\[4px\].
4
+
4
5
  const gapVariants = {
5
- 2: 'd-gap-2',
6
- 4: 'd-gap-4',
7
- 6: 'd-gap-6',
8
- 8: 'd-gap-8',
9
- 10: 'd-gap-10',
10
- 12: 'd-gap-12',
11
- 14: 'd-gap-14',
12
- 16: 'd-gap-16',
13
- 18: 'd-gap-18',
14
- 20: 'd-gap-20'
6
+ 2: 'd-gap-[2px]',
7
+ 4: 'd-gap-[4px]',
8
+ 6: 'd-gap-[6px]',
9
+ 8: 'd-gap-[8px]',
10
+ 10: 'd-gap-[10px]',
11
+ 12: 'd-gap-[12px]',
12
+ 14: 'd-gap-[14px]',
13
+ 16: 'd-gap-[16px]',
14
+ 18: 'd-gap-[18px]',
15
+ 20: 'd-gap-[20px]'
15
16
  };
16
17
  const tabSlots = csv({
17
18
  root: {
18
- base: [style.root, 'd-min-w-0'],
19
+ base: ['d-min-w-0']
20
+ },
21
+ list: {
22
+ base: [style.list, 'd-relative', 'd-min-w-0'],
19
23
  config: {
20
24
  variants: {
21
- size: {
22
- [SIZE.SMALL]: style.small,
23
- [SIZE.MEDIUM]: style.medium,
24
- [SIZE.LARGE]: style.large
25
- },
26
- variant: {
27
- [VARIANT.UNDERLINE]: style.underline,
28
- [VARIANT.ELEVATED]: style.elevated,
29
- [VARIANT.SPACED]: style.spaced,
30
- [VARIANT.DOTTED]: style.dotted
25
+ isFullWidth: {
26
+ true: 'd-w-full'
31
27
  },
32
- hasListBorder: {
33
- false: style.noListBorder
28
+ hasSurface: {
29
+ true: style.listSurface
34
30
  },
35
- hasListPadding: {
36
- false: style.noListPadding
31
+ // border-style is a utility, so every variant names exactly one.
32
+ variant: {
33
+ [VARIANT.UNDERLINE]: 'd-border-solid',
34
+ [VARIANT.ELEVATED]: [style.listElevated, 'd-border-solid'],
35
+ [VARIANT.SPACED]: [style.listSpaced, 'd-border-solid'],
36
+ [VARIANT.DOTTED]: [style.listDotted, 'd-border-dotted']
37
37
  },
38
38
  orientation: {
39
- [ORIENTATION.VERTICAL]: style.vertical
39
+ [ORIENTATION.VERTICAL]: style.listVertical
40
40
  },
41
41
  position: {
42
- [POSITION.TOP]: style.top,
43
- [POSITION.BOTTOM]: style.bottom,
44
- [POSITION.LEFT]: style.left,
45
- [POSITION.RIGHT]: style.right
42
+ [POSITION.TOP]: style.listTop,
43
+ [POSITION.BOTTOM]: style.listBottom,
44
+ [POSITION.LEFT]: style.listLeft,
45
+ [POSITION.RIGHT]: style.listRight
46
46
  },
47
- hasSurface: {
48
- true: style.hasSurface
49
- }
50
- }
51
- }
52
- },
53
- list: {
54
- base: [style.list, 'd-relative', 'd-min-w-0'],
55
- config: {
56
- variants: {
57
- isFullWidth: {
58
- true: 'd-w-full'
47
+ hasListBorder: {
48
+ false: style.listNoBorder
49
+ },
50
+ hasListPadding: {
51
+ false: style.listNoPadding
59
52
  }
60
53
  }
61
54
  }
62
55
  },
63
56
  tab: {
64
- base: [style.tab, 'd-relative', 'd-m-0', 'd-no-underline', 'd-border-solid', 'd-select-none'],
57
+ // No d-m-0 here: variants and orientation set tab margins in the stylesheet,
58
+ // and the utility layer has no declared order against the component layer.
59
+ base: [style.tab, 'd-relative', 'd-min-w-0', 'd-no-underline', 'd-border-solid', 'd-select-none'],
65
60
  config: {
66
61
  variants: {
62
+ isDisabled: {
63
+ true: 'd-cursor-not-allowed',
64
+ false: 'd-cursor-pointer'
65
+ },
67
66
  isFullWidth: {
68
67
  true: ['d-flex-1', 'd-min-w-0']
69
68
  },
@@ -72,13 +71,44 @@ const tabSlots = csv({
72
71
  canShrink: {
73
72
  true: ['d-min-w-0', 'd-flex-shrink'],
74
73
  false: 'd-flex-shrink-0'
74
+ },
75
+ hasSurface: {
76
+ true: style.tabSurface
77
+ },
78
+ size: {
79
+ [SIZE.SMALL]: style.tabSmall,
80
+ [SIZE.MEDIUM]: style.tabMedium,
81
+ [SIZE.LARGE]: style.tabLarge
82
+ },
83
+ variant: {
84
+ [VARIANT.ELEVATED]: style.tabElevated,
85
+ [VARIANT.SPACED]: style.tabSpaced,
86
+ [VARIANT.DOTTED]: style.tabDotted
87
+ },
88
+ orientation: {
89
+ [ORIENTATION.VERTICAL]: style.tabVertical
90
+ },
91
+ position: {
92
+ [POSITION.TOP]: style.tabTop,
93
+ [POSITION.BOTTOM]: style.tabBottom,
94
+ [POSITION.LEFT]: style.tabLeft,
95
+ [POSITION.RIGHT]: style.tabRight
75
96
  }
76
97
  }
77
98
  }
78
99
  },
100
+ // With `renderAction` the `tab` slot styles a wrapper; the role="tab"
101
+ // trigger inside it is flush, and its ::after stretches over the wrapper
102
+ // so the whole tab stays clickable.
103
+ tabTrigger: {
104
+ base: [style.tabTrigger, 'd-min-w-0', 'd-max-w-full', 'd-no-underline', 'd-select-none']
105
+ },
106
+ tabAction: {
107
+ base: [style.tabAction, 'd-relative', 'd-inline-flex', 'd-items-center']
108
+ },
79
109
  content: {
80
110
  // `d-flex` comes from the FlexContainer that renders this slot.
81
- base: [style.content, 'd-min-w-0'],
111
+ base: ['d-min-w-0', 'd-max-w-full'],
82
112
  config: {
83
113
  variants: {
84
114
  iconSpacing: gapVariants
@@ -89,10 +119,10 @@ const tabSlots = csv({
89
119
  base: [style.iconBox, 'd-flex', 'd-items-center', 'd-justify-center']
90
120
  },
91
121
  tabText: {
92
- base: [style.tabText]
122
+ base: ['d-min-w-0', 'd-max-w-full']
93
123
  },
94
124
  moreWrapper: {
95
- base: [style.moreWrapper, 'd-relative', 'd-inline-flex'],
125
+ base: ['d-relative', 'd-inline-flex', 'd-flex-none', 'd-cursor-pointer'],
96
126
  config: {
97
127
  variants: {
98
128
  orientation: {
@@ -102,11 +132,24 @@ const tabSlots = csv({
102
132
  }
103
133
  },
104
134
  more: {
105
- base: [style.more, 'd-m-0', 'd-inline-flex', 'd-items-center', 'd-justify-center'],
135
+ base: [style.more, 'd-m-0', 'd-border-none', 'd-cursor-pointer', 'd-inline-flex', 'd-items-center', 'd-justify-center'],
106
136
  config: {
107
137
  variants: {
108
138
  orientation: {
109
139
  [ORIENTATION.VERTICAL]: 'd-w-full'
140
+ },
141
+ hasSurface: {
142
+ true: style.moreSurface
143
+ },
144
+ size: {
145
+ [SIZE.SMALL]: style.moreSmall,
146
+ [SIZE.MEDIUM]: style.moreMedium,
147
+ [SIZE.LARGE]: style.moreLarge
148
+ },
149
+ variant: {
150
+ [VARIANT.ELEVATED]: style.moreElevated,
151
+ [VARIANT.SPACED]: style.moreSpaced,
152
+ [VARIANT.DOTTED]: style.moreDotted
110
153
  }
111
154
  }
112
155
  }
@@ -121,7 +164,7 @@ const tabSlots = csv({
121
164
  base: [style.moreMenuHeight, 'd-overflow-y-auto']
122
165
  },
123
166
  moreItem: {
124
- base: style.moreItem
167
+ base: 'd-w-full'
125
168
  },
126
169
  moreItemIcon: {
127
170
  base: [style.moreItemIcon, 'd-inline-flex', 'd-justify-center']
@@ -133,7 +176,7 @@ const tabSlots = csv({
133
176
  base: style.emptyStateContainer
134
177
  },
135
178
  emptyStateTitle: {
136
- base: [style.emptyStateTitle, 'd-font-semibold', 'd-text-center']
179
+ base: [style.emptyStateTitle, 'd-font-semibold', 'd-text-center', 'd-wrap-break-word']
137
180
  },
138
181
  panel: {
139
182
  base: [style.panel, 'd-relative', 'd-min-w-0'],
@@ -144,6 +187,14 @@ const tabSlots = csv({
144
187
  },
145
188
  isFullWidth: {
146
189
  true: 'd-w-full'
190
+ },
191
+ hasSurface: {
192
+ true: style.panelSurface
193
+ },
194
+ variant: {
195
+ [VARIANT.ELEVATED]: style.panelElevated,
196
+ [VARIANT.SPACED]: style.panelSpaced,
197
+ [VARIANT.DOTTED]: style.panelDotted
147
198
  }
148
199
  }
149
200
  }
@@ -5,4 +5,4 @@ export { default as Tab } from "./Tab";
5
5
  export { default as TabPanel } from "./TabPanel";
6
6
  export { default as TabsStyleContext, useTabsStyle } from "./context";
7
7
  export { SIZE, VARIANT, POSITION, LABEL_STYLE, ACTIVATION, ICON_PLACEMENT, ICON_SPACING, TEXT_TRANSFORM, TEXT_TRUNCATE, PANEL_SCROLL } from "./constants";
8
- export { INFO_BAR_RAIL, SUBTAB_STRIP } from "./constants/presets";
8
+ export { INFO_BAR_RAIL, INFO_BAR_RAIL_TEXT, INFO_BAR_RAIL_ICON_LEFT, INFO_BAR_RAIL_ICON_TOP, SUBTAB_STRIP } from "./constants/presets";
@@ -5,6 +5,8 @@ const renderableType = PropTypes.oneOfType([PropTypes.node, PropTypes.func]);
5
5
  const classType = PropTypes.string;
6
6
  const tabSlotClasses = {
7
7
  tab: classType,
8
+ tabTrigger: classType,
9
+ tabAction: classType,
8
10
  content: classType,
9
11
  iconBox: classType,
10
12
  tabText: classType
@@ -102,6 +104,10 @@ const tabItemShape = PropTypes.shape({
102
104
  renderIcon: renderableType,
103
105
  renderBefore: renderableType,
104
106
  renderAfter: renderableType,
107
+
108
+ /* Rendered beside the tab button, outside it; not shown in the more menu. */
109
+ renderAction: renderableType,
110
+ customClass: PropTypes.shape(tabSlotClasses),
105
111
  customId: PropTypes.string,
106
112
  testId: PropTypes.string,
107
113
  dataSelectorId: PropTypes.string
@@ -148,6 +154,11 @@ export const Tab_propTypes = {
148
154
  renderIcon: renderableType,
149
155
  renderBefore: renderableType,
150
156
  renderAfter: renderableType,
157
+
158
+ /* Interactive node rendered beside the role="tab" button, outside it. The
159
+ * `tab` slot then styles a wrapper that also carries customId, testId,
160
+ * dataSelectorId and tourId. */
161
+ renderAction: renderableType,
151
162
  onClick: PropTypes.func,
152
163
  getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
153
164
  customClass: PropTypes.shape(tabSlotClasses),
package/lib/v1/Tab/Tab.js CHANGED
@@ -55,6 +55,7 @@ var Tab = function Tab(props) {
55
55
  renderIcon = props.renderIcon,
56
56
  renderBefore = props.renderBefore,
57
57
  renderAfter = props.renderAfter,
58
+ renderAction = props.renderAction,
58
59
  onClick = props.onClick,
59
60
  getRef = props.getRef,
60
61
  customClass = props.customClass,
@@ -75,23 +76,31 @@ var Tab = function Tab(props) {
75
76
  getClasses = _useTabsStyle.getClasses,
76
77
  iconPlacement = _useTabsStyle.iconPlacement,
77
78
  labelStyle = _useTabsStyle.labelStyle,
79
+ orientation = _useTabsStyle.orientation,
78
80
  size = _useTabsStyle.size,
79
81
  hasScroll = _useTabsStyle.hasScroll,
80
82
  hasOverflow = _useTabsStyle.hasOverflow,
81
83
  textTransformFromGroup = _useTabsStyle.textTransform,
82
84
  textTruncateFromGroup = _useTabsStyle.textTruncate;
83
85
 
86
+ var _useTabsData = (0, _core.useTabsData)('Tab'),
87
+ selectedValue = _useTabsData.selectedValue;
88
+
84
89
  var textTransform = textTransformFromGroup || _constants.TEXT_TRANSFORM.CAPITAL;
85
90
  var textTruncate = textTruncateFromGroup || _constants.TEXT_TRUNCATE.CLAMP;
86
91
  var isTextOnly = labelStyle === _constants.LABEL_STYLE.TEXT;
87
92
  var isIconMode = labelStyle === _constants.LABEL_STYLE.ICON;
88
93
  var hasText = !isIconMode && !!text;
89
94
  var showIcon = !isTextOnly;
95
+ var textAlign = isTextOnly ? _constants.TEXT_ONLY_TEXT_ALIGN : _constants.ICON_PLACEMENT_TEXT_ALIGN[iconPlacement];
96
+ var hasIconAndText = !isTextOnly && !isIconMode;
97
+ var justifyContent = orientation === _constants.ORIENTATION.VERTICAL && hasIconAndText ? _constants.ICON_PLACEMENT_JUSTIFY[iconPlacement] : 'center';
90
98
  var resolvedTextSize = _constants.SIZE_TEXT_SIZE[size] || _constants.SIZE_TEXT_SIZE[_constants.SIZE.MEDIUM];
91
99
  var canShrink = !hasOverflow && !hasScroll;
92
100
  var styleOverrides = {
93
101
  labelStyle: labelStyle,
94
102
  canShrink: canShrink,
103
+ isDisabled: isDisabled,
95
104
  customClass: customClass
96
105
  };
97
106
  var accessibleName = ariaLabel || (isIconMode ? text : undefined);
@@ -101,30 +110,34 @@ var Tab = function Tab(props) {
101
110
  }
102
111
 
103
112
  var classes = getClasses(styleOverrides);
104
- var isAnchor = !!href;
113
+ var isAnchor = !!href; // With an action the visual tab becomes a wrapper around the role="tab"
114
+ // trigger, so an interactive action never nests inside the <button>.
115
+
116
+ var hasAction = (0, _renderNode.isRenderable)(renderAction);
105
117
  var elementProps = (0, _mergeProps["default"])({
106
- className: classes.tab,
118
+ className: hasAction ? classes.tabTrigger : classes.tab,
107
119
  href: isAnchor && !isDisabled ? href : undefined,
108
120
  target: isAnchor ? target : undefined,
109
121
  rel: isAnchor ? rel : undefined,
110
- 'data-tour': tourId,
122
+ 'data-tour': hasAction ? undefined : tourId,
111
123
  'aria-label': accessibleName,
112
124
  'data-title': title
113
125
  }, {
114
126
  onClick: onClick
115
127
  }, tabAttributes, a11yAttributes);
116
- return /*#__PURE__*/_react["default"].createElement(_core.Tab, _extends({
128
+
129
+ var trigger = /*#__PURE__*/_react["default"].createElement(_core.Tab, _extends({
117
130
  value: value,
118
131
  isDisabled: isDisabled,
119
132
  isAnchor: isAnchor,
120
133
  getRef: getRef,
121
134
  displayMode: "inlineFlex",
122
135
  alignItems: "center",
123
- justifyContent: "center"
136
+ justifyContent: justifyContent
124
137
  }, elementProps, {
125
- customId: customId,
126
- testId: testId,
127
- "data-selector-id": dataSelectorId
138
+ customId: hasAction ? undefined : customId,
139
+ testId: hasAction ? undefined : testId,
140
+ "data-selector-id": hasAction ? undefined : dataSelectorId
128
141
  }), function (_ref) {
129
142
  var isSelected = _ref.isSelected;
130
143
  var slot = {
@@ -141,7 +154,7 @@ var Tab = function Tab(props) {
141
154
  display: "flex",
142
155
  direction: _constants.ICON_PLACEMENT_DIRECTION[iconPlacement],
143
156
  alignItems: "center",
144
- justifyContent: "center",
157
+ justifyContent: justifyContent,
145
158
  customClass: classes.content,
146
159
  customAttributes: contentAttributes
147
160
  }, icon ? /*#__PURE__*/_react["default"].createElement(_FlexItem["default"], {
@@ -156,12 +169,43 @@ var Tab = function Tab(props) {
156
169
  $flag_dotted: textTruncate === _constants.TEXT_TRUNCATE.ELLIPSIS,
157
170
  $ui_wordBreak: textTruncate === _constants.TEXT_TRUNCATE.CLAMP ? 'breakWord' : undefined,
158
171
  $ui_transform: textTransform,
159
- $ui_textAlign: _constants.ICON_PLACEMENT_TEXT_ALIGN[iconPlacement],
172
+ $ui_textAlign: textAlign,
160
173
  $ui_className: classes.tabText,
161
174
  $i18n_dataTitle: title || text,
162
175
  $tagAttributes_container: tabTextAttributes
163
176
  }), text) : null, children, (0, _renderNode.isRenderable)(renderAfter) ? (0, _renderNode["default"])(renderAfter, slot) : null);
164
177
  });
178
+
179
+ if (!hasAction) {
180
+ return trigger;
181
+ }
182
+
183
+ var isSelected = value === selectedValue;
184
+ var actionSlot = {
185
+ value: value,
186
+ isSelected: isSelected,
187
+ isDisabled: isDisabled
188
+ };
189
+ return /*#__PURE__*/_react["default"].createElement(_FlexContainer["default"], {
190
+ as: "span",
191
+ display: "inlineFlex",
192
+ alignItems: "center",
193
+ justifyContent: justifyContent,
194
+ customClass: classes.tab,
195
+ customId: customId,
196
+ testId: testId,
197
+ customAttributes: {
198
+ role: 'presentation',
199
+ 'data-selected': String(isSelected),
200
+ 'data-disabled': String(!!isDisabled),
201
+ 'data-tour': tourId,
202
+ 'data-selector-id': dataSelectorId
203
+ }
204
+ }, trigger, /*#__PURE__*/_react["default"].createElement(_FlexItem["default"], {
205
+ as: "span",
206
+ shrink: "0",
207
+ customClass: classes.tabAction
208
+ }, (0, _renderNode["default"])(renderAction, actionSlot)));
165
209
  };
166
210
 
167
211
  var _default = Tab;
@@ -89,11 +89,20 @@ var TabList = function TabList(props) {
89
89
  return _objectSpread(_objectSpread({}, styleContext), {}, {
90
90
  hasOverflow: isDataDriven
91
91
  });
92
- }, [styleContext, isDataDriven]);
93
- var scroll = hasScroll ? orientation === _constants2.ORIENTATION.VERTICAL ? 'vertical' : 'horizontal' : isDataDriven ? 'hidden' : undefined;
92
+ }, [styleContext, isDataDriven]); // An inline (absolutely positioned) more menu renders inside the list, so
93
+ // clipping the list would hide it; a portalled menu escapes the clip.
94
+
95
+ var isMoreMenuInline = !!popupOptions.isAbsolutePositioningNeeded;
96
+ var scroll = hasScroll ? orientation === _constants2.ORIENTATION.VERTICAL ? 'vertical' : 'horizontal' : isDataDriven && !isMoreMenuInline ? 'hidden' : undefined;
97
+
98
+ var getClassSignature = function getClassSignature(itemClass) {
99
+ return itemClass ? Object.keys(itemClass).map(function (slot) {
100
+ return "".concat(slot, ":").concat(itemClass[slot] || '');
101
+ }).join(',') : '';
102
+ };
94
103
 
95
104
  var itemsSignature = "".concat(labelStyle || '', "\x01").concat(position || '', "\x01") + (items || _constants.DUMMY_ARRAY).map(function (item) {
96
- return "".concat(item.value, "|").concat(item.text || '', "|").concat(item.iconName || '', "|").concat(item.isDisabled ? 1 : 0, "|").concat(item.renderBefore ? 1 : 0, "|").concat(item.renderAfter ? 1 : 0);
105
+ return "".concat(item.value, "|").concat(item.text || '', "|").concat(item.iconName || '', "|").concat(item.isDisabled ? 1 : 0, "|").concat(item.renderBefore ? 1 : 0, "|").concat(item.renderAfter ? 1 : 0, "|").concat(item.renderAction ? 1 : 0, "|").concat(getClassSignature(item.customClass));
97
106
  }).join("\0");
98
107
 
99
108
  var dataList = (0, _react.useMemo)(function () {
@@ -154,6 +163,8 @@ var TabList = function TabList(props) {
154
163
  renderIcon: item.renderIcon,
155
164
  renderBefore: item.renderBefore,
156
165
  renderAfter: item.renderAfter,
166
+ renderAction: item.renderAction,
167
+ customClass: item.customClass,
157
168
  customId: item.customId,
158
169
  testId: item.testId,
159
170
  dataSelectorId: item.dataSelectorId