-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[system] Box accept any value in TypeScript #15451
Comments
Something like
Is also better than demo in the document. |
@Jack-Works On a very basic level this is a better solution. String paths usually create a refactoring hazard. But what happens with the types in custom themes? We would need type helpers that take a This is also something to keep in mind when we introduce a dynamic @Losses Where does |
@eps1lon Some hypothetical variable |
This is not actionable for us. If you hide implementation details then the demo is always better than a demo with implementation details. But we want to showcase actual usage where your code doesn't apply. |
To support both approach, use string | [ tuple ]. |
@eps1lon Aren't we in much better shape now? |
I have used box days ago. I feel its better typed now. |
But only some attributes get typed I thought. color and bg.color seems keep the same |
@eps1lon I am working on exactly that. And actually have a semi-working solution. Semi, because it works - but not with generic theme mapping functions, which you need to resolve something like this: It would work perfectly well with custom themes, it even make the whole process precise, because styles in the demo specify only exactly what they need and whether they need theme at all. There is a custom style function, not from system, as it is currently not in a way I would like it to be, but I try to work on the issues and make proposals, one after another, currently there is a breaking bug in jss I have PR running, after which I can continue with the refined PRs from the draft you might recall. Instead of themeKey, you have a themeMap function which projects values from prop/theme to value(s). Advantage of this method is also that you can can not only map a prop value to theme value, but also use additional theme values, which maybe are not directly tied to the prop. The downside of passing array literals is the performance. Not part of the demo, just a naive thought: <Component bgcolor={color("primary", "main")} textcolor={color("secondary", "main")} /> Where bgcolor/textcolor simply takes a css color and not theme key. This has obviously some cost in term of design then... and some benefits, like easier typing, better performance. However:
Note: |
Demo in the document
Let's see the demo in the https://material-ui.com/system/basics/
The content of
color
bgcolor
font-Family` ... is not type-friendly.Now we can use
variant
(typed as 'outlined' | 'contained' | ...etc ) orcolor
(typed as 'primary' | 'secondary' | ...etc). In the case ofBox
, it just like you want to type it as "outline.primary". You need to write all the combinations to get the correct type.Consider a better API like:
Then we can type
Box
asAnd this doesn't need to break the current behavior. Just
.join('.')
and['primary', 'main']
becomes"primary.main"
The text was updated successfully, but these errors were encountered: