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