-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(alert): remove self-closing alert component
BREAKING CHANGE: the `NgbSelfClosingAlert` component has been removed. Check the self-closing alert demo to know how to achieve the same thing with `NgbAlert`. Closes #758
- Loading branch information
1 parent
21eb610
commit 79e393d
Showing
11 changed files
with
40 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 4 additions & 11 deletions
15
demo/src/app/components/alert/demos/config/alert-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
import {Component, Input} from '@angular/core'; | ||
import {NgbAlertConfig, NgbSelfClosingAlertConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
import {NgbAlertConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-alert-config', | ||
templateUrl: './alert-config.html', | ||
// add NgbProgressbarConfig and NgbSelfClosingAlertConfig to the component providers | ||
providers: [NgbAlertConfig, NgbSelfClosingAlertConfig] | ||
// add NgbAlertConfig to the component providers | ||
providers: [NgbAlertConfig] | ||
}) | ||
export class NgbdAlertConfig { | ||
@Input() public alerts: Array<string> = []; | ||
|
||
constructor(alertConfig: NgbAlertConfig, selfClosingAlertConfig: NgbSelfClosingAlertConfig) { | ||
constructor(alertConfig: NgbAlertConfig) { | ||
// customize default values of alerts used by this component tree | ||
alertConfig.type = 'success'; | ||
alertConfig.dismissible = false; | ||
selfClosingAlertConfig.dismissible = true; | ||
selfClosingAlertConfig.dismissOnTimeout = 5000; | ||
selfClosingAlertConfig.type = 'danger'; | ||
} | ||
|
||
public addAlert() { | ||
this.alerts.push('This alert has type danger and will close automatically after 5 seconds thanks to the custom config'); | ||
} | ||
} |
13 changes: 9 additions & 4 deletions
13
demo/src/app/components/alert/demos/selfclosing/alert-selfclosing.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
<p> | ||
These alerts will be dismissed in 5 seconds. Click "Add Alert" to add an alert. | ||
Static self-closing alert that disappears after 20 seconds (refresh the page if it has already disappeared) | ||
</p> | ||
<p *ngFor="let alert of alerts"> | ||
<template ngbAlert [dismissOnTimeout]="5000">{{ alert }}</template> | ||
<ngb-alert *ngIf="!staticAlertClosed" (close)="staticAlertClosed = true">Check out our awesome new features!</ngb-alert> | ||
|
||
<hr/> | ||
|
||
<p> | ||
Show a self-closing success message that disappears after 5 seconds. | ||
</p> | ||
<ngb-alert *ngIf="successMessage" type="success" (close)="successMessage = null">{{ successMessage }}</ngb-alert> | ||
<p> | ||
<button class="btn btn-primary" (click)="addAlert()">Add Alert</button> | ||
<button class="btn btn-primary" (click)="changeSuccessMessage()">Change message</button> | ||
</p> |
22 changes: 16 additions & 6 deletions
22
demo/src/app/components/alert/demos/selfclosing/alert-selfclosing.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import {Component, Input} from '@angular/core'; | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {Subject} from 'rxjs/Rx'; | ||
|
||
@Component({ | ||
selector: 'ngbd-alert-selfclosing', | ||
templateUrl: './alert-selfclosing.html' | ||
}) | ||
export class NgbdAlertSelfclosing { | ||
@Input() | ||
public alerts: Array<string> = []; | ||
export class NgbdAlertSelfclosing implements OnInit { | ||
private _success = new Subject<string>(); | ||
|
||
public addAlert() { | ||
this.alerts.push('This alert will close automatically after 5 seconds'); | ||
staticAlertClosed = false; | ||
successMessage: string; | ||
|
||
ngOnInit(): void { | ||
setTimeout(() => this.staticAlertClosed = true, 20000); | ||
|
||
this._success.subscribe((message) => this.successMessage = message); | ||
this._success.debounceTime(5000).subscribe(() => this.successMessage = null); | ||
} | ||
|
||
public changeSuccessMessage() { | ||
this._success.next(`${new Date()} - Message successfully changed.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters