4.1.3 • Published 5 months ago

ngx-ellipsis v4.1.3

Weekly downloads
7,056
License
MIT
Repository
github
Last release
5 months ago

ngx-ellipsis

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

Supports text only (no html contents)!

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-ellipsis --save.

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

import { EllipsisModule } from 'ngx-ellipsis';

// ...

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

Usage

Anywhere in your template:

<div style="width: 100px; height: 100px;" ellipsis>Your very long text</div>

<!-- Or for dynamic content: -->
<div style="width: 100px; height: 100px;" ellipsis [ellipsis-content]="yourDynamicContent"></div>

As you can see, you need to define the dimensions of your element yourself. (ngx-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
ellipsisrequired If you pass an attribute value (e.g. ellipsis=" More ...") you can override the text that will be appended, should it be necessary to truncate the text (default: "...")
ellipsis-contentUse this for dynamic content, that will be subject to asynchronous changes (e.g.: [ellipsis-content]="myVar")
ellipsis-word-boundariesIf 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 ellipsis-word-boundaries=" \n" will allow the text to break at spaces and newlines only
ellipsis-resize-detectionHow resize events should be detected - these are the possible values: element-resize-detector: default Use wnr/element-resize-detector with its scroll strategy. (-> Even when you change the element's width using javascript, the ellipsis will auto-adept)element-resize-detector-object: deprecated Use wnr/element-resize-detector with its object strategywindow: Only check if the whole window has been resized/changed orientation by using angular's built-in HostListener (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="ellipsis" in the template and this.ell.applyEllipsis() in the component code.
ellipsis-click-moreEvent emitter - If set, the text defined by the ellipsis attribute will be converted into a clickable link. For example (ellipsis-click-more)="moreClicked()" will call your component's moreClicked() method when the user clicks on the link.
ellipsis-changeEvent emitter - Will be emitted whenever the ellipsis has been recalculated (depending on ellipsis-resize-detection). If the text had to be truncated the position of the last visible character will be emitted, else null.

Build & publish on npm

In case you want to contribute/fork:

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

Running unit tests

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

Thank you...

License

MIT

4.1.3

5 months ago

4.1.2

12 months ago

4.1.1

1 year ago

4.1.0

2 years ago

4.0.0

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

4 years ago

2.3.2

4 years ago

2.3.0

4 years ago

2.3.1

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.7

6 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago