@zat-design/sisyphus-react 3.13.1-beta.3 → 3.13.1-beta.5
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/es/ProForm/propsType.d.ts +4 -0
- package/es/ProTable/components/RenderColumn/index.js +26 -3
- package/es/ProTable/utils/index.d.ts +2 -0
- package/es/ProTable/utils/index.js +20 -0
- package/es/ProTooltip/index.d.ts +0 -1
- package/es/ProTooltip/index.js +48 -59
- package/es/ProTooltip/propsType.d.ts +4 -4
- package/es/utils/index.d.ts +8 -0
- package/es/utils/index.js +17 -0
- package/lib/ProForm/propsType.d.ts +4 -0
- package/lib/ProTable/components/RenderColumn/index.js +25 -2
- package/lib/ProTable/utils/index.d.ts +2 -0
- package/lib/ProTable/utils/index.js +21 -1
- package/lib/ProTooltip/index.d.ts +0 -1
- package/lib/ProTooltip/index.js +47 -58
- package/lib/ProTooltip/propsType.d.ts +4 -4
- package/lib/utils/index.d.ts +8 -0
- package/lib/utils/index.js +18 -1
- package/package.json +1 -1
@@ -65,6 +65,10 @@ export interface ProFormType<Values = any> extends FormProps<Values> {
|
|
65
65
|
/** 全局控制优先 */
|
66
66
|
globalControl?: boolean;
|
67
67
|
mode?: ModeEnum;
|
68
|
+
/**
|
69
|
+
* 如果有formKey,则会在全局中查找或创建表单实例
|
70
|
+
* 可以不需要手动传入form实例 且formKey的优先级高于form
|
71
|
+
*/
|
68
72
|
formKey?: string;
|
69
73
|
/** 是否查看 */
|
70
74
|
isView?: boolean;
|
@@ -7,12 +7,13 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
7
7
|
import "antd/es/typography/style";
|
8
8
|
import _Typography from "antd/es/typography";
|
9
9
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
10
|
+
import { useRef } from 'react';
|
10
11
|
import { useSetState } from 'ahooks';
|
11
12
|
import { isBoolean } from 'lodash';
|
12
13
|
import classNames from 'classnames';
|
13
14
|
import { CheckOutlined } from '@ant-design/icons';
|
14
15
|
import { ReactSVG } from 'react-svg';
|
15
|
-
import { getPadding } from '../../utils';
|
16
|
+
import { getPadding, parseWidth } from '../../utils';
|
16
17
|
import { isEmpty } from '../../../utils';
|
17
18
|
import copySvg from '../../../assets/copy.svg';
|
18
19
|
var Paragraph = _Typography.Paragraph,
|
@@ -32,12 +33,26 @@ var RenderColumn = function RenderColumn(props) {
|
|
32
33
|
minWidth = props.minWidth,
|
33
34
|
isInNewRowFlag = props.isInNewRowFlag,
|
34
35
|
scroll = props.scroll;
|
36
|
+
var textRef = useRef(null);
|
35
37
|
var _useSetState = useSetState({
|
36
38
|
tooltip: false
|
37
39
|
}),
|
38
40
|
_useSetState2 = _slicedToArray(_useSetState, 2),
|
39
41
|
tooltip = _useSetState2[0].tooltip,
|
40
42
|
setState = _useSetState2[1];
|
43
|
+
// 计算并更新宽度
|
44
|
+
var updateCalculatedWidth = function updateCalculatedWidth(element) {
|
45
|
+
if (!element) return null;
|
46
|
+
if (!textRef.current) return;
|
47
|
+
// 使用closest方法查找最近的tr
|
48
|
+
var tr = element.closest('tr');
|
49
|
+
if (!tr) return;
|
50
|
+
// 获取tr的宽度
|
51
|
+
var trWidth = tr.getBoundingClientRect().width;
|
52
|
+
// 计算实际宽度
|
53
|
+
var newWidth = parseWidth(width, trWidth);
|
54
|
+
return newWidth;
|
55
|
+
};
|
41
56
|
var cellDiffCls = classNames({
|
42
57
|
'varied-cell': props === null || props === void 0 ? void 0 : props.isChanged,
|
43
58
|
'add-cell': props === null || props === void 0 ? void 0 : props.isAddCell
|
@@ -96,6 +111,9 @@ var RenderColumn = function RenderColumn(props) {
|
|
96
111
|
if (ellipsis) {
|
97
112
|
return _jsx(_Tooltip, _objectSpread(_objectSpread({
|
98
113
|
title: currentValue,
|
114
|
+
getTooltipContainer: function getTooltipContainer() {
|
115
|
+
return document.body;
|
116
|
+
},
|
99
117
|
onOpenChange: function onOpenChange(open) {
|
100
118
|
setState({
|
101
119
|
tooltip: false
|
@@ -198,9 +216,13 @@ var RenderColumn = function RenderColumn(props) {
|
|
198
216
|
children: "-"
|
199
217
|
});
|
200
218
|
}
|
219
|
+
var calculatedWidth = updateCalculatedWidth(textRef.current);
|
201
220
|
return _jsx(_Tooltip, _objectSpread(_objectSpread({
|
202
221
|
title: value,
|
203
|
-
|
222
|
+
getTooltipContainer: function getTooltipContainer() {
|
223
|
+
return document.body;
|
224
|
+
},
|
225
|
+
onOpenChange: function onOpenChange() {
|
204
226
|
setState({
|
205
227
|
tooltip: false
|
206
228
|
});
|
@@ -208,8 +230,9 @@ var RenderColumn = function RenderColumn(props) {
|
|
208
230
|
open: tooltip
|
209
231
|
}, tooltipProps), {}, {
|
210
232
|
children: _jsx(Text, {
|
233
|
+
ref: textRef,
|
211
234
|
style: {
|
212
|
-
width:
|
235
|
+
width: calculatedWidth,
|
213
236
|
minWidth: minWidth
|
214
237
|
},
|
215
238
|
ellipsis: true,
|
@@ -41,3 +41,5 @@ export declare const getPadding: (el: HTMLElement) => {
|
|
41
41
|
};
|
42
42
|
/** 判断是有值的对象 */
|
43
43
|
export declare const isNonEmptyObject: (obj: any) => obj is Record<string, any>;
|
44
|
+
/** 解析宽度值 */
|
45
|
+
export declare const parseWidth: (widthValue: number | string | undefined, trWidth: number) => number;
|
@@ -105,4 +105,24 @@ export var getPadding = function getPadding(el) {
|
|
105
105
|
/** 判断是有值的对象 */
|
106
106
|
export var isNonEmptyObject = function isNonEmptyObject(obj) {
|
107
107
|
return obj !== null && _typeof(obj) === 'object' && !Array.isArray(obj) && Object.keys(obj).length > 0;
|
108
|
+
};
|
109
|
+
/** 解析宽度值 */
|
110
|
+
export var parseWidth = function parseWidth(widthValue, trWidth) {
|
111
|
+
// 如果是数字,直接返回
|
112
|
+
if (typeof widthValue === 'number') return widthValue;
|
113
|
+
// 如果是字符串,检查是否是百分比
|
114
|
+
if (typeof widthValue === 'string') {
|
115
|
+
if (widthValue.endsWith('%')) {
|
116
|
+
// 计算百分比
|
117
|
+
var percentage = parseFloat(widthValue) / 100;
|
118
|
+
return Math.max(trWidth * percentage, 0);
|
119
|
+
}
|
120
|
+
// 尝试解析为数字(处理如'300px'这样的情况)
|
121
|
+
var numericValue = parseFloat(widthValue);
|
122
|
+
if (!Number.isNaN(numericValue)) {
|
123
|
+
return numericValue;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
// 所有其他情况,返回默认值
|
127
|
+
return null;
|
108
128
|
};
|
package/es/ProTooltip/index.d.ts
CHANGED
package/es/ProTooltip/index.js
CHANGED
@@ -4,32 +4,31 @@ import "antd/es/tooltip/style";
|
|
4
4
|
import _Tooltip from "antd/es/tooltip";
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
7
|
-
var _excluded = ["text", "mode", "width", "line", "
|
7
|
+
var _excluded = ["text", "mode", "width", "line", "className", "style", "lineHeight", "scrollFollowParent"];
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
9
|
-
import { useSize, useSetState, useDebounce
|
9
|
+
import { useSize, useSetState, useDebounce } from 'ahooks';
|
10
10
|
import { useEffect, useRef } from 'react';
|
11
11
|
import classnames from 'classnames';
|
12
|
-
import '
|
12
|
+
import { isEllipsisActive } from '../utils';
|
13
13
|
var ProTooltip = function ProTooltip(props) {
|
14
|
-
var _useSize;
|
14
|
+
var _useSize, _parentElement$tagNam;
|
15
15
|
var ref = useRef();
|
16
16
|
var childRef = useRef();
|
17
17
|
var contentWrapRef = useRef();
|
18
18
|
var text = props.text,
|
19
19
|
_props$mode = props.mode,
|
20
20
|
mode = _props$mode === void 0 ? 'default' : _props$mode,
|
21
|
-
|
22
|
-
width = _props$width === void 0 ? '120px' : _props$width,
|
21
|
+
width = props.width,
|
23
22
|
_props$line = props.line,
|
24
23
|
line = _props$line === void 0 ? 1 : _props$line,
|
25
|
-
_props$isResponsiveWi = props.isResponsiveWidth,
|
26
|
-
isResponsiveWidth = _props$isResponsiveWi === void 0 ? false : _props$isResponsiveWi,
|
27
24
|
_props$className = props.className,
|
28
25
|
className = _props$className === void 0 ? '' : _props$className,
|
29
26
|
_props$style = props.style,
|
30
27
|
style = _props$style === void 0 ? {} : _props$style,
|
31
28
|
_props$lineHeight = props.lineHeight,
|
32
29
|
lineHeight = _props$lineHeight === void 0 ? 22 : _props$lineHeight,
|
30
|
+
_props$scrollFollowPa = props.scrollFollowParent,
|
31
|
+
scrollFollowParent = _props$scrollFollowPa === void 0 ? true : _props$scrollFollowPa,
|
33
32
|
restProps = _objectWithoutProperties(props, _excluded);
|
34
33
|
var _width = mode === 'auto' ? 'auto' : width;
|
35
34
|
var content = text !== null && text !== void 0 ? text : '-';
|
@@ -59,6 +58,7 @@ var ProTooltip = function ProTooltip(props) {
|
|
59
58
|
});
|
60
59
|
var _ref = (_useSize = useSize(localElement)) !== null && _useSize !== void 0 ? _useSize : {},
|
61
60
|
_localSizeWidth = _ref.width;
|
61
|
+
var isTable = (parentElement === null || parentElement === void 0 ? void 0 : (_parentElement$tagNam = parentElement.tagName) === null || _parentElement$tagNam === void 0 ? void 0 : _parentElement$tagNam.toLowerCase()) === 'td';
|
62
62
|
var overlayStyle = mode === 'auto' ? {
|
63
63
|
maxWidth: _localSizeWidth
|
64
64
|
} : {};
|
@@ -141,23 +141,6 @@ var ProTooltip = function ProTooltip(props) {
|
|
141
141
|
}
|
142
142
|
return line > 1 ? _jsx(AutoMixinMulti, {}) : _jsx(AutoMixinSingle, {});
|
143
143
|
};
|
144
|
-
useDebounceEffect(function () {
|
145
|
-
if (isResponsiveWidth && parentElement) {
|
146
|
-
var cWidth = parentElement.clientWidth - 32;
|
147
|
-
var contentDom = childRef.current;
|
148
|
-
setState({
|
149
|
-
isShowToolTip: contentDom.scrollWidth > contentDom.offsetWidth,
|
150
|
-
localWidth: cWidth
|
151
|
-
});
|
152
|
-
}
|
153
|
-
if (!isResponsiveWidth) {
|
154
|
-
setState({
|
155
|
-
localWidth: _width
|
156
|
-
});
|
157
|
-
}
|
158
|
-
}, [isResponsiveWidth, size], {
|
159
|
-
wait: 300
|
160
|
-
});
|
161
144
|
useEffect(function () {
|
162
145
|
if (mode === 'auto' && line === 1) {
|
163
146
|
var localDom = ref.current;
|
@@ -237,57 +220,63 @@ var ProTooltip = function ProTooltip(props) {
|
|
237
220
|
}, [debouncedValue]);
|
238
221
|
useEffect(function () {
|
239
222
|
var localDom = ref.current;
|
240
|
-
var
|
223
|
+
var isEllipsis = isEllipsisActive(childRef === null || childRef === void 0 ? void 0 : childRef.current);
|
241
224
|
setState({
|
242
225
|
parentElement: localDom.parentElement,
|
243
|
-
isShowToolTip:
|
226
|
+
isShowToolTip: isEllipsis
|
244
227
|
});
|
245
228
|
}, []);
|
246
229
|
var cls = classnames(_defineProperty({
|
247
230
|
'pro-tooltip': true
|
248
231
|
}, "".concat(className), className));
|
249
|
-
|
250
|
-
|
251
|
-
ref: ref,
|
252
|
-
style: _objectSpread(_objectSpread(_objectSpread({}, style), multiStyle), {}, {
|
253
|
-
width: localWidth
|
254
|
-
}),
|
255
|
-
children: isResponsiveWidth && isShowToolTip ? _jsx(_Tooltip, _objectSpread(_objectSpread({
|
256
|
-
title: text,
|
257
|
-
getPopupContainer: function getPopupContainer(triggerNode) {
|
258
|
-
return triggerNode.parentNode;
|
259
|
-
}
|
260
|
-
}, restProps), {}, {
|
261
|
-
children: _jsx("div", {
|
262
|
-
className: isMultiLine ? 'multiLine' : 'singleLine',
|
263
|
-
style: _objectSpread(_objectSpread({}, multiStyle), {}, {
|
264
|
-
width: localWidth
|
265
|
-
}),
|
266
|
-
ref: childRef,
|
267
|
-
children: content
|
268
|
-
})
|
269
|
-
})) : isResponsiveWidth ? _jsx("div", {
|
232
|
+
var renderContentBox = function renderContentBox() {
|
233
|
+
return _jsx("div", {
|
270
234
|
className: isMultiLine ? 'multiLine' : 'singleLine',
|
271
235
|
style: _objectSpread(_objectSpread({}, multiStyle), {}, {
|
272
236
|
width: localWidth
|
273
237
|
}),
|
274
238
|
ref: childRef,
|
275
239
|
children: content
|
276
|
-
})
|
240
|
+
});
|
241
|
+
};
|
242
|
+
var renderTooltipContent = function renderTooltipContent() {
|
243
|
+
return _jsx(_Tooltip, _objectSpread(_objectSpread({
|
277
244
|
title: text,
|
278
245
|
getPopupContainer: function getPopupContainer(triggerNode) {
|
279
|
-
|
246
|
+
// 修复scrollFollowParent为false时tooltip不显示的问题
|
247
|
+
// 当scrollFollowParent为false时,应该返回document.body而不是triggerNode本身
|
248
|
+
return scrollFollowParent ? triggerNode.parentNode : document.body;
|
280
249
|
}
|
281
250
|
}, restProps), {}, {
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
})
|
290
|
-
}
|
251
|
+
overlayStyle: mode === 'auto' ? overlayStyle : {},
|
252
|
+
children: renderContentBox()
|
253
|
+
}));
|
254
|
+
};
|
255
|
+
var renderContent = function renderContent() {
|
256
|
+
// 自动模式使用专门的渲染逻辑
|
257
|
+
if (mode === 'auto') {
|
258
|
+
return _jsx(AutoMixin, {});
|
259
|
+
}
|
260
|
+
// 响应式宽度模式,根据是否需要显示tooltip决定渲染内容 且 父元素为table
|
261
|
+
if (isTable) {
|
262
|
+
if (isShowToolTip) {
|
263
|
+
return renderTooltipContent();
|
264
|
+
}
|
265
|
+
return renderContentBox();
|
266
|
+
}
|
267
|
+
// 默认模式始终显示tooltip
|
268
|
+
if (mode === 'default') {
|
269
|
+
return renderTooltipContent();
|
270
|
+
}
|
271
|
+
return renderContentBox();
|
272
|
+
};
|
273
|
+
return _jsx("div", {
|
274
|
+
className: cls,
|
275
|
+
ref: ref,
|
276
|
+
style: _objectSpread(_objectSpread(_objectSpread({}, style), multiStyle), {}, {
|
277
|
+
width: localWidth
|
278
|
+
}),
|
279
|
+
children: renderContent()
|
291
280
|
});
|
292
281
|
};
|
293
282
|
export default ProTooltip;
|
@@ -19,11 +19,11 @@ export interface ProTooltipType {
|
|
19
19
|
*/
|
20
20
|
line?: number;
|
21
21
|
/**
|
22
|
-
*
|
23
|
-
* @description
|
24
|
-
* @default
|
22
|
+
* 是否跟随父元素滚动
|
23
|
+
* @description 启用后,提示框将跟随父元素滚动
|
24
|
+
* @default true
|
25
25
|
*/
|
26
|
-
|
26
|
+
scrollFollowParent?: boolean;
|
27
27
|
/**
|
28
28
|
* 自定义类名
|
29
29
|
* @description 额外的CSS类名
|
package/es/utils/index.d.ts
CHANGED
@@ -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;
|
package/es/utils/index.js
CHANGED
@@ -19,6 +19,23 @@ export var isEmpty = function isEmpty(value, emptyValue) {
|
|
19
19
|
}
|
20
20
|
return false;
|
21
21
|
};
|
22
|
+
/**
|
23
|
+
* 判断一个元素是否触发了省略号(文本溢出)
|
24
|
+
* 如果元素设置为单行(white-space: nowrap)则比较 scrollWidth 与 clientWidth,
|
25
|
+
* 如果是多行文本(例如使用 -webkit-line-clamp 实现多行截断)则比较 scrollHeight 与 clientHeight。
|
26
|
+
* @param {HTMLElement} element 要检测的元素
|
27
|
+
* @returns {boolean} 如果内容溢出返回 true,否则返回 false
|
28
|
+
*/
|
29
|
+
export var isEllipsisActive = function isEllipsisActive(element) {
|
30
|
+
if (!element) return false;
|
31
|
+
var computedStyle = window.getComputedStyle(element);
|
32
|
+
// 如果使用单行显示(nowrap),则判断宽度是否足够
|
33
|
+
if (computedStyle.whiteSpace === 'nowrap') {
|
34
|
+
return element.scrollWidth > element.clientWidth;
|
35
|
+
}
|
36
|
+
// 多行情况下,判断高度是否足够
|
37
|
+
return element.scrollHeight > element.clientHeight;
|
38
|
+
};
|
22
39
|
export var useFocus = function useFocus(element) {
|
23
40
|
var _useState = useState(false),
|
24
41
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -65,6 +65,10 @@ export interface ProFormType<Values = any> extends FormProps<Values> {
|
|
65
65
|
/** 全局控制优先 */
|
66
66
|
globalControl?: boolean;
|
67
67
|
mode?: ModeEnum;
|
68
|
+
/**
|
69
|
+
* 如果有formKey,则会在全局中查找或创建表单实例
|
70
|
+
* 可以不需要手动传入form实例 且formKey的优先级高于form
|
71
|
+
*/
|
68
72
|
formKey?: string;
|
69
73
|
/** 是否查看 */
|
70
74
|
isView?: boolean;
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
10
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
11
|
+
var _react = require("react");
|
11
12
|
var _antd = require("antd");
|
12
13
|
var _ahooks = require("ahooks");
|
13
14
|
var _lodash = require("lodash");
|
@@ -34,12 +35,26 @@ var RenderColumn = function RenderColumn(props) {
|
|
34
35
|
minWidth = props.minWidth,
|
35
36
|
isInNewRowFlag = props.isInNewRowFlag,
|
36
37
|
scroll = props.scroll;
|
38
|
+
var textRef = (0, _react.useRef)(null);
|
37
39
|
var _useSetState = (0, _ahooks.useSetState)({
|
38
40
|
tooltip: false
|
39
41
|
}),
|
40
42
|
_useSetState2 = (0, _slicedToArray2.default)(_useSetState, 2),
|
41
43
|
tooltip = _useSetState2[0].tooltip,
|
42
44
|
setState = _useSetState2[1];
|
45
|
+
// 计算并更新宽度
|
46
|
+
var updateCalculatedWidth = function updateCalculatedWidth(element) {
|
47
|
+
if (!element) return null;
|
48
|
+
if (!textRef.current) return;
|
49
|
+
// 使用closest方法查找最近的tr
|
50
|
+
var tr = element.closest('tr');
|
51
|
+
if (!tr) return;
|
52
|
+
// 获取tr的宽度
|
53
|
+
var trWidth = tr.getBoundingClientRect().width;
|
54
|
+
// 计算实际宽度
|
55
|
+
var newWidth = (0, _utils.parseWidth)(width, trWidth);
|
56
|
+
return newWidth;
|
57
|
+
};
|
43
58
|
var cellDiffCls = (0, _classnames.default)({
|
44
59
|
'varied-cell': props === null || props === void 0 ? void 0 : props.isChanged,
|
45
60
|
'add-cell': props === null || props === void 0 ? void 0 : props.isAddCell
|
@@ -98,6 +113,9 @@ var RenderColumn = function RenderColumn(props) {
|
|
98
113
|
if (ellipsis) {
|
99
114
|
return (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
100
115
|
title: currentValue,
|
116
|
+
getTooltipContainer: function getTooltipContainer() {
|
117
|
+
return document.body;
|
118
|
+
},
|
101
119
|
onOpenChange: function onOpenChange(open) {
|
102
120
|
setState({
|
103
121
|
tooltip: false
|
@@ -200,9 +218,13 @@ var RenderColumn = function RenderColumn(props) {
|
|
200
218
|
children: "-"
|
201
219
|
});
|
202
220
|
}
|
221
|
+
var calculatedWidth = updateCalculatedWidth(textRef.current);
|
203
222
|
return (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
204
223
|
title: value,
|
205
|
-
|
224
|
+
getTooltipContainer: function getTooltipContainer() {
|
225
|
+
return document.body;
|
226
|
+
},
|
227
|
+
onOpenChange: function onOpenChange() {
|
206
228
|
setState({
|
207
229
|
tooltip: false
|
208
230
|
});
|
@@ -210,8 +232,9 @@ var RenderColumn = function RenderColumn(props) {
|
|
210
232
|
open: tooltip
|
211
233
|
}, tooltipProps), {}, {
|
212
234
|
children: (0, _jsxRuntime.jsx)(Text, {
|
235
|
+
ref: textRef,
|
213
236
|
style: {
|
214
|
-
width:
|
237
|
+
width: calculatedWidth,
|
215
238
|
minWidth: minWidth
|
216
239
|
},
|
217
240
|
ellipsis: true,
|
@@ -41,3 +41,5 @@ export declare const getPadding: (el: HTMLElement) => {
|
|
41
41
|
};
|
42
42
|
/** 判断是有值的对象 */
|
43
43
|
export declare const isNonEmptyObject: (obj: any) => obj is Record<string, any>;
|
44
|
+
/** 解析宽度值 */
|
45
|
+
export declare const parseWidth: (widthValue: number | string | undefined, trWidth: number) => number;
|
@@ -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.removeEmptyKeys = exports.isNonEmptyObject = exports.isListResult = exports.getRowKey = exports.getPadding = exports.getOriginalValue = exports.getDecimalDigits = exports.getColumnDataIndex = void 0;
|
7
|
+
exports.removeEmptyKeys = exports.parseWidth = exports.isNonEmptyObject = exports.isListResult = exports.getRowKey = exports.getPadding = exports.getOriginalValue = exports.getDecimalDigits = exports.getColumnDataIndex = void 0;
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
10
10
|
var _lodash = require("lodash");
|
@@ -112,4 +112,24 @@ var getPadding = exports.getPadding = function getPadding(el) {
|
|
112
112
|
/** 判断是有值的对象 */
|
113
113
|
var isNonEmptyObject = exports.isNonEmptyObject = function isNonEmptyObject(obj) {
|
114
114
|
return obj !== null && (0, _typeof2.default)(obj) === 'object' && !Array.isArray(obj) && Object.keys(obj).length > 0;
|
115
|
+
};
|
116
|
+
/** 解析宽度值 */
|
117
|
+
var parseWidth = exports.parseWidth = function parseWidth(widthValue, trWidth) {
|
118
|
+
// 如果是数字,直接返回
|
119
|
+
if (typeof widthValue === 'number') return widthValue;
|
120
|
+
// 如果是字符串,检查是否是百分比
|
121
|
+
if (typeof widthValue === 'string') {
|
122
|
+
if (widthValue.endsWith('%')) {
|
123
|
+
// 计算百分比
|
124
|
+
var percentage = parseFloat(widthValue) / 100;
|
125
|
+
return Math.max(trWidth * percentage, 0);
|
126
|
+
}
|
127
|
+
// 尝试解析为数字(处理如'300px'这样的情况)
|
128
|
+
var numericValue = parseFloat(widthValue);
|
129
|
+
if (!Number.isNaN(numericValue)) {
|
130
|
+
return numericValue;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
// 所有其他情况,返回默认值
|
134
|
+
return null;
|
115
135
|
};
|
package/lib/ProTooltip/index.js
CHANGED
@@ -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("
|
18
|
-
var _excluded = ["text", "mode", "width", "line", "
|
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
|
-
|
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
|
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:
|
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
|
-
|
256
|
-
|
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
|
-
})
|
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
|
-
|
252
|
+
// 修复scrollFollowParent为false时tooltip不显示的问题
|
253
|
+
// 当scrollFollowParent为false时,应该返回document.body而不是triggerNode本身
|
254
|
+
return scrollFollowParent ? triggerNode.parentNode : document.body;
|
286
255
|
}
|
287
256
|
}, restProps), {}, {
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
})
|
296
|
-
}
|
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
|
22
|
+
* 是否跟随父元素滚动
|
23
|
+
* @description 启用后,提示框将跟随父元素滚动
|
24
|
+
* @default true
|
25
25
|
*/
|
26
|
-
|
26
|
+
scrollFollowParent?: boolean;
|
27
27
|
/**
|
28
28
|
* 自定义类名
|
29
29
|
* @description 额外的CSS类名
|
package/lib/utils/index.d.ts
CHANGED
@@ -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;
|
package/lib/utils/index.js
CHANGED
@@ -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),
|