Skip to content

Commit

Permalink
update theming toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
codymullins committed Sep 27, 2024
1 parent 8e187a7 commit 0e0e000
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Pure.Blazor.Components.Dialogs;
using Pure.Blazor.Components.Feedback;
using Pure.Blazor.Components.Primitives;
using Theme = Pure.Blazor.Components.Primitives.Theme;

namespace Pure.Blazor.Components.AspNetCore;

Expand All @@ -28,6 +29,8 @@ public static IHostApplicationBuilder AddPureBlazorComponents(this IHostApplicat
return source;
});

builder.Services.TryAddCascadingValue(_ => Theme.Auto);

return builder;
}
}
10 changes: 9 additions & 1 deletion src/Pure.Blazor.Components.Primitives/PureComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;

namespace Pure.Blazor.Components.Primitives;

Expand All @@ -10,6 +11,8 @@ protected override void OnParametersSet()
BuildCss();
}

[Inject] public required ILogger<PureComponent> Logger { get; set; }

/// <summary>
/// Add additional css classes to this component
/// </summary>
Expand All @@ -20,7 +23,7 @@ protected override void OnParametersSet()
/// Disables or enables the theme. Default is Auto, which means the theme is inherited from the parent component.
/// </summary>
[CascadingParameter]
public Theme Theme { get; set; } = Theme.Auto;
public Theme Theme { get; set; }

/// <summary>
/// The current theme styles
Expand Down Expand Up @@ -60,6 +63,11 @@ protected virtual void BuildCss()
/// <returns></returns>
protected virtual string ApplyStyle(string? style)
{
if (Theme == Theme.Off)
{
return "";
}

if (style == null)
{
return Styles ?? "";
Expand Down
1 change: 0 additions & 1 deletion src/Pure.Blazor.Components/Common/InteropComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
}
}

[Inject] public required ILogger<InteropComponent> Logger { get; set; }
[Inject] public required IJSRuntime Js { get; set; }

async ValueTask IAsyncDisposable.DisposeAsync()
Expand Down
1 change: 0 additions & 1 deletion src/Pure.Blazor.Components/Display/PureCode.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@using Pure.Blazor.Components.Display
@* @implements IAsyncDisposable *@
@* @implements IHandleEvent *@
@inject ILogger<PureCode> Logger
@inject IJSRuntime JS

<figure class="@Styles relative">
Expand Down
1 change: 0 additions & 1 deletion src/Pure.Blazor.Components/Layout/PureTabButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@code {
private ElementReference _elementReference;
private bool prevStateActive = false;
[Inject] public required ILogger<PureTabButton> Logger { get; set; }
[Parameter] public string Title { get; set; } = string.Empty;

[Parameter] public bool IsActive { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Pure.Blazor.Components.Dialogs;
using Pure.Blazor.Components.Feedback;
using Pure.Blazor.Components.Primitives;
using Theme = Pure.Blazor.Components.Primitives.Theme;

namespace Pure.Blazor.Components;

Expand All @@ -19,12 +20,14 @@ public static WebAssemblyHostBuilder AddPureBlazorComponents(this WebAssemblyHos
// services
builder.Services.AddScoped<AlertService>();
builder.Services.AddScoped<DialogService>();
builder.Services.AddCascadingValue(sp =>
builder.Services.AddCascadingValue(_ =>
{
theme ??= new DefaultTheme();
var source = new CascadingValueSource<PureTheme>(theme, isFixed: true);
return source;
});

builder.Services.TryAddCascadingValue(_ => Theme.Auto);
return builder;
}
}

0 comments on commit 0e0e000

Please sign in to comment.