@elliemae/ds-truncated-tooltip-text 3.37.0-rc.4 → 3.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/SimpleTruncatedTooltipText.js +2 -2
- package/dist/cjs/SimpleTruncatedTooltipText.js.map +2 -2
- package/dist/cjs/truncateTextWithTooltip/react-desc-prop-types.js.map +1 -1
- package/dist/cjs/useCancellableDelayedCallback.js +55 -0
- package/dist/cjs/useCancellableDelayedCallback.js.map +7 -0
- package/dist/esm/SimpleTruncatedTooltipText.js +1 -1
- package/dist/esm/SimpleTruncatedTooltipText.js.map +2 -2
- package/dist/esm/truncateTextWithTooltip/react-desc-prop-types.js.map +1 -1
- package/dist/esm/useCancellableDelayedCallback.js +25 -0
- package/dist/esm/useCancellableDelayedCallback.js.map +7 -0
- package/dist/types/SimpleTruncatedTooltipText.d.ts +1 -1
- package/dist/types/truncateTextWithTooltip/react-desc-prop-types.d.ts +1 -1
- package/dist/types/useCancellableDelayedCallback.d.ts +3 -0
- package/package.json +7 -8
@@ -35,10 +35,10 @@ module.exports = __toCommonJS(SimpleTruncatedTooltipText_exports);
|
|
35
35
|
var React = __toESM(require("react"));
|
36
36
|
var import_jsx_runtime = require("react/jsx-runtime");
|
37
37
|
var import_react = require("react");
|
38
|
-
var import_ds_utilities = require("@elliemae/ds-utilities");
|
39
38
|
var import_prop_types = __toESM(require("prop-types"));
|
40
39
|
var import_ds_system = require("@elliemae/ds-system");
|
41
40
|
var import_ds_popover = require("@elliemae/ds-popover");
|
41
|
+
var import_useCancellableDelayedCallback = require("./useCancellableDelayedCallback.js");
|
42
42
|
const dsTestId = "DS-SimpleTruncateText";
|
43
43
|
const isEllipsisActive = ({ offsetWidth, scrollWidth }) => offsetWidth < scrollWidth;
|
44
44
|
const initialTooltipState = (value = "", options = {}) => ({
|
@@ -69,7 +69,7 @@ const SimpleTruncatedTooltipText = (props) => {
|
|
69
69
|
},
|
70
70
|
[tooltipState]
|
71
71
|
);
|
72
|
-
const [showTooltip, cancelShowTooltip] = (0,
|
72
|
+
const [showTooltip, cancelShowTooltip] = (0, import_useCancellableDelayedCallback.useCancellableDelayedCallback)(show, tooltipDelay);
|
73
73
|
const handleMouseEnter = (0, import_react.useCallback)(
|
74
74
|
(e) => {
|
75
75
|
const { target } = e;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../src/SimpleTruncatedTooltipText.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
4
|
-
"sourcesContent": ["/* eslint-disable max-lines */\nimport React, { useCallback, useContext, useMemo, useState } from 'react';\nimport
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADwFjB;AAvFN,mBAAkE;AAClE,
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\nimport React, { useCallback, useContext, useMemo, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { styled, ThemeContext } from '@elliemae/ds-system';\nimport { DSPopover, PopperPositions as positions } from '@elliemae/ds-popover';\nimport { useCancellableDelayedCallback } from './useCancellableDelayedCallback.js';\n\nconst dsTestId = 'DS-SimpleTruncateText';\n\nconst isEllipsisActive = ({ offsetWidth, scrollWidth }) => offsetWidth < scrollWidth;\n\nconst initialTooltipState = (value = '', options = {}) => ({\n reference: null,\n visible: false,\n value,\n options,\n});\n// reduce the possibility of error showing the tooltip(text-overflow: ellipsis) https://jira.elliemae.io/browse/PUI-1755\nconst Text = styled.span`\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n display: inline-block;\n max-width: 100%;\n`;\n\ninterface SimpleTruncatedTooltipTextProps {\n containerProps?: Record<string, unknown>;\n tooltipDelay?: number;\n placement?: string;\n value?: string | JSX.Element;\n zIndex?: number;\n tooltipOptions?: Record<string, unknown>;\n textOptions?: Record<string, unknown>;\n}\n\nconst SimpleTruncatedTooltipText = (props: SimpleTruncatedTooltipTextProps) => {\n const { containerProps, tooltipDelay, placement, value, zIndex, tooltipOptions, textOptions } = props;\n // not using \"usePopoverProviderState\" because usePopoverState has memory leak issues\n const [tooltipState, setTooltipState] = useState(initialTooltipState(value, tooltipOptions));\n const show = useCallback(\n (newState) => {\n setTooltipState({ ...tooltipState, ...newState, visible: true });\n },\n [tooltipState],\n );\n const hideTooltip = useCallback(\n (newState) => {\n setTooltipState({ ...tooltipState, ...newState, visible: false });\n },\n [tooltipState],\n );\n const [showTooltip, cancelShowTooltip] = useCancellableDelayedCallback(show, tooltipDelay);\n\n const handleMouseEnter = useCallback(\n (e) => {\n const { target } = e;\n // we search for the closest parent with data-testid matching this component\n // this is required because the target may not be this component itself\n // when the user gives JSX as a value.\n // JSX as a value is required for features like text highlight during research\n // wich would still allow the truncation behaviour (see tree view for example)\n // when the target has the test-id itself target===SimpleTruncatedTextEl\n const SimpleTruncatedTextEl = target.closest(`[data-testid=\"${dsTestId}\"]`);\n if (SimpleTruncatedTextEl && isEllipsisActive(SimpleTruncatedTextEl)) {\n showTooltip({ value, reference: SimpleTruncatedTextEl });\n }\n },\n [showTooltip, value],\n );\n\n const handleMouseLeave = useCallback(() => {\n cancelShowTooltip();\n hideTooltip({ reference: null });\n }, [hideTooltip, cancelShowTooltip]);\n\n const handlers = useMemo(() => {\n if (!showTooltip) return {};\n return {\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n };\n }, [showTooltip, handleMouseEnter, handleMouseLeave]);\n\n const theme = useContext(ThemeContext);\n\n const PurePopover = useMemo(\n () => (\n <>\n {tooltipState.visible ? (\n <DSPopover\n boundaries=\"window\"\n style={{ pointerEvents: 'none', zIndex: zIndex ?? theme.zIndex.tooltip }}\n placement={placement}\n content={tooltipState.value}\n referenceEl={tooltipState.reference}\n visible={tooltipState.visible}\n showArrow\n />\n ) : null}\n </>\n ),\n [tooltipState, placement, zIndex],\n );\n const PureText = useMemo(\n () => (\n <>\n <Text\n {...(containerProps && { ...containerProps })}\n {...(textOptions && { ...textOptions })}\n {...(handlers && { ...handlers })}\n data-testid={dsTestId} // this is used by mouse enter too. required to support value as JSX\n >\n {value}\n </Text>\n </>\n ),\n [containerProps, textOptions, handlers, value],\n );\n\n const PureSimpleTruncatedTooltipText = useMemo(\n () => (\n <>\n {PureText}\n {PurePopover}\n </>\n ),\n [PureText, PurePopover],\n );\n\n return PureSimpleTruncatedTooltipText;\n};\n\nSimpleTruncatedTooltipText.propTypes = {\n containerProps: PropTypes.object,\n tooltipOptions: PropTypes.object,\n textOptions: PropTypes.object,\n /** Text that when truncated will trigger the tooltip interaction */\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.node]),\n /** Position of the tooltip */\n placement: PropTypes.oneOf([\n positions.AUTO_START,\n positions.AUTO_END,\n positions.AUTO,\n positions.TOP_START,\n positions.TOP,\n positions.TOP_END,\n positions.RIGHT_START,\n positions.RIGHT,\n positions.RIGHT_END,\n positions.BOTTOM_START,\n positions.BOTTOM,\n positions.BOTTOM_END,\n positions.LEFT_START,\n positions.LEFT,\n positions.LEFT_END,\n ]),\n /** Delay to show the tooltip */\n tooltipDelay: PropTypes.number,\n /** override default zIndex */\n zIndex: PropTypes.number,\n};\n\nSimpleTruncatedTooltipText.defaultProps = {\n containerProps: {},\n tooltipOptions: {},\n textOptions: {},\n value: '',\n placement: positions.TOP,\n tooltipDelay: 200,\n};\n\nexport { SimpleTruncatedTooltipText };\nexport default SimpleTruncatedTooltipText;\n", "import * as React from 'react';\nexport { React };\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADwFjB;AAvFN,mBAAkE;AAClE,wBAAsB;AACtB,uBAAqC;AACrC,wBAAwD;AACxD,2CAA8C;AAE9C,MAAM,WAAW;AAEjB,MAAM,mBAAmB,CAAC,EAAE,aAAa,YAAY,MAAM,cAAc;A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A,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,IACV,kBAAAA,gBAAU;AAAA,EACZ,CAAC;AAAA;AAAA,EAED,cAAc,kBAAAD,QAAU;AAAA;AAAA,EAExB,QAAQ,kBAAAA,QAAU;AACpB;AAEA,2BAA2B,eAAe;AAAA,EACxC,gBAAgB,CAAC;AAAA,EACjB,gBAAgB,CAAC;AAAA,EACjB,aAAa,CAAC;AAAA,EACd,OAAO;AAAA,EACP,WAAW,kBAAAC,gBAAU;AAAA,EACrB,cAAc;AAChB;AAGA,IAAO,qCAAQ;",
|
6
6
|
"names": ["PropTypes", "positions"]
|
7
7
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../src/truncateTextWithTooltip/react-desc-prop-types.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type { WeakValidationMap } from 'react';\nimport type { DSPropTypesSchema } from '@elliemae/ds-
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type { WeakValidationMap } from 'react';\nimport type { DSPropTypesSchema } from '@elliemae/ds-props-helpers';\nimport { PropTypes } from '@elliemae/ds-props-helpers';\n// import type { GlobalAttributesT, XstyledProps } from '@elliemae/ds-props-helpers';\n\nexport declare namespace DSTruncateTextWithTooltipT {\n export interface DefaultProps {\n tooltipProps: Record<string, unknown>;\n }\n export interface OptionalProps {}\n export interface RequiredProps {\n text: string;\n }\n\n export interface Props\n extends Partial<DefaultProps>,\n OptionalProps,\n // Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof OptionalProps | keyof RequiredProps>,\n // XstyledProps,\n RequiredProps {}\n\n export interface InternalProps\n extends DefaultProps,\n OptionalProps,\n // Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof OptionalProps | keyof RequiredProps>,\n // XstyledProps,\n RequiredProps {}\n}\n\nexport const defaultProps: DSTruncateTextWithTooltipT.DefaultProps = {\n tooltipProps: {},\n};\n\nexport const DSTruncateTextWithTooltipPropTypes: DSPropTypesSchema<DSTruncateTextWithTooltipT.Props> = {\n text: PropTypes.string.description('Text to show.').isRequired,\n tooltipProps: PropTypes.object\n .description(\n 'This component uses DSTooltip component, you can set properties directly to this component with this property.',\n )\n .defaultValue({}),\n};\n\nexport const DSTruncateTextWithTooltipPropTypesSchema =\n DSTruncateTextWithTooltipPropTypes as unknown as WeakValidationMap<DSTruncateTextWithTooltipT.Props>;\n", "import * as React from 'react';\nexport { React };\n"],
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,8BAA0B;AA2BnB,MAAM,eAAwD;AAAA,EACnE,cAAc,CAAC;AACjB;AAEO,MAAM,qCAA0F;AAAA,EACrG,MAAM,kCAAU,OAAO,YAAY,eAAe,EAAE;AAAA,EACpD,cAAc,kCAAU,OACrB;AAAA,IACC;AAAA,EACF,EACC,aAAa,CAAC,CAAC;AACpB;AAEO,MAAM,2CACX;",
|
6
6
|
"names": []
|
7
7
|
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var useCancellableDelayedCallback_exports = {};
|
30
|
+
__export(useCancellableDelayedCallback_exports, {
|
31
|
+
default: () => useCancellableDelayedCallback_default,
|
32
|
+
useCancellableDelayedCallback: () => useCancellableDelayedCallback
|
33
|
+
});
|
34
|
+
module.exports = __toCommonJS(useCancellableDelayedCallback_exports);
|
35
|
+
var React = __toESM(require("react"));
|
36
|
+
var import_react = require("react");
|
37
|
+
const useCancellableDelayedCallback = (cb, delay) => {
|
38
|
+
const timeoutRef = (0, import_react.useRef)();
|
39
|
+
const cancel = (0, import_react.useCallback)(() => {
|
40
|
+
const timeoutId = timeoutRef.current;
|
41
|
+
if (timeoutId) {
|
42
|
+
timeoutRef.current = void 0;
|
43
|
+
clearTimeout(timeoutId);
|
44
|
+
}
|
45
|
+
}, [timeoutRef]);
|
46
|
+
const delayedCb = (0, import_react.useCallback)(
|
47
|
+
(...args) => {
|
48
|
+
timeoutRef.current = setTimeout(() => cb(...args), delay);
|
49
|
+
},
|
50
|
+
[cb, delay]
|
51
|
+
);
|
52
|
+
return [delayedCb, cancel];
|
53
|
+
};
|
54
|
+
var useCancellableDelayedCallback_default = useCancellableDelayedCallback;
|
55
|
+
//# sourceMappingURL=useCancellableDelayedCallback.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../../src/useCancellableDelayedCallback.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
4
|
+
"sourcesContent": ["import { useCallback, useRef } from 'react';\n\ntype Callback = (...args: unknown[]) => unknown;\n\nexport const useCancellableDelayedCallback = (cb: Callback, delay: number) => {\n const timeoutRef = useRef<NodeJS.Timeout>();\n const cancel = useCallback(() => {\n const timeoutId = timeoutRef.current;\n if (timeoutId) {\n timeoutRef.current = undefined;\n clearTimeout(timeoutId);\n }\n }, [timeoutRef]);\n const delayedCb: Callback = useCallback(\n (...args) => {\n timeoutRef.current = setTimeout(() => cb(...args), delay);\n },\n [cb, delay],\n );\n\n return [delayedCb, cancel];\n};\n\nexport default useCancellableDelayedCallback;\n", "import * as React from 'react';\nexport { React };\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAoC;AAI7B,MAAM,gCAAgC,CAAC,IAAc,UAAkB;AAC5E,QAAM,iBAAa,qBAAuB;AAC1C,QAAM,aAAS,0BAAY,MAAM;AAC/B,UAAM,YAAY,WAAW;AAC7B,QAAI,WAAW;AACb,iBAAW,UAAU;AACrB,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AACf,QAAM,gBAAsB;AAAA,IAC1B,IAAI,SAAS;AACX,iBAAW,UAAU,WAAW,MAAM,GAAG,GAAG,IAAI,GAAG,KAAK;AAAA,IAC1D;AAAA,IACA,CAAC,IAAI,KAAK;AAAA,EACZ;AAEA,SAAO,CAAC,WAAW,MAAM;AAC3B;AAEA,IAAO,wCAAQ;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import * as React from "react";
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
3
3
|
import { useCallback, useContext, useMemo, useState } from "react";
|
4
|
-
import { useCancellableDelayedCallback } from "@elliemae/ds-utilities";
|
5
4
|
import PropTypes from "prop-types";
|
6
5
|
import { styled, ThemeContext } from "@elliemae/ds-system";
|
7
6
|
import { DSPopover, PopperPositions as positions } from "@elliemae/ds-popover";
|
7
|
+
import { useCancellableDelayedCallback } from "./useCancellableDelayedCallback.js";
|
8
8
|
const dsTestId = "DS-SimpleTruncateText";
|
9
9
|
const isEllipsisActive = ({ offsetWidth, scrollWidth }) => offsetWidth < scrollWidth;
|
10
10
|
const initialTooltipState = (value = "", options = {}) => ({
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/SimpleTruncatedTooltipText.tsx"],
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport React, { useCallback, useContext, useMemo, useState } from 'react';\nimport
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACwFjB,mBAEI,KAgCJ,YAlCA;AAvFN,SAAgB,aAAa,YAAY,SAAS,gBAAgB;AAClE,
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport React, { useCallback, useContext, useMemo, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { styled, ThemeContext } from '@elliemae/ds-system';\nimport { DSPopover, PopperPositions as positions } from '@elliemae/ds-popover';\nimport { useCancellableDelayedCallback } from './useCancellableDelayedCallback.js';\n\nconst dsTestId = 'DS-SimpleTruncateText';\n\nconst isEllipsisActive = ({ offsetWidth, scrollWidth }) => offsetWidth < scrollWidth;\n\nconst initialTooltipState = (value = '', options = {}) => ({\n reference: null,\n visible: false,\n value,\n options,\n});\n// reduce the possibility of error showing the tooltip(text-overflow: ellipsis) https://jira.elliemae.io/browse/PUI-1755\nconst Text = styled.span`\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n display: inline-block;\n max-width: 100%;\n`;\n\ninterface SimpleTruncatedTooltipTextProps {\n containerProps?: Record<string, unknown>;\n tooltipDelay?: number;\n placement?: string;\n value?: string | JSX.Element;\n zIndex?: number;\n tooltipOptions?: Record<string, unknown>;\n textOptions?: Record<string, unknown>;\n}\n\nconst SimpleTruncatedTooltipText = (props: SimpleTruncatedTooltipTextProps) => {\n const { containerProps, tooltipDelay, placement, value, zIndex, tooltipOptions, textOptions } = props;\n // not using \"usePopoverProviderState\" because usePopoverState has memory leak issues\n const [tooltipState, setTooltipState] = useState(initialTooltipState(value, tooltipOptions));\n const show = useCallback(\n (newState) => {\n setTooltipState({ ...tooltipState, ...newState, visible: true });\n },\n [tooltipState],\n );\n const hideTooltip = useCallback(\n (newState) => {\n setTooltipState({ ...tooltipState, ...newState, visible: false });\n },\n [tooltipState],\n );\n const [showTooltip, cancelShowTooltip] = useCancellableDelayedCallback(show, tooltipDelay);\n\n const handleMouseEnter = useCallback(\n (e) => {\n const { target } = e;\n // we search for the closest parent with data-testid matching this component\n // this is required because the target may not be this component itself\n // when the user gives JSX as a value.\n // JSX as a value is required for features like text highlight during research\n // wich would still allow the truncation behaviour (see tree view for example)\n // when the target has the test-id itself target===SimpleTruncatedTextEl\n const SimpleTruncatedTextEl = target.closest(`[data-testid=\"${dsTestId}\"]`);\n if (SimpleTruncatedTextEl && isEllipsisActive(SimpleTruncatedTextEl)) {\n showTooltip({ value, reference: SimpleTruncatedTextEl });\n }\n },\n [showTooltip, value],\n );\n\n const handleMouseLeave = useCallback(() => {\n cancelShowTooltip();\n hideTooltip({ reference: null });\n }, [hideTooltip, cancelShowTooltip]);\n\n const handlers = useMemo(() => {\n if (!showTooltip) return {};\n return {\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n };\n }, [showTooltip, handleMouseEnter, handleMouseLeave]);\n\n const theme = useContext(ThemeContext);\n\n const PurePopover = useMemo(\n () => (\n <>\n {tooltipState.visible ? (\n <DSPopover\n boundaries=\"window\"\n style={{ pointerEvents: 'none', zIndex: zIndex ?? theme.zIndex.tooltip }}\n placement={placement}\n content={tooltipState.value}\n referenceEl={tooltipState.reference}\n visible={tooltipState.visible}\n showArrow\n />\n ) : null}\n </>\n ),\n [tooltipState, placement, zIndex],\n );\n const PureText = useMemo(\n () => (\n <>\n <Text\n {...(containerProps && { ...containerProps })}\n {...(textOptions && { ...textOptions })}\n {...(handlers && { ...handlers })}\n data-testid={dsTestId} // this is used by mouse enter too. required to support value as JSX\n >\n {value}\n </Text>\n </>\n ),\n [containerProps, textOptions, handlers, value],\n );\n\n const PureSimpleTruncatedTooltipText = useMemo(\n () => (\n <>\n {PureText}\n {PurePopover}\n </>\n ),\n [PureText, PurePopover],\n );\n\n return PureSimpleTruncatedTooltipText;\n};\n\nSimpleTruncatedTooltipText.propTypes = {\n containerProps: PropTypes.object,\n tooltipOptions: PropTypes.object,\n textOptions: PropTypes.object,\n /** Text that when truncated will trigger the tooltip interaction */\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.node]),\n /** Position of the tooltip */\n placement: PropTypes.oneOf([\n positions.AUTO_START,\n positions.AUTO_END,\n positions.AUTO,\n positions.TOP_START,\n positions.TOP,\n positions.TOP_END,\n positions.RIGHT_START,\n positions.RIGHT,\n positions.RIGHT_END,\n positions.BOTTOM_START,\n positions.BOTTOM,\n positions.BOTTOM_END,\n positions.LEFT_START,\n positions.LEFT,\n positions.LEFT_END,\n ]),\n /** Delay to show the tooltip */\n tooltipDelay: PropTypes.number,\n /** override default zIndex */\n zIndex: PropTypes.number,\n};\n\nSimpleTruncatedTooltipText.defaultProps = {\n containerProps: {},\n tooltipOptions: {},\n textOptions: {},\n value: '',\n placement: positions.TOP,\n tooltipDelay: 200,\n};\n\nexport { SimpleTruncatedTooltipText };\nexport default SimpleTruncatedTooltipText;\n"],
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACwFjB,mBAEI,KAgCJ,YAlCA;AAvFN,SAAgB,aAAa,YAAY,SAAS,gBAAgB;AAClE,OAAO,eAAe;AACtB,SAAS,QAAQ,oBAAoB;AACrC,SAAS,WAAW,mBAAmB,iBAAiB;AACxD,SAAS,qCAAqC;AAE9C,MAAM,WAAW;AAEjB,MAAM,mBAAmB,CAAC,EAAE,aAAa,YAAY,MAAM,cAAc;AAEzE,MAAM,sBAAsB,CAAC,QAAQ,IAAI,UAAU,CAAC,OAAO;AAAA,EACzD,WAAW;AAAA,EACX,SAAS;AAAA,EACT;AAAA,EACA;AACF;AAEA,MAAM,OAAO,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBpB,MAAM,6BAA6B,CAAC,UAA2C;AAC7E,QAAM,EAAE,gBAAgB,cAAc,WAAW,OAAO,QAAQ,gBAAgB,YAAY,IAAI;AAEhG,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,oBAAoB,OAAO,cAAc,CAAC;AAC3F,QAAM,OAAO;AAAA,IACX,CAAC,aAAa;AACZ,sBAAgB,EAAE,GAAG,cAAc,GAAG,UAAU,SAAS,KAAK,CAAC;AAAA,IACjE;AAAA,IACA,CAAC,YAAY;AAAA,EACf;AACA,QAAM,cAAc;AAAA,IAClB,CAAC,aAAa;AACZ,sBAAgB,EAAE,GAAG,cAAc,GAAG,UAAU,SAAS,MAAM,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,YAAY;AAAA,EACf;AACA,QAAM,CAAC,aAAa,iBAAiB,IAAI,8BAA8B,MAAM,YA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AAa,UAAU,KAAK;AAAA,EAC/C;AAEA,QAAM,iCAAiC;AAAA,IACrC,MACE,iCACG;AAAA;AAAA,MACA;AAAA,OACH;AAAA,IAEF,CAAC,UAAU,WAAW;AAAA,EACxB;AAEA,SAAO;AACT;AAEA,2BAA2B,YAAY;AAAA,EACrC,gBAAgB,UAAU;AAAA,EAC1B,gBAAgB,UAAU;AAAA,EAC1B,aAAa,UAAU;AAAA;AAAA,EAEvB,OAAO,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,QAAQ,UAAU,IAAI,CAAC;AAAA;AAAA,EAE/E,WAAW,UAAU,MAAM;AAAA,IACzB,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,EACZ,CAAC;AAAA;AAAA,EAED,cAAc,UAAU;AAAA;AAAA,EAExB,QAAQ,UAAU;AACpB;AAEA,2BAA2B,eAAe;AAAA,EACxC,gBAAgB,CAAC;AAAA,EACjB,gBAAgB,CAAC;AAAA,EACjB,aAAa,CAAC;AAAA,EACd,OAAO;AAAA,EACP,WAAW,UAAU;AAAA,EACrB,cAAc;AAChB;AAGA,IAAO,qCAAQ;",
|
6
6
|
"names": []
|
7
7
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/truncateTextWithTooltip/react-desc-prop-types.tsx"],
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type { WeakValidationMap } from 'react';\nimport type { DSPropTypesSchema } from '@elliemae/ds-
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type { WeakValidationMap } from 'react';\nimport type { DSPropTypesSchema } from '@elliemae/ds-props-helpers';\nimport { PropTypes } from '@elliemae/ds-props-helpers';\n// import type { GlobalAttributesT, XstyledProps } from '@elliemae/ds-props-helpers';\n\nexport declare namespace DSTruncateTextWithTooltipT {\n export interface DefaultProps {\n tooltipProps: Record<string, unknown>;\n }\n export interface OptionalProps {}\n export interface RequiredProps {\n text: string;\n }\n\n export interface Props\n extends Partial<DefaultProps>,\n OptionalProps,\n // Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof OptionalProps | keyof RequiredProps>,\n // XstyledProps,\n RequiredProps {}\n\n export interface InternalProps\n extends DefaultProps,\n OptionalProps,\n // Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof OptionalProps | keyof RequiredProps>,\n // XstyledProps,\n RequiredProps {}\n}\n\nexport const defaultProps: DSTruncateTextWithTooltipT.DefaultProps = {\n tooltipProps: {},\n};\n\nexport const DSTruncateTextWithTooltipPropTypes: DSPropTypesSchema<DSTruncateTextWithTooltipT.Props> = {\n text: PropTypes.string.description('Text to show.').isRequired,\n tooltipProps: PropTypes.object\n .description(\n 'This component uses DSTooltip component, you can set properties directly to this component with this property.',\n )\n .defaultValue({}),\n};\n\nexport const DSTruncateTextWithTooltipPropTypesSchema =\n DSTruncateTextWithTooltipPropTypes as unknown as WeakValidationMap<DSTruncateTextWithTooltipT.Props>;\n"],
|
5
5
|
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,iBAAiB;AA2BnB,MAAM,eAAwD;AAAA,EACnE,cAAc,CAAC;AACjB;AAEO,MAAM,qCAA0F;AAAA,EACrG,MAAM,UAAU,OAAO,YAAY,eAAe,EAAE;AAAA,EACpD,cAAc,UAAU,OACrB;AAAA,IACC;AAAA,EACF,EACC,aAAa,CAAC,CAAC;AACpB;AAEO,MAAM,2CACX;",
|
6
6
|
"names": []
|
7
7
|
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import * as React from "react";
|
2
|
+
import { useCallback, useRef } from "react";
|
3
|
+
const useCancellableDelayedCallback = (cb, delay) => {
|
4
|
+
const timeoutRef = useRef();
|
5
|
+
const cancel = useCallback(() => {
|
6
|
+
const timeoutId = timeoutRef.current;
|
7
|
+
if (timeoutId) {
|
8
|
+
timeoutRef.current = void 0;
|
9
|
+
clearTimeout(timeoutId);
|
10
|
+
}
|
11
|
+
}, [timeoutRef]);
|
12
|
+
const delayedCb = useCallback(
|
13
|
+
(...args) => {
|
14
|
+
timeoutRef.current = setTimeout(() => cb(...args), delay);
|
15
|
+
},
|
16
|
+
[cb, delay]
|
17
|
+
);
|
18
|
+
return [delayedCb, cancel];
|
19
|
+
};
|
20
|
+
var useCancellableDelayedCallback_default = useCancellableDelayedCallback;
|
21
|
+
export {
|
22
|
+
useCancellableDelayedCallback_default as default,
|
23
|
+
useCancellableDelayedCallback
|
24
|
+
};
|
25
|
+
//# sourceMappingURL=useCancellableDelayedCallback.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/useCancellableDelayedCallback.ts"],
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useRef } from 'react';\n\ntype Callback = (...args: unknown[]) => unknown;\n\nexport const useCancellableDelayedCallback = (cb: Callback, delay: number) => {\n const timeoutRef = useRef<NodeJS.Timeout>();\n const cancel = useCallback(() => {\n const timeoutId = timeoutRef.current;\n if (timeoutId) {\n timeoutRef.current = undefined;\n clearTimeout(timeoutId);\n }\n }, [timeoutRef]);\n const delayedCb: Callback = useCallback(\n (...args) => {\n timeoutRef.current = setTimeout(() => cb(...args), delay);\n },\n [cb, delay],\n );\n\n return [delayedCb, cancel];\n};\n\nexport default useCancellableDelayedCallback;\n"],
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,cAAc;AAI7B,MAAM,gCAAgC,CAAC,IAAc,UAAkB;AAC5E,QAAM,aAAa,OAAuB;AAC1C,QAAM,SAAS,YAAY,MAAM;AAC/B,UAAM,YAAY,WAAW;AAC7B,QAAI,WAAW;AACb,iBAAW,UAAU;AACrB,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AACf,QAAM,YAAsB;AAAA,IAC1B,IAAI,SAAS;AACX,iBAAW,UAAU,WAAW,MAAM,GAAG,GAAG,IAAI,GAAG,KAAK;AAAA,IAC1D;AAAA,IACA,CAAC,IAAI,KAAK;AAAA,EACZ;AAEA,SAAO,CAAC,WAAW,MAAM;AAC3B;AAEA,IAAO,wCAAQ;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -10,7 +10,7 @@ interface SimpleTruncatedTooltipTextProps {
|
|
10
10
|
textOptions?: Record<string, unknown>;
|
11
11
|
}
|
12
12
|
declare const SimpleTruncatedTooltipText: {
|
13
|
-
(props: SimpleTruncatedTooltipTextProps): import("react/jsx-runtime").JSX.Element;
|
13
|
+
(props: SimpleTruncatedTooltipTextProps): import("react/jsx-runtime.js").JSX.Element;
|
14
14
|
propTypes: {
|
15
15
|
containerProps: PropTypes.Requireable<object>;
|
16
16
|
tooltipOptions: PropTypes.Requireable<object>;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { WeakValidationMap } from 'react';
|
2
|
-
import type { DSPropTypesSchema } from '@elliemae/ds-
|
2
|
+
import type { DSPropTypesSchema } from '@elliemae/ds-props-helpers';
|
3
3
|
export declare namespace DSTruncateTextWithTooltipT {
|
4
4
|
interface DefaultProps {
|
5
5
|
tooltipProps: Record<string, unknown>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@elliemae/ds-truncated-tooltip-text",
|
3
|
-
"version": "3.37.0
|
3
|
+
"version": "3.37.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "ICE MT - Dimsum - Truncated Tooltip Text",
|
6
6
|
"files": [
|
@@ -37,17 +37,16 @@
|
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
39
|
"prop-types": "~15.8.1",
|
40
|
-
"@elliemae/ds-
|
41
|
-
"@elliemae/ds-
|
42
|
-
"@elliemae/ds-system": "3.37.0
|
43
|
-
"@elliemae/ds-tooltip": "3.37.0
|
44
|
-
"@elliemae/ds-
|
45
|
-
"@elliemae/ds-popover": "3.37.0-rc.4"
|
40
|
+
"@elliemae/ds-popover": "3.37.0",
|
41
|
+
"@elliemae/ds-popper": "3.37.0",
|
42
|
+
"@elliemae/ds-system": "3.37.0",
|
43
|
+
"@elliemae/ds-tooltip": "3.37.0",
|
44
|
+
"@elliemae/ds-props-helpers": "3.37.0"
|
46
45
|
},
|
47
46
|
"devDependencies": {
|
48
47
|
"@elliemae/pui-cli": "9.0.0-next.50",
|
49
48
|
"styled-components": "~5.3.9",
|
50
|
-
"@elliemae/ds-monorepo-devops": "3.37.0
|
49
|
+
"@elliemae/ds-monorepo-devops": "3.37.0"
|
51
50
|
},
|
52
51
|
"peerDependencies": {
|
53
52
|
"react": "^17.0.2",
|