feat(theme): NavRailItem + NavRailSection
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
@* Components/NavRailItem.razor *@
|
||||
<NavLink class="rail-link" href="@Href" Match="@Match" ActiveClass="active">
|
||||
@if (Icon is not null) { <span class="rail-ico">@Icon</span> }
|
||||
@Text
|
||||
</NavLink>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public string Href { get; set; } = string.Empty;
|
||||
[Parameter, EditorRequired] public string Text { get; set; } = string.Empty;
|
||||
[Parameter] public RenderFragment? Icon { get; set; }
|
||||
[Parameter] public NavLinkMatch Match { get; set; } = NavLinkMatch.Prefix;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
@* Components/NavRailSection.razor — CSS-only collapsible (no JS, works in static SSR).
|
||||
Apps that want cookie-persisted expand state keep their own interactive NavSection. *@
|
||||
<details class="rail-section" open="@Expanded">
|
||||
<summary class="rail-eyebrow-toggle"><span class="rail-eyebrow-label">@Title</span></summary>
|
||||
<div class="rail-section-body">@ChildContent</div>
|
||||
</details>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public string Title { get; set; } = string.Empty;
|
||||
[Parameter] public bool Expanded { get; set; } = true;
|
||||
[Parameter] public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace ZB.MOM.WW.Theme.Tests;
|
||||
|
||||
public class NavRailTests : TestContext
|
||||
{
|
||||
[Fact]
|
||||
public void NavRailItem_renders_rail_link_with_href_and_text()
|
||||
{
|
||||
var cut = RenderComponent<NavRailItem>(p => p
|
||||
.Add(x => x.Href, "/clusters")
|
||||
.Add(x => x.Text, "Clusters"));
|
||||
var a = cut.Find("a.rail-link");
|
||||
Assert.Equal("/clusters", a.GetAttribute("href"));
|
||||
Assert.Contains("Clusters", a.TextContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NavRailSection_renders_title_and_children_open_by_default()
|
||||
{
|
||||
var cut = RenderComponent<NavRailSection>(p => p
|
||||
.Add(x => x.Title, "Navigation")
|
||||
.AddChildContent("<a class='rail-link'>X</a>"));
|
||||
var details = cut.Find("details.rail-section");
|
||||
Assert.True(details.HasAttribute("open"));
|
||||
Assert.Contains("Navigation", cut.Find("summary").TextContent);
|
||||
Assert.NotNull(cut.Find(".rail-section-body .rail-link"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user