Simple multiline ellipsis component for React.JS
npm install react-lines-ellipsis


Poor man's multiline ellipsis component for React.JS https://xiaody.github.io/react-lines-ellipsis/
To install the stable version:
```
npm install --save react-lines-ellipsis
`jsx
import LinesEllipsis from 'react-lines-ellipsis'
maxLine='3'
ellipsis='...'
trimRight
basedOn='letters'
/>
`
The text you want to clamp.
Max count of lines allowed. Default 1.
Text content of the ellipsis. Default ….
Trim right the clamped text to avoid putting the ellipsis on an empty line. Default true.
Split by letters or words. By default it uses a guess based on your text.
The tagName of the rendered node. Default div.
Callback function invoked when the reflow logic complete.
Type: ({ clamped: boolean, text: string }) => any
`jsx
handleReflow = (rleState) => {
const {
clamped,
text,
} = rleState
// do sth...
}
render() {
const text = 'lorem text'
return (
onReflow={this.handleReflow}
maxLine={3}
/>
)
}
`
Is the text content clamped.
- not clamps text on the server side or with JavaScript disabled
- only accepts plain text by default. Use lib/html.js for experimental rich html support::first-letter
- can be fooled by some special styles: , ligatures, etc.
- requires modern browsers env
Instead of props.text, use props.unsafeHTML to pass your content.
Also, props.ellipsis here only supports plain text,props.ellipsisHTML
use is to fully customize the ellipsis style.
The props.onReflow gives you html instead of text.
props.trimRight is not supported by HTMLEllipsis.
`jsx
import HTMLEllipsis from 'react-lines-ellipsis/lib/html'
maxLine='5'
ellipsis='...'
basedOn='letters'
/>
`
js
import LinesEllipsis from 'react-lines-ellipsis'
import responsiveHOC from 'react-lines-ellipsis/lib/responsiveHOC'const ResponsiveEllipsis = responsiveHOC()(LinesEllipsis)
// then just use ResponsiveEllipsis
`Loose version
This is a non-standardized css-based solution for some webkit-based browsers.
It may have better render performance but also can be fragile.
Be sure to test your use case if you use it.
See https://css-tricks.com/line-clampin/#article-header-id-0 for some introduction.
Also, you may want to star and follow https://crbug.com/305376.
`jsx
import LinesEllipsisLoose from 'react-lines-ellipsis/lib/loose' text='long long text'
maxLine='2'
lineHeight='16'
/>
`Common issues
$3
Chances are your text rendering is unstable. Like you are using a web font whose chars are fatter, or the container width is set dynamically, or some words in the text are set dynamically, etc.
$3
word-break white-space`, etc.Please fill a issue with a stackblitz reproduction link.