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

lib-dialog-component

v1.0.2

Published

Dialog component for Angular projects to show modal dialogs

Downloads

23

Readme

LibDialogComponent

Dialog component for Angular projects to show modal dialogs

Install

npm install djw/lib-dialog-component

Usage

In your app.module.ts (or any module.ts file):

import { LibDialogComponent } from 'lib-dialog-component/dist/lib-dialog-component/public-api';

then:

@NgModule({
  declarations: [
    AppComponent,
    LibDialogComponent,
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Dialog types

| Dialog type | Icon | Button's class | | ----------- | --------------------- | -------------- | | message | faInfoCircle | btn-success | | error | faExclamationTriangle | btn-primary | | delete | faExclamationTriangle | btn-danger |

Icons from Font Awesome 5

Class names based on Bootstrap 4

Inputs

| Option | Type | Description | | --------------- | ------- | --- | | showDialog | boolean | Control the dialog open/close status. | | title | string | Title of the dialog. | | content | string | Contnet of the dialog. | | type | enum | See types in Dialog types section. | | disableCancel | boolean | You can disable cancel button. |

Outputs

| Method | Emit type | Description | | ------ | --------- | ----------- | | dialogChange | string | The return value can be ok or cancel depends on user's behavior. If clicks on "OK" or "Delete" button, the result will be ok. Otherwise it will be cancel. If close the dialog, it means cancel too. |

Examples

Info dialog

Show a simple message dialog to notify the user about message has been sent.

<lib-dialog-component
  type="message"
  [showDialog]="isOpen"
  [disableCancel]="true"
  title="Message sent"
  content="You message has been sent."
  (dialogChange)="close()"
  ></lib-dialog-component>

Error dialog

A simple error dialog to notify the user about unauthorized event happend.

In my.component.html:

<lib-dialog-component
  type="error"
  [showDialog]="isOpen"
  [disableCancel]="true"
  title="Unauthorized"
  content="You don't have permission to this page or function."
  (dialogChange)="close()"
  ></lib-dialog-component>

In my.component.ts:

import { Component, OnInit } from '@angular/core';
import { User } from 'src/models/user.model';

@Component({
  selector: 'app-my',
  templateUrl: './my.component.html',
  styleUrls: ['./my.component.scss']
})
export class MyComponent implements OnInit {
  isOpen = false;

  constructor() {}

  ngOnInit() {
  }

  isAuthorized(user: User) {
    if (!user.hasPermission('my-component.write')) {
      this.isOpen = true;
    }
  }

  close() {
    this.isOpen = false;
  }
}

Delete dialog

In this example I show you a way how to handle returning value from dialog.

In my.component.html:

<lib-dialog-component
  type="delete"
  [showDialog]="isOpen"
  title="Are you sure?"
  content="You will be delete this information permanently. After deletion it will be lost and will not be recoverable!"
  (dialogChange)="closeOrDelete()"
  ></lib-dialog-component>

In my.component.ts:

import { Component, OnInit } from '@angular/core';
import { User } from 'src/models/user.model';
import { UserService } from 'src/services/user.service';

@Component({
  selector: 'app-my',
  templateUrl: './my.component.html',
  styleUrls: ['./my.component.scss']
})
export class MyComponent implements OnInit {
  isOpen = false;
  users: User[] = [];
  selectedUser: User;

  constructor(
    userService: UserService,
  ) {
    // we load users data collection from server and push it into `users`
    userService.getAll().subscribe((users: User[]) => {
      this.users.push(...users);
    });
  }

  ngOnInit() {
  }

  closeOrDelete(destroy: string) {
    this.isOpen = false;

    if (destroy === 'cancel') {
      return;
    }

    userService.delete(selectedUser.id).subscribe((result: any) => {
      // remove the user from `users`
    })

  }
}