mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
31aac9f914
* refactor: support to use the same template for confirm and modal * refactor: support to use the same template for drawer * refactor: separate interface IOkCancelRef * chore: modify EventUtil class summary Co-authored-by: James Yeung <shunjiey@hotmail.com>
85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AntDesign
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ModalRef : FeedbackRefWithOkCancelBase
|
|
{
|
|
public ModalOptions Config { get; private set; }
|
|
private readonly ModalService _service;
|
|
|
|
internal ModalRef(ModalOptions config, ModalService modalService)
|
|
{
|
|
Config = config;
|
|
_service = modalService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// open the Modal dialog
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override async Task OpenAsync()
|
|
{
|
|
if (!Config.Visible)
|
|
{
|
|
Config.Visible = true;
|
|
}
|
|
|
|
await _service.CreateOrOpenModalAsync(this);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// close the Modal dialog
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override async Task CloseAsync()
|
|
{
|
|
await _service.CloseModalAsync(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update modal
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override async Task UpdateConfigAsync()
|
|
{
|
|
await _service.UpdateModalAsync(this);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <typeparam name="TResult"></typeparam>
|
|
public class ModalRef<TResult> : ModalRef, IOkCancelRef<TResult>
|
|
{
|
|
internal ModalRef(ModalOptions config, ModalService modalService) : base(config, modalService)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public new Func<TResult, Task> OnCancel { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public new Func<TResult, Task> OnOk { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public async Task OkAsync(TResult result)
|
|
{
|
|
await (OnOk?.Invoke(result) ?? Task.CompletedTask);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task CancelAsync(TResult result)
|
|
{
|
|
await (OnOk?.Invoke(result) ?? Task.CompletedTask);
|
|
}
|
|
}
|
|
}
|