Skip to content

Commit 2b4bb80

Browse files
committed
Convert toast notification list to component syntax
1 parent b089350 commit 2b4bb80

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

src/notification/toast-notification-list.component.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* @ngdoc directive
3-
* @name patternfly.notification.directive:pfToastNotificationList
4-
* @restrict A
3+
* @name patternfly.notification.component:pfToastNotificationList
4+
* @restrict E
55
* @scope
66
*
7-
* @param {Array} notifications The list of current notifcations to display. Each notification should have the following (see pfToastNotification):
7+
* @param {Array} notifications The list of current notifications to display. Each notification should have the following (see pfToastNotification):
88
* <ul style='list-style-type: none'>
99
* <li>.type - (String) The type of the notification message. Allowed value is one of these: 'success','info','danger', 'warning'
1010
* <li>.header - (String) The header to display for the notification (optional)
@@ -25,14 +25,14 @@
2525
* @param {function} updateViewing (function(boolean, data)) Function to invoke when user is viewing/not-viewing (hovering on) a toast notification
2626
*
2727
* @description
28-
* Using this directive displayes a list of toast notifications
28+
* Using this component displayes a list of toast notifications
2929
*
3030
* @example
3131
<example module="patternfly.notification">
3232
3333
<file name="index.html">
3434
<div ng-controller="ToastNotificationListDemoCtrl" >
35-
<div pf-toast-notification-list notifications="notifications" show-close="showClose" close-callback="handleClose" update-viewing="updateViewing"></div>
35+
<pf-toast-notification-list notifications="notifications" show-close="showClose" close-callback="handleClose" update-viewing="updateViewing"></pf-toast-notification-list>
3636
<div class="row example-container">
3737
<div class="col-md-12">
3838
<form class="form-horizontal">
@@ -201,29 +201,27 @@
201201
202202
</example>
203203
*/
204-
angular.module('patternfly.notification').directive('pfToastNotificationList', function () {
205-
'use strict';
204+
angular.module('patternfly.notification').component('pfToastNotificationList', {
205+
bindings: {
206+
notifications: '=',
207+
showClose: '=?',
208+
closeCallback: '=?',
209+
updateViewing: '=?'
210+
},
211+
templateUrl: 'notification/toast-notification-list.html',
212+
controller: function () {
213+
'use strict';
214+
var ctrl = this;
206215

207-
return {
208-
restrict: 'A',
209-
scope: {
210-
notifications: '=',
211-
showClose: '=?',
212-
closeCallback: '=?',
213-
updateViewing: '=?'
214-
},
215-
templateUrl: 'notification/toast-notification-list.html',
216-
controller: function ($scope) {
217-
$scope.handleClose = function (notification) {
218-
if (angular.isFunction($scope.closeCallback)) {
219-
$scope.closeCallback(notification);
220-
}
221-
};
222-
$scope.handleViewingChange = function (isViewing, notification) {
223-
if (angular.isFunction($scope.updateViewing)) {
224-
$scope.updateViewing(isViewing, notification);
225-
}
226-
};
227-
}
228-
};
216+
ctrl.handleClose = function (notification) {
217+
if (angular.isFunction(ctrl.closeCallback)) {
218+
ctrl.closeCallback(notification);
219+
}
220+
};
221+
ctrl.handleViewingChange = function (isViewing, notification) {
222+
if (angular.isFunction(ctrl.updateViewing)) {
223+
ctrl.updateViewing(isViewing, notification);
224+
}
225+
};
226+
}
229227
});

src/notification/toast-notification-list.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<div class="toast-notifications-list-pf" data-ng-show="notifications.length > 0">
2-
<div ng-repeat="notification in notifications">
1+
<div class="toast-notifications-list-pf" data-ng-show="$ctrl.notifications.length > 0">
2+
<div ng-repeat="notification in $ctrl.notifications">
33
<pf-toast-notification notification-type="{{notification.type}}"
44
header="{{notification.header}}"
55
message="{{notification.message}}"
6-
show-close="{{(showClose || notification.isPersistent === true) && !(notification.menuActions && notification.menuActions.length > 0)}}"
7-
close-callback="handleClose"
6+
show-close="{{($ctrl.showClose || notification.isPersistent === true) && !(notification.menuActions && notification.menuActions.length > 0)}}"
7+
close-callback="$ctrl.handleClose"
88
action-title="{{notification.actionTitle}}"
99
action-callback="notification.actionCallback"
1010
menu-actions="notification.menuActions"
11-
update-viewing="handleViewingChange"
11+
update-viewing="$ctrl.handleViewingChange"
1212
data="notification">
1313
</pf-toast-notification>
1414
</div>

test/notification/toast-notification-list.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('Directive: pfToastNotificationList', function () {
1+
describe('Component: pfToastNotificationList', function () {
22

33
var $scope;
44
var $compile;
@@ -115,7 +115,7 @@ describe('Directive: pfToastNotificationList', function () {
115115
}
116116
];
117117

118-
var htmlTmp = '<div pf-toast-notification-list notifications="notifications" show-close="false" close-callback="handleClose"></div>';
118+
var htmlTmp = '<pf-toast-notification-list notifications="notifications" show-close="false" close-callback="handleClose"></pf-toast-notification-list>';
119119

120120
compileHTML(htmlTmp, $scope);
121121
});
@@ -158,7 +158,7 @@ describe('Directive: pfToastNotificationList', function () {
158158
$scope.notifications.forEach(function(nextItem) {
159159
nextItem.menuActions = undefined;
160160
})
161-
var htmlTmp = '<div pf-toast-notification-list notifications="notifications" show-close="false" close-callback="handleClose"></div>';
161+
var htmlTmp = '<pf-toast-notification-list notifications="notifications" show-close="false" close-callback="handleClose"></pf-toast-notification-list>';
162162

163163
compileHTML(htmlTmp, $scope);
164164

0 commit comments

Comments
 (0)