All Projects → ngneat → Dialog

ngneat / Dialog

Licence: mit
👻 A simple to use, highly customizable, and powerful modal for Angular Applications

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Dialog

Alertifyjs
A javascript framework for developing pretty browser dialogs and notifications.
Stars: ✭ 1,922 (+1116.46%)
Mutual labels:  dialog, modal
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+691.77%)
Mutual labels:  dialog, modal
React Native Alert Pro
The Pro Version of React Native Alert (Android & iOS)
Stars: ✭ 69 (-56.33%)
Mutual labels:  dialog, modal
Popmodal
jquery plugin for showing tooltips, titles, modal dialogs and etc
Stars: ✭ 149 (-5.7%)
Mutual labels:  dialog, modal
A11y Dialog
A very lightweight and flexible accessible modal dialog script.
Stars: ✭ 1,768 (+1018.99%)
Mutual labels:  dialog, modal
Bootstrap Show Modal
A Bootstrap 4 / jQuery plugin wrapper, to create modals dynamically in JavaScript
Stars: ✭ 38 (-75.95%)
Mutual labels:  dialog, modal
Ng Popups
🎉 Alert, confirm and prompt dialogs for Angular. Simple as that.
Stars: ✭ 80 (-49.37%)
Mutual labels:  dialog, modal
Ngx Modialog
Modal / Dialog for Angular
Stars: ✭ 691 (+337.34%)
Mutual labels:  dialog, modal
React Native Push Notification Popup
A <NotificationPopup/> component for presenting your own push notification in react-native app
Stars: ✭ 111 (-29.75%)
Mutual labels:  dialog, modal
Customalertviewdialogue
Custom AlertView Dialogue is the world's most advanced alert view library. Custom AlertView Dialogue includes simple message popups, confirmation alerts, selector popups, action sheet bottom menus, and input/feedback contact forms.
Stars: ✭ 100 (-36.71%)
Mutual labels:  dialog, modal
Rodal
A React modal with animations.
Stars: ✭ 754 (+377.22%)
Mutual labels:  dialog, modal
Svelte Simple Modal
A simple, small, and content-agnostic modal for Svelte v3
Stars: ✭ 130 (-17.72%)
Mutual labels:  dialog, modal
Simplelightbox
Touch-friendly image lightbox for mobile and desktop
Stars: ✭ 744 (+370.89%)
Mutual labels:  dialog, modal
Ng2 Bootstrap Modal
Library to simplify the work with bootstrap modal dialogs
Stars: ✭ 53 (-66.46%)
Mutual labels:  dialog, modal
React Useportal
🌀 React hook for Portals
Stars: ✭ 698 (+341.77%)
Mutual labels:  dialog, modal
React Poppop
A mobile support and multi-directional modal for ReactJS
Stars: ✭ 78 (-50.63%)
Mutual labels:  dialog, modal
Rmodal.js
A simple 1.2 KB modal dialog with no dependencies
Stars: ✭ 613 (+287.97%)
Mutual labels:  dialog, modal
Sweet Modal Vue
The sweetest library to happen to modals.
Stars: ✭ 682 (+331.65%)
Mutual labels:  dialog, modal
Launchy
Launchy: An Accessible Modal Window
Stars: ✭ 89 (-43.67%)
Mutual labels:  dialog, modal
Vue Final Modal
🍕Vue Final Modal is a tiny, renderless, mobile-friendly, feature-rich modal component for Vue.js.
Stars: ✭ 128 (-18.99%)
Mutual labels:  dialog, modal


A simple to use, highly customizable, and powerful modal for Angular Applications

MIT commitizen PRs styled with prettier All Contributors ngneat spectator

Features

✅  TemplateRef/Component Support
✅  Dialog Guards Support
✅  Resizable
✅  Draggable
✅  Multiple Dialogs Support
✅  Built-in Confirm/Success/Error Dialogs
✅  Customizable

Table of Contents

Installation

From your project folder, run:

ng add @ngneat/dialog

This command will import the DialogModule.forRoot() in your AppModule:

import { DialogModule } from '@ngneat/dialog';

@NgModule({
  declarations: [AppComponent],
  imports: [DialogModule.forRoot()],
  bootstrap: [AppComponent]
})
export class AppModule {}

Usage

Using a Component

First, create the component to be displayed in the modal:

import { DialogService, DialogRef } from '@ngneat/dialog';

