ConfirmModal.razor 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. @if (IsOpen)
  2. {
  3. <div class="fixed inset-0 z-50 flex items-center justify-center">
  4. <!-- Backdrop -->
  5. <div
  6. class="absolute inset-0 bg-black/60"
  7. @onclick="Close">
  8. </div>
  9. <!-- Modal -->
  10. <div class="relative z-10 w-full max-w-md rounded border border-zinc-800 bg-zinc-900 p-4 shadow-lg">
  11. <div class="mb-3 text-lg font-semibold text-zinc-100">
  12. @Title
  13. </div>
  14. <div class="mb-4 text-sm text-zinc-300">
  15. @ChildContent
  16. </div>
  17. <div class="flex justify-end gap-2">
  18. <button
  19. class="px-3 py-1 text-sm rounded bg-zinc-800 hover:bg-zinc-700 text-zinc-300 transition"
  20. @onclick="Close">
  21. Cancel
  22. </button>
  23. <button
  24. class="px-3 py-1 text-sm rounded text-white transition @ConfirmClass"
  25. @onclick="Confirm">
  26. @ConfirmText
  27. </button>
  28. </div>
  29. </div>
  30. </div>
  31. }
  32. @code{
  33. [Parameter] public bool IsOpen { get; set; }
  34. [Parameter] public EventCallback<bool> IsOpenChanged { get; set; }
  35. [Parameter, EditorRequired] public string Title { get; set; } = default!;
  36. [Parameter] public string ConfirmText { get; set; } = "Confirm";
  37. [Parameter] public string ConfirmClass { get; set; } = "bg-emerald-600 hover:bg-emerald-500";
  38. [Parameter] public RenderFragment? ChildContent { get; set; }
  39. [Parameter, EditorRequired] public EventCallback OnConfirm { get; set; }
  40. async Task Close()
  41. {
  42. IsOpen = false;
  43. await IsOpenChanged.InvokeAsync(false);
  44. }
  45. async Task Confirm()
  46. {
  47. await OnConfirm.InvokeAsync();
  48. await Close();
  49. }
  50. }