Skip to content

Commit

Permalink
Added the service and getting ready to animate the notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sstorie committed Jul 4, 2016
1 parent e8e3624 commit a55319c
Show file tree
Hide file tree
Showing 28 changed files with 506 additions and 86 deletions.
6 changes: 6 additions & 0 deletions angular2-animated-notifications-panel/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@

.content {
flex: 1;
display: flex;
flex-direction: row;
justify-content: center;
min-width: 0;
min-height: 0;
padding: 8px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<span>Content</span>
</div>

<notifications></notifications>
<notification-panel></notification-panel>

</div>
16 changes: 14 additions & 2 deletions angular2-animated-notifications-panel/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';

import {NotificationsComponent} from "./notifications/index";
import {NotificationService} from "./shared/index";
import {NotificationPanelComponent} from "./notification-panel/index";

@Component({
selector: 'my-app',
moduleId: module.id,
directives: [NotificationsComponent],
directives: [NotificationPanelComponent],
templateUrl: "app.component.html",
styleUrls: ['app.component.css']
})
export class AppComponent {

constructor(
private notificationService: NotificationService
) {

// this.notificationService.startRandomGeneration();
for(let i = 0; i < 10; i++) {
let n = this.notificationService.createRandomNotification();
this.notificationService.addNotification(n);
}
}
}
5 changes: 4 additions & 1 deletion angular2-animated-notifications-panel/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { bootstrap } from '@angular/platform-browser-dynamic';

import {NotificationService} from "./shared/index";
import {AppComponent} from './app.component';


bootstrap(AppComponent, []);
bootstrap(AppComponent, [
NotificationService
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require("./notification-panel.component"));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./notification-panel.component";
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
flex-direction: column;
min-width: 0;
min-height: 0;
padding: 8px;
overflow: hidden;
}

Expand All @@ -26,10 +25,14 @@ i {
flex-direction: row;
justify-content: flex-end;
color: #E74C3C;
padding: 0 8px 0 8px;
height: 38px;
}

.title span {
flex: 1;
font-family: 'Hind', sans-serif;
font-size: 1.5em;
}

.title--collapsed {
Expand All @@ -39,9 +42,9 @@ i {

a {
text-decoration: none;
margin-top: 6px;
}

a:hover {
text-decoration: underline;
cursor: pointer;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<div class="container" @panelWidthTrigger="expandedState">
<div class="title">
<div class="title" @titleColorTrigger="expandedState">
<span *ngIf="expanded" @titleTextTrigger="'in'">Notifications</span>
<a class="link" (click)="toggleExpandedState()">
<i @iconTrigger="expandedState" class="fa fa-arrow-circle-left" aria-hidden="true"></i>
</a>
</div>

<div class="notifications">
<notification *ngFor="let n of notificationService.notifications$ | async"
[notification]="n"
[expanded]="expanded"></notification>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,48 @@ var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require('@angular/core');
var NotificationsComponent = (function () {
function NotificationsComponent() {
var index_1 = require("../shared/index");
var index_2 = require("../notification/index");
var NotificationPanelComponent = (function () {
function NotificationPanelComponent(notificationService) {
this.notificationService = notificationService;
this.expanded = false;
this.expandedState = 'collapsed';
}
NotificationsComponent.prototype.ngOnInit = function () { };
NotificationsComponent.prototype.toggleExpandedState = function () {
NotificationPanelComponent.prototype.ngOnInit = function () { };
NotificationPanelComponent.prototype.toggleExpandedState = function () {
this.expandedState = this.expanded ? 'collapsed' : 'expanded';
this.expanded = !this.expanded;
};
NotificationsComponent = __decorate([
NotificationPanelComponent = __decorate([
core_1.Component({
moduleId: module.id,
selector: 'notifications',
templateUrl: 'notifications.component.html',
styleUrls: ['notifications.component.css'],
selector: 'notification-panel',
directives: [index_2.NotificationComponent],
templateUrl: 'notification-panel.component.html',
styleUrls: ['notification-panel.component.css'],
animations: [
core_1.trigger('panelWidthTrigger', [
core_1.state('expanded', core_1.style({
width: '300px'
})),
core_1.state('collapsed', core_1.style({
width: '50px'
width: '38px'
})),
core_1.transition('collapsed => expanded', core_1.animate('300ms ease-in')),
core_1.transition('expanded => collapsed', core_1.animate('300ms ease-out'))
core_1.transition('collapsed => expanded', core_1.animate('200ms ease-in')),
core_1.transition('expanded => collapsed', core_1.animate('200ms 200ms ease-out'))
]),
core_1.trigger('titleColorTrigger', [
core_1.state('collapsed', core_1.style({
backgroundColor: '#FFFFFF',
color: '#E74C3C'
})),
core_1.state('expanded', core_1.style({
backgroundColor: '#E74C3C',
color: '#FFFFFF'
})),
core_1.transition('collapsed => expanded', core_1.animate('200ms ease-in')),
core_1.transition('expanded => collapsed', core_1.animate('200ms 200ms ease-out'))
]),
core_1.trigger('titleTextTrigger', [
core_1.state('in', core_1.style({ opacity: '1' })),
Expand All @@ -43,19 +59,19 @@ var NotificationsComponent = (function () {
core_1.animate('100ms 300ms')
]),
core_1.transition('* => void', [
core_1.animate('100ms', core_1.style({ opacity: '0' }))
core_1.animate('50ms', core_1.style({ opacity: '0' }))
])
]),
core_1.trigger('iconTrigger', [
core_1.state('collapsed', core_1.style({ transform: 'rotate(0deg)' })),
core_1.state('expanded', core_1.style({ transform: 'rotate(180deg)' })),
core_1.transition('collapsed => expanded', core_1.animate('300ms ease-in')),
core_1.transition('expanded => collapsed', core_1.animate('300ms ease-out'))
core_1.transition('collapsed => expanded', core_1.animate('200ms ease-in')),
core_1.transition('expanded => collapsed', core_1.animate('200ms ease-out'))
])
]
}),
__metadata('design:paramtypes', [])
], NotificationsComponent);
return NotificationsComponent;
__metadata('design:paramtypes', [index_1.NotificationService])
], NotificationPanelComponent);
return NotificationPanelComponent;
}());
exports.NotificationsComponent = NotificationsComponent;
exports.NotificationPanelComponent = NotificationPanelComponent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
Component,
OnInit,
trigger,
state,
style,
transition,
animate
} from '@angular/core';

import {NotificationService} from "../shared/index";
import {NotificationComponent} from "../notification/index";

@Component({
moduleId: module.id,
selector: 'notification-panel',
directives: [NotificationComponent],
templateUrl: 'notification-panel.component.html',
styleUrls: ['notification-panel.component.css'],
animations: [
trigger('panelWidthTrigger', [
state('expanded', style({
width: '300px'
})),
state('collapsed', style({
width: '38px'
})),
transition('collapsed => expanded', animate('200ms ease-in')),
transition('expanded => collapsed', animate('200ms 200ms ease-out'))
]),
trigger('titleColorTrigger', [
state('collapsed', style({
backgroundColor: '#FFFFFF',
color: '#E74C3C'
})),
state('expanded', style({
backgroundColor: '#E74C3C',
color: '#FFFFFF'
})),
transition('collapsed => expanded', animate('200ms ease-in')),
transition('expanded => collapsed', animate('200ms 200ms ease-out'))
]),
trigger('titleTextTrigger', [
state('in', style({ opacity: '1' })),
transition('void => *', [
style({ opacity: '0' }),
animate('100ms 300ms')
]),
transition('* => void', [
animate('50ms', style({ opacity: '0' }))
])
]),
trigger('iconTrigger', [
state('collapsed', style({ transform: 'rotate(0deg)' })),
state('expanded', style({ transform: 'rotate(180deg)' })),
transition('collapsed => expanded', animate('200ms ease-in')),
transition('expanded => collapsed', animate('200ms ease-out'))
])
]
})
export class NotificationPanelComponent implements OnInit {
expanded = false;
expandedState = 'collapsed';

constructor(
private notificationService: NotificationService
) { }

ngOnInit() { }

toggleExpandedState() {
this.expandedState = this.expanded ? 'collapsed' : 'expanded';
this.expanded = !this.expanded;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require("./notifications.component"));
__export(require("./notification.component"));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./notification.component";
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

:host {
display: flex;
flex-direction: row;
justify-content: center;
min-height: 0;
min-width: 0;
padding: 8px;
}

.details {
flex: 1;
display: flex;
flex-direction: column;
margin-left: 8px;
}

.icon {
}

.message {

}

.date {
display: flex;
flex-direction: row;
justify-content: flex-end;
font-size: 0.8em;
color: #444444;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="icon" [ngSwitch]="notification.type">
<i *ngSwitchCase="0" class="fa fa-comment"></i>
<i *ngSwitchCase="1" class="fa fa-exclamation-triangle"></i>
<i *ngSwitchCase="2" class="fa fa-code"></i>
<i *ngSwitchCase="3" class="fa fa-credit-card"></i>
</div>
<div *ngIf="expanded" class="details">
<div class="message">
<span>{{notification.message}}</span>
</div>
<div class="date">
<span>{{notification.date | date:'mediumTime'}}</span>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require('@angular/core');
var index_1 = require("../shared/index");
var NotificationComponent = (function () {
function NotificationComponent() {
this.remove = new core_1.EventEmitter(false);
this.notificationTypes = index_1.NotificationType;
}
NotificationComponent.prototype.ngOnInit = function () { };
__decorate([
core_1.Input(),
__metadata('design:type', index_1.Notification)
], NotificationComponent.prototype, "notification", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Boolean)
], NotificationComponent.prototype, "expanded", void 0);
__decorate([
core_1.Output(),
__metadata('design:type', Object)
], NotificationComponent.prototype, "remove", void 0);
NotificationComponent = __decorate([
core_1.Component({
moduleId: module.id,
selector: 'notification',
templateUrl: 'notification.component.html',
styleUrls: ['notification.component.css']
}),
__metadata('design:paramtypes', [])
], NotificationComponent);
return NotificationComponent;
}());
exports.NotificationComponent = NotificationComponent;
Loading

0 comments on commit a55319c

Please sign in to comment.