@zat-design/sisyphus-react 3.13.1 → 3.13.2-beta.1

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 (39) hide show
  1. package/dist/index.esm.css +3 -0
  2. package/dist/less.esm.css +3 -0
  3. package/es/ProForm/components/render/RenderFields.js +5 -1
  4. package/es/ProForm/components/render/propsType.d.ts +6 -1
  5. package/es/ProForm/propsType.d.ts +4 -0
  6. package/es/ProForm/utils/processDependencies.d.ts +29 -0
  7. package/es/ProForm/utils/processDependencies.js +55 -0
  8. package/es/ProIcon/index.js +7 -4
  9. package/es/ProLayout/components/ProCollapse/index.js +2 -0
  10. package/es/ProStepTab/index.js +14 -10
  11. package/es/ProTable/components/RenderColumn/index.js +28 -25
  12. package/es/ProTable/hooks/useAntdTable.js +3 -9
  13. package/es/ProTable/style/index.less +3 -0
  14. package/es/ProTable/utils/index.d.ts +2 -6
  15. package/es/ProTable/utils/index.js +20 -14
  16. package/es/ProTooltip/index.d.ts +0 -1
  17. package/es/ProTooltip/index.js +48 -59
  18. package/es/ProTooltip/propsType.d.ts +4 -4
  19. package/es/utils/index.d.ts +8 -0
  20. package/es/utils/index.js +17 -0
  21. package/lib/ProForm/components/render/RenderFields.js +5 -1
  22. package/lib/ProForm/components/render/propsType.d.ts +6 -1
  23. package/lib/ProForm/propsType.d.ts +4 -0
  24. package/lib/ProForm/utils/processDependencies.d.ts +29 -0
  25. package/lib/ProForm/utils/processDependencies.js +63 -0
  26. package/lib/ProIcon/index.js +7 -4
  27. package/lib/ProLayout/components/ProCollapse/index.js +2 -0
  28. package/lib/ProStepTab/index.js +14 -10
  29. package/lib/ProTable/components/RenderColumn/index.js +26 -23
  30. package/lib/ProTable/hooks/useAntdTable.js +3 -9
  31. package/lib/ProTable/style/index.less +3 -0
  32. package/lib/ProTable/utils/index.d.ts +2 -6
  33. package/lib/ProTable/utils/index.js +21 -15
  34. package/lib/ProTooltip/index.d.ts +0 -1
  35. package/lib/ProTooltip/index.js +47 -58
  36. package/lib/ProTooltip/propsType.d.ts +4 -4
  37. package/lib/utils/index.d.ts +8 -0
  38. package/lib/utils/index.js +18 -1
  39. package/package.json +1 -1
@@ -14,28 +14,27 @@ var _ahooks = require("ahooks");
14
14
  var _antd = require("antd");
15
15
  var _react = require("react");
16
16
  var _classnames2 = _interopRequireDefault(require("classnames"));
17
- require("./style/index.less");
18
- var _excluded = ["text", "mode", "width", "line", "isResponsiveWidth", "className", "style", "lineHeight"];
17
+ var _utils = require("../utils");
18
+ var _excluded = ["text", "mode", "width", "line", "className", "style", "lineHeight", "scrollFollowParent"];
19
19
  var ProTooltip = function ProTooltip(props) {
20
- var _useSize;
20
+ var _useSize, _parentElement$tagNam;
21
21
  var ref = (0, _react.useRef)();
22
22
  var childRef = (0, _react.useRef)();
23
23
  var contentWrapRef = (0, _react.useRef)();
24
24
  var text = props.text,
25
25
  _props$mode = props.mode,
26
26
  mode = _props$mode === void 0 ? 'default' : _props$mode,
27
- _props$width = props.width,
28
- width = _props$width === void 0 ? '120px' : _props$width,
27
+ width = props.width,
29
28
  _props$line = props.line,
30
29
  line = _props$line === void 0 ? 1 : _props$line,
31
- _props$isResponsiveWi = props.isResponsiveWidth,
32
- isResponsiveWidth = _props$isResponsiveWi === void 0 ? false : _props$isResponsiveWi,
33
30
  _props$className = props.className,
34
31
  className = _props$className === void 0 ? '' : _props$className,
35
32
  _props$style = props.style,
36
33
  style = _props$style === void 0 ? {} : _props$style,
37
34
  _props$lineHeight = props.lineHeight,
38
35
  lineHeight = _props$lineHeight === void 0 ? 22 : _props$lineHeight,
36
+ _props$scrollFollowPa = props.scrollFollowParent,
37
+ scrollFollowParent = _props$scrollFollowPa === void 0 ? true : _props$scrollFollowPa,
39
38
  restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
40
39
  var _width = mode === 'auto' ? 'auto' : width;
41
40
  var content = text !== null && text !== void 0 ? text : '-';
@@ -65,6 +64,7 @@ var ProTooltip = function ProTooltip(props) {
65
64
  });
