JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular-animate.js"></script>
<div ng-app="demoApp" class="cont">
<div ng-controller="FlashDemoCtrl">
<button class="btn btn-success" ng-click="success()">Success</button>
<button class="btn btn-info" ng-click="info()">Info</button>
<button class="btn btn-warning" ng-click="warning()">Warning</button>
<button class="btn btn-danger" ng-click="danger()">Danger</button>
<button class="btn btn-primary" ng-disabled="hasFlash == false;" ng-click="pause()">Pause</button>
<div flash-message="5000"></div>
</div>
</div>
CSS
.alert {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}
.alert h4 {
margin-top: 0;
color: inherit;
}
.alert .alert-link {
font-weight: bold;
}
.alert > p, .alert > ul {
margin-bottom: 0;
}
.alert > p + p {
margin-top: 5px;
}
.alert-dismissable, .alert-dismissible {
padding-right: 35px;
}
.alert-dismissable .close, .alert-dismissible .close {
position: relative;
top: -2px;
right: -21px;
color: inherit;
}
.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
}
.alert-success hr {
border-top-color: #c9e2b3;
}
.alert-success .alert-link {
color: #2b542c;
}
.alert-info {
color: #31708f;
background-color: #d9edf7;
border-color: #bce8f1;
}
.alert-info hr {
border-top-color: #a6e1ec;
}
.alert-info .alert-link {
color: #245269;
}
.alert-warning {
color: #8a6d3b;
background-color: #fcf8e3;
border-color: #faebcc;
}
.alert-warning hr {
border-top-color: #f7e1b5;
}
.alert-warning .alert-link {
color: #66512c;
}
.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
.alert-danger hr {
border-top-color: #e4b9c0;
}
.alert-danger .alert-link {
color: #843534;
}
.close {
float: right;
font-size: 21px;
font-weight: bold;
line-height: 1;
color: #000;
text-shadow: 0 1px 0 #fff;
filter: alpha(opacity=20);
opacity: .2;
}
.close:hover, .close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
filter: alpha(opacity=50);
opacity: .5;
}
button.close {
-webkit-appearance: none;
padding: 0;
cursor: pointer;
background: transparent;
border: 0;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
.alertIn, .alertOut {
-webkit-transition: -webkit-transform 0.22s...
JavaScript
// Demo controller
var app = angular.module('demoApp', ['flash', 'ngAnimate']);
app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', function ($rootScope, $scope, Flash) {
$scope.success = function () {
var message = '<strong>Well done!</strong> You successfully read this important alert message.';
Flash.create('success', message);
};
$scope.info = function () {
var message = '<strong>Heads up!</strong> This alert needs your attention, but it\'s not super important.';
Flash.create('info', message);
};
$scope.warning = function () {
var message = '<strong>Warning!</strong> Better check yourself, you\'re not looking too good.';
Flash.create('warning', message);
};
$scope.danger = function () {
var message = '<strong>Oh snap!</strong> Change a few things up and try submitting again.';
Flash.create('danger', message);
};
$scope.pause = function () {
Flash.pause();
};
}]);
(function () {
'use strict';
var app = angular.module('flash', []);
app.run(function ($rootScope) {
// initialize variables
$rootScope.flash = {};
$rootScope.flash.text = '';
$rootScope.flash.type = '';
$rootScope.flash.timeout = 50;
$rootScope.hasFlash = false;
});
// Directive for compiling dynamic html
app.directive('dynamic', function ($compile) {
return {
restrict: 'A',
replace: true,
link: function (scope, ele, attrs) {
scope.$watch(attrs.dynamic, function (html) {
ele.html(html);
$compile(ele.contents())(scope);
});
}
};
});
// Directive for closing the flash message
app.directive('closeFlash', function ($compile, Flash) {
return {
link: function (scope, ele, attrs) {
ele.on('click', function () {
...