Skip to content

tsung-ju/react-truncate-lines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-truncate-lines

React component for text truncation. Number of lines is measured using Element.getClientRects().

Try it out

Install

npm install react-truncate-lines

Usage

API is similar to react-truncate.

import { TruncateLines } from "react-truncate-lines";

function MyComponent() {
  return (
    <TruncateLines lines={2} ellipsis={<span>...Read More</span>}>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
      veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
      commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
      velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
      cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
      est laborum.
    </TruncateLines>
  );
}

For multiline text use <TruncateLines style={{ whiteSpace: 'pre-line' }}>.

About

React component for text truncation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published