You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding ellipses to the end of long text is cool. But not always! Sometimes the
end of the text contains vital information, particularly for URLs or filenames.
This React component is designed with that use case in mind.
Install
yarn add react-middle-ellipsis
Usage
Once imported, you can then wrap any node with <MiddleEllipsis>. This will
compute the width of the surrounding parent node. Then, it will look for the
child node (so make sure to add a span at minimum internally): it will use
this element to compute the width of the child, and then shorten the text
element whose class is ellipseMe (optional) to fit within the parent.
The component re-computes things if the browser window is resized, too!
importReactfrom"react";importMiddleEllipsisfrom"react-middle-ellipsis";constComponent=props=>{return(<><divstyle={{width: "350px",whiteSpace: "nowrap"}}><MiddleEllipsis><span>
I am some long text that should be ellipsed in the middle because
the end contains important stuff.
</span></MiddleEllipsis></div><divstyle={{width: "350px",whiteSpace: "nowrap"}}><MiddleEllipsis><span>
Don't ellipse me.{" "}<spanclassName="ellipseMe">
I am some long text that should be ellipsed in the middle because
the end contains important stuff.
</span></span></MiddleEllipsis></div><>
);
};exportdefaultComponent;
Development
Notes for developing this component.
yarn && yarn run start in this directory and separately also in /example.
This will live reload any changes made in /src.
Change the version number in package.json and npm publish once
complete.Then, go to Github Releases and follow the instructions to publish a
new version there too.