Skip to content

Commit

Permalink
Layout manager fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
sjefvanleeuwen committed Nov 12, 2020
1 parent e384ff4 commit f7d11b6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/Blazor.AdminLte.Site.Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@inherits LayoutComponentBase
@inject NavigationManager NavigationManager
@inject IJSRuntime JS
@inject ILayoutManager layoutManager
@inject NavBarLeftInjectableMenu navBarLeftInjectableMenu
<NavBar>
<NavBarLeft>
Expand Down Expand Up @@ -203,9 +204,12 @@

protected override void OnAfterRender(bool isFirstRender)
{
JS.InvokeVoidAsync("sideBarFixed", true);
JS.InvokeVoidAsync("navBarFixed", true);
JS.InvokeVoidAsync("footerFixed", true);
layoutManager.IsFooterFixed = true;
layoutManager.IsNavBarFixed = true;
layoutManager.IsSideBarFixed = true;
//JS.InvokeVoidAsync("sideBarFixed", true);
// JS.InvokeVoidAsync("navBarFixed", true);
// JS.InvokeVoidAsync("footerFixed", true);
base.OnAfterRender(isFirstRender);
}
}
11 changes: 11 additions & 0 deletions src/Blazor.AdminLte/Layout/ILayoutManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Blazor.AdminLte
{
public interface ILayoutManager
{
bool IsFooterFixed { get; set; }
bool IsNavBarFixed { get; set; }
bool IsSideBarFixed { get; set; }

void OverlayMode(bool isOverlayMode);
}
}
36 changes: 36 additions & 0 deletions src/Blazor.AdminLte/Layout/LayoutManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.JSInterop;

namespace Blazor.AdminLte
{
public class LayoutManager : ILayoutManager
{
private bool _IsSideBarFixed;
private bool _IsNavBarFixed;
private bool _IsFooterFixed;

public bool IsSideBarFixed { get { return _IsSideBarFixed; } set { _IsSideBarFixed = value; js.InvokeVoidAsync("sideBarFixed", value); } }
public bool IsNavBarFixed { get { return _IsNavBarFixed; } set { _IsNavBarFixed = value; js.InvokeVoidAsync("navBarFixed", value); } }
public bool IsFooterFixed { get { return _IsFooterFixed; } set { _IsFooterFixed = value; js.InvokeVoidAsync("footerFixed", value); } }

private readonly IJSRuntime js;

public LayoutManager(IJSRuntime js)
{
this.js = js;
}

public void OverlayMode(bool isOverlayMode)
{
if (isOverlayMode)
{
js.InvokeVoidAsync("navBarFixed", false);
js.InvokeVoidAsync("footerFixed", false);
}
else
{
js.InvokeVoidAsync("navBarFixed", _IsNavBarFixed);
js.InvokeVoidAsync("footerFixed", _IsFooterFixed);
}
}
}
}
4 changes: 3 additions & 1 deletion src/Blazor.AdminLte/Layout/Overlay.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@implements IDisposable
@namespace Blazor.AdminLte

@inject ILayoutManager layoutManager
@inject IJSRuntime js

@inject NavigationManager NavigationManager
Expand Down Expand Up @@ -32,6 +32,7 @@
}
void LocationChanged(object sender, LocationChangedEventArgs e)
{
layoutManager.OverlayMode(false);
js.InvokeVoidAsync("overlay", false);
}
void IDisposable.Dispose()
Expand All @@ -43,6 +44,7 @@

protected override Task OnAfterRenderAsync(bool firstRender)
{
layoutManager.OverlayMode(true);
js.InvokeVoidAsync("overlay", true);
return base.OnAfterRenderAsync(firstRender);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Blazor.AdminLte/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddAdminLte(this IServiceCollection services)
{
return services.AddScoped<NavBarLeftInjectableMenu>().AddBlazorState((aOptions) =>
return services
.AddScoped<NavBarLeftInjectableMenu>()
.AddBlazorState((aOptions) =>
aOptions.Assemblies = new Assembly[]
{
typeof(BaseClasses).GetTypeInfo().Assembly,
Assembly.GetExecutingAssembly()
}
);
).AddScoped<ILayoutManager, LayoutManager>();
}
}
}

0 comments on commit f7d11b6

Please sign in to comment.