npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-lines-ellipsis-observer

v0.15.4

Published

Simple multiline ellipsis component for React.JS (With Observer)

Downloads

12

Readme

Build Status npm version js-standard-style

react-lines-ellipsis-observer

Fork with some improvements of Xiaody multiline ellipsis component for React.JS https://github.com/xiaody/react-lines-ellipsis

Installation

To install the stable version:

npm install --save react-lines-ellipsis-observer

Usage

import LinesEllipsis from 'react-lines-ellipsis-observer'

<LinesEllipsis
  text='long long text'
  maxLine='3'
  ellipsis='...'
  trimRight
  basedOn='letters'
/>

Options

props.text {String}

The text you want to clamp.

props.maxLine {Number|String}

Max count of lines allowed. Default 1.

props.ellipsis {Node}

Text content of the ellipsis. Default .

props.trimRight {Boolean}

Trim right the clamped text to avoid putting the ellipsis on an empty line. Default true.

props.basedOn {String}

Split by letters or words. By default it uses a guess based on your text.

props.component {String}

The tagName of the rendered node. Default div.

props.onReflow {Function} (version >= 0.13.0)

Callback function invoked when the reflow logic complete.

Type: ({ clamped: boolean, text: string }) => any

  handleReflow = (rleState) => {
    const {
      clamped,
      text,
    } = rleState
    // do sth...
  }

  render() {
    const text = 'lorem text'
    return (
      <LinesEllipsis
        text={text}
        onReflow={this.handleReflow}
        maxLine={3}
      />
    )
  }

Methods

isClamped() {Boolean}

Is the text content clamped.

Limitations

  • 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
  • can be fooled by some special styles: ::first-letter, ligatures, etc.
  • requires modern browsers env

Experimental html truncation

Instead of props.text, use props.unsafeHTML to pass your content.

Also, props.ellipsis here only supports plain text, use props.ellipsisHTML is to fully customize the ellipsis style.

The props.onReflow gives you html instead of text.

props.trimRight is not supported by HTMLEllipsis.

import HTMLEllipsis from 'react-lines-ellipsis-observer/lib/html'

<HTMLEllipsis
  unsafeHTML='simple html content'
  maxLine='5'
  ellipsis='...'
  basedOn='letters'
/>

Responsive to window resize and orientation change

import LinesEllipsis from 'react-lines-ellipsis-observer'
import responsiveHOC from 'react-lines-ellipsis-observer/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.

import LinesEllipsisLoose from 'react-lines-ellipsis-observer/lib/loose'

<LinesEllipsisLoose
  text='long long text'
  maxLine='2'
  lineHeight='16'
/>