Git Product home page Git Product logo

ngx-clampy's Introduction

ngx-clampy

Angular (2+) directive that clamps the content of an element by adding an ellipsis to it if the content inside is too long.

Build Status GitHub issues GitHub license npm

It uses @clampy-js/clampy library (a fork of Clamp.js) behind the scene to apply the ellipsis.

It automatically re-clamps itself when the element or the browser window change size.

You can also listen to 'originalContent' event which is emitting the original vlue uppon clamping. This can be useful if you want to display the original content in a tooltip for instance. Example:

<p clampy (originalContent)="getTooltipContent($event)">
...
</p>

Options

Option Type Default Description
clampy string auto This controls where and when to clamp the text of an element. Submitting a number controls the number of lines that should be displayed. Second, you can submit a CSS value (in px or em) that controls the height of the element as a String. Finally, you can submit the word 'auto' as a string. Auto will try to fill up the available space with the content and then automatically clamp once content no longer fits.
clampyContent string undefined Sometimes you need to apply an ellipsis on HTML content. The prefered Angular way to usually do this is to bind the HTML content to the innerHTML attribute. However, this directive also modifies the innerHTML property and this may produce unexpected results. To counter this, you can instead bind it to the clampyContent attribute. The content will be automatically sanitized by the directive so that only safe HTML content will be present.
clampyTruncationCharacter string The character to insert at the end of the HTML element after truncation is performed. This defaults to an ellipsis (…).
clampyTruncationHTML string A string of HTML to insert before the truncation character. This is useful if you'd like to add a "Read more" link or some such thing at the end of your clamped node.

Installation

For Angular 2 up to version 6, use version 1.3.x. For angular 7, use version 7.0.x. For angular 8, use version 8.0.x.

You can install @clampy-js/ngx-clampy using NPM or Yarn:

npm install @clampy-js/ngx-clampy
yarn install @clampy-js/ngx-clampy

Note: Starting from version 1.3.0, @clampy-js/ngx-clampy requires the following peer dependencies:

  • @angular/common
  • @angular/core
  • @angular/platform-browser
  • element-resize-detector
  • lodash-es

Simply check the warnings in the console to know which exact versions are required.

ngx-clampy's People

Contributors

alexandremoore avatar

Stargazers

 avatar

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.