-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathThemeSwitcherContainer.razor
More file actions
90 lines (80 loc) · 3.78 KB
/
ThemeSwitcherContainer.razor
File metadata and controls
90 lines (80 loc) · 3.78 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@using DevExpress.Blazor
@using System.Text.RegularExpressions
@inject ThemesService ThemesService
@rendermode InteractiveServer
<div class="theme-@ThemesService.ActiveTheme?.Name themeswitcher-container @StateCssClass">
<div class="themeswitcher-content">
<div class="themeswitcher-title">DevExpress Fluent</div>
<ul class="themeswitcher-colors">
<ThemeSwitcherItem Theme="ThemesCollection.FluentLight()" Title="Fluent Light"
Click="OnThemeChange" />
<ThemeSwitcherItem Theme="ThemesCollection.FluentDark()" Title="Fluent Dark"
Click="OnThemeChange" />
</ul>
<div class="themeswitcher-subtitle">Custom Color</div>
<div class="themeswitcher-custom-color active">
<DxMaskedInput ValueChanged="e => OnFluentSetCustomAccentColor(e)"
T="string"
Mask="#([0-9a-fA-F]{6})"
MaskMode="MaskMode.RegEx"
NullText="#hex"
Value="@GetColorPickerText()" />
<DxButton CssClass="themeswitcher-custom-color-button"
RenderStyle="ButtonRenderStyle.Secondary"
RenderStyleMode="ButtonRenderStyleMode.Contained"
IconCssClass="themeswitcher-custom-color-button-icon">
<div class="themeswitcher-custom-color-button-icon">
</div>
<input type="color" value="@GetColorPickerText()" @onchange="(e) => OnFluentSetCustomAccentColor(e.Value?.ToString())" />
</DxButton>
</div>
</div>
<div class="themeswitcher-content">
<div class="themeswitcher-title">DevExpress Classic</div>
<ul class="themeswitcher-colors">
<ThemeSwitcherItem Theme="ThemesCollection.BlazingBerry" Title="Blazing Berry"
Click="OnThemeChange" />
<ThemeSwitcherItem Theme="ThemesCollection.BlazingDark" Title="Blazing Dark"
Click="OnThemeChange" />
<ThemeSwitcherItem Theme="ThemesCollection.Purple"
Click="OnThemeChange" />
<ThemeSwitcherItem Theme="ThemesCollection.OfficeWhite" Title="Office White"
Click="OnThemeChange" />
</ul>
</div>
<div class="themeswitcher-content">
<div class="themeswitcher-title">Bootstrap</div>
<ul class="themeswitcher-colors">
<ThemeSwitcherItem Theme="ThemesCollection.BootstrapDefault"
Click="OnThemeChange" />
</ul>
</div>
</div>
@code {
[Parameter] public bool Shown { get; set; }
[Parameter] public EventCallback<bool> ShownChanged { get; set; }
const string hexRegexStr = "#([0-9a-fA-F]{6})";
string? CustomAccentColor = "";
string StateCssClass => Shown ? "themeswitcher-container-shown" : "themeswitcher-container-hidden";
async Task OnThemeChange(ITheme theme) {
CustomAccentColor = null;
await ThemesService.SetActiveThemeAsync(theme);
await ToggleThemeSwitcherPanel(false);
}
async Task OnFluentSetCustomAccentColor(string? color) {
if (string.IsNullOrEmpty(color) || !Regex.IsMatch(color, hexRegexStr))
return;
CustomAccentColor = color;
await ThemesService.SetActiveThemeAsync(ThemesService.ActiveTheme, color);
await ToggleThemeSwitcherPanel(false);
}
async Task ToggleThemeSwitcherPanel(bool shown) {
if (shown != Shown) {
Shown = shown;
await ShownChanged.InvokeAsync(shown);
}
}
private string? GetColorPickerText() {
return string.IsNullOrEmpty(CustomAccentColor) ? null : CustomAccentColor;
}
}