0.2.0 • Published 3 years ago

alert-leobonhart v0.2.0

Weekly downloads
36
License
-
Repository
-
Last release
3 years ago

Alert

This library was generated with Angular CLI version 10.0.14.

How to use

To use this library you need import AlertModule in your AppModule

import { AlertModule } from 'alert-leobonhart';

Then add imported module to the property imports in decorator @NgModule

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AlertModule <---
  ],
  providers: [],
  bootstrap: [AppComponent]
})

After that you can be used service AlertService to add alerts.

AlertService has only one method

add

input data is an object with interface IAlertModal

interface IAlertModal {
  text: string; // text or html
  color?: TShowAlert; // background color of alert (by default color is #323232)
  seconds?: number; // alert display time
}

/** All this colors is material colors with brigtnes 500 */
type TShowAlert = 'red' | 'yellow' | 'green' | 'blue';

example usage AlertService

...
import { AlertService } from 'alert-leobonhart';
@Component({
  selector: 'your-component',
  templateUrl: './your.component.html',
  styleUrls: ['./your.component.scss']
})
export class YourComponent implements OnInit {

  ngOnInit(): void {

    /** only text */
    this.alert.add({
      text: 'Hello World'
    });

    /** text with color */
    this.alert.add({
      text: 'Hello World',
      color: 'red'
    });

    /** text with color and display time in 5 seconds*/
    this.alert.add({
      text: 'Hello World',
      color: 'red',
      seconds: 5
    });
  }

  constructor(private alert: AlertService) {
  }

}

Config

You can config default options Injection token that can be used to specify default options

const ALERT_DEFAULT_OPTIONS: InjectionToken<AlertConfig>

or can use service AlertSettingService

example

...
import { AlertModule, AlertSettingService } from 'alert-leobonhart';

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

  constructor(private setting: AlertSettingService) {
    this.setting.config.defaultSecodns = 5;
    this.setting.config.maxShowAlerts = 3;
    this.setting.config.position = 'left-top';
  }

}
settings
NameTypeDescription
defaultSecodnsnumberAlert display time by default 2 seconds
maxShowAlertsnumberMaximum simultaneously displayed alerts by default 2
positionPositionAlertPosition of alerts by default left-bottom
type PositionAlert = 'left-bottom' | 'left-top' | 'right-bottom' | 'right-top';
0.2.0

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

4 years ago

0.0.1

4 years ago