-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚚 refactor(Breadcrumbs): merge code from BlazorComponent (#1905)
* 🚚 refactor(Breadcrumbs): merge code from BlazorComponent * docs update * remove unnecessary code
- Loading branch information
Showing
21 changed files
with
311 additions
and
109 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
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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
@namespace Masa.Blazor | ||
@inherits MasaComponentBase | ||
|
||
<CascadingValue Value="IsDark" Name="IsDark"> | ||
<CascadingValue Value="this" IsFixed> | ||
<ul class="@GetClass()" | ||
style="@GetStyle()" | ||
id="@Id" | ||
@attributes="@Attributes"> | ||
@if (ChildContent == null) | ||
{ | ||
@for (var i = 0; i < Items.Count; i++) | ||
{ | ||
var index = i; | ||
var item = Items[index]; | ||
var isLast = index == Items.Count - 1; | ||
|
||
@GenGroup(item, isLast) | ||
} | ||
} | ||
else | ||
{ | ||
@ChildContent | ||
} | ||
</ul> | ||
</CascadingValue> | ||
</CascadingValue> | ||
|
||
@code | ||
{ | ||
private RenderFragment GenGroup(BreadcrumbItem? item, bool isLast) => __builder => | ||
{ | ||
if (item == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (ItemContent != null) | ||
{ | ||
@ItemContent(item) | ||
|
||
if (!isLast) | ||
{ | ||
@GenDivider() | ||
} | ||
} | ||
else | ||
{ | ||
<MBreadcrumbsItem Text="@item.Text" | ||
Href="@item.Href" | ||
Disabled="@item.Disabled" | ||
Exact="@item.Exact"> | ||
</MBreadcrumbsItem> | ||
|
||
if (!isLast) | ||
{ | ||
@GenDivider() | ||
} | ||
} | ||
}; | ||
|
||
internal RenderFragment GenDivider() | ||
{ | ||
return RenderFragments.RenderFragmentOrText(DividerContent, Divider, "m-breadcrumbs__divider", "li"); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/Masa.Blazor/Components/Breadcrumbs/MBreadcrumbs.razor.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,82 @@ | ||
namespace Masa.Blazor; | ||
|
||
public partial class MBreadcrumbs : MasaComponentBase | ||
{ | ||
[Inject] private MasaBlazor MasaBlazor { get; set; } = null!; | ||
|
||
[Parameter] public bool Large { get; set; } | ||
|
||
[Parameter, MasaApiParameter("/")] public string? Divider { get; set; } = "/"; | ||
|
||
[Parameter] public RenderFragment? DividerContent { get; set; } | ||
|
||
[Parameter] public bool Routable { get; set; } | ||
|
||
[Parameter] public IReadOnlyList<BreadcrumbItem> Items { get; set; } = new List<BreadcrumbItem>(); | ||
|
||
[Parameter] public RenderFragment<BreadcrumbItem>? ItemContent { get; set; } | ||
|
||
[Parameter] public RenderFragment? ChildContent { get; set; } | ||
|
||
[Parameter] public bool Dark { get; set; } | ||
|
||
[Parameter] public bool Light { get; set; } | ||
|
||
[CascadingParameter(Name = "IsDark")] public bool CascadingIsDark { get; set; } | ||
|
||
public bool IsDark | ||
{ | ||
get | ||
{ | ||
if (Dark) | ||
{ | ||
return true; | ||
} | ||
|
||
if (Light) | ||
{ | ||
return false; | ||
} | ||
|
||
return CascadingIsDark; | ||
} | ||
} | ||
|
||
#region When using razor definition without Items parameter | ||
|
||
internal List<MBreadcrumbsItem> SubBreadcrumbsItems { get; } = new(); | ||
|
||
internal void AddSubBreadcrumbsItem(MBreadcrumbsItem item) | ||
{ | ||
if (!SubBreadcrumbsItems.Contains(item)) | ||
{ | ||
SubBreadcrumbsItems.Add(item); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
private bool IndependentTheme => | ||
(IsDirtyParameter(nameof(Dark)) && Dark) || (IsDirtyParameter(nameof(Light)) && Light); | ||
|
||
protected override void OnParametersSet() | ||
{ | ||
base.OnParametersSet(); | ||
|
||
#if NET8_0_OR_GREATER | ||
if (MasaBlazor.IsSsr && !IndependentTheme) | ||
{ | ||
CascadingIsDark = MasaBlazor.Theme.Dark; | ||
} | ||
#endif | ||
} | ||
|
||
private Block _block = new("m-breadcrumbs"); | ||
|
||
protected override IEnumerable<string> BuildComponentClass() | ||
{ | ||
return _block.Modifier(Large) | ||
.AddTheme(IsDark, IndependentTheme) | ||
.GenerateCssClasses(); | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/Masa.Blazor/Components/Breadcrumbs/MBreadcrumbsDivider.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.