MudBlazor / ThemeManager

ThemeManager built to showcase MudBlazor theming.
MIT License
204 stars 59 forks source link

add new css root variable as mud attribute #17

Open saberpooyan opened 1 year ago

saberpooyan commented 1 year ago

Hi i'm going to add some property attributes to mud palette so I created new class as you can see in the picture: Capture1 and then I used that in PresetThemes.cs class like this Capture2 Now as a result I can see my property in c# code but I can't use it as a CSS variable like this var(--mud-palette-ForegroundColor). How can i solve this problem?

henon commented 1 year ago

@Garderoben @JonBunator ?

JonBunator commented 1 year ago

This won't work because MudTheme requires the more generic Palette class. You can override the theme provider instead:

public class MyOwnThemeProvider : MudThemeProvider
{
    protected override void GenerateTheme(StringBuilder theme)
    {
        base.GenerateTheme(theme);

        if(base.IsDarkMode == true)
        {
            theme.AppendLine($"--mud-palette-ForegroundColor {new MudColor("#dd5858")};");
        }
        else
        {
            theme.AppendLine($"--mud-palette-ForegroundColor: red;");
        }
    }
}

But imo it should be possible to add custom variables without overriding the theme provider. See https://github.com/MudBlazor/MudBlazor/discussions/6148

saberpooyan commented 1 year ago

Thank you for your guidance.