This commit is contained in:
Samuele Locatelli
2026-05-05 11:19:22 +02:00
parent 1936d43a04
commit aaab18910b
-75
View File
@@ -1,75 +0,0 @@
@using Microsoft.JSInterop
@inject IJSRuntime JS
<div class="modal fade" id="@ModalId" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-top">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
@onclick="Cancel"></button>
</div>
<div class="modal-body">
<p>@Message</p>
<input @bind="UserInput" class="form-control" placeholder="Type here..." />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" @onclick="Confirm">OK</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @onclick="Cancel">Cancel</button>
</div>
</div>
</div>
</div>
@code {
private TaskCompletionSource<string?>? tcs;
private string ModalId { get; } = $"modal_{Guid.NewGuid():N}";
[Parameter]
public string Title { get; set; } = "";
[Parameter]
public string Message { get; set; } = "";
[Parameter]
public string UserInput { get; set; } = "";
/// <summary>
/// Shows the Bootstrap modal and waits for user input.
/// </summary>
public async Task<string?> ShowAsync()
{
// Title = title;
// Message = message;
// UserInput = defaultValue;
tcs = new TaskCompletionSource<string?>();
await JS.InvokeVoidAsync("bootstrapModalHelper.show", $"#{ModalId}");
return await tcs.Task;
}
/// <summary>
/// Shows the Bootstrap modal and waits for user input.
/// </summary>
public async Task<string?> ShowAsync(string message, string defaultValue = "", string title = "Prompt")
{
Title = title;
Message = message;
UserInput = defaultValue;
tcs = new TaskCompletionSource<string?>();
await JS.InvokeVoidAsync("bootstrapModalHelper.show", $"#{ModalId}");
return await tcs.Task;
}
private async Task Confirm()
{
await JS.InvokeVoidAsync("bootstrapModalHelper.hide", $"#{ModalId}");
tcs?.TrySetResult(UserInput);
}
private async Task Cancel()
{
await JS.InvokeVoidAsync("bootstrapModalHelper.hide", $"#{ModalId}");
tcs?.TrySetResult(null);
}
}