-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
v3 #40
v3 #40
Conversation
Hi @olee, what do you think about an API like the following one where we provide the refs as type only instead of passing an actual argument? const useStyles = makeStyles<{ color: "red"; }, "child" | "child2">()((theme, { color }, refs) => ({
"parent": {
"padding": theme.spacing(3),
[`&:hover .${refs.child}`]: {
"background": color,
},
[`&:hover .${refs.child2}`]: {
"background": "red",
},
},
"child": {
"background": "blue",
},
"child2": {
}
})); This could potentially unlock the situation we have with It's hard to achieve but using es5 Proxies we could theoretically pull it off. |
Yes it could work but the difference between It would be much cleaner if we could make it work without requiring the user to specify an information we already have... |
Hi @olee, Thank you for your help, Best |
Yeah I actually got my workplace to give me time to take care of this PR as we will be using this productively. |
bdf1c02
to
3cd695e
Compare
I updated our CI framework to be able the publish beta versions. |
The counter should still be global imho, as creating multiple makeStyles when used by libraries etc. can still create duplicates. I think there is no issue in just moving up those few lines to be outside of the makeStyles function. |
@olee alright! Thanks for the review. It's live. |
What about the other review comments? 😅 |
@olee Sorry have I missed something? |
|
||
return useMemo(() => { | ||
const refClassesCache: Record<string, string> = {}; | ||
|
||
const refClasses = new Proxy< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if using a proxy is super smart or actually a bad idea here...
While on the one side it allows not having the define the ref names prior to the styles, it makes it necessary to provide explicit generic arguments to the makeStyles
invocation which is quite annoying and it also provides no safety at all for non-typescript use (totally optional imho as pretty much everyone should use TS, but it's still a thing to consider).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit generic arguments to the makeStyles invocation which is quite annoying
Passing { "ref": [ "a", "b", "c" ] }
if anything is more verbose that "a" | "b" | "c". The only thing that pain me is to have to explicitly provide void as the Param
argument. makeStyle<void, "a" | "b" | "c">
😔
it also provides no safety at all for non-typescript use
Making explicitly provide the "ref": [ "a", "b", "c" ]
provide no safety to the JS users. If anything it's one more place where they can screw up. In JSS they where used to $ruleName
without having to provide an extra parameter. They expect the same with TSS.
There is also two extra argument in favor of using type only param instead of runtime param:
- For
withStyles()
(API that I personally don't use but that is important to many non the less) combined with MUI components, it's a game changer:
https://user-images.githubusercontent.com/6702424/143791304-7705816a-4d25-4df7-9d45-470c5c9ec1bf.mp4 - It make writing the codemod for automatic migration from v4's
makeStyles
andwithStyles
achievable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well as mentioned before already, withStyles
also has a third argument to pass options so that should not be an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I provided the wrong gif.
I already explained it to you. Why would you require user to explicitly pass in an information we don't need and we already have?
It would be a fundamentally flawed design.
In withStyles
, it's not the user that get to decide the rules name. They are defined by the type of theclasses
props.
Oh man... I didn't know I had to specifically "submit" a review because I never did this 😣 |
Thank you very much for taking the time to review the code so thoughtfully. Many thanks. |
The remaining question is: How to we make this work with
withStyles
.