Skip to content

Commit f3c4517

Browse files
committed
feat: info,success,error,warning,Error,Danger styles for toast NotificationUI
1 parent 408d36f commit f3c4517

File tree

6 files changed

+102
-7
lines changed

6 files changed

+102
-7
lines changed

src/styles/brackets.less

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,11 +2679,11 @@ label input {
26792679

26802680
.notification-popup-container {
26812681
border-radius: 3px;
2682-
background: #005f8f;
2682+
background: var(--bc-toast-info-bg-color);
26832683
box-shadow: 0 0 20px rgba(0, 0, 0, 0.24);
26842684
padding: 9px 12px 9px 12px;
26852685
font-family: "SourceSansPro", serif;
2686-
color: #eee;
2686+
color: black;
26872687
line-height: 1.5;
26882688
margin-top: 7px;
26892689

@@ -2692,6 +2692,22 @@ label input {
26922692
transform: translateY(-50px);
26932693
}
26942694

2695+
.notification-popup-container.style-danger {
2696+
background: var(--bc-toast-danger-bg-color);
2697+
}
2698+
.notification-popup-container.style-error {
2699+
background: var(--bc-toast-error-bg-color);
2700+
}
2701+
.notification-popup-container.style-info {
2702+
background: var(--bc-toast-info-bg-color);
2703+
}
2704+
.notification-popup-container.style-success {
2705+
background: var(--bc-toast-success-bg-color);
2706+
}
2707+
.notification-popup-container.style-warning {
2708+
background: var(--bc-toast-warning-bg-color);
2709+
}
2710+
26952711
.notification-popup-container.animateOpen {
26962712
opacity: 1;
26972713
transition: transform 500ms, opacity 500ms;
@@ -2722,7 +2738,6 @@ label input {
27222738
.notification-dialog-title {
27232739
font-size: 16px;
27242740
font-weight: bold;
2725-
color: #ddd;
27262741
}
27272742

27282743
.notification-dialog-content strong {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
// Copyright (c) 2021 - present core.ai . All rights reserved.
3+
// Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a
6+
// copy of this software and associated documentation files (the "Software"),
7+
// to deal in the Software without restriction, including without limitation
8+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
// and/or sell copies of the Software, and to permit persons to whom the
10+
// Software is furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
// DEALINGS IN THE SOFTWARE.
22+
* Brackets Colors
23+
*
24+
* These are general purpose colors that can be used in defining
25+
* themes or UI elements. you can override these by overriding the :root{} element
26+
* with your own variable definitions in the theme css.
27+
* All brackets color variable names (that refer to an actual color)
28+
* are prefixed with "bc-" for "brackets". This is to avoid confusion
29+
* with system and css color names. (We define our own colors because system
30+
* colors are ugly.)
31+
*/
32+
33+
:root {
34+
--bc-toast-danger-bg-color: #FF5C33;
35+
--bc-toast-error-bg-color: #f74687;
36+
--bc-toast-success-bg-color: #82b839;
37+
--bc-toast-warning-bg-color: #FFAA00;
38+
--bc-toast-info-bg-color: #60A3D9;
39+
}

src/styles/brackets_core_ui_variables.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
* colors are ugly.)
4141
*/
4242

43+
44+
@import "./brackets_core_ui_variables.css";
45+
46+
// DEPRECATION WARNING: This file is here for legacy reasons and will be removed as we migrate entirely to css variables
47+
// this is necessary for extension them-ability.
48+
// Please use brackets_core_ui_variables.css for defining new style variables
49+
4350
// General
4451
@bc-bg-highlight: #e0f0fa;
4552
@bc-bg-inline-widget: #e6e9e9;

src/widgets/NotificationUI.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ define(function (require, exports, module) {
7171
const NOTIFICATION_TYPE_ARROW = "arrow",
7272
NOTIFICATION_TYPE_TOAST = "toast";
7373

74+
const NOTIFICATION_STYLES_CSS_CLASS = {
75+
INFO: "style-info",
76+
WARNING: "style-warning",
77+
SUCCESS: "style-success",
78+
ERROR: "style-error",
79+
DANGER: "style-danger"
80+
};
81+
7482
const CLOSE_REASON ={
7583
TIMEOUT: 'closeTimeout',
7684
CLICK_DISMISS: 'clickDismiss',
@@ -305,19 +313,22 @@ define(function (require, exports, module) {
305313
*
306314
* @param {string} title The title for the notification.
307315
* @param {string|Element} template A string template or HTML Element to use as the dialog HTML.
308-
* @param {{dismissOnClick, autoCloseTimeS}} [options] optional, supported
316+
* @param {{dismissOnClick, autoCloseTimeS, toastStyle}} [options] optional, supported
309317
* * options are:
310318
* * `autoCloseTimeS` - Time in seconds after which the notification should be auto closed. Default is never.
311319
* * `dismissOnClick` - when clicked, the notification is closed. Default is true(dismiss).
320+
* * `toastStyle` - To style the toast notification for error, warning, info etc. Can be
321+
* one of `NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.*` or your own css class name.
312322
* @return {Notification} Object with a done handler that resolves when the notification closes.
313323
* @type {function}
314324
*/
315325
function createToastFromTemplate(title, template, options = {}) {
316326
options.dismissOnClick = options.dismissOnClick === undefined ? true : options.dismissOnClick;
317327
notificationWidgetCount++;
318328
const widgetID = `notification-toast-${notificationWidgetCount}`,
319-
$NotificationPopup = $(Mustache.render(ToastPopupHtml,
320-
{id: widgetID, title: title}));
329+
$NotificationPopup = $(Mustache.render(ToastPopupHtml, {id: widgetID, title: title,
330+
containerStyle: NOTIFICATION_STYLES_CSS_CLASS[options.toastStyle]
331+
|| options.toastStyle || NOTIFICATION_STYLES_CSS_CLASS.INFO}));
321332
$NotificationPopup.find(".notification-dialog-content")
322333
.append($(template));
323334

@@ -354,4 +365,5 @@ define(function (require, exports, module) {
354365
exports.createFromTemplate = createFromTemplate;
355366
exports.createToastFromTemplate = createToastFromTemplate;
356367
exports.CLOSE_REASON = CLOSE_REASON;
368+
exports.NOTIFICATION_STYLES_CSS_CLASS = NOTIFICATION_STYLES_CSS_CLASS;
357369
});

src/widgets/html/toast-popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="{{id}}" class="notification-popup-container">
1+
<div id="{{id}}" class="notification-popup-container {{containerStyle}}">
22
<div>
33
<p class='notification-popup-close-button'>×</p>
44
</div>

test/spec/NotificationUI-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,27 @@ define(function (require, exports, module) {
9292
return $("#toast-notification-container").children().length === 0;
9393
}, "waiting for notification to close");
9494
});
95+
96+
async function verifyToast(cssClass) {
97+
let notification = NotificationUI.createToastFromTemplate("hello", "world", {
98+
toastStyle: cssClass
99+
});
100+
await awaitsFor(()=>{
101+
return $(`#toast-notification-container .${cssClass}`).length === 1;
102+
}, "waiting for notification to appear");
103+
notification.close("test");
104+
await awaitsFor(()=>{
105+
return $(`#toast-notification-container .${cssClass}`).length === 0;
106+
}, "waiting for notification to close");
107+
}
108+
109+
it("Should style toast notification", async function () {
110+
await verifyToast(NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.INFO);
111+
await verifyToast(NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.WARNING);
112+
await verifyToast(NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.SUCCESS);
113+
await verifyToast(NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.ERROR);
114+
await verifyToast(NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.DANGER);
115+
await verifyToast("custom-class-name");
116+
}, 10000);
95117
});
96118
});

0 commit comments

Comments
 (0)