forked from CodeBeamOrg/CodeBeam.MudBlazor.Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMudBaseInputExtended.cs
More file actions
180 lines (158 loc) · 6.73 KB
/
MudBaseInputExtended.cs
File metadata and controls
180 lines (158 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MudBlazor;
namespace MudExtensions
{
/// <summary>
/// The extended base input fundamentals.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class MudBaseInputExtended<T> : MudBaseInput<T>
{
private string? _userAttributesId = Identifier.Create("mudinputextended");
private readonly string _componentId = Identifier.Create("mudinputextended");
/// <summary>
///
/// </summary>
[DynamicDependency(nameof(OnBeforeInputFromJs))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(BeforeInputJsDto))]
protected MudBaseInputExtended()
{
//using var registerScope = CreateRegisterScope();
//_textState = registerScope.RegisterParameter<string?>(nameof(Text))
// .WithParameter(() => Text)
// .WithEventCallback(() => TextChanged)
// .WithChangeHandler(OnTextParameterChangedAsync);
//_valueState = registerScope.RegisterParameter<T?>(nameof(Value))
// .WithParameter(() => Value)
// .WithEventCallback(() => ValueChanged)
// .WithChangeHandler(OnValueParameterChangedAsync);
//_formatState = registerScope.RegisterParameter<string?>(nameof(Format))
// .WithParameter(() => Format)
// .WithChangeHandler(OnCultureAndFormatChangedAsync);
//_inputIdState = registerScope.RegisterParameter<string?>(nameof(InputId))
// .WithParameter(() => InputId)
// .WithChangeHandler(UpdateInputIdStateAsync);
}
/// <summary>
/// Fires on input.
/// </summary>
[Parameter] public EventCallback OnInput { get; set; }
/// <summary>
/// Fires on change.
/// </summary>
[Parameter] public EventCallback OnChange { get; set; }
/// <summary>
/// Gets or sets a callback that is invoked before input is processed.
/// </summary>
/// <remarks>Use this callback to perform custom logic or validation before the input event is
/// handled. This can be useful for intercepting or modifying input behavior in advanced scenarios
/// </remarks>
[Parameter]
public EventCallback<BeforeInputEventArgs> OnBeforeInput { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the component has an adornment at the start.
/// </summary>
[Parameter]
public bool HasAdornmentStart { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the component has an adornment at the end.
/// </summary>
[Parameter]
public bool HasAdornmentEnd { get; set; }
/// <summary>
/// The Adornment if used. By default, it is set to None.
/// </summary>
[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public RenderFragment? AdornmentStart { get; set; }
/// <summary>
/// The Adornment if used. By default, it is set to None.
/// </summary>
[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public RenderFragment? AdornmentEnd { get; set; }
/// <summary>
/// CSS style of the child content.
/// </summary>
[Parameter]
public string? ChildContentStyle { get; set; }
/// <summary>
/// If true disables paste to input component. Default is false.
/// </summary>
[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public bool DisablePaste { get; set; } = false;
/// <summary>
/// Override to read Value from ParameterState instead of backing field.
/// </summary>
protected internal new T? ReadValue => base.ReadValue;
/// <summary>
/// Override to write Value to ParameterState instead of backing field.
/// </summary>
protected internal new string? ReadText => base.ReadText;
/// <summary>
/// Invokes logic to be executed before input is processed, including raising the BeforeInput event if a
/// delegate is assigned.
/// </summary>
/// <param name="args">The event data associated with the before input operation.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
protected async Task InvokeBeforeInputAsync(BeforeInputEventArgs args)
{
_isFocused = true;
await OnBeforeInputAsync(args);
if (OnBeforeInput.HasDelegate)
await OnBeforeInput.InvokeAsync(args);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override async Task OnCultureAndFormatChangedAsync()
{
await base.OnCultureAndFormatChangedAsync();
await UpdateTextPropertyAsync(false);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override async Task OnConverterChangedAsync()
{
await base.OnConverterChangedAsync();
await UpdateTextPropertyAsync(false);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected string? ResolveAriaDescribedBy() => GetAriaDescribedByString();
/// <summary>
///
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[JSInvokable("OnBeforeInput")]
public async Task<bool> OnBeforeInputFromJs(BeforeInputJsDto dto)
{
var args = new BeforeInputEventArgs
{
Data = dto.Data,
InputType = dto.InputType ?? string.Empty,
IsComposing = dto.IsComposing
};
await InvokeBeforeInputAsync(args);
return args.PreventDefault;
}
/// <summary>
/// Invoked before processing input, allowing for custom logic or validation to be performed asynchronously.
/// </summary>
/// <remarks>Override this method in a derived class to implement custom pre-processing or
/// validation logic before input is handled. This method is called before the main input processing
/// occurs.</remarks>
/// <param name="args">An object containing event data for the input operation.</param>
/// <returns>A task that represents the asynchronous operation. The default implementation returns a completed task.</returns>
protected virtual Task OnBeforeInputAsync(BeforeInputEventArgs args) => Task.CompletedTask;
}
}