UNPKG

rc-tc-ifn

Version:

React component that truncates text with ellipsis and shows tooltip only when content overflows.

3 lines (2 loc) 2.25 kB
import e,{useState as r,useLayoutEffect as t,useRef as n,isValidElement as o,cloneElement as a}from"react";import{Tooltip as i}from"react-tooltip-z";import c from"joinclass";import{createStyleEngine as s,createDOMSheet as l}from"rsx-z";var u=function(){return u=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},u.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var p=s(l()),f=p.style({display:"inline-block",whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden"});function d(e){return p.style({display:"inline-block",width:e})}function m(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return function(r){e.forEach(function(e){"function"==typeof e?e(r):e&&(e.current=r)})}}function v(s){var l=s.children,p=s.content,m=s.width,v=s.wrapperWidth,y=s.tagTruncate,h=s.truncateClassName,w=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}(s,["children","content","width","wrapperWidth","tagTruncate","truncateClassName"]),O=n(null),b=function(e){var n=r(!1),o=n[0],a=n[1];return t(function(){var r=e.current;if(r){var t=function(){a(r.scrollWidth>r.clientWidth)};if(t(),"undefined"!=typeof ResizeObserver){var n=new ResizeObserver(t);return n.observe(r),function(){return n.disconnect()}}return window.addEventListener("resize",t),function(){window.removeEventListener("resize",t)}}},[e]),o}(O),g=r(!1),E=g[0],N=g[1],j=u({},m?{width:m}:{});var z=e.Children.toArray(l)[0],x=y||"span",S=o(z)?a(z,{ref:O,className:c(z.props.className,h,f),style:u(u({},j),z.props.style)}):e.createElement(x,{ref:O,className:c(h,f),style:j},l);return e.createElement(i,u({},w,{tagName:w.tagName||"span",className:c(w.className,d(v)),content:null!=p?p:l,trigger:"manual",open:E,onMouseEnter:function(){b&&N(!0)},onMouseLeave:function(){N(!1)}}),S)}export{v as TooltipIfn,v as default,m as mergeRefs}; //# sourceMappingURL=index.esm.js.map