@inject IJSRuntime JS
@implements IAsyncDisposable
@code {
[Parameter] public EventCallback OnFirmaCambiata { get; set; }
readonly string _canvasId = $"sig-{Guid.NewGuid():N}";
DotNetObjectReference? _dotNetRef;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_dotNetRef = DotNetObjectReference.Create(this);
await JS.InvokeVoidAsync("signaturePad.init", _canvasId, _dotNetRef);
}
}
[JSInvokable]
public Task OnSignatureChanged(string dataUrl) => OnFirmaCambiata.InvokeAsync(dataUrl);
async Task CancellaFirma()
{
await JS.InvokeVoidAsync("signaturePad.clear", _canvasId);
await OnFirmaCambiata.InvokeAsync(string.Empty);
}
public async ValueTask DisposeAsync()
{
_dotNetRef?.Dispose();
await ValueTask.CompletedTask;
}
}