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

dialog-service

v0.2.3

Published

Reactive Angular modal dialogs. Create alert, confirmation, progress and form based dialogs without writing component templates.

Downloads

21

Readme

dialog-service

Build Status npm version

Reactive Angular modal dialogs. Create alert, confirmation, progress and form based dialogs without writing component templates.

Documentation & Demos

  • Create pre-defined modal dialogs without writing Angular component templates.
  • Support for alert, confirmation and progress dialogs.
  • Support for form based dialogs using ng-quick-form.
    • Simplify usage of Angular forms with Angular Material for common use cases.
    • Supports standard Angular form validators and async validators.
    • Just receive JSON object with validated form values when user submits the form.
  • API Design
    • Simple. Four primary API functions: withAlert(), withProgress(), withConfirm(), withForm().
    • Reactive. Functions return observables with appropriate data to facilitate a more fluent reactive programming pattern.
    • API designed to be UI toolkit agnostic. Currently supports Angular Material and Material Web Components for Angular (deprecated).

Getting Started

  • Before installing this library, you need an existing Angular application configured with Angular Material (or Material Web Components for Angular).

  • Add dialog-service as an NPM dependency with npm install dialog-service.

  • Import this module to your application:

import { MatDialogServiceModule } from 'dialog-service'
// import { MdcDialogServiceModule } from 'dialog-service'

@NgModule({
  ...
  imports: [
    // --- if you are using Angular Material
    MatDialogServiceModule
    
    // --- if you are using Material Web Components for Angular
    // MdcDialogServiceModule
  ]
  ...
})
export class AppModule {
}
  • Inject DialogService to your components and call the withXxx() functions.
@Component()
export class AppComponent {
  constructor (private dialogService: DialogService) {
  }
  
  doDemo() {
    // no need to subscribe if not piping with additional operators
    this.dialogService.withAlert('Hello!')
  }
  
  doDemo2() {
    // need to subscribe for piped operators to run
    this.dialogService.withAlert('Get ready...').pipe(
      concatMap(() => this.dialogService.withAlert('Go!'))
    ).subscribe()
  }
}

DialogService API

The DialogService class exposes functions used to create alert, confirmation, progress and form based dialogs.

withAlert()

withAlert (
    title: string,
    options?: {
        content?: string
        acceptButton?: string // defaults to 'OK'
    }
): Observable<boolean>

Displays an alert dialog with optional title and content. User clicks OK to close the dialog.

Returns true after the dialog is closed. TODO: provide option to cancel the alert and return false.

withConfirm()

withConfirm (
    title?: string,           // defaults to 'Confirm?'
    options?: { 
      content?: string
      acceptButton?: string   // defaults to 'Yes'
      cancelButton?: string   // defaults to 'No
      cancelMessage?: string  // defaults to 'Cancel?'
    }
): Observable<boolean>

Display confirmation dialog. The dialog will close when user clicks on either the accept or cancel button.

Returns true if user clicks on the acceptButton and false if user clicks on cancelButton.

withProgress()

withProgress<T = any> (
  work: Observable<T>
  title?: string // defaults to 'Please Wait...'
): Observable<T | undefined>

Display dialog with a spinner/progress bar that blocks UI interaction until processing of associated observable workload completes.

Returns the last value emitted by the workload. If workload throws error, progress dialog will close and return undefined.

withForm()

withForm (
    title: string,
    fields: QuickFormField[],
    options?: {
        content?: string
        submitButton?: string
        cancelButton?: string
    }
): Observable<any>

DialogService class exposes functions to create alert, confirmation, progress and form based dialogs.

The dialog will close and return form values (as a JSON object) when user clicks on submit button (provided all field validation passed).If user cancels the form, the dialog will close and return false. For documentation on QuickFormField, refer to ng-quick-form.

Support

Reach out to me on Twitter at @kctang

License

MIT