@elliemae/ds-truncated-tooltip-text 2.3.1 → 3.0.0-alpha.3

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 (71) hide show
  1. package/dist/cjs/DSTruncatedTooltipText.js +145 -0
  2. package/dist/cjs/DSTruncatedTooltipText.js.map +7 -0
  3. package/dist/cjs/SimpleTruncatedTooltipText.js +151 -0
  4. package/dist/cjs/SimpleTruncatedTooltipText.js.map +7 -0
  5. package/dist/cjs/TooltipTextProvider.js +106 -0
  6. package/dist/cjs/TooltipTextProvider.js.map +7 -0
  7. package/dist/cjs/index.js +45 -0
  8. package/dist/cjs/index.js.map +7 -0
  9. package/dist/cjs/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js +37 -0
  10. package/dist/cjs/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js.map +7 -0
  11. package/dist/cjs/truncateTextWithTooltip/DSTruncateTextWithTooltip.js +95 -0
  12. package/dist/cjs/truncateTextWithTooltip/DSTruncateTextWithTooltip.js.map +7 -0
  13. package/dist/cjs/truncateTextWithTooltip/defaultProps.js +37 -0
  14. package/dist/cjs/truncateTextWithTooltip/defaultProps.js.map +7 -0
  15. package/dist/cjs/truncateTextWithTooltip/index.js +29 -0
  16. package/dist/cjs/truncateTextWithTooltip/index.js.map +7 -0
  17. package/dist/cjs/truncateTextWithTooltip/propTypes.js +39 -0
  18. package/dist/cjs/truncateTextWithTooltip/propTypes.js.map +7 -0
  19. package/dist/cjs/truncateTextWithTooltip/styles.js +47 -0
  20. package/dist/cjs/truncateTextWithTooltip/styles.js.map +7 -0
  21. package/dist/esm/DSTruncatedTooltipText.js +118 -0
  22. package/dist/esm/DSTruncatedTooltipText.js.map +7 -0
  23. package/dist/esm/SimpleTruncatedTooltipText.js +124 -0
  24. package/dist/esm/SimpleTruncatedTooltipText.js.map +7 -0
  25. package/dist/esm/TooltipTextProvider.js +79 -0
  26. package/dist/esm/TooltipTextProvider.js.map +7 -0
  27. package/dist/esm/index.js +16 -0
  28. package/dist/esm/index.js.map +7 -0
  29. package/dist/esm/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js +8 -0
  30. package/dist/esm/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js.map +7 -0
  31. package/dist/esm/truncateTextWithTooltip/DSTruncateTextWithTooltip.js +68 -0
  32. package/dist/esm/truncateTextWithTooltip/DSTruncateTextWithTooltip.js.map +7 -0
  33. package/dist/esm/truncateTextWithTooltip/defaultProps.js +8 -0
  34. package/dist/esm/truncateTextWithTooltip/defaultProps.js.map +7 -0
  35. package/dist/esm/truncateTextWithTooltip/index.js +4 -0
  36. package/dist/esm/truncateTextWithTooltip/index.js.map +7 -0
  37. package/dist/esm/truncateTextWithTooltip/propTypes.js +10 -0
  38. package/dist/esm/truncateTextWithTooltip/propTypes.js.map +7 -0
  39. package/dist/esm/truncateTextWithTooltip/styles.js +18 -0
  40. package/dist/esm/truncateTextWithTooltip/styles.js.map +7 -0
  41. package/package.json +39 -50
  42. package/cjs/DSTruncatedTooltipText.js +0 -112
  43. package/cjs/SimpleTruncatedTooltipText.js +0 -148
  44. package/cjs/TooltipTextProvider.js +0 -78
  45. package/cjs/index.js +0 -21
  46. package/cjs/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js +0 -9
  47. package/cjs/truncateTextWithTooltip/DSTruncateTextWithTooltip.js +0 -78
  48. package/cjs/truncateTextWithTooltip/defaultProps.js +0 -9
  49. package/cjs/truncateTextWithTooltip/index.js +0 -12
  50. package/cjs/truncateTextWithTooltip/propTypes.js +0 -13
  51. package/cjs/truncateTextWithTooltip/styles.js +0 -20
  52. package/esm/DSTruncatedTooltipText.js +0 -100
  53. package/esm/SimpleTruncatedTooltipText.js +0 -136
  54. package/esm/TooltipTextProvider.js +0 -64
  55. package/esm/index.js +0 -5
  56. package/esm/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js +0 -5
  57. package/esm/truncateTextWithTooltip/DSTruncateTextWithTooltip.js +0 -69
  58. package/esm/truncateTextWithTooltip/defaultProps.js +0 -5
  59. package/esm/truncateTextWithTooltip/index.js +0 -2
  60. package/esm/truncateTextWithTooltip/propTypes.js +0 -9
  61. package/esm/truncateTextWithTooltip/styles.js +0 -12
  62. package/types/DSTruncatedTooltipText.d.ts +0 -59
  63. package/types/SimpleTruncatedTooltipText.d.ts +0 -29
  64. package/types/TooltipTextProvider.d.ts +0 -14
  65. package/types/index.d.ts +0 -5
  66. package/types/truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.d.ts +0 -3
  67. package/types/truncateTextWithTooltip/DSTruncateTextWithTooltip.d.ts +0 -5
  68. package/types/truncateTextWithTooltip/defaultProps.d.ts +0 -2
  69. package/types/truncateTextWithTooltip/index.d.ts +0 -2
  70. package/types/truncateTextWithTooltip/propTypes.d.ts +0 -14
  71. package/types/truncateTextWithTooltip/styles.d.ts +0 -1
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const DSTruncateTextWithTooltipDatatestid = {
6
- TEXT: 'ds-truncatetextwithtooltip-text'
7
- };
8
-
9
- exports.DSTruncateTextWithTooltipDatatestid = DSTruncateTextWithTooltipDatatestid;
@@ -1,78 +0,0 @@
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 dsPropsHelpers = require('@elliemae/ds-props-helpers');
15
- var defaultProps = require('./defaultProps.js');
16
- var DSTruncateTextWIthTooltipDatatestid = require('./DSTruncateTextWIthTooltipDatatestid.js');
17
- var propTypes = require('./propTypes.js');
18
- var styles = require('./styles.js');
19
- var jsxRuntime = require('react/jsx-runtime');
20
-
21
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
-
23
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
24
-
25
- 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; }
26
-
27
- 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; }
28
-
29
- const DSTruncateTextWithTooltip = props => {
30
- const propsWithDefault = dsPropsHelpers.useMemoMergePropsWithDefault(props, defaultProps.defaultProps);
31
- dsPropsHelpers.useValidateTypescriptPropTypes(propsWithDefault, propTypes.propTypes);
32
- const {
33
- text,
34
- tooltipProps
35
- } = propsWithDefault;
36
- const [textWrapperEl, setTextWrapperEl] = React.useState(null);
37
- const [isShowingEllipsis, setIsShowingEllipsis] = React.useState(false);
38
- const resizeObserver = React.useMemo(() => new ResizeObserver(entries => {
39
- if (entries.length) {
40
- const [textWrapperEntry] = entries;
41
- const el = textWrapperEntry.target;
42
- setIsShowingEllipsis((el === null || el === void 0 ? void 0 : el.scrollWidth) > (el === null || el === void 0 ? void 0 : el.clientWidth));
43
- }
44
- }), []);
45
- React.useEffect(() => {
46
- if (textWrapperEl) {
47
- setIsShowingEllipsis((textWrapperEl === null || textWrapperEl === void 0 ? void 0 : textWrapperEl.scrollWidth) > (textWrapperEl === null || textWrapperEl === void 0 ? void 0 : textWrapperEl.clientWidth));
48
- resizeObserver.observe(textWrapperEl);
49
- }
50
-
51
- return () => {
52
- if (textWrapperEl) {
53
- resizeObserver.unobserve(textWrapperEl);
54
- }
55
- };
56
- }, [resizeObserver, textWrapperEl]);
57
- if (isShowingEllipsis) return /*#__PURE__*/jsxRuntime.jsx(dsTooltip.DSTooltipV3, _objectSpread(_objectSpread({
58
- text: text
59
- }, tooltipProps), {}, {
60
- children: /*#__PURE__*/jsxRuntime.jsx(styles.Text, {
61
- ref: setTextWrapperEl,
62
- tabIndex: 0,
63
- "data-testid": DSTruncateTextWIthTooltipDatatestid.DSTruncateTextWithTooltipDatatestid.TEXT,
64
- children: text
65
- })
66
- }));
67
- return /*#__PURE__*/jsxRuntime.jsx(styles.Text, {
68
- ref: setTextWrapperEl,
69
- "data-testid": DSTruncateTextWIthTooltipDatatestid.DSTruncateTextWithTooltipDatatestid.TEXT,
70
- children: text
71
- });
72
- };
73
-
74
- const DSTruncateTextWithTooltipWithSchema = dsPropsHelpers.describe(DSTruncateTextWithTooltip);
75
- DSTruncateTextWithTooltipWithSchema.propTypes = propTypes.propTypes;
76
-
77
- exports.DSTruncateTextWithTooltip = DSTruncateTextWithTooltip;
78
- exports.DSTruncateTextWithTooltipWithSchema = DSTruncateTextWithTooltipWithSchema;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const defaultProps = {
6
- tooltipProps: {}
7
- };
8
-
9
- exports.defaultProps = defaultProps;
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var DSTruncateTextWithTooltip = require('./DSTruncateTextWithTooltip.js');
6
- var DSTruncateTextWIthTooltipDatatestid = require('./DSTruncateTextWIthTooltipDatatestid.js');
7
-
8
-
9
-
10
- exports.DSTruncateTextWithTooltip = DSTruncateTextWithTooltip.DSTruncateTextWithTooltip;
11
- exports.DSTruncateTextWithTooltipWithSchema = DSTruncateTextWithTooltip.DSTruncateTextWithTooltipWithSchema;
12
- exports.DSTruncateTextWithTooltipDatatestid = DSTruncateTextWIthTooltipDatatestid.DSTruncateTextWithTooltipDatatestid;
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var dsPropsHelpers = require('@elliemae/ds-props-helpers');
6
-
7
- /* eslint-disable max-len */
8
- const propTypes = {
9
- text: dsPropsHelpers.PropTypes.string.description('Text to show.').isRequired,
10
- tooltipProps: dsPropsHelpers.PropTypes.object.description('This component uses DSTooltip component, you can set properties directly to this component with this property.').defaultValue({})
11
- };
12
-
13
- exports.propTypes = propTypes;
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var styled = require('styled-components');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
10
-
11
- const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
12
- componentId: "sc-1i0ijyj-0"
13
- })(["text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:inline-block;max-width:100%;&:focus{border:none;outline:none;background:", ";}"], _ref => {
14
- let {
15
- theme
16
- } = _ref;
17
- return theme.colors.brand[200];
18
- });
19
-
20
- exports.Text = Text;
@@ -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,5 +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, DSTruncateTextWithTooltipWithSchema } from './truncateTextWithTooltip/DSTruncateTextWithTooltip.js';
5
- export { DSTruncateTextWithTooltipDatatestid } from './truncateTextWithTooltip/DSTruncateTextWIthTooltipDatatestid.js';
@@ -1,5 +0,0 @@
1
- const DSTruncateTextWithTooltipDatatestid = {
2
- TEXT: 'ds-truncatetextwithtooltip-text'
3
- };
4
-
5
- export { DSTruncateTextWithTooltipDatatestid };
@@ -1,69 +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 { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
11
- import { defaultProps } from './defaultProps.js';
12
- import { DSTruncateTextWithTooltipDatatestid } from './DSTruncateTextWIthTooltipDatatestid.js';
13
- import { propTypes } from './propTypes.js';
14
- import { Text } from './styles.js';
15
- import { jsx } from 'react/jsx-runtime';
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 DSTruncateTextWithTooltip = props => {
22
- const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
23
- useValidateTypescriptPropTypes(propsWithDefault, propTypes);
24
- const {
25
- text,
26
- tooltipProps
27
- } = propsWithDefault;
28
- const [textWrapperEl, setTextWrapperEl] = useState(null);
29
- const [isShowingEllipsis, setIsShowingEllipsis] = useState(false);
30
- const resizeObserver = useMemo(() => new ResizeObserver(entries => {
31
- if (entries.length) {
32
- const [textWrapperEntry] = entries;
33
- const el = textWrapperEntry.target;
34
- setIsShowingEllipsis((el === null || el === void 0 ? void 0 : el.scrollWidth) > (el === null || el === void 0 ? void 0 : el.clientWidth));
35
- }
36
- }), []);
37
- useEffect(() => {
38
- if (textWrapperEl) {
39
- setIsShowingEllipsis((textWrapperEl === null || textWrapperEl === void 0 ? void 0 : textWrapperEl.scrollWidth) > (textWrapperEl === null || textWrapperEl === void 0 ? void 0 : textWrapperEl.clientWidth));
40
- resizeObserver.observe(textWrapperEl);
41
- }
42
-
43
- return () => {
44
- if (textWrapperEl) {
45
- resizeObserver.unobserve(textWrapperEl);
46
- }
47
- };
48
- }, [resizeObserver, textWrapperEl]);
49
- if (isShowingEllipsis) return /*#__PURE__*/jsx(DSTooltipV3, _objectSpread(_objectSpread({
50
- text: text
51
- }, tooltipProps), {}, {
52
- children: /*#__PURE__*/jsx(Text, {
53
- ref: setTextWrapperEl,
54
- tabIndex: 0,
55
- "data-testid": DSTruncateTextWithTooltipDatatestid.TEXT,
56
- children: text
57
- })
58
- }));
59
- return /*#__PURE__*/jsx(Text, {
60
- ref: setTextWrapperEl,
61
- "data-testid": DSTruncateTextWithTooltipDatatestid.TEXT,
62
- children: text
63
- });
64
- };
65
-
66
- const DSTruncateTextWithTooltipWithSchema = describe(DSTruncateTextWithTooltip);
67
- DSTruncateTextWithTooltipWithSchema.propTypes = propTypes;
68
-
69
- export { DSTruncateTextWithTooltip, DSTruncateTextWithTooltipWithSchema };
@@ -1,5 +0,0 @@
1
- const defaultProps = {
2
- tooltipProps: {}
3
- };
4
-
5
- export { defaultProps };
@@ -1,2 +0,0 @@
1
- export { DSTruncateTextWithTooltip, DSTruncateTextWithTooltipWithSchema } from './DSTruncateTextWithTooltip.js';
2
- export { DSTruncateTextWithTooltipDatatestid } from './DSTruncateTextWIthTooltipDatatestid.js';
@@ -1,9 +0,0 @@
1
- import { PropTypes } from '@elliemae/ds-props-helpers';
2
-
3
- /* eslint-disable max-len */
4
- const propTypes = {
5
- text: PropTypes.string.description('Text to show.').isRequired,
6
- tooltipProps: PropTypes.object.description('This component uses DSTooltip component, you can set properties directly to this component with this property.').defaultValue({})
7
- };
8
-
9
- export { propTypes };
@@ -1,12 +0,0 @@
1
- import styled from 'styled-components';
2
-
3
- const Text = /*#__PURE__*/styled.span.withConfig({
4
- componentId: "sc-1i0ijyj-0"
5
- })(["text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:inline-block;max-width:100%;&:focus{border:none;outline:none;background:", ";}"], _ref => {
6
- let {
7
- theme
8
- } = _ref;
9
- return theme.colors.brand[200];
10
- });
11
-
12
- export { Text };
@@ -1,59 +0,0 @@
1
- /// <reference path="../../../../shared/typings/react-desc.d.ts" />
2
- /// <reference types="react" />
3
- declare const DSTruncatedTooltipText: {
4
- ({ containerProps, value, zIndex, ...otherTextProps }: {
5
- [x: string]: any;
6
- containerProps?: {} | undefined;
7
- value?: string | undefined;
8
- zIndex?: number | undefined;
9
- }): string | JSX.Element;
10
- defaultProps: {
11
- value: string;
12
- zIndex: number;
13
- containerProps?: undefined;
14
- tooltipPlacement?: undefined;
15
- tooltipDelay?: undefined;
16
- } | {
17
- containerProps: {};
18
- value: string;
19
- tooltipPlacement: undefined;
20
- tooltipDelay: undefined;
21
- zIndex?: undefined;
22
- };
23
- propTypes: {
24
- containerProps: {
25
- defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
26
- deprecated: import("react-desc").PropTypesDescValidator;
27
- };
28
- isRequired: import("react-desc").PropTypesDescValue;
29
- };
30
- value: {
31
- defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
32
- deprecated: import("react-desc").PropTypesDescValidator;
33
- };
34
- isRequired: import("react-desc").PropTypesDescValue;
35
- };
36
- tooltipPlacement: {
37
- defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
38
- deprecated: import("react-desc").PropTypesDescValidator;
39
- };
40
- isRequired: import("react-desc").PropTypesDescValue;
41
- };
42
- tooltipDelay: {
43
- defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
44
- deprecated: import("react-desc").PropTypesDescValidator;
45
- };
46
- isRequired: import("react-desc").PropTypesDescValue;
47
- };
48
- zIndex: {
49
- deprecated: import("react-desc").PropTypesDescValidator;
50
- };
51
- };
52
- };
53
- declare const TruncatedTooltipTextWithSchema: {
54
- (props?: unknown): JSX.Element;
55
- propTypes: unknown;
56
- toTypescript: () => import("react-desc").TypescriptSchema;
57
- };
58
- export { DSTruncatedTooltipText, TruncatedTooltipTextWithSchema };
59
- export default DSTruncatedTooltipText;
@@ -1,29 +0,0 @@
1
- /// <reference types="react" />
2
- import PropTypes from 'prop-types';
3
- declare const SimpleTruncatedTooltipText: {
4
- (props: any): JSX.Element;
5
- propTypes: {
6
- containerProps: PropTypes.Requireable<object>;
7
- tooltipOptions: PropTypes.Requireable<object>;
8
- textOptions: PropTypes.Requireable<object>;
9
- /** Text that when truncated will trigger the tooltip interaction */
10
- value: PropTypes.Requireable<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
11
- /** Position of the tooltip */
12
- placement: PropTypes.Requireable<string>;
13
- /** Delay to show the tooltip */
14
- tooltipDelay: PropTypes.Requireable<number>;
15
- /** override default zIndex */
16
- zIndex: PropTypes.Requireable<number>;
17
- };
18
- defaultProps: {
19
- containerProps: {};
20
- tooltipOptions: {};
21
- textOptions: {};
22
- value: string;
23
- placement: string;
24
- tooltipDelay: number;
25
- zIndex: number;
26
- };
27
- };
28
- export { SimpleTruncatedTooltipText };
29
- export default SimpleTruncatedTooltipText;