Skip to content

Commit 1191f1e

Browse files
authored
support mudblazor v9.0.0-rc.1 ToDescriptionString removed (#66)
1 parent 37fb160 commit 1191f1e

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

src/Components/MudStaticButton.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@namespace MudBlazor.StaticInput
22

3+
34
@inherits MudButton
45

56
@if (FormAction == FormAction.Post)
@@ -51,9 +52,9 @@ else
5152

5253
private string GetButtonType() => FormAction switch
5354
{
54-
FormAction.Submit => ButtonType.Submit.ToDescriptionString(),
55-
FormAction.Reset => ButtonType.Reset.ToDescriptionString(),
56-
_ => ButtonType.Submit.ToDescriptionString()
55+
FormAction.Submit => ButtonType.Submit.ToEnumDescriptionString(),
56+
FormAction.Reset => ButtonType.Reset.ToEnumDescriptionString(),
57+
_ => ButtonType.Submit.ToEnumDescriptionString()
5758
};
5859

5960
private RenderFragment RenderButton()

src/Components/MudStaticSwitch.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
</span>
2727
@if (!string.IsNullOrEmpty(Label))
2828
{
29-
<MudText Class="@(Typo is null ? LabelClassname : $"mud-typography-{Typo.Value.ToDescriptionString()}")" Color="HasErrors ? Color.Error : Color.Inherit">
29+
<MudText Class="@(Typo is null ? LabelClassname : $"mud-typography-{Typo.Value.ToEnumDescriptionString()}")" Color="HasErrors? Color.Error: Color.Inherit">
3030
@Label
3131
</MudText>
3232
}
3333
@if (ChildContent != null)
3434
{
35-
<MudText Class="@(Typo is null ? LabelClassname : $"mud-typography-{Typo.Value.ToDescriptionString()}")" Color="HasErrors ? Color.Error : Color.Inherit">
35+
<MudText Class="@(Typo is null ? LabelClassname : $"mud-typography-{Typo.Value.ToEnumDescriptionString()}")" Color="HasErrors? Color.Error: Color.Inherit">
3636
@ChildContent
3737
</MudText>
3838
}

src/Components/MudStaticSwitch.razor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ private bool IsStatic()
2727
/*
2828
* Options for SwitchClassname
2929
*/
30-
private string CheckedTextColor => $"mud-{Color.ToDescriptionString()}-text";
31-
private string CheckedHoverColor => $"hover:mud-{Color.ToDescriptionString()}-hover";
32-
private string UncheckedTextColor => $"mud-{UncheckedColor.ToDescriptionString()}-text";
33-
private string UncheckedHoverColor => $"hover:mud-{UncheckedColor.ToDescriptionString()}-hover";
30+
private string CheckedTextColor => $"mud-{Color.ToString().ToLower()}-text";
31+
private string CheckedHoverColor => $"hover:mud-{Color.ToString().ToLower()}-hover";
32+
private string UncheckedTextColor => $"mud-{UncheckedColor.ToString().ToLower()}-text";
33+
private string UncheckedHoverColor => $"hover:mud-{UncheckedColor.ToString().ToLower()}-hover";
3434

3535
/*
3636
* Options for TrackClassname
3737
*/
38-
private string CheckedColor => $"mud-{Color.ToDescriptionString()}";
39-
private string UnCheckedColor => $"mud-{UncheckedColor.ToDescriptionString()}";
38+
private string CheckedColor => $"mud-{Color.ToString().ToLower()}";
39+
private string UnCheckedColor => $"mud-{UncheckedColor.ToString().ToLower()}";
4040
}

src/Enums/EnumExtensions.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace MudBlazor.StaticInput.Enums
9+
{
10+
public static class EnumExtensions
11+
{
12+
/// <summary>
13+
///
14+
/// </summary>
15+
/// <param name="value"></param>
16+
/// <returns></returns>
17+
public static string ToEnumDescriptionString(this Enum value)
18+
{
19+
var field = value.GetType().GetField(value.ToString());
20+
if (field is null)
21+
{
22+
return value.ToString().ToLower();
23+
}
24+
25+
var attributes = Attribute.GetCustomAttributes(field, typeof(DescriptionAttribute), false) as DescriptionAttribute[];
26+
27+
return attributes is { Length: > 0 }
28+
? attributes[0].Description
29+
: value.ToString().ToLower();
30+
}
31+
32+
}
33+
}

src/_Imports.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
@using System.Windows.Input
44
@using System.Linq.Expressions
55
@using MudBlazor
6-
@using MudBlazor.StaticInput
6+
@using MudBlazor.StaticInput
7+
@using MudBlazor.StaticInput.Enums

0 commit comments

Comments
 (0)