chanan / BlazorStrap

Bootstrap 4 Components for Blazor Framework
https://blazorstrap.io
The Unlicense
910 stars 156 forks source link

Tooltips, Popover, Modal, Offcanvas #591

Closed jbomhold3 closed 1 year ago

jbomhold3 commented 1 year ago

Example Goal

Modal.cs

public class Modal 
{
    public ConcurrentDictionary<string, dynamicType<object>> Children = new();
    public BSModal Add<T>(Action<T> params, string id= Guid.NewGuid.ToString()) where T : class, new()
    {
         var result = new T();
         T parameters;
         params.Invoke(parameters);
         result.Fragment = // Build component match attribute for parameters
         if(!Children .TryAdd(id, result, out _)
         {
               throw("Blah");
         }
        return parameters.ObjectReferance;
    }
    public void Remove<T>(T blah) 
    {
        // Remove
    }
    public void Remove<T>(string name) 
    {
       // Remove
    }

    [JSInvokable]
    public override async Task InteropEventCallback(string id, CallerName name, EventType type,
            Dictionary<string, string>? classList, JavascriptEvent? e)
    {
    //loop children see if event is related do actions
    }
}

MainLayout

@Body
<BSDynamics/>

Any other component

private BSModal _blah;
protected override OnInitialized
{
_blah = BlazorStrap.Modal.Add<ModalComponent>(params, "optionalStringName");
}
public async Task ShowModalAsync()
{
    await _blah.ShowAsync();
    // Or
    BlazorStrap.Modal.ShowAsync("optionalStringName");
}

ModalComponent.razor

<BSModal DataId="modal1" @ref="ObjectReferance">
    <Header>Modal Title</Header>
    <Content>Woohoo, you're reading this text in a modal!</Content>
    <Footer Context="modal">
        <BSButton MarginStart="Margins.Auto" Color="BSColor.Secondary" @onclick="modal.HideAsync">Close</BSButton>
        <BSButton Color="BSColor.Primary">Save changes</BSButton>
    </Footer>
</BSModal>

ModalComponent.razor.cs

   public partial ModalComponent : IDynamicInterface<BSModal?>
   {
        public BSModal? ObjectReferance {get;set;}  // This is on the interface
   }
jbomhold3 commented 1 year ago

Changed the way the core interop works this is no longer needed.