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 (…). |

Installation

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:

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