|
1 | | -import { Intent, OverlayToaster, Position } from '@blueprintjs/core'; |
| 1 | +import { createTheme, MantineProvider, Notification as MantineNotification } from '@mantine/core'; |
| 2 | +import { Notifications, notifications } from '@mantine/notifications'; |
2 | 3 | import $ from 'jquery'; |
| 4 | +import React from 'react'; |
3 | 5 | import { tpl, zIndexManager } from 'vj/utils/base'; |
4 | 6 |
|
5 | | -const ToasterContainer = document.createElement('div'); |
6 | | -ToasterContainer.style.position = 'fixed'; |
7 | | -ToasterContainer.style.bottom = '0px'; |
8 | | -ToasterContainer.style.width = '100%'; |
9 | | -ToasterContainer.style.zIndex = '9999'; |
10 | | -document.body.append(ToasterContainer); |
| 7 | +const colorWhite = { |
| 8 | + color: 'var(--mantine-color-white)', |
| 9 | +} as const; |
11 | 10 |
|
12 | | -const AppToaster = OverlayToaster.create( |
13 | | - { position: Position.BOTTOM_LEFT, usePortal: false }, |
14 | | - { container: ToasterContainer }, |
| 11 | +const theme = createTheme({ |
| 12 | + components: { |
| 13 | + Notification: MantineNotification.extend({ |
| 14 | + classNames: { |
| 15 | + closeButton: 'mantine-notifications-close-button', |
| 16 | + }, |
| 17 | + styles: { |
| 18 | + root: { |
| 19 | + backgroundColor: 'var(--notification-color, var(--mantine-primary-color-filled))', |
| 20 | + paddingInlineStart: 'var(--mantine-spacing-xs)', |
| 21 | + }, |
| 22 | + title: { |
| 23 | + ...colorWhite, |
| 24 | + fontSize: 'var(--mantine-font-size-md)', |
| 25 | + }, |
| 26 | + icon: { |
| 27 | + fontSize: '24px', |
| 28 | + marginInlineEnd: 'var(--mantine-spacing-xs)', |
| 29 | + }, |
| 30 | + description: colorWhite, |
| 31 | + closeButton: colorWhite, |
| 32 | + }, |
| 33 | + }), |
| 34 | + }, |
| 35 | +}); |
| 36 | + |
| 37 | +document.body.append(tpl( |
| 38 | + React.createElement(MantineProvider, { theme }, |
| 39 | + React.createElement(Notifications, { position: 'bottom-left', zIndex: 99999 }), |
| 40 | + ), true), |
15 | 41 | ); |
16 | 42 |
|
17 | 43 | interface NotificationOptions { |
@@ -66,20 +92,44 @@ export default class Notification { |
66 | 92 | setTimeout(() => this.$n.remove(), 200); |
67 | 93 | } |
68 | 94 |
|
69 | | - static async success(message: string, duration?: number) { |
70 | | - return (await AppToaster).show({ message, timeout: duration, intent: Intent.SUCCESS }); |
| 95 | + static success(message: string, duration?: number) { |
| 96 | + return notifications.show({ |
| 97 | + title: message, |
| 98 | + color: '#238551', |
| 99 | + message: '', |
| 100 | + icon: React.createElement('i', { className: 'icon icon-check' }), |
| 101 | + autoClose: duration, |
| 102 | + }); |
71 | 103 | } |
72 | 104 |
|
73 | | - static async info(message: string, duration?: number) { |
74 | | - return (await AppToaster).show({ message, timeout: duration, intent: Intent.PRIMARY }); |
| 105 | + static info(message: string, duration?: number) { |
| 106 | + return notifications.show({ |
| 107 | + title: message, |
| 108 | + color: '#2d72d2', |
| 109 | + message: '', |
| 110 | + icon: React.createElement('i', { className: 'icon icon-info--circle' }), |
| 111 | + autoClose: duration, |
| 112 | + }); |
75 | 113 | } |
76 | 114 |
|
77 | | - static async warn(message: string, duration?: number) { |
78 | | - return (await AppToaster).show({ message, timeout: duration, intent: Intent.WARNING }); |
| 115 | + static warn(message: string, duration?: number) { |
| 116 | + return notifications.show({ |
| 117 | + title: message, |
| 118 | + color: '#fbb360', |
| 119 | + message: '', |
| 120 | + icon: React.createElement('i', { className: 'icon icon-warning' }), |
| 121 | + autoClose: duration, |
| 122 | + }); |
79 | 123 | } |
80 | 124 |
|
81 | | - static async error(message: string, duration?: number) { |
82 | | - return (await AppToaster).show({ message, timeout: duration, intent: Intent.DANGER }); |
| 125 | + static error(message: string, duration?: number) { |
| 126 | + return notifications.show({ |
| 127 | + title: message, |
| 128 | + color: '#cd4246', |
| 129 | + message: '', |
| 130 | + icon: React.createElement('i', { className: 'icon icon-close--circle' }), |
| 131 | + autoClose: duration, |
| 132 | + }); |
83 | 133 | } |
84 | 134 | } |
85 | 135 |
|
|
0 commit comments