Skip to content

Commit 8d6754e

Browse files
authored
🆕 feat(Theme): add OnError, OnInfo, OnSuccess, OnWarning, InverseSurface, InverseOnSurface and InversePrimary colo roles (#599)
1 parent ce529cb commit 8d6754e

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎src/Component/BlazorComponent/Abstracts/Builder/ThemeCssBuilder.cs‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public string Build(Theme theme)
2020
$$"""
2121
:root {
2222
color-scheme: {{(isDark ? "dark" : "normal")}};
23-
--m-theme-surface: {{options.Surface}};
24-
--m-theme-on-surface: {{options.OnSurface}};
2523
--m-theme-primary: {{options.Primary}};
2624
--m-theme-primary-text: {{options.Primary}};
2725
--m-theme-on-primary: {{options.OnPrimary}};
@@ -33,27 +31,43 @@ public string Build(Theme theme)
3331
--m-theme-on-accent: {{options.OnAccent}};
3432
--m-theme-error: {{options.Error}};
3533
--m-theme-error-text: {{options.Error}};
34+
--m-theme-on-error: {{options.OnError}};
3635
--m-theme-info: {{options.Info}};
3736
--m-theme-info-text: {{options.Info}};
37+
--m-theme-on-info: {{options.OnInfo}};
3838
--m-theme-success: {{options.Success}};
3939
--m-theme-success-text: {{options.Success}};
40+
--m-theme-on-success: {{options.OnSuccess}};
4041
--m-theme-warning: {{options.Warning}};
4142
--m-theme-warning-text: {{options.Warning}};
43+
--m-theme-on-warning: {{options.OnWarning}};
44+
45+
--m-theme-surface: {{options.Surface}};
46+
--m-theme-on-surface: {{options.OnSurface}};
47+
--m-theme-inverse-surface: {{options.InverseSurface}};
48+
--m-theme-inverse-on-surface: {{options.InverseOnSurface}};
49+
--m-theme-inverse-primary: {{options.InversePrimary}};
4250
4351
--m-theme-light-surface: {{light.Surface}};
4452
--m-theme-light-on-surface: {{light.OnSurface}};
4553
--m-theme-dark-surface: {{dark.Surface}};
4654
--m-theme-dark-on-surface: {{dark.OnSurface}};
55+
--m-theme-light-inverse-surface: {{light.InverseSurface}};
56+
--m-theme-light-inverse-on-surface: {{light.InverseOnSurface}};
57+
--m-theme-light-inverse-primary: {{light.InversePrimary}};
58+
--m-theme-dark-inverse-surface: {{dark.InverseSurface}};
59+
--m-theme-dark-inverse-on-surface: {{dark.InverseOnSurface}};
60+
--m-theme-dark-inverse-primary: {{dark.InversePrimary}};
4761
}
4862
""",
4963
$"{combinePrefix}a {{ color: {options.Primary}; }}",
5064
Build(combinePrefix, nameof(options.Primary).ToLowerInvariant(), hasOnColor: true),
5165
Build(combinePrefix, nameof(options.Secondary).ToLowerInvariant(), hasOnColor: true),
5266
Build(combinePrefix, nameof(options.Accent).ToLowerInvariant(), hasOnColor: true),
53-
Build(combinePrefix, nameof(options.Info).ToLowerInvariant()),
54-
Build(combinePrefix, nameof(options.Success).ToLowerInvariant()),
55-
Build(combinePrefix, nameof(options.Warning).ToLowerInvariant()),
56-
Build(combinePrefix, nameof(options.Error).ToLowerInvariant()),
67+
Build(combinePrefix, nameof(options.Info).ToLowerInvariant(), hasOnColor: true),
68+
Build(combinePrefix, nameof(options.Success).ToLowerInvariant(), hasOnColor: true),
69+
Build(combinePrefix, nameof(options.Warning).ToLowerInvariant(), hasOnColor: true),
70+
Build(combinePrefix, nameof(options.Error).ToLowerInvariant(), hasOnColor: true),
5771
Build(combinePrefix, nameof(options.Surface).ToLowerInvariant(), hasOnColor: true),
5872
};
5973

@@ -78,6 +92,7 @@ private string Build(string combinePrefix, string selector, bool hasOnColor = fa
7892
if (hasOnColor)
7993
{
8094
stringBuilder.Append($"""
95+
8196
color: var(--m-theme-on-{selector}) !important;
8297
""");
8398
}

‎src/Component/BlazorComponent/Services/ThemeOptions.cs‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ public class ThemeOptions
55
public string? CombinePrefix { get; set; }
66

77
public string? Primary { get; set; }
8-
8+
99
public string? OnPrimary { get; set; }
1010

1111
public string? Secondary { get; set; }
12-
12+
1313
public string? OnSecondary { get; set; }
1414

1515
/// <summary>
@@ -21,16 +21,30 @@ public class ThemeOptions
2121

2222
public string? Error { get; set; }
2323

24+
public string? OnError { get; set; }
25+
2426
public string? Info { get; set; }
2527

28+
public string? OnInfo { get; set; }
29+
2630
public string? Success { get; set; }
2731

32+
public string? OnSuccess { get; set; }
33+
2834
public string? Warning { get; set; }
29-
35+
36+
public string? OnWarning { get; set; }
37+
3038
public string? Surface { get; set; }
31-
39+
3240
public string? OnSurface { get; set; }
3341

42+
public string? InverseSurface { get; set; }
43+
44+
public string? InverseOnSurface { get; set; }
45+
46+
public string? InversePrimary { get; set; }
47+
3448
public Dictionary<string, string> UserDefined { get; } = new();
3549
}
3650

@@ -45,7 +59,7 @@ public Theme(bool dark, ThemeOptions lightTheme, ThemeOptions darkTheme)
4559
public bool Dark { get; set; }
4660

4761
public Themes Themes { get; }
48-
62+
4963
public ThemeOptions CurrentTheme => Dark ? Themes.Dark : Themes.Light;
5064
}
5165

@@ -60,4 +74,4 @@ public Themes(ThemeOptions light, ThemeOptions dark)
6074
public ThemeOptions Dark { get; }
6175

6276
public ThemeOptions Light { get; }
63-
}
77+
}

0 commit comments

Comments
 (0)