-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[RFC] Replace variant with kind in the components where the variant is used for altering the DOM structure #22259
Comments
If I understand correctly, developers will do: <TextField kind="outlined" />
<Button variant="outlined" /> This feels inconsistent. Have we considered alternative solutions? What if we had these components covered later on, by supporting any prop in the |
The other alternative that I had in mind was, adding different prop for styling purposes or allowing clients to specify their own (but that I believe would be later down the road), I believe that is what you are suggesting? My only worry with this was, how would clients know that they cannot use the |
It feels like we're leaking implementation details. Developers shouldn't need to know about the internal DOM structure or what is applied by CSS, JS etc to decide whether something is a This will lock the current implementation to the technology used at the time. If we later discover that we don't need to change the internal structure or we do want to change the internal structure then we can't do this because of the variable naming. I understand that we do already leak some of these details but we do it in a controlled fashion in a per-component basis. Not as a general concept that we need to teach users of this library.
Could you include a brief summary of the problem in the opening description of this issue? It's not clear to me whether this is an implementation problem or interface problem or teaching problem. |
@mnajdova Yes, this is what I was suggesting, we could hold on these components (CircularProgress, Drawer, etc.) until we resolve this other issue.
The first layer of an answer will be the prop-type and types that will complain. The second layer of an answer would be the generated documentation that doesn't include "string" as part of the available options. |
Types can only tell you what does or does not work. They can't tell you what you should use which is the problem here. |
@eps1lon I am missing here the description of why this is a problem, thanks of bringing it up. The problem is that if developers define their own custom |
@eps1lon As a specific example, the TextField component is a wrapper around the Input, FilledInput and OutlinedInput components. The |
@mbrookes I understand the technical problem for the implementation. However, none of this should affect the API because then you lock the implementation in place. What if we want to split up the Button into each variant? We couldn't do this without a breaking change where we switch from Edit: Which wouldn't be a problem with wrapper components because the user would be in charge of handling variants. |
Do you have any idea how long it took me to merge them? 😅
Understood, and I'm not arguing in favour of "kind", i jut misinterpreted the last paragraph of #22259 (comment) to mean that clarification of the nature of issue was needed, so I was simply adding a specific example. @mnajdova Thinking out loud, how about:
|
We can definitely do this.
This sounds interesting, let me see how the structure would look like. Another similar idea I had was prefixing the variants with the original variant, something like |
Ideally we'd be able to extract specific variants with a compiler for bundle size reduction. So that people who only use variant X only get the code for variant X. That's a topic for #16280 though. |
@mnajdova What's left to be done on this issue for v5? |
We still need for these component a different prop in order to allow developers to add custom variants. We cannot simply use the |
I don't think this PR will be brought back to discussion. Ideally, the |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. |
Summary 💡
This RFC is proposing solution to the problem that we faced in #21749 - supporting custom variants for the component. The problem is the following: we want to offer developers the possibility to add their own custom
variant
values so that they can style their components differently that the supported options we have by default. However in some of the components, thevariant
property is used not only for styling, but also for changing the internal DOM structure. The problem is that if developers define their own customvariant
, likedashed
the component will not render anything, or at least will behave unexpectedly because it depends on thevariant
prop to be some of the defined values. This is the list of the components where we faced this issue:Solution
My proposal for solving this issue is the following. We would replace the
variant
prop in this component with a different property -kind
. This property will behave exactly as the currentvariant
prop. After this change is done, we can safely then use thevariant
property for purely styling purposes and expose it to the developers for defining their custom variants.The text was updated successfully, but these errors were encountered: