Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HxSidebar] responsive collapsing #943

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 53 additions & 53 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspNetCoreVersion8>8.0.11</AspNetCoreVersion8>
<AspNetCoreVersion9>9.0.0</AspNetCoreVersion9>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Blazored.FluentValidation" Version="2.2.0" />
<PackageVersion Include="bunit.web" Version="1.36.0" />
<PackageVersion Include="Grpc.AspNetCore.Web" Version="2.66.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.66.0" />
<PackageVersion Include="Grpc.Net.Client.Web" Version="2.66.0" />
<PackageVersion Include="Havit.Core" Version="2.0.31" />
<PackageVersion Include="Havit.AspNetCore" Version="2.0.22" />
<PackageVersion Include="LoxSmoke.DocXml" Version="3.7.1" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion9)" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion8)" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(AspNetCoreVersion9)" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(AspNetCoreVersion8)" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCoreVersion9)" Condition="'$(TargetFramework)' == 'net9.0'"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCoreVersion8)" Condition="'$(TargetFramework)' == 'net8.0'"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="$(AspNetCoreVersion9)" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="$(AspNetCoreVersion9)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Localization" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest" Version="3.6.3" />
<PackageVersion Include="protobuf-net" Version="3.2.45" />
<PackageVersion Include="protobuf-net.Grpc" Version="1.2.2" />
<PackageVersion Include="protobuf-net.Grpc.AspNetCore" Version="1.2.2" />
<PackageVersion Include="protobuf-net.Grpc.ClientFactory" Version="1.2.2" />
<PackageVersion Include="SmartComponents.AspNetCore" Version="0.1.0-preview10148" />
<PackageVersion Include="SmartComponents.AspNetCore.Components" Version="0.1.0-preview10148" />
<PackageVersion Include="SmartComponents.Inference.OpenAI" Version="0.1.0-preview10148" />
<PackageVersion Include="SmartComponents.LocalEmbeddings" Version="0.1.0-preview10148" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<!-- https://github.com/microsoft/MSBuildSdks/tree/main/src/CopyOnWrite -->
<GlobalPackageReference Include="Microsoft.Build.CopyOnWrite" Version="1.0.334">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
<ItemGroup Condition="'$(ProjectName.EndsWith(`Tests`))' == 'False'">
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspNetCoreVersion8>8.0.11</AspNetCoreVersion8>
<AspNetCoreVersion9>9.0.0</AspNetCoreVersion9>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Blazored.FluentValidation" Version="2.2.0" />
<PackageVersion Include="bunit.web" Version="1.36.0" />
<PackageVersion Include="Grpc.AspNetCore.Web" Version="2.66.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.66.0" />
<PackageVersion Include="Grpc.Net.Client.Web" Version="2.66.0" />
<PackageVersion Include="Havit.Core" Version="2.0.31" />
<PackageVersion Include="Havit.AspNetCore" Version="2.0.22" />
<PackageVersion Include="LoxSmoke.DocXml" Version="3.7.1" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion9)" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion8)" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(AspNetCoreVersion9)" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(AspNetCoreVersion8)" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCoreVersion9)" Condition="'$(TargetFramework)' == 'net9.0'"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCoreVersion8)" Condition="'$(TargetFramework)' == 'net8.0'"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="$(AspNetCoreVersion9)" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="$(AspNetCoreVersion9)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Localization" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest" Version="3.6.3" />
<PackageVersion Include="protobuf-net" Version="3.2.45" />
<PackageVersion Include="protobuf-net.Grpc" Version="1.2.2" />
<PackageVersion Include="protobuf-net.Grpc.AspNetCore" Version="1.2.2" />
<PackageVersion Include="protobuf-net.Grpc.ClientFactory" Version="1.2.2" />
<PackageVersion Include="SmartComponents.AspNetCore" Version="0.1.0-preview10148" />
<PackageVersion Include="SmartComponents.AspNetCore.Components" Version="0.1.0-preview10148" />
<PackageVersion Include="SmartComponents.Inference.OpenAI" Version="0.1.0-preview10148" />
<PackageVersion Include="SmartComponents.LocalEmbeddings" Version="0.1.0-preview10148" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<!-- https://github.com/microsoft/MSBuildSdks/tree/main/src/CopyOnWrite -->
<GlobalPackageReference Include="Microsoft.Build.CopyOnWrite" Version="1.0.334">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
<ItemGroup Condition="'$(ProjectName.EndsWith(`Tests`))' == 'False'">
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
</Project>
11 changes: 4 additions & 7 deletions Havit.Blazor.Components.Web.Bootstrap/Navigation/HxSidebar.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace Havit.Blazor.Components.Web.Bootstrap

<div class="@CssClassHelper.Combine("hx-sidebar", GetResponsiveCssClass("flex-??-grow-0"), GetCollapsedCssClass(), CssClass)" id="@Id">
<div class="@CssClassHelper.Combine("hx-sidebar", ResponsiveBreakpoint.GetCssClass("flex-??-grow-0"), GetCollapsedCssClass(), CssClass)" id="@Id">
<div class="nav-menu d-flex flex-column flex-grow-1 position-relative">

