2.0.1 • Published 3 years ago

rl-dialogs v2.0.1

Weekly downloads
19
License
MIT
Repository
-
Last release
3 years ago

RL Dialogs

This library is used to display custom Angular components as a dialog in Angular 12+ applications.

Installation

The library can be installed via npm:

npm install rl-dialogs --save

Usage

Add DialogsModule to your Angular module imports:

import { DialogsModule } from 'rl-dialogs'

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    DialogsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Dialog Anchor

Place the dialog anchor in the root of your app (app.component for example):

<div *rlDialogsAnchor></div>

Custom Dialog

To render your custom component as a dialog, create a new Angular component and extend it from the base dialog class DialogComponent. The base class provides all the required functionality to show/hide the dialog, set animation duration and so on. As result, you only need to implement the component template.

@Component({
  selector: 'app-dialog',
  templateUrl: './dialog.component.html',
  styleUrls: ['./dialog.component.scss']
})
export class Dialog extends DialogComponent {

  constructor(protected dialogRef: ElementRef) {
    super(dialogRef)
  }

}

Dialog component API

Properties
PropertyTypeDefaultDescription
animationDurationnumber700Duration of the dialog show/hide animation in milliseconds. Use setAnimationDuration to set the duration after a dialog is created.
positionDialogPositionDialogPosition.CenterDialog position on the screen. The possible options are DialogPosition.Left, DialogPosition.Right, DialogPosition.Center
dataanynullData which can be passed to the dialog. Accessible after the dialog creation, so you should use NgOnInit lifecycle hook to initialize your component with a given data
Methods
MethodDescription
setAnimationDurationSets the show/hide dialog animation duration in milliseconds
hideHides the dialog

Show a dialog using DialogsService

Use DialogsService.show() method to show the dialog:

dialogService.show<DialigOutputData>(id: string, dialogType: Type<IDialog>, data: any, options: IDialogOptions, injector: Injector): Promise<DialigOutputData | undefined>
Options
PropertyTypeRequiredDescription
idstringtrueDialog ID. Can be generated using the static method DialogComponent.generateId()
dialogTypeTypetrueDialog position on the screen. The possible options are DialogPosition.Left, DialogPosition.Right, DialogPosition.Center
dataanyfalseData which can be passed to the dialog. Accessible after the dialog creation, so you should use NgOnInit lifecycle hook to initialize your component with a given data
optionsIDialogOptionsfalseDialog options, see the description below
injectorInjectorfalseAngular Injector. Can be provided to override a dialog dependencies
IDialogOptions
PropertyTypeDefaultDescription
overlaybooleanfalseDefines whether to display dialog overlay or not.
positionDialogPositionDialogPosition.CenterDialog position on the screen. The possible options are DialogPosition.Left, DialogPosition.Right, DialogPosition.Center
closeOnClickOutsidebooleanfalseDefines whether a dialog should be closed on click outside or not

Close a dialog using DialogsService

To close a dialog using the service:

dialogService.close(id: string)

Close all the open dialogs using DialogsService

To close a dialog using the service:

dialogService.closeAll()

Overlay Customization

You can override the overlay class rl-overlay to customize the background color or other CSS properties.

Scrolling inside the dialog (iOS)

To disable body scrolling on iOS, the library prevents touchmove events, so scrolling on a child element in the dialog is also disabled. To enable scrolling on a child element in iOS, apply rl-dialog-scrollable class to the element.

2.0.1

3 years ago

2.0.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago