You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that we can do better by using classes type (PaperClassKeyOptions in this case) and turning them into some constraint maybe by using this lib:
For sure there will be a problem with media queries as keys. We could provide the above as unsafeWithStyles and type safe (but too constrained) version as withStyles to cover these all cases.
I'm not sure why but the above rerenders to much. I've tried to put constant JSS instead of a function Theme -> JSS as argument but is still unmounting I think (for example it looses focus in forms etc.) Even when elementKeyed is used this bad behavior is preserved and even when to whole styled component is created statically up front.
Do you have any idea what is wrong with the above?
It seems that we can do better by using classes type (PaperClassKeyOptions in this case) and turning them into some constraint maybe by using this lib:
Yes, and in fact there needs to be a function that convert the *ClassKeyOptions to something that changes the value type from String to JSS to make Overrides work properly. I'll ask in slack if there is some existing way of doing this, but otherwise, it'll have to be one of those recursive typelevel brain f*cks that I only do often enough to forget how every time :)
I'm not sure why but the above rerenders to much.
have you tried memo from the lumi React Hooks lib?
Regarding rerendering it seems that we have to work with ReactComponents directly (to be honest I don't understand mui docs related to HOC and withStyles). Given this untyped bindings:
related *_component functions probably won't type check. Likepaper_component function (which is also a bit unclear to me - I have to reread your explanation ;-)) doesn't typecheck in this case.
I've tried to turn row of String into row of JSS with purescript-typelevel-eval (which I've updated on my fork to use new purs). It is quite straightforward. Just copy and paste from README.md:
to talk about components which use subset of a given field set. I was not able using this type to provides constraints which are usable without annotation. I've tried this flow:
take classes record from this phantom type (assuming that classes contains record value with Strings like PaperClassKeyOptions
compute type of a record with JSS values from the above
use this type inside callback type (I mean this: (Theme → { | jss }))
Maybe the above attempt is irrelevant as I'm not "compiler guy" and I'm usually lost when compilers tells me about his inference problems ;-) But maybe we should tag MUIComponent with props but also with JSS rows to avoid this Eval stuff and then this function type signature will be much easier to write. I know that there will be redundancy of information in types but we probably gain usability by improving all related error messages ;-)
@srghma
Thanks for suggestion! For sure we have to cover that as well. I have not experience with hooks and react-basic-hooks yet (@dwhitney do you use hooks already? ;-))
Regarding current status of withStyles I allow myself to copy comment from the other thread here:
There are *WithStyles functions in every component module which allow styling. For example:
yes I use hooks for styling. I put something together with react-basic-hooks. Someone else also asked for an example. I'm going to be working all day again on this project, so I'll put together an example.
The classes value above is of type Object String where the keys are the keys of the record defined in the useStyles function (root in this example) and the value is whatever class name JSS creates (something like root_1234).
I use the above hook all over my codebase and it has worked well. We should probably ship it with this lib.
yeah there is probably a useful idea in there somewhere, but in general what I posted above is independent of the *ClassKey because you can use the values from the classes object along with the className attribute that exists in most react elements.
@srghma I just want to add that I've not tested or used API hooks yet with useStyles etc. We are using functions like MUI.Core.Grid.gridWithStyles with react-basic components so I'm not able to help at the moment.
P.S.
I think you should not use my PR branch but codegen-read-dts branch from this repo which contains all changes from the PR. @dwhitney Do you think that we should close this PR to clarify current status?
Activity
paluh commentedon Jul 29, 2019
I'm not sure why but the above rerenders to much. I've tried to put constant
JSSinstead of a functionTheme -> JSSas argument but is still unmounting I think (for example it looses focus in forms etc.) Even whenelementKeyedis used this bad behavior is preserved and even when to whole styled component is created statically up front.Do you have any idea what is wrong with the above?
dwhitney commentedon Jul 29, 2019
Yes, and in fact there needs to be a function that convert the
*ClassKeyOptionsto something that changes the value type fromStringtoJSSto make Overrides work properly. I'll ask in slack if there is some existing way of doing this, but otherwise, it'll have to be one of those recursive typelevel brain f*cks that I only do often enough to forget how every time :)have you tried
memofrom the lumi React Hooks lib?dwhitney commentedon Jul 29, 2019
ok I've added the JSS types mentioned above
paluh commentedon Jul 29, 2019
Wow! Cool!
Regarding rerendering it seems that we have to work with
ReactComponentsdirectly (to be honest I don't understand mui docs related to HOC andwithStyles). Given this untyped bindings:This works fiine without unnecessary unmounting:
element (withStyles (const $ jss { root: { padding: "100px" }}) MUI.Core.Paper._Paper)dwhitney commentedon Jul 29, 2019
paluh commentedon Jul 29, 2019
The problem is that we have only untyped versions of
ReactComponentvalues in the lib. If we provide types forReactComponentvalues something like:related
*_componentfunctions probably won't type check. Likepaper_componentfunction (which is also a bit unclear to me - I have to reread your explanation ;-)) doesn't typecheck in this case.dwhitney commentedon Jul 29, 2019
paluh commentedon Jul 29, 2019
Please, don't rush on my account. I'm one foot offline already ;-)
paluh commentedon Jul 30, 2019
I've tried to turn row of
Stringinto row ofJSSwithpurescript-typelevel-eval(which I've updated on my fork to use newpurs). It is quite straightforward. Just copy and paste from README.md:Usage as constraint:
Using the above and explicite types - this works fine:
Let's assume that we introduce something like:
to talk about components which use subset of a given field set. I was not able using this type to provides constraints which are usable without annotation. I've tried this flow:
classesrecord from this phantom type (assuming thatclassescontains record value withStringslikePaperClassKeyOptionsJSSvalues from the above(Theme → { | jss }))Maybe the above attempt is irrelevant as I'm not "compiler guy" and I'm usually lost when compilers tells me about his inference problems ;-) But maybe we should tag
MUIComponentwithpropsbut also withJSSrows to avoid thisEvalstuff and then this function type signature will be much easier to write. I know that there will be redundancy of information in types but we probably gain usability by improving all related error messages ;-)paluh commentedon Nov 13, 2019
@srghma
Thanks for suggestion! For sure we have to cover that as well. I have not experience with hooks and react-basic-hooks yet (@dwhitney do you use hooks already? ;-))
Regarding current status of
withStylesI allow myself to copy comment from the other thread here:There are
*WithStylesfunctions in every component module which allow styling. For example:https://github.com/dwhitney/purescript-react-basic-mui/blob/codegen-read-dts/src/MUI/Core/Fab.purs#L71
We can build restyled component with it:
and use it:
render _ = myStyledFabButton { children: [ DOM.text "TEST" ]}dwhitney commentedon Nov 13, 2019
hey @paluh and @srghma
yes I use hooks for styling. I put something together with
react-basic-hooks. Someone else also asked for an example. I'm going to be working all day again on this project, so I'll put together an example.dwhitney commentedon Nov 13, 2019
I'm not going to have time to put together an example today, so I'll leave some sample code here, which may help you.
how to create a hook for styles:
FFI
Usage:
The
classesvalue above is of typeObject Stringwhere the keys are the keys of the record defined in theuseStylesfunction (rootin this example) and the value is whatever class name JSS creates (something likeroot_1234).I use the above hook all over my codebase and it has worked well. We should probably ship it with this lib.
dwhitney commentedon Nov 13, 2019
cc @srghma
paluh commentedon Nov 13, 2019
Probably we should be able to add layer of our
*ClassKeyOptionsJSStype safety to it somehow too.dwhitney commentedon Nov 13, 2019
yeah there is probably a useful idea in there somewhere, but in general what I posted above is independent of the
*ClassKeybecause you can use the values from theclassesobject along with theclassNameattribute that exists in most react elements.dwhitney commentedon Jan 11, 2020
paluh commentedon Jan 12, 2020
@srghma I just want to add that I've not tested or used API hooks yet with
useStylesetc. We are using functions likeMUI.Core.Grid.gridWithStyleswithreact-basiccomponents so I'm not able to help at the moment.P.S.
I think you should not use my PR branch but
codegen-read-dtsbranch from this repo which contains all changes from the PR.@dwhitney Do you think that we should close this PR to clarify current status?