npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-pops

v0.1.10

Published

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

Downloads

9

Readme

ngx-pops

npm version

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

Demo: Link

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 file for details