JSFiddle - React, Tailwind, and code Playground
by RobinBressan
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.min.js"></script>
<script src="https://cdn.rawgit.com/RobinBressan/ng-n/1.2.1/ng-n.min.js"></script>
<n-view>
<div class="notification" ng-class="notification.title().toLowerCase()" ng-if="!notification.flush">
<h4>{{ notification.title() }}</h4>
<p>
{{ notification.content() }}
<a class="close" ng-click="notification.kill()">X</a>
<a class="cancel" ng-if="notification.isCancellable && notification.isCancellable()" ng-click="notification.trigger('cancel').kill()"> ( Cancel )</a>
</p>
</div>
<div class="notification stacked" ng-if="notification.flush">
<!-- We are in a stacked notification -->
<h4>{{ notification.size() }} notifications stacked</h4>
<p>
<!-- You can display all notifications in the stack by calling the `flush` method -->
<a ng-click="notification.flush()">Show all</a>
<a class="close" ng-click="notification.kill()">X</a>
</p>
</div>
</n-view>
CSS
/** This css is very basic, just to show you that you can do whatever you want as you decide which template you want to use **/
body {
padding-top: 30px;
}
a {
cursor: pointer;
}
.notification {
position: relative;
font-family: "Helvetica Neue";
border: 1px solid #ccc;
background-color: #eee;
padding: 5px 5px;
margin-bottom: 10px;
border-radius: 5px;
}
.notification.stacked {
background-color: #34495e;
color: #fff;
}
.notification.error {
background-color: #e74c3c;
color: #fff;
}
.notification.info {
background-color: #3498db;
color: #fff;
}
.notification.success {
background-color: #2ecc71;
color: #fff;
}
a.close {
position:absolute;
right: 10px;
top: 10px;
}
a.close, a.cancel {
color: #fff;
cursor: pointer;
font-size: 11px;
}
JavaScript
var app = angular.module('testApp', ['ngN']);
app.factory('withContent', ['$n', function($n) {
return $n.extend({ content: ''});
}]);
app.factory('info', ['withContent', function(withContent) {
return withContent.extend({ title: 'Info' });
}]);
app.factory('error', ['withContent', function(withContent) {
return withContent.extend({ title: 'Error' });
}]);
app.factory('success', ['withContent', function(withContent) {
return withContent.extend({ title: 'Success' });
}]);
app.run(function(info, error, success) {
// Let's display an information with extra attribute
info({ isCancellable: true })
.content("What's up")
.on('cancel', function(n) {
// To confirm our cancel action we create a success notification which will be killed 4000ms later
success()
.content('Information canceled!')
.timeout(4000)
.save();
})
.save();
// Or an error
error()
.content('Oops an unknown error occured!')
.save();
// And a success and delay saving by 2000ms
success()
.content('I am a success notification and as you can see, everything is customizable with ngN, you make it as you wish!')
.save(2000);
console.log(info.stack);
var myStack = info.stack(); // You can create a stack from any factory but it will be created using the root $n factory
myStack.push(info().content('I am stacked!'));
myStack.push(info().content('I am stacked 2!'));
myStack().save(); // Create the stacked notification and display it
});