-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathDefaultThemeProvider.cs
More file actions
41 lines (36 loc) · 1.15 KB
/
DefaultThemeProvider.cs
File metadata and controls
41 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
namespace BootstrapBlazor.Components;
class DefaultThemeProvider(IJSRuntime jsRuntime) : IThemeProvider
{
/// <summary>
/// <inheritdoc/>
/// </summary>
public Func<string, Task>? ThemeChangedAsync { get; set; }
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="themeName"></param>
public async ValueTask SetThemeAsync(string themeName)
{
var module = await jsRuntime.LoadUtility();
await module.SetThemeAsync(themeName);
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public async ValueTask<string?> GetThemeAsync()
{
var module = await jsRuntime.LoadUtility();
return await module.GetThemeAsync();
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public void TriggerThemeChanged(string themeName)
{
ThemeChangedAsync?.Invoke(themeName);
}
}