Skip to content

Commit af7597b

Browse files
authored
feat(alert): added isOpen input and marked as OnPush (#2940)
* feat(alert): added isOpen input and marked as OnPush * fix(alerts-test): fixed alert component test and few style issues * demo(alert): add dissmissible toggle and dynamic content demo
1 parent 1b6ed56 commit af7597b

File tree

13 files changed

+89
-30
lines changed

13 files changed

+89
-30
lines changed

demo/src/app/components/+alerts/alerts-section.list.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DemoAlertLinkComponent } from './demos/link/link';
33
import { DemoAlertContentComponent } from './demos/content/content';
44
import { DemoAlertDismissComponent } from './demos/dismiss/dismiss';
55
import { DemoAlertDynamicHtmlComponent } from './demos/dynamic-html/dynamic-html';
6+
import { DemoAlertDynamicContentComponent } from './demos/dynamic-content/dynamic-content';
67
import { DemoAlertTimeoutComponent } from './demos/dismiss-on-timeout/dismiss-on-timeout';
78
import { DemoAlertStylingGlobalComponent } from './demos/styling-global/styling-global';
89
import { DemoAlertStylingLocalComponent } from './demos/styling-local/styling-local';
@@ -80,6 +81,14 @@ export const demoComponentContent: ContentSection[] = [
8081
html: require('!!raw-loader?lang=markup!./demos/dynamic-html/dynamic-html.html'),
8182
outlet: DemoAlertDynamicHtmlComponent
8283
},
84+
{
85+
title: 'Dynamic content',
86+
anchor: 'dynamic-content',
87+
description: `<p>Alerts fully support bindings.</p>`,
88+
component: require('!!raw-loader?lang=typescript!./demos/dynamic-content/dynamic-content.ts'),
89+
html: require('!!raw-loader?lang=markup!./demos/dynamic-content/dynamic-content.html'),
90+
outlet: DemoAlertDynamicContentComponent
91+
},
8392
{
8493
title: 'Dismiss on timeout',
8594
anchor: 'dismiss-on-timeout',
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div *ngFor="let alert of alerts">
2-
<alert [type]="alert.type" [dismissible]="true">{{ alert.msg }}</alert>
2+
<alert [type]="alert.type" [dismissible]="dismissible">{{ alert.msg }}</alert>
33
</div>
4+
<button type="button" class="btn btn-primary" (click)="dismissible = !dismissible">Toggle dismissible</button>
45
<button type="button" class="btn btn-primary" (click)="reset()">Reset</button>

demo/src/app/components/+alerts/demos/dismiss/dismiss.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Component } from '@angular/core';
55
templateUrl: './dismiss.html'
66
})
77
export class DemoAlertDismissComponent {
8+
dismissible = true;
89
alerts: any = [
910
{
1011
type: 'success',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<alert type="success">{{messages[index]}}</alert>
2+
3+
<div *ngIf="index !== messages.length -1; else elseBlock">
4+
<button class="btn btn-primary" (click)="changeText()">Change text</button>
5+
</div>
6+
<ng-template #elseBlock>
7+
<button class="btn btn-primary" (click)="index = 0">Reset</button>
8+
</ng-template>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'demo-alert-content-html',
5+
templateUrl: './dynamic-content.html'
6+
})
7+
export class DemoAlertDynamicContentComponent {
8+
index = 0;
9+
messages = [
10+
'You successfully read this important alert message.',
11+
'Now this text is different from what it was before. Go ahead and click the button one more time',
12+
'Well done! Click reset button and you\'ll see the first message'
13+
];
14+
15+
changeText() {
16+
if (this.messages.length - 1 !== this.index) {
17+
this.index++;
18+
}
19+
}
20+
}

demo/src/app/components/+alerts/demos/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { DemoAlertTimeoutComponent } from './dismiss-on-timeout/dismiss-on-timeo
77
import { DemoAlertStylingGlobalComponent } from './styling-global/styling-global';
88
import { DemoAlertStylingLocalComponent } from './styling-local/styling-local';
99
import { DemoAlertConfigComponent } from './config/config';
10+
import { DemoAlertDynamicContentComponent } from './dynamic-content/dynamic-content';
1011

1112
export const DEMO_COMPONENTS = [
1213
DemoAlertBasicComponent,
1314
DemoAlertLinkComponent,
1415
DemoAlertContentComponent,
1516
DemoAlertDismissComponent,
1617
DemoAlertDynamicHtmlComponent,
18+
DemoAlertDynamicContentComponent,
1719
DemoAlertTimeoutComponent,
1820
DemoAlertStylingGlobalComponent,
1921
DemoAlertStylingLocalComponent,

demo/src/app/components/+pagination/demos/pager/pager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Component } from '@angular/core';
1+
import { Component, ViewEncapsulation } from '@angular/core';
22

33
@Component({
44
selector: 'demo-pagination-pager',
5-
templateUrl: './pager.html'
5+
templateUrl: './pager.html',
6+
styles: ['.pager li.btn:active { box-shadow: none; }'],
7+
encapsulation: ViewEncapsulation.None
68
})
79
export class DemoPaginationPagerComponent {
810
totalItems: number = 64;

demo/src/app/components/+tooltip/demos/styling-local/styling-local.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { Component } from '@angular/core';
66
/* tslint:disable no-unused-css*/
77
styles: [
88
`
9-
:host >>> .tooltip-inner {
10-
background-color: #009688;
11-
color: #fff;
12-
}
13-
:host >>> .tooltip .tooltip-arrow {
14-
border-bottom-color: #009688;
15-
}
16-
`
9+
:host >>> .tooltip-inner {
10+
background-color: #009688;
11+
color: #fff;
12+
}
13+
:host >>> .tooltip.top .tooltip-arrow:before,
14+
:host >>> .tooltip.top .tooltip-arrow {
15+
border-top-color: #009688;
16+
}
17+
`
1718
]
1819
})
1920
export class DemoTooltipStylingLocalComponent {}

demo/src/assets/css/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ a:hover {
111111
.main {
112112
display: flex;
113113
flex-wrap: wrap;
114+
position: relative;
115+
z-index: 1;
114116
}
115117
/* entry */
116118
.entry {
@@ -452,6 +454,8 @@ a:hover {
452454

453455
.nav-item {
454456
&.customClass {
457+
float: right;
458+
455459
&:first-child {
456460
margin-left: auto;
457461
}

src/alert/alert.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ng-template [ngIf]="!isClosed">
1+
<ng-template [ngIf]="isOpen">
22
<div [class]="'alert alert-' + type" role="alert" [ngClass]="classes">
33
<ng-template [ngIf]="dismissible">
44
<button type="button" class="close" aria-label="Close" (click)="close()">

0 commit comments

Comments
 (0)