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