@deque/cauldron-react 6.15.0-canary.d8a9b670 → 6.15.0-canary.e71ae167
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,11 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type TooltipProps } from '../Tooltip';
|
|
3
3
|
import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
|
|
4
|
-
interface
|
|
4
|
+
interface TextEllipsisBaseProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
|
|
5
5
|
children: string;
|
|
6
6
|
maxLines?: number;
|
|
7
7
|
refProp?: string;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Using this prop may introduce accessibility issues by hiding content from the user.
|
|
10
|
+
* Only use this prop if you have an alternative way to make the full text accessible.
|
|
11
|
+
*/
|
|
12
|
+
hideTooltip?: boolean;
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
interface TextEllipsisWithTooltipProps extends TextEllipsisBaseProps {
|
|
15
|
+
tooltipProps?: Omit<TooltipProps, 'target' | 'association' | 'children'>;
|
|
16
|
+
}
|
|
17
|
+
interface TextEllipsisWithoutTooltipProps extends TextEllipsisBaseProps {
|
|
18
|
+
tooltipProps: never;
|
|
19
|
+
/** Prevent TextEllipsis from showing a tooltip when the text is ellipsized. */
|
|
20
|
+
hideTooltip: true;
|
|
21
|
+
}
|
|
22
|
+
declare const TextEllipsis: PolymorphicComponent<TextEllipsisWithTooltipProps | TextEllipsisWithoutTooltipProps>;
|
|
11
23
|
export default TextEllipsis;
|
package/lib/index.js
CHANGED
|
@@ -4628,10 +4628,11 @@ function TimelineItem(_a) {
|
|
|
4628
4628
|
}
|
|
4629
4629
|
|
|
4630
4630
|
var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
|
|
4631
|
-
var className = _a.className, children = _a.children, maxLines = _a.maxLines, as = _a.as, tooltipProps = _a.tooltipProps, props = tslib.__rest(_a, ["className", "children", "maxLines", "as", "tooltipProps"]);
|
|
4631
|
+
var className = _a.className, children = _a.children, maxLines = _a.maxLines, as = _a.as, tooltipProps = _a.tooltipProps, hideTooltip = _a.hideTooltip, props = tslib.__rest(_a, ["className", "children", "maxLines", "as", "tooltipProps", "hideTooltip"]);
|
|
4632
4632
|
var Element = 'div';
|
|
4633
4633
|
var sharedRef = useSharedRef(ref);
|
|
4634
|
-
var _b = tslib.__read(React.useState(false), 2),
|
|
4634
|
+
var _b = tslib.__read(React.useState(false), 2), hasOverflow = _b[0], setHasOverflow = _b[1];
|
|
4635
|
+
var showTooltip = hasOverflow && !hideTooltip;
|
|
4635
4636
|
if (as) {
|
|
4636
4637
|
Element = as;
|
|
4637
4638
|
}
|
|
@@ -4646,16 +4647,18 @@ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
4646
4647
|
props.style = tslib.__assign({ WebkitLineClamp: maxLines || 2 }, props.style);
|
|
4647
4648
|
}
|
|
4648
4649
|
React.useEffect(function () {
|
|
4650
|
+
if (hideTooltip) {
|
|
4651
|
+
return;
|
|
4652
|
+
}
|
|
4649
4653
|
var listener = function () {
|
|
4650
4654
|
requestAnimationFrame(function () {
|
|
4651
4655
|
var overflowElement = sharedRef.current;
|
|
4652
4656
|
if (!overflowElement) {
|
|
4653
4657
|
return;
|
|
4654
4658
|
}
|
|
4655
|
-
|
|
4659
|
+
setHasOverflow(typeof maxLines === 'number'
|
|
4656
4660
|
? overflowElement.clientHeight < overflowElement.scrollHeight
|
|
4657
|
-
: overflowElement.clientWidth < overflowElement.scrollWidth;
|
|
4658
|
-
setShowTooltip(hasOverflow);
|
|
4661
|
+
: overflowElement.clientWidth < overflowElement.scrollWidth);
|
|
4659
4662
|
});
|
|
4660
4663
|
};
|
|
4661
4664
|
var observer = new ResizeObserver(listener);
|
|
@@ -4663,7 +4666,7 @@ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
4663
4666
|
return function () {
|
|
4664
4667
|
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
4665
4668
|
};
|
|
4666
|
-
}, []);
|
|
4669
|
+
}, [hideTooltip]);
|
|
4667
4670
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
4668
4671
|
React__default["default"].createElement(Element, tslib.__assign({ className: classNames__default["default"]('TextEllipsis', className, {
|
|
4669
4672
|
'TextEllipsis--multiline': !!maxLines
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deque/cauldron-react",
|
|
3
|
-
"version": "6.15.0-canary.
|
|
3
|
+
"version": "6.15.0-canary.e71ae167",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Fully accessible react components library for Deque Cauldron",
|
|
6
6
|
"homepage": "https://cauldron.dequelabs.com/",
|