Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using System.Text
@namespace MudExtensions
@inject IJSRuntime JsRuntime
@inject IBrowserViewportService BrowserViewportService
@inherits ComponentBase

<MudPaper Elevation="@Elevation" Class="@OuterClass">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MudBlazor;
using MudBlazor.Services;
using MudBlazor.Utilities;
using MudExtensions.Utilities;

Expand All @@ -9,10 +10,10 @@ namespace MudExtensions
/// <summary>
/// Signature pad component.
/// </summary>
public partial class MudSignaturePad : ComponentBase, IAsyncDisposable
public partial class MudSignaturePad : ComponentBase, IBrowserViewportObserver, IAsyncDisposable
{
/// <summary>
///
/// Constructor for MudSignaturePad.
/// </summary>
public MudSignaturePad()
{
Expand All @@ -23,6 +24,7 @@ public MudSignaturePad()
///
/// </summary>
protected string CanvasContainerClassname => new CssBuilder()
.AddClass("mud-signature-pad-container")
.AddClass(CanvasContainerClass)
.Build();

Expand Down Expand Up @@ -67,7 +69,7 @@ record JsOptionsStructRecord(decimal LineWidth, string LineCap, string LineJoin,
public SignaturePadLocalizedStrings LocalizedStrings { get; set; } = new();

/// <summary>
///
/// Options for the signature pad.
/// </summary>
[Parameter]
public SignaturePadOptions Options { get; set; } = new SignaturePadOptions();
Expand All @@ -79,13 +81,13 @@ record JsOptionsStructRecord(decimal LineWidth, string LineCap, string LineJoin,
public string? ToolbarClass { get; set; }

/// <summary>
///
/// Style for the toolbar.
/// </summary>
[Parameter]
public string? ToolbarStyle { get; set; }

/// <summary>
///
/// Outer class for the component.
/// </summary>
[Parameter]
public string? OuterClass { get; set; }
Expand All @@ -107,16 +109,16 @@ record JsOptionsStructRecord(decimal LineWidth, string LineCap, string LineJoin,
/// </summary>
[Parameter]
public string? CanvasContainerStyle { get; set; } =
"height: 100%;width: 100%; box-shadow: rgb(204, 219, 232) 3px 3px 6px 0px inset, rgba(255, 255, 255, 0.5) -3px -3px 6px 1px inset;";
"height: 100%;width: 100%; display: block; box-shadow: rgb(204, 219, 232) 3px 3px 6px 0px inset, rgba(255, 255, 255, 0.5) -3px -3px 6px 1px inset;";

/// <summary>
///
/// Shows the eraser toggle button.
/// </summary>
[Parameter]
public bool ShowClear { get; set; } = true;

/// <summary>
///
///
/// </summary>
[Parameter]
public bool ShowLineWidth { get; set; } = true;
Expand All @@ -128,7 +130,7 @@ record JsOptionsStructRecord(decimal LineWidth, string LineCap, string LineJoin,
public bool ShowStrokeStyle { get; set; } = true;

/// <summary>
///
///
/// </summary>
[Parameter]
public bool ShowDownload { get; set; } = true;
Expand All @@ -155,7 +157,7 @@ record JsOptionsStructRecord(decimal LineWidth, string LineCap, string LineJoin,
///
/// </summary>
[Parameter]
public Variant Variant { get; set; }
public Variant Variant { get; set; } = MudGlobal.InputDefaults.Variant;

/// <summary>
///
Expand All @@ -178,8 +180,9 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JsRuntime.InvokeVoidAsync("mudSignaturePad.addPad", _dotnetObjectRef, _reference,
JsOptionsStruct);
await JsRuntime.InvokeVoidAsync("mudSignaturePad.addPad", _dotnetObjectRef, _reference, JsOptionsStruct);
await BrowserViewportService.SubscribeAsync(this, fireImmediately: true);

if (Value.Length > 0)
{
await PushImageUpdateToJsRuntime();
Expand Down Expand Up @@ -250,11 +253,13 @@ public async ValueTask DisposeAsync()
try
{
await JsRuntime.InvokeVoidAsync("mudSignaturePad.disposePad", _reference);
await BrowserViewportService.UnsubscribeAsync(this);
}
catch
{
//ignore
}
_dotnetObjectRef?.Dispose();
}

/// <summary>
Expand All @@ -276,5 +281,25 @@ public async Task SignatureDataChangedAsync()

await ValueChanged.InvokeAsync(Value);
}

Guid IBrowserViewportObserver.Id { get; } = Guid.NewGuid();

ResizeOptions IBrowserViewportObserver.ResizeOptions { get; } = new()
{
ReportRate = 200,
NotifyOnBreakpointOnly = false
};

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public async Task NotifyBrowserViewportChangeAsync(BrowserViewportEventArgs args)
{
await JsRuntime.InvokeVoidAsync("mudSignaturePad.setCanvasSize", _reference);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.mud-signature-pad-container {
touch-action: none;
}
3 changes: 3 additions & 0 deletions CodeBeam.MudBlazor.Extensions/Styles/MudExtensions.css
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@
.mud-range-display {
text-align: center; }

.mud-signature-pad-container {
touch-action: none; }

.mud-splitter {
display: grid;
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion CodeBeam.MudBlazor.Extensions/Styles/MudExtensions.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions CodeBeam.MudBlazor.Extensions/Styles/MudExtensions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import 'components/_page';
@import 'components/_popup';
@import 'components/_rangeslider';
@import 'components/_signaturepad';
@import 'components/_splitter';
@import 'components/_stepper';
@import 'components/_switchm3';
Expand Down
Loading
Loading