66
65
  var _ref = (_useSize = (0, _ahooks.useSize)(localElement)) !== null && _useSize !== void 0 ? _useSize : {},
67
66
  _localSizeWidth = _ref.width;
67
+ var isTable = (parentElement === null || parentElement === void 0 ? void 0 : (_parentElement$tagNam = parentElement.tagName) === null || _parentElement$tagNam === void 0 ? void 0 : _parentElement$tagNam.toLowerCase()) === 'td';
68
68
  var overlayStyle = mode === 'auto' ? {
69
69
  maxWidth: _localSizeWidth
70
70
  } : {};
@@ -147,23 +147,6 @@ var ProTooltip = function ProTooltip(props) {
147
147
  }
148
148
  return line > 1 ? (0, _jsxRuntime.jsx)(AutoMixinMulti, {}) : (0, _jsxRuntime.jsx)(AutoMixinSingle, {});
149
149
  };
150
- (0, _ahooks.useDebounceEffect)(function () {
151
- if (isResponsiveWidth && parentElement) {
152
- var cWidth = parentElement.clientWidth - 32;
153
- var contentDom = childRef.current;
154
- setState({
155
- isShowToolTip: contentDom.scrollWidth > contentDom.offsetWidth,
156
- localWidth: cWidth
157
- });
158
- }
159
- if (!isResponsiveWidth) {
160
- setState({
161
- localWidth: _width
162
- });
163
- }
164
- }, [isResponsiveWidth, size], {
165
- wait: 300
166
- });
167
150
  (0, _react.useEffect)(function () {
168
151
  if (mode === 'auto' && line === 1) {
169
152
  var localDom = ref.current;
@@ -243,57 +226,63 @@ var ProTooltip = function ProTooltip(props) {
243
226
  }, [debouncedValue]);
244
227
  (0, _react.useEffect)(function () {
245
228
  var localDom = ref.current;
246
- var contentDom = childRef.current;
229
+ var isEllipsis = (0, _utils.isEllipsisActive)(childRef === null || childRef === void 0 ? void 0 : childRef.current);
247
230
  setState({
248
231
  parentElement: localDom.parentElement,
249
- isShowToolTip: contentDom.scrollWidth > contentDom.offsetWidth
232
+ isShowToolTip: isEllipsis
250
233
  });
251
234
  }, []);
252
235
  var cls = (0, _classnames2.default)((0, _defineProperty2.default)({
253
236
  'pro-tooltip': true
254
237
  }, "".concat(className), className));
255
- return (0, _jsxRuntime.jsx)("div", {
256
- className: cls,
257
- ref: ref,
258
- style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, style), multiStyle), {}, {
259
- width: localWidth
260
- }),
261
- children: isResponsiveWidth && isShowToolTip ? (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
262
- title: text,
263
- getPopupContainer: function getPopupContainer(triggerNode) {
264
- return triggerNode.parentNode;
265
- }
266
- }, restProps), {}, {
267
- children: (0, _jsxRuntime.jsx)("div", {
268
- className: isMultiLine ? 'multiLine' : 'singleLine',
269
- style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, multiStyle), {}, {
270
- width: localWidth
271
- }),
272
- ref: childRef,
273
- children: content
274
- })
275
- })) : isResponsiveWidth ? (0, _jsxRuntime.jsx)("div", {
238
+ var renderContentBox = function renderContentBox() {
239
+ return (0, _jsxRuntime.jsx)("div", {
276
240
  className: isMultiLine ? 'multiLine' : 'singleLine',
277
241
  style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, multiStyle), {}, {
278
242
  width: localWidth
279
243
  }),
280
244
  ref: childRef,
281
245
  children: content
282
- }) : mode === 'default' ? (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
246
+ });
247
+ };
248
+ var renderTooltipContent = function renderTooltipContent() {
249
+ return (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
283
250
  title: text,
284
251
  getPopupContainer: function getPopupContainer(triggerNode) {
285
- return triggerNode.parentNode;
252
+ // 修复scrollFollowParent为false时tooltip不显示的问题
253
+ // 当scrollFollowParent为false时,应该返回document.body而不是triggerNode本身
254
+ return scrollFollowParent ? triggerNode.parentNode : document.body;
286
255
  }
287
256
  }, restProps), {}, {
288
- children: (0, _jsxRuntime.jsx)("div", {
289
- className: isMultiLine ? 'multiLine' : 'singleLine',
290
- style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, multiStyle), {}, {
291
- width: localWidth
292
- }),
293
- ref: childRef,
294
- children: content
295
- })
296
- })) : (0, _jsxRuntime.jsx)(AutoMixin, {})
257
+ overlayStyle: mode === 'auto' ? overlayStyle : {},
258
+ children: renderContentBox()
259
+ }));
260
+ };
261
+ var renderContent = function renderContent() {
262
+ // 自动模式使用专门的渲染逻辑
263
+ if (mode === 'auto') {
264
+ return (0, _jsxRuntime.jsx)(AutoMixin, {});
265
+ }
266
+ // 响应式宽度模式,根据是否需要显示tooltip决定渲染内容 且 父元素为table
267
+ if (isTable) {
268
+ if (isShowToolTip) {
269
+ return renderTooltipContent();
270
+ }
271
+ return renderContentBox();
272
+ }
273
+ // 默认模式始终显示tooltip
274
+ if (mode === 'default') {
275
+ return renderTooltipContent();
276
+ }
277
+ return renderContentBox();
278
+ };
279
+ return (0, _jsxRuntime.jsx)("div", {
280
+ className: cls,
281
+ ref: ref,
282
+ style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, style), multiStyle), {}, {
283
+ width: localWidth
284
+ }),
285
+ children: renderContent()
297
286
  });
