mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 01:11:52 +08:00
6aff9d370c
* fix(module: Modal&Drawer): render reducing and demo update * docs(module: modal): add FAQ section * docs: add English comments * fix: wrong format in Modal_service_for_confirm.razor 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>
|
|
/// ModalRef with return value
|
|
/// </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);
|
|
}
|
|
}
|
|
}
|