@if (HeaderTemplate is not null)
Expand All @@ -9,7 +9,7 @@
<CascadingValue Value="@(this)">
@HeaderTemplate
</CascadingValue>
<HxButton CssClass="@CssClassHelper.Combine("hx-sidebar-navbar-toggler", GetResponsiveCssClass("d-??-none"))"
<HxButton CssClass="@CssClassHelper.Combine("hx-sidebar-navbar-toggler", ResponsiveBreakpoint.GetCssClass("d-??-none"))"
data-bs-toggle="collapse"
data-bs-target="@($"#{NavContentElementId}")"
aria-controls="@NavContentElementId"
Expand All @@ -19,17 +19,14 @@
</div>
}

<div class="@CssClassHelper.Combine("hx-sidebar-collapse collapse", GetResponsiveCssClass("d-??-flex"), (!Collapsed) ? "overflow-auto": null)" id="@NavContentElementId">
<div class="@CssClassHelper.Combine("hx-sidebar-collapse collapse", ResponsiveBreakpoint.GetCssClass("d-??-flex"), (!Collapsed) ? "overflow-auto": null)" id="@NavContentElementId">
<div class="hx-sidebar-body mb-auto w-100">
<HxNav Id="@_navId" Orientation="NavOrientation.Vertical">
<CascadingValue Value="@(this)" IsFixed="true">
@ItemsTemplate
</CascadingValue>
</HxNav>
<div class="@CssClassHelper.Combine(
"hx-sidebar-toggler",
Collapsed ? "collapsed" : null,
GetResponsiveCssClass("d-??-block"))"
<div class="@CssClassHelper.Combine("hx-sidebar-toggler", Collapsed ? "collapsed" : null, ResponsiveBreakpoint.GetCssClass("d-??-block"))"
role="button"
@onclick="HandleCollapseToggleClick"
@onclick:stopPropagation="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,4 @@ private async Task HandleCollapseToggleClick()
Collapsed = !Collapsed;
await InvokeCollapsedChangedAsync(Collapsed);
}

private string GetResponsiveCssClass(string cssClassPattern)
{
return ResponsiveBreakpoint switch
{
SidebarResponsiveBreakpoint.None => cssClassPattern.Replace("-??-", "-"), // !!! Simplified for the use case of this component.
SidebarResponsiveBreakpoint.Small => cssClassPattern.Replace("??", "sm"),
SidebarResponsiveBreakpoint.Medium => cssClassPattern.Replace("??", "md"),
SidebarResponsiveBreakpoint.Large => cssClassPattern.Replace("??", "lg"),
SidebarResponsiveBreakpoint.ExtraLarge => cssClassPattern.Replace("??", "xl"),
SidebarResponsiveBreakpoint.Xxl => cssClassPattern.Replace("??", "xxl"),
_ => throw new InvalidOperationException($"Unknown nameof(ResponsiveBreakpoint) value {ResponsiveBreakpoint}")
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@media (min-width: 768px) {
.hx-sidebar,
.hx-sidebar .nav-menu {
max-height: var(--hx-sidebar-max-height);;
max-height: var(--hx-sidebar-max-height);
}
}

Expand Down Expand Up @@ -104,21 +104,10 @@
transform: translateY(-.15rem) rotate(15deg) translateZ(0px);
}

.hx-sidebar-navbar-toggler:hover {
::deep .hx-sidebar-navbar-toggler:hover {
color: var(--bs-primary);
}

::deep a[aria-expanded="true"] .bi-chevron-right {
transform: rotate(90deg);
}

/*Desktop collapsed*/
.hx-sidebar.collapsed {
width: var(--hx-sidebar-collapsed-width);
}

.hx-sidebar.collapsed ::deep .hx-sidebar-brand-name,
.hx-sidebar.collapsed ::deep .hx-sidebar-item-navlink-content-inner,
.hx-sidebar.collapsed ::deep .expand-icon {
display: none;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@namespace Havit.Blazor.Components.Web.Bootstrap

<a class="hx-sidebar-brand" href="./">
@if (LogoTemplate != null)
{
Expand All @@ -8,6 +9,5 @@
{
<div class="hx-sidebar-brand-shortname">@BrandNameShort</div>
}

<span class="hx-sidebar-brand-name">@BrandName</span>
<span class="@CssClassHelper.Combine("hx-sidebar-brand-name", ParentSidebar.Collapsed ? ParentSidebar.ResponsiveBreakpoint.GetCssClass("d-??-none") : null)">@BrandName</span>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
{
<HxIcon Icon="Icon" />
}
<span class="hx-sidebar-footer-item-navlink-content-inner">
<span class="@CssClassHelper.Combine("hx-sidebar-footer-item-navlink-content-inner", TextCssClass)">
@Text
</span>
</div>

</HxNavLink>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ public partial class HxSidebarFooter
[Parameter] public NavLinkMatch? Match { get; set; } = NavLinkMatch.Prefix;

/// <summary>
/// Allows you to disable the item with <c>false</c>.
/// The default value is <c>true</c>.
/// Any additional CSS class to add.
/// </summary>
[Parameter] public string CssClass { get; set; }

/// <summary>
/// Any additional CSS class to add to inner text.
/// </summary>
[Parameter] public string TextCssClass { get; set; }

/// <summary>
/// Sub-items (not intended to be used for any other purpose).
/// </summary>
Expand Down
Loading