From f7d11b6402f2f8af9bbc4062acff2420b8b0f2bd Mon Sep 17 00:00:00 2001 From: Sjef van Leeuwen Date: Thu, 12 Nov 2020 13:11:32 +0100 Subject: [PATCH] Layout manager fixes #30 --- .../MainLayout.razor | 10 ++++-- src/Blazor.AdminLte/Layout/ILayoutManager.cs | 11 ++++++ src/Blazor.AdminLte/Layout/LayoutManager.cs | 36 +++++++++++++++++++ src/Blazor.AdminLte/Layout/Overlay.razor | 4 ++- .../ServiceCollectionExtensions.cs | 6 ++-- 5 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/Blazor.AdminLte/Layout/ILayoutManager.cs create mode 100644 src/Blazor.AdminLte/Layout/LayoutManager.cs diff --git a/src/Blazor.AdminLte.Site.Shared/MainLayout.razor b/src/Blazor.AdminLte.Site.Shared/MainLayout.razor index 21b0980b..c484e2e4 100644 --- a/src/Blazor.AdminLte.Site.Shared/MainLayout.razor +++ b/src/Blazor.AdminLte.Site.Shared/MainLayout.razor @@ -1,6 +1,7 @@ @inherits LayoutComponentBase @inject NavigationManager NavigationManager @inject IJSRuntime JS +@inject ILayoutManager layoutManager @inject NavBarLeftInjectableMenu navBarLeftInjectableMenu @@ -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); } } \ No newline at end of file diff --git a/src/Blazor.AdminLte/Layout/ILayoutManager.cs b/src/Blazor.AdminLte/Layout/ILayoutManager.cs new file mode 100644 index 00000000..8c49f627 --- /dev/null +++ b/src/Blazor.AdminLte/Layout/ILayoutManager.cs @@ -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); + } +} \ No newline at end of file diff --git a/src/Blazor.AdminLte/Layout/LayoutManager.cs b/src/Blazor.AdminLte/Layout/LayoutManager.cs new file mode 100644 index 00000000..d0dee355 --- /dev/null +++ b/src/Blazor.AdminLte/Layout/LayoutManager.cs @@ -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); + } + } + } +} diff --git a/src/Blazor.AdminLte/Layout/Overlay.razor b/src/Blazor.AdminLte/Layout/Overlay.razor index f19ad554..c07e605b 100644 --- a/src/Blazor.AdminLte/Layout/Overlay.razor +++ b/src/Blazor.AdminLte/Layout/Overlay.razor @@ -1,6 +1,6 @@ @implements IDisposable @namespace Blazor.AdminLte - +@inject ILayoutManager layoutManager @inject IJSRuntime js @inject NavigationManager NavigationManager @@ -32,6 +32,7 @@ } void LocationChanged(object sender, LocationChangedEventArgs e) { + layoutManager.OverlayMode(false); js.InvokeVoidAsync("overlay", false); } void IDisposable.Dispose() @@ -43,6 +44,7 @@ protected override Task OnAfterRenderAsync(bool firstRender) { + layoutManager.OverlayMode(true); js.InvokeVoidAsync("overlay", true); return base.OnAfterRenderAsync(firstRender); } diff --git a/src/Blazor.AdminLte/ServiceCollectionExtensions.cs b/src/Blazor.AdminLte/ServiceCollectionExtensions.cs index f7a0c8e5..f2147b73 100644 --- a/src/Blazor.AdminLte/ServiceCollectionExtensions.cs +++ b/src/Blazor.AdminLte/ServiceCollectionExtensions.cs @@ -8,13 +8,15 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddAdminLte(this IServiceCollection services) { - return services.AddScoped().AddBlazorState((aOptions) => + return services + .AddScoped() + .AddBlazorState((aOptions) => aOptions.Assemblies = new Assembly[] { typeof(BaseClasses).GetTypeInfo().Assembly, Assembly.GetExecutingAssembly() } - ); + ).AddScoped(); } } }