-
Notifications
You must be signed in to change notification settings - Fork 428
[DRAFT] FluentUI defaults #3856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@dvoituron thanks for your input! :) The reason I've used the You got any idea how to determine if the user has specified the parameter or not? |
I know why you place this code in this method. But it can't add other problems 😁 It depends on the use cases, but with |
@dvoituron how about this approach? :) It works fine for me. However I cannot get the Unittests to work since they require now the injection of the |
@MarvinKlein1508 we already have tests where the library configuration is being injected. You should be able to find them with a search on the test project. |
@vnbaaij alright. Tests have been updated and all have passed. What do you think about this approach in general? |
Personally I would create sub classes for the components like So instead of: public bool DefaultFluentCardAreaRestricted { get; set; } = true; I would do: public FluentCardDefaults FluentCardDefaults { get; set; } = new();
public class FluentCardDefaults
{
public bool AreaRestricted { get; set; } = true;
} |
I had not actually looked at the code yet, but now that I have, I do not like that we as maintainers are 'determining' what the default are/should be. What I propose to do instead is to create an attribute like Code could look something like:
We then create code that runs on startup that scans the assemblies for this attribute and applies them though the config to the components. Or to make scanning faster, we could dictate a specific namespace where the class/properties need to be in. |
You then need to use reflection to retrieve the values, which may cause performance issues and also problems with the Blazor WASM compilation process (trimming). I find that using options specified when starting the application ( In addition, the use of |
You already do so. There are many properties which have a default value defined from the library itself. What I like about the LibraryConfig approach is that it is super easy to change on startup or even via appsettings.json I'm not a hige fan of attributes and reflection either. Everytime I has to use it it always resulted in some hard to find bugs |
Also how would you handle same property names from different components in this case. Sorry for any typos I'm currently in the bus on my way home |
Another idea would be to create an interface which can be registered on startup for esch component. I this will give you access to all (public) properties of the component. If an interface for this type of component is being registered it will run during OnInitializedAsync |
But then the same question applies again. How can we determine if the user has provided the Parameter manually. |
But us (and only us) specifying what defaults there are (like By using a namespace (that we control), I think we can alleviate the trimming problem. That fact that is costs some performance will be negligible and only occurs on startup. In my opinion that is then the 'price' the dev needs to pay for being able to set defaults. But it will be a really small price. And by limiting the reflection to just one namespace, the performance impact will be even smaller.
It's pseudo code...I just want to make clear what the idea is. |
It is not about setting the default value, it is about letting the system know about the existence of a default value for a specific parameter
Sorry, but that is a non-argument :), You use [Parameter] all the time and that works pretty reliably |
In my opinion, the question is not “how to do it” but “should we do it.” In my opinion, no. FluentUI offers a style of use with default values. It is not a good idea to suggest changing these default values. However, |
As part of the attribute, you specify the Component name as a parameter of the attribute
|
I'm more on Marvin's side on this. Why not offer it? With my approach, it always needs to be a conscious decision of the developer to override/change a default. Any (negative) effect of that will be their concern, not ours |
Because you won't be able to decide which parameters to include in this list :-) In my opinion, |
Let me give you some more insights why I want to have any kind of this. FluentCardI always find it strange that the area is restricted to the card's height by default. I cannot think of any useful scenario where I actually wanna have this behaviour at all (I'm just used to it to adapt automatically from Bootstrap). That's why I want to have FluentInputsI always set MessageBarI use this component as a replacement for Boostrap alerts. Because I display some additional information or warnings by default, I don't want to have them fading in. That's why I always set StacksI always use them to align my content vertically with some gaps between them. Therefore I always set That's currently all use-cases I have. Perhaps as additional info: I wrap my parameters line by line and every line counts within the razor editor. I think I need to restart VS like 5 times a day just because the razor editor crashes and doesn't do anything at all. Especially when you have razor files with more than 1000 lines of code. |
@dvoituron I envision it to be used exactly like Marvin describes: Offer a way to always use a All we need to do is make sure that as part of the initialization, the component applies any provided defaults. If that would lead to a malfunctioning component, then it is up to the dev to not use that deautl value or change it or whatever. I believe that doesn't have to be our problem. I created a PR for this code idea with some GH Copilot help: PR #3857 |
@vnbaaij there is still one big issue to overcome. How would you check if I want to use another value just one time. Lets say I define my default value to be |
From the docs in the other PR:
|
@MarvinKlein1508 I added this feature in dev-v5. See #3875 I suggest closing this PR for now. |
@dvoituron I am fine waiting for v5. In my current application I already have provided the parameters everywhere. Before I need to touch it twice I rather wait for the v5 release. In theory I could already use v5 in my app. I'm only waiting for some components to get startet (navigation, dropdown and autocomplete) |
Pull Request
📖 Description
I've previously talked about this within some PR or discussion. I would like to be able to change some default behaviour within the FluentUI library, so I don't need to write the same stuff over and over again.
This PR is just meant as a draft to gather your feedback on this purpose.
The new static class allows the user to override any allowed property in their default value. In this example for the
FluentCard
theAreaRestriced
parameter. In my app I never want any FluentCard to restrict it's area.Other possible properties which come into my mind:
FluentMessageBar
->FadeIn
(which I always want to be false)FluentStack
->Orientation
(which I always want to be Vertical in my case)Those 3 I overrite in any component within my app. There might be more scenarios for different useful default values as well.