Skip to content

Commit

Permalink
Responsive condition to show/hide Sidebar brand
Browse files Browse the repository at this point in the history
  • Loading branch information
crdo committed Nov 15, 2024
1 parent a553f83 commit 8a8e157
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
{
<div class="hx-sidebar-brand-shortname">@BrandNameShort</div>
}
@if(!ParentSidebar.Collapsed)
{
<span class="hx-sidebar-brand-name">@BrandName</span>
}
<span class="@CssClassHelper.Combine("hx-sidebar-brand-name", ParentSidebar.Collapsed ? GetResponsiveCssClass("d-??-none") : null)">@BrandName</span>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ protected override void OnParametersSet()
{
Contract.Requires<InvalidOperationException>(ParentSidebar is not null, $"{nameof(HxSidebarBrand)} has to be placed inside {nameof(HxSidebar)}.");
}

private string GetResponsiveCssClass(string cssClassPattern)
{
return ParentSidebar.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 {ParentSidebar.ResponsiveBreakpoint}")
};
}
}

0 comments on commit 8a8e157

Please sign in to comment.