@deque/cauldron-react 6.2.1-canary.fca8b9e6 → 6.3.0-canary.564cfe71
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type TooltipProps } from '../Tooltip';
|
|
3
|
+
interface TextEllipsisProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
children: string;
|
|
5
|
+
maxLines?: number;
|
|
6
|
+
as?: React.ElementType;
|
|
7
|
+
refProp?: string;
|
|
8
|
+
tooltipProps?: Omit<TooltipProps, 'target' | 'association'>;
|
|
9
|
+
}
|
|
10
|
+
declare const TextEllipsis: React.ForwardRefExoticComponent<TextEllipsisProps & React.RefAttributes<HTMLElement>>;
|
|
11
|
+
export default TextEllipsis;
|
|
@@ -5,7 +5,7 @@ export interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
5
5
|
className?: string;
|
|
6
6
|
target: React.RefObject<HTMLElement> | HTMLElement;
|
|
7
7
|
variant?: 'text' | 'info' | 'big';
|
|
8
|
-
association?: 'aria-labelledby' | 'aria-describedby';
|
|
8
|
+
association?: 'aria-labelledby' | 'aria-describedby' | 'none';
|
|
9
9
|
show?: boolean | undefined;
|
|
10
10
|
placement?: Placement;
|
|
11
11
|
portal?: React.RefObject<HTMLElement> | HTMLElement;
|
package/lib/index.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export { default as Listbox, ListboxOption, ListboxGroup } from './components/Li
|
|
|
55
55
|
export { default as Combobox, ComboboxOption, ComboboxGroup } from './components/Combobox';
|
|
56
56
|
export { default as Popover } from './components/Popover';
|
|
57
57
|
export { default as Timeline, TimelineItem } from './components/Timeline';
|
|
58
|
+
export { default as TextEllipsis } from './components/TextEllipsis';
|
|
58
59
|
/**
|
|
59
60
|
* Helpers / Utils
|
|
60
61
|
*/
|
package/lib/index.js
CHANGED
|
@@ -1659,6 +1659,7 @@ function Tooltip(_a) {
|
|
|
1659
1659
|
var _j = tslib.__read(React.useState(null), 2), targetElement = _j[0], setTargetElement = _j[1];
|
|
1660
1660
|
var _k = tslib.__read(React.useState(null), 2), tooltipElement = _k[0], setTooltipElement = _k[1];
|
|
1661
1661
|
var _l = tslib.__read(React.useState(null), 2), arrowElement = _l[0], setArrowElement = _l[1];
|
|
1662
|
+
var hasAriaAssociation = association !== 'none';
|
|
1662
1663
|
var _m = reactPopper.usePopper(targetElement, tooltipElement, {
|
|
1663
1664
|
placement: initialPlacement,
|
|
1664
1665
|
modifiers: [
|
|
@@ -1760,14 +1761,16 @@ function Tooltip(_a) {
|
|
|
1760
1761
|
}, [tooltipElement, show, hide]);
|
|
1761
1762
|
// Keep the target's id in sync
|
|
1762
1763
|
React.useEffect(function () {
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1764
|
+
if (hasAriaAssociation) {
|
|
1765
|
+
var idRefs = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
|
|
1766
|
+
if (!hasIdRef(idRefs, id)) {
|
|
1767
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, addIdRef(idRefs, id));
|
|
1768
|
+
}
|
|
1766
1769
|
}
|
|
1767
1770
|
return function () {
|
|
1768
|
-
if (targetElement) {
|
|
1769
|
-
var
|
|
1770
|
-
targetElement.setAttribute(association, removeIdRef(
|
|
1771
|
+
if (targetElement && hasAriaAssociation) {
|
|
1772
|
+
var idRefs = targetElement.getAttribute(association);
|
|
1773
|
+
targetElement.setAttribute(association, removeIdRef(idRefs, id));
|
|
1771
1774
|
}
|
|
1772
1775
|
};
|
|
1773
1776
|
}, [targetElement, id, association]);
|
|
@@ -3959,6 +3962,51 @@ function TimelineItem(_a) {
|
|
|
3959
3962
|
React__default["default"].createElement("div", { className: "TimelineItem__details" }, children)));
|
|
3960
3963
|
}
|
|
3961
3964
|
|
|
3965
|
+
var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
|
|
3966
|
+
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"]);
|
|
3967
|
+
var Element = 'div';
|
|
3968
|
+
var sharedRef = useSharedRef(ref);
|
|
3969
|
+
var _b = tslib.__read(React.useState(false), 2), showTooltip = _b[0], setShowTooltip = _b[1];
|
|
3970
|
+
if (as) {
|
|
3971
|
+
Element = as;
|
|
3972
|
+
}
|
|
3973
|
+
else if (showTooltip) {
|
|
3974
|
+
props = Object.assign({
|
|
3975
|
+
role: 'button',
|
|
3976
|
+
'aria-disabled': true,
|
|
3977
|
+
tabIndex: 0
|
|
3978
|
+
}, props);
|
|
3979
|
+
}
|
|
3980
|
+
if (typeof maxLines === 'number') {
|
|
3981
|
+
props.style = tslib.__assign({ WebkitLineClamp: maxLines || 2 }, props.style);
|
|
3982
|
+
}
|
|
3983
|
+
React.useEffect(function () {
|
|
3984
|
+
var listener = function () {
|
|
3985
|
+
requestAnimationFrame(function () {
|
|
3986
|
+
var overflowElement = sharedRef.current;
|
|
3987
|
+
if (!overflowElement) {
|
|
3988
|
+
return;
|
|
3989
|
+
}
|
|
3990
|
+
var hasOverflow = typeof maxLines === 'number'
|
|
3991
|
+
? overflowElement.clientHeight < overflowElement.scrollHeight
|
|
3992
|
+
: overflowElement.clientWidth < overflowElement.scrollWidth;
|
|
3993
|
+
setShowTooltip(hasOverflow);
|
|
3994
|
+
});
|
|
3995
|
+
};
|
|
3996
|
+
var observer = new ResizeObserver(listener);
|
|
3997
|
+
observer.observe(sharedRef.current);
|
|
3998
|
+
return function () {
|
|
3999
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
4000
|
+
};
|
|
4001
|
+
}, []);
|
|
4002
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
4003
|
+
React__default["default"].createElement(Element, tslib.__assign({ className: classNames__default["default"]('TextEllipsis', className, {
|
|
4004
|
+
'TextEllipsis--multiline': !!maxLines
|
|
4005
|
+
}), ref: sharedRef }, props), children),
|
|
4006
|
+
showTooltip && (React__default["default"].createElement(Tooltip, tslib.__assign({ target: sharedRef, association: "none" }, tooltipProps), children))));
|
|
4007
|
+
});
|
|
4008
|
+
TextEllipsis.displayName = 'TextEllipsis';
|
|
4009
|
+
|
|
3962
4010
|
var LIGHT_THEME_CLASS = 'cauldron--theme-light';
|
|
3963
4011
|
var DARK_THEME_CLASS = 'cauldron--theme-dark';
|
|
3964
4012
|
var ThemeContext = React.createContext({
|
|
@@ -4116,6 +4164,7 @@ exports.Tabs = Tabs;
|
|
|
4116
4164
|
exports.Tag = Tag;
|
|
4117
4165
|
exports.TagButton = TagButton;
|
|
4118
4166
|
exports.TagLabel = TagLabel;
|
|
4167
|
+
exports.TextEllipsis = TextEllipsis;
|
|
4119
4168
|
exports.TextField = TextField;
|
|
4120
4169
|
exports.ThemeContext = ThemeContext;
|
|
4121
4170
|
exports.ThemeProvider = ThemeProvider;
|
package/package.json
CHANGED