@inject IJSRuntime js
@code {
[Parameter] public RenderFragment Title { get; set; }
[Parameter] public RenderFragment Body { get; set; }
[Parameter] public RenderFragment Footer { get; set; }
[Parameter] public bool ShowCloseButton { get; set; } = true;
[Parameter] public bool StaticBackDrop { get; set; }
}
@code {
private const string HTML_ID_PREFIX = "select2-input-";
private readonly string inputGuid = Guid.NewGuid().ToString();
private string ElementId => HTML_ID_PREFIX + inputGuid;
private ValueTask ShowInternal() => js.InvokeVoidAsync("BootstrapModal", ElementId, true);
private ValueTask HideInternal() => js.InvokeVoidAsync("BootstrapModal", ElementId, false);
private ValueTask ToggleInternal() => js.InvokeVoidAsync("BootstrapModal", ElementId);
private ValueTask UpdateBackDropInternal() => js.InvokeVoidAsync("BootstrapModalSetBackDrop", ElementId, StaticBackDrop);
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
UpdateBackDropInternal();
}
private void CloseButton_Click() => HideInternal();
public void Show() => ShowInternal();
public void Hide() => HideInternal();
public void Toggle() => ToggleInternal();
}