-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve BusyButton, Add StateProvider, add ExpandTracker
- Loading branch information
Showing
7 changed files
with
184 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@typeparam TState | ||
|
||
<CascadingValue Value="this"> | ||
@ChildContent | ||
</CascadingValue> |
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,25 @@ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace LoreSoft.Blazor.Controls; | ||
|
||
public partial class StateProvider<TState> | ||
{ | ||
[Parameter] | ||
public required RenderFragment ChildContent { get; set; } | ||
|
||
public event Action<object> OnStateChange; | ||
|
||
public TState? State { get; protected set; } | ||
|
||
public virtual void Set(TState model) | ||
{ | ||
State = model; | ||
NotifyStateChanged(this); | ||
} | ||
|
||
public void NotifyStateChanged(object sender = null) | ||
{ | ||
StateHasChanged(); | ||
OnStateChange?.Invoke(sender); | ||
} | ||
} |
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,34 @@ | ||
namespace LoreSoft.Blazor.Controls.Utilities; | ||
|
||
public class ExpandTracker<TItem> | ||
{ | ||
private readonly HashSet<TItem> _expandedItems = []; | ||
|
||
public event Action OnChange; | ||
|
||
public bool IsExpanded(TItem item) | ||
{ | ||
return _expandedItems.Contains(item); | ||
} | ||
|
||
public void Toggle(TItem item) | ||
{ | ||
if (_expandedItems.Contains(item)) | ||
_expandedItems.Remove(item); | ||
else | ||
_expandedItems.Add(item); | ||
|
||
NotifyStateChanged(); | ||
} | ||
|
||
public virtual void Clear() | ||
{ | ||
_expandedItems.Clear(); | ||
NotifyStateChanged(); | ||
} | ||
|
||
public void NotifyStateChanged() | ||
{ | ||
OnChange?.Invoke(); | ||
} | ||
} |
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