Skip to content

Commit 71d481d

Browse files
committed
DEV Notification Opt-In
Default HTML content to false, allow it on option true
1 parent 0886143 commit 71d481d

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/notification/toast-notification.component.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* @scope
66
*
77
* @param {string} notificationType The type of the notification message. Allowed value is one of these: 'success','info','danger', 'warning'
8-
* @param {string} header The header text of the notification. Accepts HTML content.
9-
* @param {string} message The main text message of the notification. Accepts HTML content.
8+
* @param {string} header The header text of the notification. Accepts HTML content when allowed.
9+
* @param {string} message The main text message of the notification. Accepts HTML content when allowed.
1010
* @param {boolean} showClose Flag to show the close button, default: true
11+
* @param {boolean} htmlContent Flag to allow HTML content within the header and message options.
1112
* @param {function} closeCallback (function(data)) Function to invoke when close action is selected, optional
1213
* @param {string} actionTitle Text to show for the primary action, optional.
1314
* @param {function} actionCallback (function(data)) Function to invoke when primary action is selected, optional
@@ -37,9 +38,9 @@
3738
<div ng-controller="ToastNotificationDemoCtrl" class="row example-container">
3839
<div class="col-md-12">
3940
<pf-toast-notification notification-type="{{type}}" header="{{header}}" message="{{message}}"
40-
show-close="{{showClose}}" close-callback="closeCallback"
41-
action-title="{{primaryAction}}" action-callback="handleAction"
42-
menu-actions="menuActions">
41+
show-close="{{showClose}}" html-content="htmlContent"
42+
close-callback="closeCallback" action-title="{{primaryAction}}"
43+
action-callback="handleAction" menu-actions="menuActions">
4344
</pf-toast-notification>
4445
4546
<form class="form-horizontal">
@@ -81,13 +82,17 @@
8182
</div>
8283
<div class="form-group">
8384
<label class="col-sm-2 control-label" for="type">Show Close:</label>
84-
<div class="col-sm-3">
85+
<div class="col-sm-1">
8586
<input type="checkbox" ng-model="showClose"/>
8687
</div>
8788
<label class="col-sm-2 control-label" for="type">Show Menu:</label>
88-
<div class="col-sm-3">
89+
<div class="col-sm-1">
8990
<input type="checkbox" ng-model="showMenu"/>
9091
</div>
92+
<label class="col-sm-2 control-label" for="type">Allow HTML:</label>
93+
<div class="col-sm-1">
94+
<input type="checkbox" ng-model="htmlContent"/>
95+
</div>
9196
</div>
9297
</form>
9398
</div>
@@ -105,6 +110,7 @@
105110
$scope.types = ['success','info','danger', 'warning'];
106111
$scope.type = $scope.types[0];
107112
$scope.showClose = false;
113+
$scope.htmlContent = false;
108114
109115
$scope.header = 'Default Header.';
110116
$scope.message = 'Default <strong>notification</strong> message.';
@@ -182,6 +188,7 @@ angular.module( 'patternfly.notification' ).component('pfToastNotification', {
182188
'message': '@',
183189
'header': '@',
184190
'showClose': '@',
191+
'htmlContent': '<?',
185192
'closeCallback': '=?',
186193
'actionTitle': '@',
187194
'actionCallback': '=?',

src/notification/toast-notification.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
<span class="pficon pficon-info" ng-if="$ctrl.notificationType === 'info'"></span>
2828
<span class="pficon pficon-error-circle-o" ng-if="$ctrl.notificationType === 'danger'"></span>
2929
<span class="pficon pficon-warning-triangle-o" ng-if="$ctrl.notificationType === 'warning'"></span>
30-
<span>
30+
<span ng-if="!$ctrl.htmlContent">
31+
<strong ng-if="$ctrl.header" ng-bind="$ctrl.header"></strong>
32+
<span ng-bind="$ctrl.message"></span>
33+
</span>
34+
<span ng-if="$ctrl.htmlContent">
3135
<strong ng-if="$ctrl.header" ng-bind-html="$ctrl.trustAsHtml($ctrl.header)"></strong>
3236
<span ng-bind-html="$ctrl.trustAsHtml($ctrl.message)"></span>
3337
</span>

test/notification/toast-notification.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ describe('Component: pfToastNotification', function () {
2121
scope.$digest();
2222
};
2323

24-
var setupHTML = function (notificationType, header, message, showClose, primaryAction, showMenu, data) {
24+
var setupHTML = function (notificationType, header, message, showClose, primaryAction, showMenu, data, htmlContent) {
2525
$scope.type = notificationType;
2626
$scope.header = header;
2727
$scope.message = message || "Test Toast Notification Message";
2828
$scope.showClose = showClose;
2929
$scope.primaryAction = primaryAction;
3030
$scope.data = data;
31+
$scope.htmlContent = htmlContent;
3132

3233
$scope.closeData = undefined;
3334
$scope.closeCallback = function (data) {
@@ -91,9 +92,9 @@ describe('Component: pfToastNotification', function () {
9192
title: "Test Notification"
9293
};
9394
var htmlTmp = '<pf-toast-notification notification-type="{{type}}" header="{{header}}" message="{{message}}"' +
94-
' show-close="{{showClose}}" close-callback="closeCallback"' +
95-
' action-title="{{primaryAction}}" action-callback="handleAction"' +
96-
' menu-actions="menuActions" data="data">' +
95+
' show-close="{{showClose}}" html-content="htmlContent" ' +
96+
' close-callback="closeCallback" action-title="{{primaryAction}}"' +
97+
' action-callback="handleAction" menu-actions="menuActions" data="data">' +
9798
' </pf-toast-notification>';
9899

99100
compileHTML(htmlTmp, $scope);
@@ -119,12 +120,12 @@ describe('Component: pfToastNotification', function () {
119120
});
120121

121122
it('should allow HTML content within the header and message', function () {
122-
setupHTML ("info", "<em>Test Header</em>", null, false, '', false);
123+
setupHTML ("info", "<em>Test Header</em>", null, false, '', false, null, true);
123124
var header = element.find('.toast-pf span strong em');
124125
expect(header.length).toBe(1);
125126
expect(header.text()).toContain("Test Header");
126127

127-
setupHTML ("info", "", "<em>Test Notification Message</em>", false, '', false);
128+
setupHTML ("info", "", "<em>Test Notification Message</em>", false, '', false, null, true);
128129
var message = element.find('.toast-pf > span em');
129130
expect(message.length).toBe(1);
130131
expect(message.text()).toContain("Test Notification Message");

0 commit comments

Comments
 (0)