Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ngx-clamp

MSubhan01126ISC1.0.10TypeScript support: included

This library was generated with Angular CLI version 12.2.0.

clamp, ng-clamp, ngx-clamp, html-clamp, line-clamp, text-clamp, angular-clamp

readme

ngx-clamp

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

NPM release version on NPM bundle size license GitHub issues GitHub license npm

It uses clamp.ts library behind the scene to apply the ellipsis.

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

Installation

For Angular 12, use version latest.

You can install ngx-clamp using NPM or Yarn:

npm install ngx-clamp
yarn add ngx-clamp

Usage

You can use it by just adding the directive selector to the element and it will clamp that element's content to two lines. Example:

<p ngx-clamp>
...
</p>

You can also change the options by adding the input of "ngxClampOptions" on the element. Example:

<p ngx-clamp [ngxClampOptions]="{ clamp: 3, // options here, read below for more info }">
...
</p>

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

<p ngx-clamp (ngxClampResponse)="getTooltipContent($event)">
...
</p>

ngxClampOptions

Option Type Default Description
clamp `number string ‘auto’`
useNativeClamp boolean true Enables or disables using the native -webkit-line-clamp in a supported browser (ie. Webkit). It defaults to true if you're using Webkit, but it can behave wonky sometimes so you can set it to false to use the JavaScript-based solution.
truncationChar string The character to insert at the end of the HTML element after truncation is performed. This defaults to an ellipsis (…).
truncationHTML 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.
splitOnChars Array ['.', '-', '–', '—', ' '] Determines what characters to use to chunk an element into smaller pieces. you have an option to pass a list of characters it can use. For example, it you pass an array of ['.', ',', ' '] then it will first remove sentences, then remove comma-phrases, and remove words, and finally remove individual characters to try and find the correct height. This will lead to increased performance and less looping when removing larger pieces of text (such as in paragraphs). The default is set to remove sentences (periods), hypens, en-dashes, em-dashes, and finally words (spaces). Removing by character is always enabled as the last attempt no matter what is submitted in the array.
animate Boolean false Silly little easter-egg that, when set to true, will animate removing individual characters from the end of the element until the content fits. Defaults to false.

(ngxClampResponse)

Option Type Description
original string Original content.
clamped string Clamped content.

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v1.0.10

v1.0.10-beta.6

6 February 2022

  • chore(update): prelease 1.0.10-beta.6 β a7eb42f
  • docs: documentation script fix 98e0c39

v1.0.10-beta.5

6 February 2022

  • chore: disabled steps for Github Pages Publish. 7d56001
  • chore(update): prelease 1.0.10-beta.5 β 14d2b38

v1.0.10-beta.4

6 February 2022

  • chore(update): prelease 1.0.10-beta.4 β f424ed9
  • chore: github action step changed 519deee

v1.0.10-beta.3

6 February 2022

  • chore(update): prelease 1.0.10-beta.3 β d475083
  • fix: beta dist path fix 5f64bb0

v1.0.10-beta.2

6 February 2022

  • chore(update): prelease 1.0.10-beta.0 β 0083d1f
  • chore(update): prelease 1.0.10-10 β 3079c62
  • chore: beta tag added 2e93469

v1.0.10-beta.0

6 February 2022

v1.0.10-10

6 February 2022

  • chore(update): prelease 1.0.10-10 β 3079c62
  • chore: beta tag added 2e93469

v1.0.10-9

6 February 2022

  • fix: test case resolved. bbcd1ae
  • chore(update): prelease 1.0.10-9 β df2d52b
  • chore: stopped "Deploy Github Pages" step. 8de50c9

v1.0.10-8

6 February 2022

  • docs: documentation added. d5cd74b
  • chore(update): prelease 1.0.10-8 β f596a91

v1.0.10-7

4 February 2022

  • chore(update): prelease 1.0.10-7 β 16a3515
  • chore: gpr script fixed da19770

v1.0.10-6

4 February 2022

  • chore: test config fixed 639a041
  • chore(update): prelease 1.0.10-6 β 5c2c57b

v1.0.10-5

4 February 2022

  • chore(update): prelease 1.0.10-5 β c232c9a
  • chore: karma config updated 61dc967

v1.0.10-4

4 February 2022

  • chore(update): prelease 1.0.10-4 β f7ec3a4
  • chore: action directory fixed b9c5f08

v1.0.10-3

4 February 2022

  • chore: adding github action 131c1cd
  • chore(update): prelease 1.0.10-3 β 9bfd488

v1.0.10-2

4 February 2022

  • chore: fixing publish script 5b799c0
  • chore(update): prelease 1.0.10-2 β ffb5d62

v1.0.10-1

4 February 2022

  • chore(update): prelease 1.0.10-1 β 01a2eee

v1.0.10-0

4 February 2022

  • chore(automation): partial initialization 44de37c
  • fix: github action and semantic-release removed from the project 5065238
  • chore(update): prelease 1.0.10-0 β a7df996

v1.0.8

29 January 2022

  • fix: version patch added 1aee19c
  • chore(release): 1.0.6 [skip ci] 2962aa1
  • chore(release): 1.0.8 [skip ci] afff6f4

v1.0.7

29 January 2022

v1.0.6

29 January 2022

v1.0.5

29 January 2022

  • fix(version): git plugin updated ec74bdb

v1.0.4

29 January 2022

  • fix(publish): publish directory for semantic-release/npm changed ba843bc
  • chore(release): 1.0.4 [skip ci] 4277266

v1.0.3

29 January 2022

  • chore(release): 1.0.3 [skip ci] 85478b0
  • fix(action): publish directory updated 859d1bd

v1.0.2

29 January 2022

  • chore(release): 1.0.2 [skip ci] 2612543
  • fix(package.json): build command updated de76257

v1.0.1

29 January 2022

  • chore(release): 1.0.1 [skip ci] 3b69b26
  • fix(package.json): version updated to v1.0.1 05dffd9

v1.0.0

29 January 2022

  • perf(init): initialize 30b83af
  • fix(action): github action updated and dependencies added. 96fcb5e
  • chore(release): 1.0.0 [skip ci] 46e554b