Last active
April 5, 2020 07:39
-
-
Save wmeints/b1234e08cf2b164e0b09179743324d79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<CascadingValue Value="@ModalDialogService"> | |
@ChildContent | |
<div class="modal @ModalClasses" tabindex="-1" role="dialog" style="@ModalStyles"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h5 class="modal-title"> | |
@Title | |
</h5> | |
<button class="close" type="button" @onclick="HideDialog"></button> | |
</div> | |
<div class="modal-body"> | |
<p>@Message</p> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-secondary" @onclick="ModalDialogService.Confirm">Yes</button> | |
<button type="button" class="btn btn-secondary" @onclick="ModalDialogService.Cancel">No</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="modal-backdrop @ModalClasses" style="@ModalStyles"></div> | |
</CascadingValue> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Components; | |
namespace Promenade.Client.Services | |
{ | |
public class ModalDialogService | |
{ | |
private readonly Action<string, string> _showDialogHandler; | |
private readonly Action _hideDialogHandler; | |
public ModalDialogService(Action<string, string> showDialogHandler, Action hideDialogHandler) | |
{ | |
_showDialogHandler = showDialogHandler; | |
_hideDialogHandler = hideDialogHandler; | |
} | |
public EventCallback Confirmed { get; set; } = EventCallback.Empty; | |
public EventCallback Cancelled { get; set; } = EventCallback.Empty; | |
public async Task Confirm() | |
{ | |
_hideDialogHandler.Invoke(); | |
await Confirmed.InvokeAsync(null); | |
} | |
public async Task Cancel() | |
{ | |
_hideDialogHandler.Invoke(); | |
await Cancelled.InvokeAsync(null); | |
} | |
public void Show(string title, string message) | |
{ | |
_showDialogHandler.Invoke(title, message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment