2.1.4 • Published 4 months ago

ngx-nested-ellipsis v2.1.4

Weekly downloads
431
License
MIT
Repository
github
Last release
4 months ago

ngx-nested-ellipsis

Library for angular (>= 6.0.0) providing a directive to display an ellipsis if the containing text would overflow.

Supports dynamic html contents. (If you require text contents only, you might want to take a look at ngx-ellipsis, which offers better performance, but escapes any html contents to text.)

Demo

For a demo either just checkout this project and run npm install && npm run start or visit the StackBlitz demo page.

Installation

For use in an existing angular project run npm install ngx-nested-ellipsis --save.

Then add the installed module to your app.module.ts:

import { NestedEllipsisModule } from 'ngx-nested-ellipsis';

// ...

@NgModule({
  // ...
  imports: [
    // ...
    NestedEllipsisModule
  ]
  // ...
})
export class AppModule {}

Usage

Anywhere in your template:

<div style="width: 130px; height: 18px;">
  <ng-template [nestedEllipsis]>Your very long <em>rich</em> text</ng-template>
</div>

As you can see, you need to define the dimensions of your element yourself. (ngx-nested-ellipsis doesn't automatically add any element styles.) But of course you don't need to use fixed widths/heights like in these examples. Flex layout shold work just fine for example.

Extra options

You may add the following attributes to change the directive's behavior:

attributemeaning
nestedEllipsisrequired Passing true (default) will perform the directive's task otherwise the template will be rendered without truncating its contents.
nestedEllipsisIndicatorPassing a string (default: '...') will append it when the passed template has been truncated. Passing a template will append that template instead.
nestedEllipsisWordBoundariesIf you pass this attribute, the text won't be truncated at just any character but only at those in the attribute's value. For example nestedEllipsisWordBoundaries=" " will allow the text to break at spaces only
nestedEllipsisMayTruncateAtFnFunction that lets you specify whether the contents may be truncated at a certain point or not. (see callback API)
nestedEllipsisResizeDetectionHow resize events should be detected - these are the possible values: resize-observer: default Use native ResizeObserver or a ponyfill if not implemented by the browser (See Web/API/ResizeObserver and que-etc/resize-observer-polyfill)window: Only listen if the whole window has been resized/changed orientation (Possibly better performance, but obviously won't trigger on resize caused directly or indirectly by javascript.)manual: Ellipsis is never applied automatically. Instead the consuming app may use #ell="ngxNestedEllipsis" in the template and this.ell.applyEllipsis() in the component code.
nestedEllipsisChangeEvent emitter - Will be emitted whenever the ellipsis has been recalculated (depending on nestedEllipsisResizeDetection). If the text had to be truncated the position of the last visible character will be emitted, else null.

nestedEllipsisMayTruncateAtFn API

Callback function parameters:

nametypedescription
nodeCharacterDataText node that is checked for truncation
positionnumberPosition within that text node where the text might be truncated

Return true if truncating at this point in this node should be allowed.

Build & publish on npm

In case you want to contribute/fork:

  1. Run npm install
  2. Adept version and author in ./projects/ngx-nested-ellipsis/package.json and commit the changes to your fork.
  3. Run npm run build-lib which outputs the build to ./dist/ngx-nested-ellipsis.
  4. Copy README.md to ./dist/ngx-nested-ellipsis and modify it accordingly.
  5. Run cd ./dist/ngx-nested-ellipsis && npm publish.

Running unit tests

Run npm run test ngx-nested-ellipsis to execute the unit tests via Karma.

Thank you...

License

MIT

2.1.4

4 months ago

2.1.3

11 months ago

2.1.2

1 year ago

2.1.1

1 year ago

2.0.3

2 years ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.0

4 years ago