1.0.1 • Published 24 days ago

@ngx-popovers/dialog v1.0.1

Weekly downloads
-
License
-
Repository
github
Last release
24 days ago

Dialog

This library was created using Nx and floating-ui for Angular apps.

Dialog Preview

Check out the Demo

To use, install the package using the following command:

npm i @ngx-popovers/dialog

Usage

The dialog component provides a simple way to display dialog elements.

<ngx-dialog>
  <button ngx-dialog-trigger>
    Toggle
  </button>

  <ng-template ngx-dialog-template>
    <div class="modal-box">
      <p class="text-2xl">Hello! I am Dialog</p>
      <p>
        Lorem ipsum dolor sit amet,
        consectetur adipisicing elit.
      </p>

      <button ngx-dialog-close>
        Close
      </button>
    </div>
  </ng-template>
</ngx-dialog>

ngx-dialog-trigger

You can include multiple components inside the <ngx-dialog />.

The ngxDialogTrigger directive can be used to set the trigger button inside <ngx-dialog /> as default.

<ngx-dialog>
  <!-- 
    The dialog opens when 
    the button[ngx-dialog-trigger] is clicked 
  -->
  <button ngx-dialog-trigger>
    Toggle
  </button>

  <ng-template ngx-dialog-template>
    <div class="dialog-box">
      <p>Dialog content</p>
    </div>
  </ng-template>
</ngx-dialog>

ngx-dialog-template

The NgxDialogTemplate directive helps locate the template for the dialog.

<ngx-dialog [value]="true">
  <!-- 
    Angular doesn't destroy elements in <ng-content />, so
    the DialogTemplate directive is used for conditional content projection.
    
    https://angular.io/guide/content-projection#conditional-content-projection
  -->
  <ng-template ngx-dialog-template>
    <div class="dialog-box">
      <p>Dialog content</p>
    </div>
  </ng-template>
</ngx-dialog>

ngx-dialog-close

The NgxDialogClose directive closes the dialog when a click event is detected on the specified element.

<ngx-dialog [value]="true">
  <ng-template ngx-dialog-template>
    <div class="dialog-box">
      <p>Dialog content</p>

      <!-- 
        The dialog will close when 
        button[ngx-dialog-close] is clicked 
      -->
      <button ngx-dialog-close>Close</button>
    </div>
  </ng-template>
</ngx-dialog>

API

Input Parameters

InputDescriptionTypeDefault
closeOnBackdropClickClose dialog when clicking backdropbooleantrue
backdropClassClass for the backdrop elementstring''
contentClassClass for the dialog wrapper elementstring''
animationDisabledDisable show/hide animationsbooleanfalse
valueShow or hide dialogbooleanfalse

Output Parameters

OutputDescriptionType
valueChangeEmits when value changesEventEmitter<boolean>
showEmits when the popover showsEventEmitter
hideEmits when the popover hidesEventEmitter
animationStartEmits when animation startsEventEmitter<AnimationEvent>
animationDoneEmits when animation endsEventEmitter<AnimationEvent>

Configuration

There is a configuration token NGX_DIALOG_CONFIG. Use the NgxDialogConfig class to change default properties.

import { Provider } from '@angular/core';
import { NGX_DIALOG_CONFIG, NgxDialogConfig } from '@ngx-popovers/dialog';

export const DialogConfigProvider: Provider = {
  provide: NGX_DIALOG_CONFIG,
  useValue: new NgxDialogConfig({
    backdropClass: 'backdrop',
    contentClass: 'content',
    closeOnBackdropClick: false,
    animationDisabled: false
  })
};

Sources

Other npm packages from this library:

1.0.1

24 days ago

1.0.0

1 month ago

0.1.5

3 months ago

0.1.4

3 months ago

0.1.3

3 months ago

0.1.2

3 months ago