mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
6bf817d1ea
* refactor: change the name of ModalRef to ConfirmRef in order to create a Modal dialog in service mode BREAKING CHANGE: all using of ModalRef must rename to ConfirmRef * refactor: chang the name of ModalTemplate to ConfirmTemplate in order to create a Modal dialog in service mode BREAKING CHANGE: all using of ModalTemplate must rename to ConfirmTemplate * feat(module: modal): support creating Modal dialog from ModalService Co-authored-by: James Yeung <shunjiey@hotmail.com>
85 lines
2.9 KiB
C#
85 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using OneOf;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public class ConfirmService
|
|
{
|
|
internal event Func<ConfirmRef, Task> OnOpenEvent;
|
|
|
|
/// <summary>
|
|
/// show a confirm dialog like MessageBox of Windows
|
|
/// </summary>
|
|
/// <param name="content">the content of dialog</param>
|
|
/// <param name="title">the title of dialog</param>
|
|
/// <param name="confirmButtons">the buttons of dialog</param>
|
|
/// <param name="confirmIcon">the icon of dialog</param>
|
|
/// <param name="options">the configuration options for dialog</param>
|
|
/// <returns></returns>
|
|
public async Task<ConfirmResult> Show(
|
|
OneOf<string, RenderFragment> content,
|
|
OneOf<string, RenderFragment> title,
|
|
ConfirmButtons confirmButtons,
|
|
ConfirmIcon confirmIcon,
|
|
ConfirmButtonOptions options)
|
|
{
|
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
|
ConfirmOptions confirmOptions = new ConfirmOptions()
|
|
{
|
|
Title = title,
|
|
Content = content,
|
|
ConfirmButtons = confirmButtons,
|
|
ConfirmIcon = confirmIcon,
|
|
};
|
|
|
|
#region config button default properties
|
|
|
|
if (options.Button1Props != null)
|
|
{
|
|
confirmOptions.Button1Props = options.Button1Props;
|
|
}
|
|
if (options.Button2Props != null)
|
|
{
|
|
confirmOptions.Button2Props = options.Button2Props;
|
|
}
|
|
if (options.Button3Props != null)
|
|
{
|
|
confirmOptions.Button3Props = options.Button3Props;
|
|
}
|
|
|
|
#endregion
|
|
|
|
var modalRef = new ConfirmRef(confirmOptions)
|
|
{
|
|
TaskCompletionSource = new TaskCompletionSource<ConfirmResult>()
|
|
};
|
|
if (OnOpenEvent != null)
|
|
{
|
|
await OnOpenEvent.Invoke(modalRef);
|
|
}
|
|
return await modalRef.TaskCompletionSource.Task;
|
|
}
|
|
|
|
/// <summary>
|
|
/// show a confirm dialog like MessageBox of Windows
|
|
/// </summary>
|
|
/// <param name="content">the content of dialog</param>
|
|
/// <param name="title">the title of dialog</param>
|
|
/// <param name="confirmButtons">the buttons of dialog</param>
|
|
/// <param name="confirmIcon">the icon of dialog</param>
|
|
/// <returns></returns>
|
|
public Task<ConfirmResult> Show
|
|
(OneOf<string, RenderFragment> content,
|
|
OneOf<string, RenderFragment> title,
|
|
ConfirmButtons confirmButtons = ConfirmButtons.OKCancel,
|
|
ConfirmIcon confirmIcon = ConfirmIcon.Info)
|
|
{
|
|
return Show(content, title, confirmButtons, confirmIcon, new ConfirmButtonOptions());
|
|
}
|
|
}
|
|
}
|