@elliemae/ds-truncated-tooltip-text 2.2.0-alpha.3 → 3.0.0-next.0
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/cjs/DSTruncateTextWithTooltip.js +57 -68
- package/cjs/DSTruncatedTooltipText.js +93 -100
- package/cjs/SimpleTruncatedTooltipText.js +125 -114
- package/cjs/TooltipTextProvider.js +64 -60
- package/cjs/index.js +19 -45
- package/esm/DSTruncateTextWithTooltip.js +46 -38
- package/esm/DSTruncatedTooltipText.js +78 -68
- package/esm/SimpleTruncatedTooltipText.js +111 -83
- package/esm/TooltipTextProvider.js +48 -29
- package/esm/index.js +4 -16
- package/package.json +5 -5
- package/types/index.d.ts +5 -4
- package/cjs/DSTruncateTextWithTooltip.js.map +0 -7
- package/cjs/DSTruncatedTooltipText.js.map +0 -7
- package/cjs/SimpleTruncatedTooltipText.js.map +0 -7
- package/cjs/TooltipTextProvider.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/esm/DSTruncateTextWithTooltip.js.map +0 -7
- package/esm/DSTruncatedTooltipText.js.map +0 -7
- package/esm/SimpleTruncatedTooltipText.js.map +0 -7
- package/esm/TooltipTextProvider.js.map +0 -7
- package/esm/index.js.map +0 -7
@@ -1,86 +1,75 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
var
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
var
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
var
|
21
|
-
|
22
|
-
};
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
})(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
white-space: nowrap;
|
40
|
-
overflow: hidden;
|
41
|
-
display: inline-block;
|
42
|
-
max-width: 100%;
|
43
|
-
:focus {
|
44
|
-
border: none;
|
45
|
-
outline: none;
|
46
|
-
background: ${(props) => props.theme.colors.brand["200"]};
|
47
|
-
}
|
48
|
-
`;
|
49
|
-
const DSTruncateTextWithTooltipDatatestId = "DS-TruncateTextWithTooltip";
|
50
|
-
const DSTruncateTextWithTooltip = ({ text, tooltipProps = {} }) => {
|
51
|
-
const [textWrapperEl, setTextWrapperEl] = (0, import_react.useState)();
|
52
|
-
const [isShowingEllipsis, setIsShowingEllipsis] = (0, import_react.useState)(false);
|
53
|
-
const resizeObserver = (0, import_react.useMemo)(() => new ResizeObserver((entries) => {
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
6
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
7
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
8
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
9
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
10
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
11
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
12
|
+
var React = require('react');
|
13
|
+
var dsTooltip = require('@elliemae/ds-tooltip');
|
14
|
+
var styled = require('styled-components');
|
15
|
+
var jsxRuntime = require('react/jsx-runtime');
|
16
|
+
|
17
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
18
|
+
|
19
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
20
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
21
|
+
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
23
|
+
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
25
|
+
const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
26
|
+
componentId: "sc-1w57q5j-0"
|
27
|
+
})(["text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:inline-block;max-width:100%;:focus{border:none;outline:none;background:", ";}"], props => props.theme.colors.brand['200']);
|
28
|
+
const DSTruncateTextWithTooltipDatatestId = 'DS-TruncateTextWithTooltip';
|
29
|
+
const DSTruncateTextWithTooltip = _ref => {
|
30
|
+
let {
|
31
|
+
text,
|
32
|
+
tooltipProps = {}
|
33
|
+
} = _ref;
|
34
|
+
const [textWrapperEl, setTextWrapperEl] = React.useState(); // const textWrapperEl = useRef<HTMLSpanElement>();
|
35
|
+
|
36
|
+
const [isShowingEllipsis, setIsShowingEllipsis] = React.useState(false); // const isShowingEllipsis = textWrapperEl?.scrollWidth > textWrapperEl?.clientWidth;
|
37
|
+
|
38
|
+
const resizeObserver = React.useMemo(() => new ResizeObserver(entries => {
|
54
39
|
if (entries.length) {
|
55
40
|
const [textWrapperEntry] = entries;
|
56
41
|
const el = textWrapperEntry.target;
|
57
|
-
setIsShowingEllipsis(el
|
42
|
+
setIsShowingEllipsis((el === null || el === void 0 ? void 0 : el.scrollWidth) > (el === null || el === void 0 ? void 0 : el.clientWidth));
|
58
43
|
}
|
59
44
|
}), []);
|
60
|
-
|
45
|
+
React.useEffect(() => {
|
61
46
|
if (textWrapperEl) {
|
62
|
-
setIsShowingEllipsis(textWrapperEl
|
47
|
+
setIsShowingEllipsis((textWrapperEl === null || textWrapperEl === void 0 ? void 0 : textWrapperEl.scrollWidth) > (textWrapperEl === null || textWrapperEl === void 0 ? void 0 : textWrapperEl.clientWidth));
|
63
48
|
resizeObserver.observe(textWrapperEl);
|
64
49
|
}
|
50
|
+
|
65
51
|
return () => {
|
66
52
|
if (textWrapperEl) {
|
67
53
|
resizeObserver.unobserve(textWrapperEl);
|
68
54
|
}
|
69
55
|
};
|
70
56
|
}, [resizeObserver, textWrapperEl]);
|
71
|
-
if (isShowingEllipsis)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}, /* @__PURE__ */ import_react.default.createElement(Text, {
|
57
|
+
if (isShowingEllipsis) return /*#__PURE__*/jsxRuntime.jsx(dsTooltip.DSTooltipV3, _objectSpread(_objectSpread({
|
58
|
+
text: text
|
59
|
+
}, tooltipProps), {}, {
|
60
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Text, {
|
76
61
|
ref: setTextWrapperEl,
|
77
62
|
tabIndex: 0,
|
78
|
-
"data-testid": DSTruncateTextWithTooltipDatatestId
|
79
|
-
|
80
|
-
|
63
|
+
"data-testid": DSTruncateTextWithTooltipDatatestId,
|
64
|
+
children: text
|
65
|
+
})
|
66
|
+
}));
|
67
|
+
return /*#__PURE__*/jsxRuntime.jsx(Text, {
|
81
68
|
ref: setTextWrapperEl,
|
82
|
-
"data-testid": DSTruncateTextWithTooltipDatatestId
|
83
|
-
|
69
|
+
"data-testid": DSTruncateTextWithTooltipDatatestId,
|
70
|
+
children: text
|
71
|
+
});
|
84
72
|
};
|
85
|
-
|
86
|
-
|
73
|
+
|
74
|
+
exports.DSTruncateTextWithTooltip = DSTruncateTextWithTooltip;
|
75
|
+
exports.DSTruncateTextWithTooltipDatatestId = DSTruncateTextWithTooltipDatatestId;
|
@@ -1,66 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
var
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
};
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
var
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
const
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
(0, import_react.useEffect)(() => {
|
56
|
-
if (zIndex && tooltipContext)
|
57
|
-
tooltipContext.setZIndex(zIndex);
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
9
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
10
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
11
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
12
|
+
var React = require('react');
|
13
|
+
var reactDesc = require('react-desc');
|
14
|
+
var styled = require('styled-components');
|
15
|
+
var dsPopper = require('@elliemae/ds-popper');
|
16
|
+
var TooltipTextProvider = require('./TooltipTextProvider.js');
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
18
|
+
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
20
|
+
|
21
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
22
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
23
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
24
|
+
|
25
|
+
const _excluded = ["containerProps", "value", "zIndex"];
|
26
|
+
|
27
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
28
|
+
|
29
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
30
|
+
|
31
|
+
const isEllipsisActive = _ref => {
|
32
|
+
let {
|
33
|
+
offsetWidth,
|
34
|
+
scrollWidth
|
35
|
+
} = _ref;
|
36
|
+
return offsetWidth < scrollWidth;
|
37
|
+
}; // reduce the possibility of error showing the tooltip (text-overflow: ellipsis) https://jira.elliemae.io/browse/PUI-1755
|
38
|
+
|
39
|
+
|
40
|
+
const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
41
|
+
componentId: "sc-1olo1o7-0"
|
42
|
+
})(["text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:inline-block;max-width:100%;"]);
|
43
|
+
|
44
|
+
const DSTruncatedTooltipText = _ref2 => {
|
45
|
+
let {
|
46
|
+
containerProps = {},
|
47
|
+
value = '',
|
48
|
+
zIndex = 110
|
49
|
+
} = _ref2,
|
50
|
+
otherTextProps = _objectWithoutProperties__default["default"](_ref2, _excluded);
|
51
|
+
|
52
|
+
const tooltipContext = React.useContext(TooltipTextProvider.TruncatedTooltipContext);
|
53
|
+
React.useEffect(() => {
|
54
|
+
if (zIndex && tooltipContext) tooltipContext.setZIndex(zIndex);
|
58
55
|
}, [zIndex]);
|
59
|
-
if (!tooltipContext)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
if (!tooltipContext) return value;
|
57
|
+
const {
|
58
|
+
showTooltip,
|
59
|
+
hideTooltip
|
60
|
+
} = tooltipContext;
|
61
|
+
|
62
|
+
const handleMouseEnter = e => {
|
63
|
+
const {
|
64
|
+
target
|
65
|
+
} = e;
|
66
|
+
|
64
67
|
if (target && isEllipsisActive(target, target.getBoundingClientRect())) {
|
65
68
|
showTooltip({
|
66
69
|
value,
|
@@ -68,52 +71,42 @@ const DSTruncatedTooltipText = ({
|
|
68
71
|
}, e);
|
69
72
|
}
|
70
73
|
};
|
71
|
-
|
72
|
-
|
74
|
+
|
75
|
+
const handleMouseLeave = e => {
|
76
|
+
hideTooltip({
|
77
|
+
reference: e.target
|
78
|
+
});
|
73
79
|
};
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
},
|
80
|
+
|
81
|
+
const handlers = showTooltip ? {
|
82
|
+
onMouseEnter: handleMouseEnter,
|
83
|
+
onMouseLeave: handleMouseLeave
|
84
|
+
} : {};
|
85
|
+
return /*#__PURE__*/jsxRuntime.jsx(Text, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, containerProps), otherTextProps), handlers), {}, {
|
86
|
+
children: value
|
87
|
+
}));
|
80
88
|
};
|
89
|
+
|
81
90
|
DSTruncatedTooltipText.defaultProps = {
|
82
|
-
value:
|
91
|
+
value: '',
|
83
92
|
zIndex: 110
|
84
93
|
};
|
85
94
|
const truncatedTooltipTextProps = {
|
86
|
-
containerProps:
|
87
|
-
value:
|
88
|
-
tooltipPlacement:
|
89
|
-
|
90
|
-
|
91
|
-
import_ds_popper.PopperPositions.AUTO,
|
92
|
-
import_ds_popper.PopperPositions.TOP_START,
|
93
|
-
import_ds_popper.PopperPositions.TOP,
|
94
|
-
import_ds_popper.PopperPositions.TOP_END,
|
95
|
-
import_ds_popper.PopperPositions.RIGHT_START,
|
96
|
-
import_ds_popper.PopperPositions.RIGHT,
|
97
|
-
import_ds_popper.PopperPositions.RIGHT_END,
|
98
|
-
import_ds_popper.PopperPositions.BOTTOM_START,
|
99
|
-
import_ds_popper.PopperPositions.BOTTOM,
|
100
|
-
import_ds_popper.PopperPositions.BOTTOM_END,
|
101
|
-
import_ds_popper.PopperPositions.LEFT_START,
|
102
|
-
import_ds_popper.PopperPositions.LEFT,
|
103
|
-
import_ds_popper.PopperPositions.LEFT_END
|
104
|
-
]).description("Position of the tooltip"),
|
105
|
-
tooltipDelay: import_react_desc.PropTypes.number.description("Delay to show the tooltip"),
|
106
|
-
zIndex: import_react_desc.PropTypes.number.description("override default zIndex").defaultValue(110)
|
95
|
+
containerProps: reactDesc.PropTypes.object.description('Set of Properties attached to the main container'),
|
96
|
+
value: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.string, reactDesc.PropTypes.number]).description('Text that when truncated will trigger the tooltip interaction'),
|
97
|
+
tooltipPlacement: reactDesc.PropTypes.oneOf([dsPopper.PopperPositions.AUTO_START, dsPopper.PopperPositions.AUTO_END, dsPopper.PopperPositions.AUTO, dsPopper.PopperPositions.TOP_START, dsPopper.PopperPositions.TOP, dsPopper.PopperPositions.TOP_END, dsPopper.PopperPositions.RIGHT_START, dsPopper.PopperPositions.RIGHT, dsPopper.PopperPositions.RIGHT_END, dsPopper.PopperPositions.BOTTOM_START, dsPopper.PopperPositions.BOTTOM, dsPopper.PopperPositions.BOTTOM_END, dsPopper.PopperPositions.LEFT_START, dsPopper.PopperPositions.LEFT, dsPopper.PopperPositions.LEFT_END]).description('Position of the tooltip'),
|
98
|
+
tooltipDelay: reactDesc.PropTypes.number.description('Delay to show the tooltip'),
|
99
|
+
zIndex: reactDesc.PropTypes.number.description('override default zIndex').defaultValue(110)
|
107
100
|
};
|
108
101
|
DSTruncatedTooltipText.defaultProps = {
|
109
102
|
containerProps: {},
|
110
|
-
value:
|
111
|
-
tooltipPlacement:
|
112
|
-
tooltipDelay:
|
103
|
+
value: '',
|
104
|
+
tooltipPlacement: undefined,
|
105
|
+
tooltipDelay: undefined
|
113
106
|
};
|
114
|
-
|
115
|
-
const TruncatedTooltipTextWithSchema = (0, import_react_desc.describe)(DSTruncatedTooltipText);
|
107
|
+
const TruncatedTooltipTextWithSchema = reactDesc.describe(DSTruncatedTooltipText);
|
116
108
|
TruncatedTooltipTextWithSchema.propTypes = truncatedTooltipTextProps;
|
117
|
-
|
118
|
-
|
119
|
-
|
109
|
+
|
110
|
+
exports.DSTruncatedTooltipText = DSTruncatedTooltipText;
|
111
|
+
exports.TruncatedTooltipTextWithSchema = TruncatedTooltipTextWithSchema;
|
112
|
+
exports["default"] = DSTruncatedTooltipText;
|
@@ -1,137 +1,148 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
var
|
6
|
-
var
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
6
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
7
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
8
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
9
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
10
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
11
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
12
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
13
|
+
var React = require('react');
|
14
|
+
var dsUtilities = require('@elliemae/ds-utilities');
|
15
|
+
var styled = require('styled-components');
|
16
|
+
var DSPopover = require('@elliemae/ds-popover');
|
17
|
+
var jsxRuntime = require('react/jsx-runtime');
|
18
|
+
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
20
|
+
|
21
|
+
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
22
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
23
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
24
|
+
var DSPopover__default = /*#__PURE__*/_interopDefaultLegacy(DSPopover);
|
25
|
+
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
27
|
+
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
29
|
+
const dsTestId = 'DS-SimpleTruncateText';
|
30
|
+
|
31
|
+
const isEllipsisActive = _ref => {
|
32
|
+
let {
|
33
|
+
offsetWidth,
|
34
|
+
scrollWidth
|
35
|
+
} = _ref;
|
36
|
+
return offsetWidth < scrollWidth;
|
11
37
|
};
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
22
|
-
};
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
24
|
-
return (module2, temp) => {
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
38
|
+
|
39
|
+
const initialTooltipState = function () {
|
40
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
41
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
42
|
+
return {
|
43
|
+
reference: null,
|
44
|
+
visible: false,
|
45
|
+
value,
|
46
|
+
options
|
26
47
|
};
|
27
|
-
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
});
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
overflow: hidden;
|
51
|
-
display: inline-block;
|
52
|
-
max-width: 100%;
|
53
|
-
`;
|
54
|
-
const SimpleTruncatedTooltipText = (props) => {
|
55
|
-
const { containerProps, tooltipDelay, placement, value, zIndex, tooltipOptions, textOptions } = props;
|
56
|
-
const [tooltipState, setTooltipState] = (0, import_react.useState)(initialTooltipState(value, tooltipOptions));
|
57
|
-
const show = (0, import_react.useCallback)((newState) => {
|
58
|
-
setTooltipState({ ...tooltipState, ...newState, visible: true });
|
48
|
+
}; // reduce the possibility of error showing the tooltip(text-overflow: ellipsis) https://jira.elliemae.io/browse/PUI-1755
|
49
|
+
|
50
|
+
|
51
|
+
const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
52
|
+
componentId: "sc-2f4vtq-0"
|
53
|
+
})(["text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:inline-block;max-width:100%;"]);
|
54
|
+
|
55
|
+
const SimpleTruncatedTooltipText = props => {
|
56
|
+
const {
|
57
|
+
containerProps,
|
58
|
+
tooltipDelay,
|
59
|
+
placement,
|
60
|
+
value,
|
61
|
+
zIndex,
|
62
|
+
tooltipOptions,
|
63
|
+
textOptions
|
64
|
+
} = props; // not using "usePopoverProviderState" because usePopoverState has memory leak issues
|
65
|
+
|
66
|
+
const [tooltipState, setTooltipState] = React.useState(initialTooltipState(value, tooltipOptions));
|
67
|
+
const show = React.useCallback(newState => {
|
68
|
+
setTooltipState(_objectSpread(_objectSpread(_objectSpread({}, tooltipState), newState), {}, {
|
69
|
+
visible: true
|
70
|
+
}));
|
59
71
|
}, [tooltipState]);
|
60
|
-
const hideTooltip =
|
61
|
-
setTooltipState({
|
72
|
+
const hideTooltip = React.useCallback(newState => {
|
73
|
+
setTooltipState(_objectSpread(_objectSpread(_objectSpread({}, tooltipState), newState), {}, {
|
74
|
+
visible: false
|
75
|
+
}));
|
62
76
|
}, [tooltipState]);
|
63
|
-
const [showTooltip, cancelShowTooltip] =
|
64
|
-
const handleMouseEnter =
|
65
|
-
const {
|
66
|
-
|
77
|
+
const [showTooltip, cancelShowTooltip] = dsUtilities.useCancellableDelayedCallback(show, tooltipDelay);
|
78
|
+
const handleMouseEnter = React.useCallback(e => {
|
79
|
+
const {
|
80
|
+
target
|
81
|
+
} = e; // we search for the closest parent with data-testid matching this component
|
82
|
+
// this is required because the target may not be this component itself
|
83
|
+
// when the user gives JSX as a value.
|
84
|
+
// JSX as a value is required for features like text highlight during research
|
85
|
+
// wich would still allow the truncation behaviour (see tree view for example)
|
86
|
+
// when the target has the test-id itself target===SimpleTruncatedTextEl
|
87
|
+
|
88
|
+
const SimpleTruncatedTextEl = target.closest("[data-testid=\"".concat(dsTestId, "\"]"));
|
89
|
+
|
67
90
|
if (SimpleTruncatedTextEl && isEllipsisActive(SimpleTruncatedTextEl)) {
|
68
|
-
showTooltip({
|
91
|
+
showTooltip({
|
92
|
+
value,
|
93
|
+
reference: SimpleTruncatedTextEl
|
94
|
+
});
|
69
95
|
}
|
70
96
|
}, [showTooltip, value]);
|
71
|
-
const handleMouseLeave =
|
97
|
+
const handleMouseLeave = React.useCallback(() => {
|
72
98
|
cancelShowTooltip();
|
73
|
-
hideTooltip({
|
99
|
+
hideTooltip({
|
100
|
+
reference: null
|
101
|
+
});
|
74
102
|
}, [hideTooltip, cancelShowTooltip]);
|
75
|
-
const handlers =
|
76
|
-
if (!showTooltip)
|
77
|
-
return {};
|
103
|
+
const handlers = React.useMemo(() => {
|
104
|
+
if (!showTooltip) return {};
|
78
105
|
return {
|
79
106
|
onMouseEnter: handleMouseEnter,
|
80
107
|
onMouseLeave: handleMouseLeave
|
81
108
|
};
|
82
109
|
}, [showTooltip, handleMouseEnter, handleMouseLeave]);
|
83
|
-
const PurePopover =
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
110
|
+
const PurePopover = React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
111
|
+
children: tooltipState.visible ? /*#__PURE__*/_jsx2__default["default"](DSPopover__default["default"], {
|
112
|
+
boundaries: "window",
|
113
|
+
style: {
|
114
|
+
pointerEvents: 'none',
|
115
|
+
zIndex
|
116
|
+
},
|
117
|
+
placement: placement,
|
118
|
+
content: tooltipState.value,
|
119
|
+
referenceEl: tooltipState.reference,
|
120
|
+
visible: tooltipState.visible,
|
121
|
+
showArrow: true
|
122
|
+
}) : null
|
123
|
+
}), [tooltipState, placement, zIndex]);
|
124
|
+
const PureText = React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
125
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Text, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, containerProps && _objectSpread({}, containerProps)), textOptions && _objectSpread({}, textOptions)), handlers && _objectSpread({}, handlers)), {}, {
|
126
|
+
"data-testid": dsTestId // this is used by mouse enter too. required to support value as JSX
|
127
|
+
,
|
128
|
+
children: value
|
129
|
+
}))
|
130
|
+
}), [containerProps, textOptions, handlers, value]);
|
131
|
+
const PureSimpleTruncatedTooltipText = React.useMemo(() => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
132
|
+
children: [PureText, PurePopover]
|
133
|
+
}), [PureText, PurePopover]);
|
99
134
|
return PureSimpleTruncatedTooltipText;
|
100
135
|
};
|
101
|
-
|
102
|
-
containerProps: import_prop_types.default.object,
|
103
|
-
tooltipOptions: import_prop_types.default.object,
|
104
|
-
textOptions: import_prop_types.default.object,
|
105
|
-
value: import_prop_types.default.oneOfType([import_prop_types.default.string, import_prop_types.default.number, import_prop_types.default.node]),
|
106
|
-
placement: import_prop_types.default.oneOf([
|
107
|
-
import_ds_popover.PopperPositions.AUTO_START,
|
108
|
-
import_ds_popover.PopperPositions.AUTO_END,
|
109
|
-
import_ds_popover.PopperPositions.AUTO,
|
110
|
-
import_ds_popover.PopperPositions.TOP_START,
|
111
|
-
import_ds_popover.PopperPositions.TOP,
|
112
|
-
import_ds_popover.PopperPositions.TOP_END,
|
113
|
-
import_ds_popover.PopperPositions.RIGHT_START,
|
114
|
-
import_ds_popover.PopperPositions.RIGHT,
|
115
|
-
import_ds_popover.PopperPositions.RIGHT_END,
|
116
|
-
import_ds_popover.PopperPositions.BOTTOM_START,
|
117
|
-
import_ds_popover.PopperPositions.BOTTOM,
|
118
|
-
import_ds_popover.PopperPositions.BOTTOM_END,
|
119
|
-
import_ds_popover.PopperPositions.LEFT_START,
|
120
|
-
import_ds_popover.PopperPositions.LEFT,
|
121
|
-
import_ds_popover.PopperPositions.LEFT_END
|
122
|
-
]),
|
123
|
-
tooltipDelay: import_prop_types.default.number,
|
124
|
-
zIndex: import_prop_types.default.number
|
125
|
-
};
|
136
|
+
|
126
137
|
SimpleTruncatedTooltipText.defaultProps = {
|
127
138
|
containerProps: {},
|
128
139
|
tooltipOptions: {},
|
129
140
|
textOptions: {},
|
130
|
-
value:
|
131
|
-
placement:
|
141
|
+
value: '',
|
142
|
+
placement: DSPopover.PopperPositions.TOP,
|
132
143
|
tooltipDelay: 200,
|
133
144
|
zIndex: 110
|
134
145
|
};
|
135
|
-
|
136
|
-
|
137
|
-
|
146
|
+
|
147
|
+
exports.SimpleTruncatedTooltipText = SimpleTruncatedTooltipText;
|
148
|
+
exports["default"] = SimpleTruncatedTooltipText;
|