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

@ashetm/ng-dialog

v15.0.2

Published

This library provide a unique UI of 3 types of dialog; alert, confirm and form.

Downloads

251

Readme

@ashetm/ng-dialog

This library provide a unique UI of 3 types of dialog; alert, confirm and form.

Only Angular 14 and above are available.

Install

You can install it with npm:

npm install @ashetm/ng-dialog

Import

You only need to import DialogModule through forRoot static method.

...
import { DialogModule } from '@ashetm/ng-dialog';
...
@NgModule({
  ...
  imports: [
    ...
    DialogModule.forRoot(), 
    ...
  ]
  ...
})
export class AppModule { }

Usage

DialogAlert

The serviec to use is DialogService#openDialogAlert, it's definition is:

openDialogAlert(
  title: string, 
  body?: string, 
  { closeLabel }?: Record<'closeLabel', string>
): DialogRef;
  • 1st argument title, is the title of dialog (REQUIRED)
  • 2nd argument body, is the body of dialog (OPTIONAL) (DEFAULT - '')
  • 3rd argument buttons, is an object with closeLabel key to override the label of close button (OPTIONAL) (DEFAULT - closeLabel = 'Okey!)

And it returns dialog reference DialogRef, here is the exposed members:

  • type returns an EDialogType value with value of 'alert'
  • getInstanceId() returns a number of instance id
  • onBeforeClose(fn: () => boolean = () => true) returns Observable<void> and can pass a function handler to execute before closing, close the dialog alert if it returns true, else it stays opened

Example:

constructor(
  ...
  private readonly _dialogService: DialogService
  ...
) { }

openAlert(): void {
  this._dialogService.openDialogAlert('Sample Title');
}

DialogConfirm

The serviec to use is DialogService#openDialogConfirm, it's definition is:

openDialogConfirm(
  title: string, 
  body?: string, 
  { closeLabel, okLabel }?: Record<'closeLabel' | 'okLabel', string>
): DialogConfirmRef;
  • 1st argument title, is the title of dialog (REQUIRED)
  • 2nd argument body, is the body of dialog (OPTIONAL) (DEFAULT - '')
  • 3rd argument buttons, is an object with closeLabel and okLabel keys to override the label of close button and okLabel (OPTIONAL) (DEFAULT - closeLabel = 'Close, okLabel = 'Okey')

And it returns dialog reference DialogConfirmRef, here is the exposed members:

  • type returns an EDialogType value with value of 'confirm'
  • getInstanceId() returns a number of instance id
  • onBeforeClose(fn: () => boolean = () => true) returns Observable<void> and can pass a function handler to execute before closing, close the dialog if it returns true, else it stays opened
  • onBeforeDecision(fn: (decision: boolean) => boolean = (decision: boolean) => true) returns Observable<boolean> observable that returns the decision made by the user/client and can pass a function handler to execute before closing, close the dialog if it returns true etlse it stays opened

Example:

constructor(
  ...
  private readonly _dialogService: DialogService
  ...
) { }

openConfirm(): void {
  this._dialogService.openDialogConfirm('Sample Title');
}

DialogForm

The service to use is DialogService#openDialogForm, it's definition is:

openDialogForm<T extends TemplateRef<unknown>, U = any>(
  title: string, 
  template: T, 
  { closeLabel, okLabel }?: Record<'closeLabel' | 'okLabel', string>
): DialogFormRef<U>;
  • 1st argument title, is the title of dialog (REQUIRED)
  • 2nd argument template, is the body template of dialog (REQUIRED)
  • 3rd argument buttons, is an object with closeLabel and okLabel keys to override the label of close button and okLabel (OPTIONAL) (DEFAULT - closeLabel = 'Cancel, okLabel = 'Submit')

And it returns dialog reference DialogFormRef<U>, here is the exposed members:

  • type returns an EDialogType value with value of 'alert'
  • getInstanceId() returns a number of instance id
  • onBeforeClose(fn: () => boolean = () => true) returns Observable<void> and can pass a function handler to execute before closing, close the dialog alert if it returns true, else it stays opened
  • onBeforeData(fn: (data: U) => boolean = (_: U) => true) returns Observable<U> observable that returns the data of the form written by the user/client and can pass a function handler to execute before closing, close the dialog if it returns true etlse it stays opened

It also needs to tag ng-template with the directive dialogFormBodyComponent, that requires also to bind formGroup directive. And also take reference of that ng-template as DialogFormBodyComponent.

Example:

...
<ng-template #dialogFormBodyComponent="DialogFormBodyComponent" 
  dialogFormBodyComponent
  [formGroup]="formGroup">
  Name: <input formControlName="name" />
</ng-template>
...
formGroup: FormGroup = new FormGroup({
  name: new FormControl('Sample name')
});
...
constructor(
  ...
  private readonly _dialogService: DialogService
  ...
) { }

openForm(template: DialogFormBodyComponentDirective): void {
  this._dialogService.openDialogForm('Sample Title', template);
}