Giter Club home page Giter Club logo

react-clamp-lines's Introduction

react-clamp-lines

npm Snyk Vulnerabilities for npm package

Responsive clamping component with «Read more»/«Read less» buttons built for React.

react-clamp-lines

Demo

React Clamp Lines

Install

npm install --save react-clamp-lines

Features

  • built for React with no dependencies
  • option for «Read more» and «Read less» buttons
  • customizable ellipsis text
  • customizable CSS classes
  • responsive
  • window resize event debounced — and why it's important

    If your web app uses JavaScript to accomplish taxing tasks, a debounce function is essential to ensuring a given task doesn't fire so often that it bricks browser performance.

Usage

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import ClampLines from 'react-clamp-lines';

class App extends Component {
  render() {
    return (
      <ClampLines
        text={text_to_clamp}
        lines="4"
        ellipsis="..."
        moreText="Expand"
        lessText="Collapse"
        className="custom-class"
      />
    );
  }
}

ReactDOM.render(<App />, document.getElementById('clamp'));

The component and the or «Read more» button always have the clamp-lines and clamp-lines__button CSS classes respectively. In the example above the custom-class will be added to clamp-lines, so the output will be:

<div class="clamp-lines custom-class">
  <div>clamped text here...</div>
  <button class="clamp-lines__button">Expand</button>
</div>

API

List of all available props with their default values and description.

<ClampLines
  text={String}
  lines={Number}
  ellipsis={String}
  buttons={Boolean}
  moreText={String}
  lessText={String}
  className={String}
  delay={Number}
  stopPropagation={Boolean}
/>
prop type default value description
text {String} Text you wish to clamp
lines {Number} 3 Number of visible lines
ellipsis {String} ... Text content for the ellipsis - will appear after the clamped lines
buttons {Boolean} true The «Read more» and «Read less» buttons
moreText {String} Read more «Read more» button value
lessText {String} Read less «Read less» button value
className {String} CSS class names added to component
delay {Number} 300 Milliseconds, the function is waiting before being triggered, after it stops being called
stopPropagation {Boolean} false Prevents the event from bubbling up the DOM tree when clicked on the «Read more» button

License

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

See Unlicense for full details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.