# ngx-pops

> [![npm version](https://badge.fury.io/js/ngx-pops.png)](https://badge.fury.io/js/ngx-pops)

Latest version **0.1.10** (published 2020-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-pops
pnpm add ngx-pops
yarn add ngx-pops
bun add ngx-pops
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.10 |
| Published | 2020-04-14 |
| First published | 2019-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 247.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Friso Hoekstra |
| Maintainers | frisohoekstra |
| Keywords | angular, dynamic, components, notifications, popup, dialog, typescript |

## Links

- npm: https://www.npmjs.com/package/ngx-pops
- Repository: https://github.com/fripso/ngx-pops
- Homepage: https://github.com/fripso/ngx-pops#readme
- Issues: https://github.com/fripso/ngx-pops/issues
- npm.io page: https://npm.io/package/ngx-pops

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [post-robot](https://npm.io/package/post-robot.md) — 93.7K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads

## Recent versions

- 0.1.10 (latest) — 2020-04-14
- 0.1.9 — 2019-07-14
- 0.1.8 — 2019-07-04
- 0.1.7 — 2019-07-04
- 0.1.6 — 2019-07-04
- 0.1.5 — 2019-07-04
- 0.1.4 — 2019-07-04
- 0.1.3 — 2019-07-04
- 0.1.2 — 2019-06-28
- 0.1.1 — 2019-06-15
- 0.1.0 — 2019-06-14
- 0.0.1 — 2019-06-14

## README

# ngx-pops
[![npm version](https://badge.fury.io/js/ngx-pops.png)](https://badge.fury.io/js/ngx-pops)

`ngx-pops` is a framework for easily rendering your own dynamic components (for example notifications) using `ComponentFactoryResolver` and component class inheritance.

##### Demo: [Link](https://ngx-pops.friso.app)


## Installation

Install the module:

    npm i ngx-pops

Import the module:

    // app.module.ts
    
    import { NgxPopsModule } from 'ngx-pops';
    
Import components to render:
  
    import { BalloonComponent } from './balloon.component';

Add both to declarations and imports:

    @NgModule({    
        declarations: [BalloonComponent],    
        imports: [
            NgxPopsModule.withComponents([
                BalloonComponent
            ])
        ]
    })

Create a component to render:    

    // balloon.component.ts
    
    import { Component, Input, OnInit } from '@angular/core';
    import { PopComponent } from 'ngx-pops';
        
    @Component({    
        template: `    
            <div class="balloon" (click)="needle()">
                {{ id }}
                {{ data.message }}
            </div>    
        `    
    })    

    export class BalloonComponent extends PopComponent implements OnInit {  
                        
        constructor() {    
            super();
        }
        
        ngOnInit() {
            // optional: enable automatic destruction
            super.autoHide();
        }
       
        needle() {
            // manually destroy component
            super.destroyComponent();
        }
    }
    

Inside the container component:

    // container.component.ts
    
    import { Component } from  '@angular/core';
    import { PopsService } from  'ngx-pops';    
    import { BalloonComponent } from  './balloon.component';

    @Component({    
        selector: 'my-container',    
        template: `    
            <button (click)="pops.doPop(balloonComponent, { message: 'I am a balloon' })">
                Balloon
            </button>
            <pops-container [duration]="3000"></pops-container>
        `    
    })

    export class ContainerComponent {
    
        balloonComponent = BalloonComponent;
        
        constructor(public pops: PopsService) {}	
            
    }


## API

#### PopService

`doPop(component, data, target): void` 
- `function` Creates a new component to be rendered inside container. Takes a component class, a data object to bind to the component instance, and an optional target to specify in which container to render the new component.

`getPopStream():  Observable<Pop>`
- `function` Returns an observable stream of the latest pop created.

`clearPops():  void`
- `Function` Destroys all components in the view.

`getFnEventStream():  Observable<string>`
- `function` Returns observable stream of function events.

#### PopComponent
This class is accessible through super() when using component inheritance, e.g.:

    export class MyComponent extends PopComponent {
    
        constructor() {
            super();
        }
        
        log() {
            console.log(super.data);
        }
    
    }


 `data`
 -  `any` Data object to bind to the component instance. Defaults to `undefined`

`setDuration(ms): void` 
- `function` Set component lifetime in ms (defaults to 3000). Used by autoHide() as a default value. Can be manipulated globally using the `[duration]` input on the PopsContainer, or locally using setDuration(), in which case make sure you set this value before you call `super.autoHide()`.
 
`autoHide(duration):  void`
- `function` Triggers a timer that will complete and then trigger destroyComponent() after specified duration. Defaults to global duration.

`setBeforeDestroy(func: () =>  Promise<void>):  void`
- `function` Sets value of beforeDestroyFunction. Takes a Promise-returning function to perform logic before the component is destroyed. Useful for performing UI logic (e.g. css animations) that needs to be executed before the component is removed from the DOM.

`destroyComponent():  void`
- `function` Triggers component destruction. If `beforeDestroyFunction()` is specified, it will call that function and wait for the promise to resolve before triggering the `destroy` event.

`destroy`
- `Output: EventEmitter<any>` The destroy event emits after beforeDestroyFunction() resolves (if it exists) and triggers destruction of the component

#### PopContainer

`duration` 
- `number` Optional: Globally set time in ms after which autoHide() completes
- `containerLabel` Optional: Set unique container label to use multiple containers in conjunction with each other. Defaults to 'default'

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

---
_Source: https://npm.io/package/ngx-pops · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
