All Projects β†’ xiaody β†’ React Lines Ellipsis

xiaody / React Lines Ellipsis

Licence: mit
Simple multiline ellipsis component for React.JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Lines Ellipsis

React New Window
πŸ”² Pop new windows in React, using `window.open`.
Stars: ✭ 281 (-26.63%)
Mutual labels:  react-component
Particles Bg
React particles animation background component
Stars: ✭ 309 (-19.32%)
Mutual labels:  react-component
React Mindmap
React component for MindNode maps
Stars: ✭ 357 (-6.79%)
Mutual labels:  react-component
Formsy React Components
Bootstrap components for a formsy-react form.
Stars: ✭ 290 (-24.28%)
Mutual labels:  react-component
React Js Pagination
Stars: ✭ 308 (-19.58%)
Mutual labels:  react-component
React Router Util
Useful components and utilities for working with React Router
Stars: ✭ 320 (-16.45%)
Mutual labels:  react-component
React Yandex Maps
Yandex Maps API bindings for React
Stars: ✭ 277 (-27.68%)
Mutual labels:  react-component
React Avatar
πŸ‘€ Load, crop & preview avatar with React
Stars: ✭ 361 (-5.74%)
Mutual labels:  react-component
Tween One
Animate One React Element
Stars: ✭ 310 (-19.06%)
Mutual labels:  react-component
React Tabtab
πŸ’ƒ Make your react tab danceπŸ•Ί
Stars: ✭ 347 (-9.4%)
Mutual labels:  react-component
Pigeon Maps
ReactJS Maps without external dependencies
Stars: ✭ 3,198 (+734.99%)
Mutual labels:  react-component
React Snakke
🐍 Reading position indicator for React
Stars: ✭ 306 (-20.1%)
Mutual labels:  react-component
React Tags
βš›οΈ A fantastically simple tagging component for your React projects
Stars: ✭ 321 (-16.19%)
Mutual labels:  react-component
React Horizontal Scrolling Menu
Horizontal scrolling menu component for React.
Stars: ✭ 289 (-24.54%)
Mutual labels:  react-component
React Pro Sidebar
Customizable and responsive react sidebar library with dropdown menus and unlimited number of nested submenus
Stars: ✭ 359 (-6.27%)
Mutual labels:  react-component
React Hotkeys
React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.
Stars: ✭ 279 (-27.15%)
Mutual labels:  react-component
React Native Card Stack Swiper
Tinder like react-native card stack swiper
Stars: ✭ 315 (-17.75%)
Mutual labels:  react-component
React Loader Spinner
Collection set of react-spinner for async operation
Stars: ✭ 378 (-1.31%)
Mutual labels:  react-component
React Joyride
Create guided tours in your apps
Stars: ✭ 4,215 (+1000.52%)
Mutual labels:  react-component
React Hint
Tooltip component for React, Preact, Inferno
Stars: ✭ 338 (-11.75%)
Mutual labels:  react-component

Build Status npm version dependencies Status js-standard-style

react-lines-ellipsis

Poor man's multiline ellipsis component for React.JS https://xiaody.github.io/react-lines-ellipsis/

Installation

To install the stable version:

npm install --save react-lines-ellipsis

Usage

import LinesEllipsis from 'react-lines-ellipsis'

<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/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'
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.

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

<LinesEllipsisLoose
  text='long long text'
  maxLine='2'
  lineHeight='16'
/>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].