-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Feature ConfirmationProtection as PropertyEdit extension "WithEdi…
…tConfirmation"
- Loading branch information
Florian Gilde
committed
Jan 1, 2025
1 parent
78998f5
commit 91d8a63
Showing
25 changed files
with
645 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
17 changes: 17 additions & 0 deletions
17
MudBlazor.Extensions/Components/ObjectEdit/Options/AdditionalComponentRenderPosition.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace MudBlazor.Extensions.Components.ObjectEdit.Options; | ||
|
||
/// <summary> | ||
/// The position at which to render an additional component. | ||
/// </summary> | ||
public enum AdditionalComponentRenderPosition | ||
{ | ||
/// <summary> | ||
/// Render the additional component before the current component. | ||
/// </summary> | ||
Before, | ||
|
||
/// <summary> | ||
/// Render the additional component after the current component. | ||
/// </summary> | ||
After | ||
} |
32 changes: 32 additions & 0 deletions
32
MudBlazor.Extensions/Components/ObjectEdit/Options/BooleanInputProtectionBase.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace MudBlazor.Extensions.Components.ObjectEdit.Options; | ||
|
||
/// <summary> | ||
/// Base class for a boolean input protection instance, providing a set of properties and methods to configure the boolean input protection. | ||
/// </summary> | ||
public abstract class BooleanInputProtectionBase<TComponent> : IConfirmationProtection where TComponent : MudBooleanInput<bool>, new() | ||
{ | ||
/// <summary> | ||
/// Constructor for a boolean input protection instance. | ||
/// </summary> | ||
/// <param name="tooltip"></param> | ||
/// <param name="configure"></param> | ||
protected BooleanInputProtectionBase(string tooltip = null, Action<TComponent>? configure = null) | ||
{ | ||
AdditionalRenderData = RenderData.For<TComponent>(cb => | ||
{ | ||
cb.ValueChanged = EventCallback.Factory.Create<bool>(new object(), b => ConfirmationCallback?.Invoke(b)); | ||
configure?.Invoke(cb); | ||
}); | ||
if (!string.IsNullOrWhiteSpace(tooltip)) | ||
{ | ||
AdditionalRenderData.OnRendered<TComponent>(cb => cb.UserAttributes.Add("title", tooltip)); | ||
} | ||
} | ||
/// <inheritdoc /> | ||
public IRenderData AdditionalRenderData { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public Action<bool>? ConfirmationCallback { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
MudBlazor.Extensions/Components/ObjectEdit/Options/CheckBoxConfirmationProtection.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace MudBlazor.Extensions.Components.ObjectEdit.Options; | ||
|
||
/// <inheritdoc /> | ||
public class CheckBoxConfirmationProtection: BooleanInputProtectionBase<MudCheckBox<bool>> | ||
{ | ||
public CheckBoxConfirmationProtection(string tooltip = null, Action<MudCheckBox<bool>> configure = null) : base(tooltip, configure) | ||
{} | ||
} |
62 changes: 62 additions & 0 deletions
62
MudBlazor.Extensions/Components/ObjectEdit/Options/ConfirmationProtection.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using MudBlazor.Extensions.Options; | ||
|
||
namespace MudBlazor.Extensions.Components.ObjectEdit.Options; | ||
|
||
/// <summary> | ||
/// Provides a set of static factory options to protect a component with a confirmation. | ||
/// </summary> | ||
public static class ConfirmationProtection | ||
{ | ||
public static SwitchConfirmationProtection Switch() => Switch(null, box => { box.UncheckedColor = Color.Default; box.Color = Color.Primary; }); | ||
public static SwitchConfirmationProtection Switch(string tooltip) => Switch(tooltip, box => { box.UncheckedColor = Color.Default; box.Color = Color.Primary; }); | ||
public static SwitchConfirmationProtection Switch(string tooltip, Action<MudSwitch<bool>> configure) => new(tooltip, configure); | ||
|
||
public static CheckBoxConfirmationProtection CheckBox() => CheckBox(null, box => { box.UncheckedColor = Color.Default; box.Color = Color.Primary;}); | ||
public static CheckBoxConfirmationProtection CheckBox(string tooltip) => CheckBox(tooltip, box => { box.UncheckedColor = Color.Default; box.Color = Color.Primary;}); | ||
public static CheckBoxConfirmationProtection CheckBox(string tooltip, Action<MudCheckBox<bool>> configure) => new (tooltip, configure); | ||
|
||
public static ToggleButtonConfirmationProtection ToggleButton() => ToggleButton(null, null); | ||
public static ToggleButtonConfirmationProtection ToggleButton(string tooltip) => ToggleButton(tooltip, null); | ||
public static ToggleButtonConfirmationProtection ToggleButton(string tooltip, Action<MudToggleIconButton> configure) => new(tooltip, configure); | ||
|
||
|
||
public static DialogConfirmationProtection ConfirmDialog(IDialogService service) => ConfirmDialog(service, "Confirmation", "Press Unlock to confirm edit", null, null); | ||
public static DialogConfirmationProtection ConfirmDialog(IDialogService service, string title, string message, | ||
Action<MudToggleIconButton> configure = null, | ||
Action<MudExMessageDialog> dialogConfigure = null) | ||
=> new(service, title, message, configure, dialogConfigure); | ||
|
||
public static DialogConfirmationProtection ConfirmDialog(IDialogService service, string title, string message, | ||
DialogOptionsEx dialogOptions, | ||
Action<MudToggleIconButton> configure = null, | ||
Action<MudExMessageDialog> dialogConfigure = null) | ||
=> new(service, title, message, configure, dialogConfigure) { DialogOptions = dialogOptions }; | ||
|
||
public static DialogConfirmationProtection ConfirmDialog(IDialogService service, string title, string message, string okText, string cancelText, | ||
DialogOptionsEx dialogOptions, | ||
Action<MudToggleIconButton> configure = null, | ||
Action<MudExMessageDialog> dialogConfigure = null) | ||
=> new(service, title, message, configure, dialogConfigure) { DialogOptions = dialogOptions, OkText = okText, CancelText = cancelText }; | ||
|
||
|
||
|
||
public static DialogConfirmationProtection PromptDialog(IDialogService service) => PromptDialog(service, "Confirmation", "confirm", "Please confirm to unlock edit", "Please type {0} to confirm", null, null); | ||
|
||
public static DialogConfirmationProtection PromptDialog(IDialogService service, string title, string confirmationWord, string message, string helperText, | ||
Action<MudToggleIconButton> configure = null, | ||
Action<MudExPromptDialog> dialogConfigure = null) | ||
=> new(service, title, confirmationWord, message, helperText, configure, dialogConfigure); | ||
|
||
public static DialogConfirmationProtection PromptDialog(IDialogService service, string title, string confirmationWord, string message, string helperText, | ||
DialogOptionsEx dialogOptions, | ||
Action<MudToggleIconButton> configure = null, | ||
Action<MudExPromptDialog> dialogConfigure = null) | ||
=> new(service, title, confirmationWord, message, helperText, configure, dialogConfigure) { DialogOptions = dialogOptions }; | ||
|
||
public static DialogConfirmationProtection PromptDialog(IDialogService service, string title, string confirmationWord, string message, string helperText, string okText, string cancelText, | ||
DialogOptionsEx dialogOptions, | ||
Action<MudToggleIconButton> configure = null, | ||
Action<MudExPromptDialog> dialogConfigure = null) | ||
=> new(service, title, confirmationWord, message, helperText, configure, dialogConfigure) { DialogOptions = dialogOptions, OkText = okText, CancelText = cancelText }; | ||
|
||
} |
Oops, something went wrong.