Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.6k
Ideas for new theme/settings management#6148
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I want to start a discussion about a new theme/global settings management system. I'll write down some ideas and requirements I had in mind. Please feel free to share your opinion. If you want to comment on a specific point, reference the feature like this: #F1 1. ThemingF1 Container colorCurrently, we only have one primary color that is used for both primary text and primary containers. You can see this in the docs: M3 solves this with the introduction of separate colors for primary text and primary containers (https://m3.material.io/styles/color/overview): F2 ElevationElevation in dark mode is still based on a dark shadow outline. It should rather change the background color. MUI: We need to support more variants of the surface color to support this feature. F3 Inject theme-serviceMany component libraries allow it to inject the theme-service into a page. This is useful if you want to change from light to dark theme. @injectIThemeServicetheming...<MudSwitch @CheckedChanged="Change"/>publicvoid Change(booleanvalue){theming.setDarkMode(value);} F3.1Every color should also be accessed via the theme-service: @injectIThemeServicetheming...theming.Palette.Primary F4 Change colors of all components globallyThe colors of all components should be able to be set via the theme. This is already partially possible. For example, there are the colors F5 Style propThe <MudButtonStyle="color:red">Button</MudButton>//this will add<button style="color:red"/> Because of that I want to try something that is also done by Emotion, styled-components etc. <MudButtonStyle="color:red">Button</MudButton>//this will add<button class="Aj3d03Te"/><style>.Aj3d03Te{style="color:red"}</style> F6 Use hex colors for componentsThe current implementation only allows pre-selected colors to be used in components. //This is possible<MudButtonColor="Color.Primary"/>//This is not possible<MudButton Color="#ff0000"/> The approach explained in #F5 can be used to achieve this.
Disadvantages:
Backwards compatibility is very important here because the Color prop is used very often. This can be achieved if we change the publicclassColor{publicstaticstringPrimary{get;}="";//<- primary color needs to be set here with functionality #F3.1...} F7 Density systemWith a density (margins/paddings) system, you should be able to set the density of all components globally. There were some efforts:#3178 F8 Define custom theme colorsI think it's a good idea. This was rejected already in#5850 F9 Change material colorsThe material colors should be changeable via the theme:https://mudblazor.com/features/colors#material-colors-list-of-material-colors F12 Customize BreakpointsIt's not possible to customize the breakpoints yet. F13 Convert themes to .json filesConverting themes to .json files (+ .json files to themes) would make it easier to save and share themes 2. Global settingsF10 SettingsServiceCurrently, there are many providers/services that each have their own way of handling settings:
Imo it makes more sense to have one provider/service that can handle all global settings and that manages the current theme. Similar to #F3 the SettingsService should also be injectable into pages to change specific settings everywhere in the application. F11 Change default prop values of componentsIt should be possible to change the default values of properties. For example, MudTextField has the default variant publicpartialclassMudButton:MudBaseButton{ .../// <summary>/// The variant to use./// </summary>[Parameter][SettingsProp][Category(CategoryTypes.Button.Appearance)]publicVariantVariant{get;set;}=Variant.Text; ...} will generate the following settings class: publicclassMudButtonSettings{publicVariantVariant{get;set;}=Variant.Text;} Then you can change the default value in the settings provider: MudSettingss=newMudSettings(){MudButtonSettings=MudButtonSettings(){Variant=Variant.Text}} |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 10
Replies: 11 comments 19 replies
-
I'm sure I'll have more later, but I really like the idea presented in F11. Changing default prop values to be configurable site wide. It would clean up a lot of standard things and make writing components a bit quicker. I do wonder if it will be easily overridable. I've had some issues with IDialogProvider not accepting local overrides from near where they're called. |
BetaWas this translation helpful?Give feedback.
All reactions
-
It would also allow us to localize components better.
That's a good question. The settings service would just set new values in the constructor. I don't think that's a problem. But we'll have to see |
BetaWas this translation helpful?Give feedback.
All reactions
-
I would like to elaborate, now, and say that after a second/third look over of these I think I'm in favor of most of them. The ones that REALLY make me excited are F1, F2, F3 (& 3.1), F5, F8 (listed two different times, for two different purposes, I mean F8 the former - about defining Custom theme colors), F10, and F11. I know that's most of them, whatever. F1 I simply like, I think it'd be a good addition. F2 I think looks amazing the way MUI does it, if that's something possible, I can't see any drawback. I don't have any big problems with how Elevation shadows look now, but I do admit the MUI look seems cleaner and draws focus better than just the shader outside the element. This might be a personal preference thing, though. F3, 3.1 are very nice ideas that I think would be great. I believe getting a ThemeService would be great as a moving implementation and allows for some more direct interaction with the theme when needed. It seems a bit niche as /is/, but I believe it expands the possibilities going forward. I believe this might be a way to hook into the MudThemes somehow as well, by injecting a theme on Startup, maybe from a json config instead of in code, allowing you to be able to export your theme from MudTheme and bundle it in your project and easily swap them out? I think that would be a pretty neat way to integrate it on load, which is separate from the portable use cases of just having the values available when you're coding to utilize portions of the theme in non default ways. F5 I think would be nice to have, though I don't know how it would feel - as in, where does the .css get generated and when? Upon build? F8 (custom colors F8, not the other) I think would be great to have some sort of... mutable collection of key values that you could add to in the ThemeService that lets you store custom colors to retrieve as needed with your own names. I think that would be neat, potentially useful. F10 I think I like the idea of a SettingsService housing the IThemeProvider as you mention here, but I would wonder what other settings you'd want to expose. Would this roll into F11's implementation of basically adding theming to components? Would that be considered a SettingsService or still, thematically, just an IThemeProvider? Speaking of, F11 just seems like it will save so much time typing the same 2 or 3 Key=Value combinations on some high use component types. Since the general theme of the whole website often uses a ton of the same basic setup for TextField / Button etc. I think F11 is my favorite single change of the whole list. Hopefully some of the above is useful. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks a lot for your detailed feedback!
That's another good idea. I think you can pretty easily convert json to C# objects. I'll add it to the list as #F13
The theme service will collect all styles from all components and then generate a single
Dark theme change, RTL, themes and all default values of the components. We'll have to see if the default values should rather be part of the theme or not Ahh I used F8 twice. I'll rename it to F12. I hope it's not too confusing |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
These are some really good points.
The struggles of getting the value from the current |
BetaWas this translation helpful?Give feedback.
All reactions
-
Exactly, that was the idea. At the moment, you have to create your own service that handles darkmode changes etc. |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
F8, F9 I think. Current :root {--mud-palette-error:#f64e62ff;}.mud-alert-filled-translucent {background-color:var(--mud-palette-error);}.mud-alert-filled-error-translucent {/* the best I can do to add transparency is this */background-color:#f64e627f;} Proposed :root {--mud-palette-error:2467898;}.mud-alert-filled-error {background-color:rgb(var(--mud-palette-error)/1.0);}.mud-alert-filled-error-translucent {background-color:rgb(var(--mud-palette-error)/0.5);} |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hmm, that's also a good idea. But that would double our css variables of course |
BetaWas this translation helpful?Give feedback.
All reactions
-
My suggestion is no longer valid I think. I just realized all palette colours are defined in the code, not CSS. That means they can be modified or derived on runtime as needed. If anyone is wondering how: @usingMudBlazor.Utilities;@injectLayoutService LayoutService@code{MudColormyDerivedColor;voidSetMyDerivedColor(){varbaseColor=LayoutService.CurrentTheme.Palette.Primary;myDerivedColor=newMudColor(baseColor.Value).SetAlpha(70);}} |
BetaWas this translation helpful?Give feedback.
All reactions
-
That's exactly what a meant with
They are converted to css variables and applied inside a |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Agree. F8 was a good idea. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I know that I'm late to the party but I couldn't resist replying since I've recently solved this same problem for myself. I'm also able to make the alpha percentage a CSS variable. |
BetaWas this translation helpful?Give feedback.
All reactions
-
One suggestion: Support Multiple Themes Yes we can change the theme dynamically, but we can't use 2 themes at the same time. If we remove the popoverprovider in theme provider and give a selector parameter, we can simply use multiple themes with css classes, like |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes, and with#6519 it is possible to make a sub theme by inheriting your base theme with only some changes but keeping it in sync with your base theme for all other settings. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Right now I'm starting a new project and have been given a palette to have the UI use. I've fallen at the first hurdle because I cannot specify a colour for the hover state of the MudButton. The solutions I've found here involve complicated hacks. So a solution that provides anyone to customise the theme fully would be good from my point of view, and some of the above look great. I can see there are conflicts in some too - a comprehensive container for all theme elements would need to be flexible enough to handle new components in future, so probably use a dictionary. The idea of a component specific attribute to specify the theming allows great flexibility, but then means lots of individual classes to manage. I very much like the .json file option as it makes editing easier. It could also be automatically updated as components reference it, so that it grows automatically to fit the components used. One thought I did have was that a theme customiser could have a default so that you set the primary color, and then from that is derived the hover color via an opacity setting, as now. But if I wanted to override that, then I could set a specific hover color, and that then gets used. So while I don't know which is the best option, I very much endorse the idea of improving the theme management, and comprehensively please to handle more than it does now. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
I had a further thought - if the theme manager is to be a repository that is organised by a dictionary of class names, like "MudButton" then a useful addition would be to have the MudButton type have a "CustomTheme" property so that it could use the "MudButton-{CustomTheme}" dictionary element to see if there is customisation for that button. This would allow users to have a general property set in the theme for MudButton, but also have CustomTheme="bluebutton" properties to make for easy centrally controlled styling. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Ad F10, the global settings service would also be the perfect place for I18N strings so users can change everything that is currently hard-coded to English. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 3
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I really like the proposal of taking inspiration from Emotion and other CSS in js solutions, but I have one question: Does this solution require inline styles (or writing <style> tags with CSS to the DOM)? If this proposal does involve writing inline styles OR writing <style> tags to the DOM dynamically, it will be really difficult to combine with a Content Security Policy without using "unsafe-inline" (or at "best" "unsafe-hashes"). These are both to be avoided. Ref discussion in issue#4529 A solution to this could be to use a module bundler to extract these styles to a separate stylesheet. |
BetaWas this translation helpful?Give feedback.
All reactions
-
It's great, if you can implement app bar with centered nav-links and square corner components. |
BetaWas this translation helpful?Give feedback.
All reactions
-
As a suggestion of density suggestion, we can define 4 kind of density: "Standard, Comfort, Slim and SuperSlim" Standard has 8px padding, Comfort 4px, Slim 2px and none for SuperSlim. Component's height should reduce in slim and SuperSlim also. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I often require a higher level of density than what is currently considered 'dense', especially when working with tabular data. However, using 0px padding never looks good IMO. Excel-like padding and row/column sizing is usually compact enough to strike a good balance between readability and the amount of data on the screen. |
BetaWas this translation helpful?Give feedback.
All reactions
-
These ideas are very good, any plans for them to be implemented? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Tag for myself to work on this tomorrow. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I would change the priority of F6 low. I am still thinking it would be cool to have it but many team members think it is not worth the effort. Maybe if we find a volunteer who wants to implement it all and can show on one component that it doesn't increase component complexity all that much then we might still have it. F11 is partially done. I would promote it to highest priority and see which other defaults we should make configurable. We should add another point F12 to find a way to inject theme styles and other dynamic styles in a CSP-compliant manner, i.e. with a custom endpoint like@meenzen suggested. Or a source generator (where applicable), or any other way if anybody has better ideas. That is essentially it. All the other points seem to be still valid. The team should discuss and agree on priorities for all the points. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Was F11, "Change default prop values of components" ever delivered? Was looking to distribute a NuGet package of our defined Theme and was wondering if style variants are covered nowadays? |
BetaWas this translation helpful?Give feedback.





