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

ngm-common-dialogs

v1.0.4

Published

A module which provides some common dialogs and a simple to use service for angular material and angular 4

Downloads

25

Readme

ngm-common-dialogs

Provides common dialogs components and a simple to use service for angular material

After developing with angularjs material and got used to the simple use of the provided dialogs I thought it will be nice to have them also in the new angular material, so I build the dialogs which were provided then and an extra dialog which I find really necessary and fun to use.

The Dialogs

  • Alert Dialog
  • Confirm Dialog
  • Prompt Dialog
  • Loading Dialog

The Service

  • Common Dialog Service

Angular and Angular Material supported version

Angular 4.X.X and Angular Material 2.X.X

Demo

https://embed.plnkr.co/I6B2JZ/

Installation

npm i --save ngm-common-dialogs

In your app.module.ts you need to import the package, don't forget to import all its dependencies before.

import { FormsModule } from '@angular/forms';
import { MdDialogModule, MdButtonModule, MdInputModule, MdProgressSpinnerModule } from '@angular/material';
import { NgmCommonDialogsModule } from 'ngm-common-dialogs';
@NgModule({
  imports: [..., 
  FormsModule,
  MdDialogModule,
  MdButtonModule,
  MdInputModule,
  MdProgressSpinnerModule,
  NgmCommonDialogsModule
  ],
  ...
})
export class AppModule {
  ...
}

Usage

Common Dialog Service

The service is very simple to use, all you need to do is to inject it to your component and than call the right show dialog function. All the functions returns a simple ES6 Promise.

import { Component } from '@angular/core';

import { CommonDialogService } from 'ngm-common-dialogs';

@Component({
 selector: 'service-example',
 templateUrl: './service-example.html'
})
export class ServiceExampleComponent {
 constructor(private commonDialogService: CommonDialogService) { }
 
 showAlertDialog () {
   return this.commonDialogService.showAlert({
     title: 'Nice One',
     message: 'You just opened an alert dialog',
     okButton: 'Yay!',
   }).then(() => ...);
 }
 
 showConfirmDialog () {
   return this.commonDialogService.showConfirm({
     title: 'Caution',
     message: 'Are you sure you want to do this?',
     cancelButton: 'No Way!',
     yesButton: 'Absolutely',
   })
   .then(() => ...)
   .catch(() => ...);
 }
 
 showPromptDialog () {
   return this.commonDialogService.showPrompt({
     title: 'Personality Test',
     message: 'What is your favorite dish?',
     inputLabel: 'Dish Name',
     cancelButton: 'No',
     okButton: 'Choose',
   })
   .then(dishName => ...);
 }
 
 showLoadingDialog() {
   return this.commonDialogService.showLoading({
     title: 'Be patient...',
     promise: Promise.resolve()
   })
   .then(() => ...)
   .catch(() => ...); // If the promise you provided will fail it will arrive here
 }
}

API

Common Dialog Service

showAlert (options)

  • options
    • title: The title
    • message: The message
    • okButton: The text of the ok button, default is ok
  • return an ES6 Promise after the dialog was closed

showConfirm (options)

  • options
    • title: The title
    • message: The message
    • cancelButton: The text of the cancel button, default is cancel
    • yesButton: The text of the yes button, default is yes
  • return an ES6 Promise after the dialog was closed. It will resolve if yes was clicked or reject with the value false if the cancel button was clicked

showPrompt (options)

  • options
    • title: The title
    • message: The message
    • inputLabel: The floating label of the input in the dialog
    • cancelButton: The text of the cancel button, default is cancel
    • okButton: The text of the ok button, default is ok
  • return an ES6 Promise with result which is the text which was entered

showLoading (options)

  • options
    • title: The title
    • promise: The Promise that be resolved while the loading dialog will be shown
  • return an ES6 Promise with result which is the result of the given promise. If the given promise rejected the promise will also reject (in that case you need to use catch instead of then)

Native Components

When you open the dialog you must supply the right component's data structure, each component has it own class that represents his data structure.

AlertDialogComponent

Represents a basic alert dialog component.

AlertDialogData

  • title: The title
  • message: The message
  • okButton: The text of the ok button, default is ok

ConfirmDialogComponent

When the cancel button is clicked the closed value of the dialog is false and when the yes button is clicked its true.

ConfirmDialogData

  • title: The title
  • message: The message
  • cancelButton: The text of the cancel button, default is cancel
  • yesButton: The text of the yes button, default is yes

PromptDialogComponent

The use of this dialog is to get an input from the user, it will show a title, message and an input with the given input label, the result is the input value.

PromptDialogData

  • title: The title
  • message: The message
  • inputLabel: The floating label of the input in the dialog
  • cancelButton: The text of the cancel button, default is cancel
  • okButton: The text of the ok button, default is ok

LoadingDialogComponent

Resolves the given promise, take the result, wrap it with Promise.resolve() and return it as the dialogResult, if the promise was rejected the error value will be wrapped with Promise.reject() and return it as the dialogResult.

LoadingDialogData

  • title: The title
  • promise: The Promise that be resolved while the loading dialog will be shown

Example Of Component Usage

import { AlertDialogComponent } from 'ngm-common-dialogs';

@Component({
  selector: 'components-example',
  templateUrl: './components-example.html',
  styleUrls: ['./components-example.scss']
})
export class ComponentsExampleComponent {
  constructor(private dialogService: MdDialog) { }
  
      showAlertDialog() : void {
        this.dialogService.open(AlertDialogComponent, {
          data: { // This data needs to be in the AlertDialogData structure
            title: 'Nice One',
            message: 'You just opened an alert dialog',
            okButton: 'Yay!',
          }
        });
      }
  }