UNPKG

@sofaws/dapp-core

Version:

A library to hold the main logic for a dapp on the Elrond Network

3 lines (2 loc) 1.23 kB
import{b as s}from"./chunk-MGT45YJE.js";import{m as p}from"./chunk-HBP5N4FR.js";p();import e,{useCallback as h,useEffect as m,useRef as d,useState as g}from"react";import T from"classnames";import w from"lodash.debounce";var C=({text:n,className:f="dapp-trim",dataTestId:l="trim-text-component",color:t})=>{let[o,c]=g(!1),r=d(document==null?void 0:document.createElement("span")),i=d(document==null?void 0:document.createElement("span")),a=h(w(()=>{if(r.current&&i.current){let u=i.current.offsetWidth-r.current.offsetWidth;c(u>1)}},300),[]);return m(()=>(window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)})),m(()=>{a()},[]),e.createElement("span",{ref:r,className:T(s.trim,t!=null?t:"",{[s.overflow]:o},f),"data-testid":l},e.createElement("span",{ref:i,className:s.hiddenTextRef},n),o?e.createElement(e.Fragment,null,e.createElement("span",{className:s.left},e.createElement("span",null,String(n).substring(0,Math.floor(n.length/2)))),e.createElement("span",{className:s.ellipsis},"..."),e.createElement("span",{className:s.right},e.createElement("span",null,String(n).substring(Math.ceil(n.length/2))))):e.createElement("span",null,n))};export{C as a}; //# sourceMappingURL=chunk-PPN7GS3V.js.map