using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; namespace AntDesign { public partial class ModalService { internal event Func OnModalOpenEvent; internal event Func OnModalCloseEvent; /// /// Create and open a Moal /// /// public Task CreateModalAsync(ModalOptions config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } ModalRef modalRef = new ModalRef(config, this); config.ModalRef = modalRef; return CreateOrOpenModalAsync(modalRef); } /// /// Create and open template modal /// /// /// /// /// /// public Task CreateModalAsync(ModalOptions config, TComponentOptions componentOptions) where TComponent : ModalTemplate { if (config == null) { throw new ArgumentNullException(nameof(config)); } ModalRef modalRef = new ModalRef(config, this); void Child(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { builder.OpenComponent(0); builder.AddAttribute(1, "ModalRef", modalRef); builder.AddAttribute(2, "Options", componentOptions); builder.CloseComponent(); } config.Content = Child; config.ModalRef = modalRef; return CreateOrOpenModalAsync(modalRef); } internal Task CreateOrOpenModalAsync(ModalRef modalRef) { OnModalOpenEvent?.Invoke(modalRef); return Task.FromResult(modalRef); } internal Task CloseModalAsync(ModalRef modalRef) { if (OnModalCloseEvent != null) { return OnModalCloseEvent.Invoke(modalRef); } return Task.CompletedTask; } } }