Skip to content

Commit f7d11b6

Browse files
Layout manager fixes #30
1 parent e384ff4 commit f7d11b6

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

src/Blazor.AdminLte.Site.Shared/MainLayout.razor

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@inherits LayoutComponentBase
22
@inject NavigationManager NavigationManager
33
@inject IJSRuntime JS
4+
@inject ILayoutManager layoutManager
45
@inject NavBarLeftInjectableMenu navBarLeftInjectableMenu
56
<NavBar>
67
<NavBarLeft>
@@ -203,9 +204,12 @@
203204

204205
protected override void OnAfterRender(bool isFirstRender)
205206
{
206-
JS.InvokeVoidAsync("sideBarFixed", true);
207-
JS.InvokeVoidAsync("navBarFixed", true);
208-
JS.InvokeVoidAsync("footerFixed", true);
207+
layoutManager.IsFooterFixed = true;
208+
layoutManager.IsNavBarFixed = true;
209+
layoutManager.IsSideBarFixed = true;
210+
//JS.InvokeVoidAsync("sideBarFixed", true);
211+
// JS.InvokeVoidAsync("navBarFixed", true);
212+
// JS.InvokeVoidAsync("footerFixed", true);
209213
base.OnAfterRender(isFirstRender);
210214
}
211215
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Blazor.AdminLte
2+
{
3+
public interface ILayoutManager
4+
{
5+
bool IsFooterFixed { get; set; }
6+
bool IsNavBarFixed { get; set; }
7+
bool IsSideBarFixed { get; set; }
8+
9+
void OverlayMode(bool isOverlayMode);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.JSInterop;
2+
3+
namespace Blazor.AdminLte
4+
{
5+
public class LayoutManager : ILayoutManager
6+
{
7+
private bool _IsSideBarFixed;
8+
private bool _IsNavBarFixed;
9+
private bool _IsFooterFixed;
10+
11+
public bool IsSideBarFixed { get { return _IsSideBarFixed; } set { _IsSideBarFixed = value; js.InvokeVoidAsync("sideBarFixed", value); } }
12+
public bool IsNavBarFixed { get { return _IsNavBarFixed; } set { _IsNavBarFixed = value; js.InvokeVoidAsync("navBarFixed", value); } }
13+
public bool IsFooterFixed { get { return _IsFooterFixed; } set { _IsFooterFixed = value; js.InvokeVoidAsync("footerFixed", value); } }
14+
15+
private readonly IJSRuntime js;
16+
17+
public LayoutManager(IJSRuntime js)
18+
{
19+
this.js = js;
20+
}
21+
22+
public void OverlayMode(bool isOverlayMode)
23+
{
24+
if (isOverlayMode)
25+
{
26+
js.InvokeVoidAsync("navBarFixed", false);
27+
js.InvokeVoidAsync("footerFixed", false);
28+
}
29+
else
30+
{
31+
js.InvokeVoidAsync("navBarFixed", _IsNavBarFixed);
32+
js.InvokeVoidAsync("footerFixed", _IsFooterFixed);
33+
}
34+
}
35+
}
36+
}

src/Blazor.AdminLte/Layout/Overlay.razor

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@implements IDisposable
22
@namespace Blazor.AdminLte
3-
3+
@inject ILayoutManager layoutManager
44
@inject IJSRuntime js
55

66
@inject NavigationManager NavigationManager
@@ -32,6 +32,7 @@
3232
}
3333
void LocationChanged(object sender, LocationChangedEventArgs e)
3434
{
35+
layoutManager.OverlayMode(false);
3536
js.InvokeVoidAsync("overlay", false);
3637
}
3738
void IDisposable.Dispose()
@@ -43,6 +44,7 @@
4344

4445
protected override Task OnAfterRenderAsync(bool firstRender)
4546
{
47+
layoutManager.OverlayMode(true);
4648
js.InvokeVoidAsync("overlay", true);
4749
return base.OnAfterRenderAsync(firstRender);
4850
}

src/Blazor.AdminLte/ServiceCollectionExtensions.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ public static class ServiceCollectionExtensions
88
{
99
public static IServiceCollection AddAdminLte(this IServiceCollection services)
1010
{
11-
return services.AddScoped<NavBarLeftInjectableMenu>().AddBlazorState((aOptions) =>
11+
return services
12+
.AddScoped<NavBarLeftInjectableMenu>()
13+
.AddBlazorState((aOptions) =>
1214
aOptions.Assemblies = new Assembly[]
1315
{
1416
typeof(BaseClasses).GetTypeInfo().Assembly,
1517
Assembly.GetExecutingAssembly()
1618
}
17-
);
19+
).AddScoped<ILayoutManager, LayoutManager>();
1820
}
1921
}
2022
}

0 commit comments

Comments
 (0)