@elliemae/ds-truncated-tooltip-text 2.2.0-alpha.3 → 3.0.0-next.0

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