298
287
  };
299
288
  var _default = exports.default = ProTooltip;
@@ -19,11 +19,11 @@ export interface ProTooltipType {
19
19
  */
20
20
  line?: number;
21
21
  /**
22
- * 是否响应式宽度
23
- * @description 启用后提示框宽度将根据内容自适应
24
- * @default false
22
+ * 是否跟随父元素滚动
23
+ * @description 启用后,提示框将跟随父元素滚动
24
+ * @default true
25
25
  */
26
- isResponsiveWidth?: Boolean;
26
+ scrollFollowParent?: boolean;
27
27
  /**
28
28
  * 自定义类名
29
29
  * @description 额外的CSS类名
@@ -3,4 +3,12 @@
3
3
  * 空值 或者 仅包含空值的数组视为空
4
4
  */
5
5
  export declare const isEmpty: (value: any, emptyValue?: string) => boolean;
6
+ /**
7
+ * 判断一个元素是否触发了省略号(文本溢出)
8
+ * 如果元素设置为单行(white-space: nowrap)则比较 scrollWidth 与 clientWidth,
9
+ * 如果是多行文本(例如使用 -webkit-line-clamp 实现多行截断)则比较 scrollHeight 与 clientHeight。
10
+ * @param {HTMLElement} element 要检测的元素
11
+ * @returns {boolean} 如果内容溢出返回 true,否则返回 false
12
+ */
13
+ export declare const isEllipsisActive: (element: Element) => boolean;
6
14
  export declare const useFocus: (element: Element) => boolean;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.useFocus = exports.isEmpty = void 0;
7
+ exports.useFocus = exports.isEmpty = exports.isEllipsisActive = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
10
  var EMPTY_VALUE = [undefined, null, ''];
@@ -26,6 +26,23 @@ var isEmpty = exports.isEmpty = function isEmpty(value, emptyValue) {
26
26
  }
27
27
  return false;
28
28
  };
29
+ /**
30
+ * 判断一个元素是否触发了省略号(文本溢出)
31
+ * 如果元素设置为单行(white-space: nowrap)则比较 scrollWidth 与 clientWidth,
32
+ * 如果是多行文本(例如使用 -webkit-line-clamp 实现多行截断)则比较 scrollHeight 与 clientHeight。
33
+ * @param {HTMLElement} element 要检测的元素
34
+ * @returns {boolean} 如果内容溢出返回 true,否则返回 false
35
+ */
36
+ var isEllipsisActive = exports.isEllipsisActive = function isEllipsisActive(element) {
37
+ if (!element) return false;
38
+ var computedStyle = window.getComputedStyle(element);
39
+ // 如果使用单行显示(nowrap),则判断宽度是否足够
40
+ if (computedStyle.whiteSpace === 'nowrap') {
41
+ return element.scrollWidth > element.clientWidth;
42
+ }
43
+ // 多行情况下,判断高度是否足够
44
+ return element.scrollHeight > element.clientHeight;
45
+ };
29
46
  var useFocus = exports.useFocus = function useFocus(element) {
30
47
  var _useState = (0, _react.useState)(false),
31
48
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.13.1",
3
+ "version": "3.13.2-beta.1",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",