mirror of https://github.com/abpframework/abp.git
12 changed files with 195 additions and 18 deletions
@ -1,12 +1,13 @@ |
|||
using System.Threading.Tasks; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public interface IUiNotificationService |
|||
{ |
|||
Task Info(string message); |
|||
Task Success(string message); |
|||
Task Warn(string message); |
|||
Task Error(string message); |
|||
Task Info(string message, string title = null, Action<UiNotificationOptions> options = null); |
|||
Task Success(string message, string title = null, Action<UiNotificationOptions> options = null); |
|||
Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null); |
|||
Task Error(string message, string title = null, Action<UiNotificationOptions> options = null); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public class UiNotificationEventArgs : EventArgs |
|||
{ |
|||
public UiNotificationEventArgs(UiNotificationType notificationType, string message, string title, UiNotificationOptions options) |
|||
{ |
|||
NotificationType = notificationType; |
|||
Message = message; |
|||
Title = title; |
|||
Options = options; |
|||
} |
|||
|
|||
public UiNotificationType NotificationType { get; set; } |
|||
|
|||
public string Message { get; } |
|||
|
|||
public string Title { get; } |
|||
|
|||
public UiNotificationOptions Options { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
/// <summary>
|
|||
/// Options to override notification appearance.
|
|||
/// </summary>
|
|||
public class UiNotificationOptions |
|||
{ |
|||
/// <summary>
|
|||
/// Custom text for the Ok button.
|
|||
/// </summary>
|
|||
public string OkButtonText { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom icon for the Ok button.
|
|||
/// </summary>
|
|||
public object OkButtonIcon { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public enum UiNotificationType |
|||
{ |
|||
Info, |
|||
Success, |
|||
Warning, |
|||
Error, |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
<SnackbarStack @ref="SnackbarStack" Location="SnackbarStackLocation.Right" Closed="@OnSnackbarClosed" /> |
|||
@ -0,0 +1,71 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Blazorise.Snackbar; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components |
|||
{ |
|||
public partial class UiNotificationAlert : ComponentBase, IDisposable |
|||
{ |
|||
protected SnackbarStack SnackbarStack { get; set; } |
|||
|
|||
[Parameter] public UiNotificationType NotificationType { get; set; } |
|||
|
|||
[Parameter] public string Message { get; set; } |
|||
|
|||
[Parameter] public string Title { get; set; } |
|||
|
|||
[Parameter] public UiNotificationOptions Options { get; set; } |
|||
|
|||
[Parameter] public EventCallback Okayed { get; set; } |
|||
|
|||
[Parameter] public EventCallback Closed { get; set; } |
|||
|
|||
[Inject] protected BlazoriseUiNotificationService UiNotificationService { get; set; } |
|||
|
|||
protected virtual SnackbarColor GetSnackbarColor(UiNotificationType notificationType) |
|||
{ |
|||
return notificationType switch |
|||
{ |
|||
UiNotificationType.Info => SnackbarColor.Info, |
|||
UiNotificationType.Success => SnackbarColor.Success, |
|||
UiNotificationType.Warning => SnackbarColor.Warning, |
|||
UiNotificationType.Error => SnackbarColor.Danger, |
|||
_ => SnackbarColor.None, |
|||
}; |
|||
} |
|||
|
|||
protected override void OnInitialized() |
|||
{ |
|||
base.OnInitialized(); |
|||
|
|||
UiNotificationService.NotificationReceived += OnNotificationReceived; |
|||
} |
|||
|
|||
protected virtual void OnNotificationReceived(object sender, UiNotificationEventArgs e) |
|||
{ |
|||
NotificationType = e.NotificationType; |
|||
Message = e.Message; |
|||
Title = e.Title; |
|||
Options = e.Options; |
|||
|
|||
SnackbarStack.Push(Message, GetSnackbarColor(e.NotificationType)); |
|||
} |
|||
|
|||
public virtual void Dispose() |
|||
{ |
|||
if (UiNotificationService != null) |
|||
{ |
|||
UiNotificationService.NotificationReceived -= OnNotificationReceived; |
|||
} |
|||
} |
|||
|
|||
protected virtual Task OnSnackbarClosed(SnackbarClosedEventArgs eventArgs) |
|||
{ |
|||
return eventArgs.CloseReason == SnackbarCloseReason.UserClosed |
|||
? Okayed.InvokeAsync() |
|||
: Closed.InvokeAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,2 +1,3 @@ |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Blazorise |
|||
@using Blazorise |
|||
@using Blazorise.Snackbar |
|||
Loading…
Reference in new issue