ant-design-blazor/components/modal/modalDialog/ModalRef.cs
zxyao 31aac9f914 refactor: unified use of FeedbackComponent for modal comfirm and drawer (#1263)
* 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>
2021-04-04 15:40:54 +08:00

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);
}
}
}