@Component({
  template: `
    <h1>Hello World</h1>
    <button (click)="ref.close()">Close</button>
  `
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class HelloWorldComponent {
  constructor(public ref: DialogRef) {}
}

Inside the component, you'll have access to a DialogRef provider. You can call its close() method to close the current modal. You can also pass data that'll be available for any subscribers to afterClosed$.

Now we can use the DialogService to open open the modal and display the component:

import { DialogService } from '@ngneat/dialog';

@Component({
  template: `
    <button (click)="open()">Open</button>
  `
})
export class AppComponent implements OnInit {
  constructor(private dialog: DialogService) {}

  ngOnInit() {
    const dialogRef = this.dialog.open(HelloWorldComponent);
  }
}

DialogRef API

The DialogRef instance exposes the following API:

  • afterClosed$ - An observable that emits after the modal closes:
const dialogRef = this.dialog.open(HelloWorldComponent);
dialogRef.afterClosed$.subscribe(result => {
  console.log(`After dialog has been closed ${result}`);
});
  • backdropClick$ - An observable that emits when the user clicks on the modal backdrop:
const dialogRef = this.dialog.open(HelloWorldComponent);
dialogRef.backdropClick$.subscribe(() => {
  console.log('Backdrop has been clicked');
});
  • beforeClose - A guard that should return a boolean, an observable, or a promise indicating whether the modal can be closed:
dialogRef.beforeClose(result => dialogCanBeClosed);
dialogRef.beforeClose(result => this.service.someMethod(result));
  • ref.data - A reference to the data that is passed by the component opened in the modal:
import { DialogService, DialogRef } from '@ngneat/dialog';

@Component({
  template: `
    <h1>{{ ref.data.title }}</h1>
    <button (click)="ref.close()">Close</button>
  `
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class HelloWorldComponent {
  constructor(public ref: DialogRef) {}
}

The library also provides the dialogClose directive helper, that you can use to close the modal:

import { DialogService, DialogRef } from '@ngneat/dialog';

@Component({
  template: `
    <h1>Hello World</h1>
    <button dialogClose>Close</button>
    <button [dialogClose]="result">Close with result</button>
  `
})
export class HelloWorldComponent {}

Using a TemplateRef

Sometimes it can be overkill to create a whole component. In these cases, you can pass a reference to an <ng-template>:

import { DialogService } from '@ngneat/dialog';

@Component({
  selector: 'app-root',
  template: `
    <ng-template #modalTpl let-ref>
      <h1>Hello World</h1>

      <button (click)="ref.close()">Close</button>
    </ng-template>

    <button (click)="open(modalTpl)">Open</button>
  `
})
export class AppComponent {
  constructor(private dialog: DialogService) {}

  open(tpl: TemplateRef<any>) {
    this.dialog.open(tpl);
  }
}

Note that in this case, you can access the ref object by using the $implicit context property.

Passing Data to the Modal Component

Sometimes we need to pass data from the opening component to our modal component. In these cases, we can use the data property, and use it to pass any data we need:

import { DialogService } from '@ngneat/dialog';

@Component({
  template: `
    <button (click)="open()">Open</button>
  `
})
export class AppComponent implements OnInit {
  private id = '...';

  constructor(private dialog: DialogService) {}

  ngOnInit() {
    const dialogRef = this.dialog.open(HelloWorldComponent, {
      data: {
        id: this.id
      }
    });
  }
}

Now we can access it inside our modal component or template, by using the ref.data property.

Modal Options

  • id - The modal unique id (defaults to random id).
  • closeButton - Whether to display an 'X' for closing the modal (default is true).
  • enableClose - Whether a click on the backdrop should close the modal (default is true).
  • backdrop - Whether to show the backdrop element (default is true).
  • resizable - Whether the modal show be resizeable (default is false).
  • draggable - Whether the modal show be draggable (default is false).
  • size - Set the modal size according to your global custom sizes (default is md).
  • windowClass - Add a custom class to the modal container.
  • width - Set a custom width (default unit is px).
  • height - Set a custom height (default unit is px).
  • minHeight - Set a custom min-height (default unit is px).
  • maxHeight - Set a custom max-height (default unit is px).
  • container - A custom element to which we append the modal (default is body).
  • vcr - A custom ViewContainerRef to use.
  • data - A data object that will be passed to the modal template or component.
this.dialog.open(compOrTemplate, {
  id: string,
  closeButton: boolean,
  enableClose: boolean,
  backdrop: boolean,
  resizable: boolean,
  draggable: boolean,
  size: sm | md | lg | fullScreen | string,
  windowClass: string,
  width: string | number,
  height: string | number,
  minHeight: string | number,
  maxHeight: string | number
});

Built-in Modals

The library provides built-in modals for common cases where we need to show a confirmation message, a success message, or an error message:

this.dialog
  .confirm({
    title: 'Are you sure?',
    body: 'This action cannot be undone.'
  })
  .afterClosed$.subscribe(confirmed => console.log(confirmed));

this.dialog.success({
  title: 'Hurray!',
  body: '<h1>You Made It!!!</h1>'
});

this.dialog.error({
  title: 'Oh no',
  body: tpl
});

The body type can be a string, HTML string, or a <ng-template>.

You can also change the default dialogs, and use your own:

import { DialogModule } from '@ngneat/dialog';

@NgModule({
  declarations: [AppComponent],
  imports: [
    DialogModule.forRoot({
      success: {
        component: AppSuccessDialog
      },
      confirm: {
        component: AppConfirmDialog
      },
      error: {
        component: AppErrorDialog
      }
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

Custom Sizes

You can define the modal sizes globally by using the sizes option:

import { DialogModule } from '@ngneat/dialog';

@NgModule({
  declarations: [AppComponent],
  imports: [
    DialogModule.forRoot({
      sizes: {
        sm: {
          width: 300, // 300px
          minHeight: 250 // 250px
        },
        md: {
          width: '60vw',
          height: '60vh'
        },
        lg: {
          width: '90vw',
          height: '90vh'
        },
        fullScreen: {
          width: '100vw',
          height: '100vh'
        },
        stretch: {
          minHeight: 500,
          maxHeight: '85%'
        }
      }
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

Styling

You can customize the styles with these classes:

ngneat-dialog {
  .ngneat-dialog-backdrop {
    // backdrop styles
    .ngneat-dialog-content {
      // dialog content, where your component/template is placed
      .ngneat-drag-marker {
        // draggable marker
      }
      .ngneat-close-dialog {
        // 'X' icon for closing the dialog
      }
      .ngneat-dialog-primary-btn,
      .ngneat-dialog-secondary-btn {
        // the default dialogs action buttons
      }
    }
  }
}

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Toni Villena

💻 🚇 ⚠️

Netanel Basal

📖 🤔 💻

Inbal Sinai

📖

Shahar Kazaz

💻 📖

beeman

💻

Ryan Hutchison

💻 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!
Logo made by itim2101 from www.flaticon.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].