Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 6ffd686

Browse files
committed
Fix update in-progress toast
1 parent c02359e commit 6ffd686

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

src/ToastJupyterLab.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export namespace INotification {
112112
* Autoclosing behavior - undefined (not closing automatically)
113113
* or number (time in milliseconds before closing a toast)
114114
*/
115-
autoClose?: number;
115+
autoClose?: number | false;
116116
}
117117

118118
/**
@@ -154,8 +154,7 @@ export namespace INotification {
154154
async function createToast(
155155
message: React.ReactNode,
156156
buttons?: IButton[],
157-
options?: ToastOptions,
158-
icon?: JSX.Element
157+
options?: ToastOptions
159158
): Promise<React.ReactText> {
160159
let _resolve: (value: React.ReactText) => void;
161160
const toast = await Private.toast();
@@ -169,10 +168,11 @@ export namespace INotification {
169168
message,
170169
closeToast,
171170
buttons,
172-
icon || Private.type2Icon.get(theOptions.type)
171+
Private.type2Icon.get(theOptions.type || "in-progress")
173172
),
174173
{
175174
...options,
175+
className: `jp-toast-${theOptions.type || "in-progress"}`,
176176
onOpen: () => _resolve(toastId)
177177
}
178178
);
@@ -194,7 +194,6 @@ export namespace INotification {
194194
): Promise<React.ReactText> => {
195195
return createToast(message, options && options.buttons, {
196196
type: "error",
197-
className: "jp-toast-error",
198197
autoClose: (options && options.autoClose) || false
199198
});
200199
};
@@ -212,7 +211,6 @@ export namespace INotification {
212211
): Promise<React.ReactText> => {
213212
return createToast(message, options && options.buttons, {
214213
type: "warning",
215-
className: "jp-toast-warning",
216214
autoClose: (options && options.autoClose) || false
217215
});
218216
};
@@ -236,7 +234,6 @@ export namespace INotification {
236234
(buttons && buttons.length > 0 ? false : undefined);
237235
return createToast(message, buttons, {
238236
type: "info",
239-
className: "jp-toast-info",
240237
autoClose: autoClose
241238
});
242239
};
@@ -260,7 +257,6 @@ export namespace INotification {
260257
(buttons && buttons.length > 0 ? false : undefined);
261258
return createToast(message, buttons, {
262259
type: "success",
263-
className: "jp-toast-success",
264260
autoClose: autoClose
265261
});
266262
};
@@ -277,21 +273,9 @@ export namespace INotification {
277273
message: React.ReactNode,
278274
options?: IOptions
279275
): Promise<React.ReactText> => {
280-
return createToast(
281-
message,
282-
options && options.buttons,
283-
{
284-
type: "default",
285-
className: "jp-toast-inprogress",
286-
autoClose: (options && options.autoClose) || false
287-
},
288-
<FontAwesomeIcon
289-
icon={faSpinner}
290-
pull="left"
291-
spin
292-
style={{ color: "var(--jp-inverse-layout-color3)" }}
293-
/>
294-
);
276+
return createToast(message, options && options.buttons, {
277+
autoClose: (options && options.autoClose) || false
278+
});
295279
};
296280

297281
/** Options needed to update an existing toast */
@@ -341,7 +325,8 @@ export namespace INotification {
341325
args.message,
342326
closeToast,
343327
args.buttons,
344-
Private.type2Icon.get(options.type)
328+
// If not type specified, assumes it is `in progress`
329+
Private.type2Icon.get(options.type || "in-progress")
345330
)
346331
});
347332
} else {
@@ -350,9 +335,7 @@ export namespace INotification {
350335
// If not type specified, assumes it is `in progress`
351336
const newOptions: ToastOptions = {
352337
autoClose: false,
353-
className: "jp-toast-inprogress",
354338
toastId: args.toastId,
355-
type: "default",
356339
...options
357340
};
358341

@@ -467,8 +450,17 @@ interface IToast {
467450
}
468451

469452
namespace Private {
470-
export const type2Icon = new Map<TypeOptions, JSX.Element>([
453+
export const type2Icon = new Map<TypeOptions | "in-progress", JSX.Element>([
471454
["default", null],
455+
[
456+
"in-progress",
457+
<FontAwesomeIcon
458+
icon={faSpinner}
459+
pull="left"
460+
spin
461+
style={{ color: "var(--jp-inverse-layout-color3)" }}
462+
/>
463+
],
472464
[
473465
"error",
474466
<FontAwesomeIcon

style/index.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
cursor: default;
1414
}
1515

16+
.Toastify__toast-body > svg.svg-inline--fa {
17+
margin-top: 0.2em;
18+
}
19+
1620
.Toastify__toast--error {
1721
border-top: 5px solid var(--jp-error-color1);
1822
}
@@ -29,7 +33,7 @@
2933
border-top: 5px solid var(--jp-success-color1);
3034
}
3135

32-
.Toastify__toast--default.jp-toast-inprogress {
36+
.Toastify__toast--default.jp-toast-in-progress {
3337
border-top: 5px solid var(--jp-layout-color1);
3438
}
3539

0 commit comments

Comments
 (0)