Open Zolomon opened 10 months ago
@Zolomon hello. Good to know that it's working good 👌 Referring to Emotion, do you mean Emotion as a whole library itself, or only some Material UI related part?
Sorry for the delayed response.
Basically, I am trying to port the following snippet from TypeScript from the MUIv5 Drawer docs:
Specifically, I am getting stuck on how to express the style for this snippet:
<Drawer
variant="permanent"
sx={{
display: { xs: 'none', sm: 'block' },
'& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
}}
open
>
{drawer}
</Drawer>
I have the following so far:
Mui.drawer [ drawer.variant.permanent
drawer.open' true
drawer.children [ drawer' ]
drawer.sx (
xs =
[ style.display.none
style.innerSlot
MuiClasses.drawer.paper
[ style.boxSizing.borderBox
style.width
Components.drawerWidth ] ],
sm =
[ style.display.block
style.innerSlot
MuiClasses.drawer.paper
[ style.boxSizing.borderBox
style.width
Components.drawerWidth ] ]
) ] ] ]
The breakpoints do not appear to function as intended on Firefox v118.0.2 (64-bits), but I am quite sure it is a failure on my part and has nothing to do with your code.
Do you have any suggestions? I have searched through the repository for similar usages and this is what led me to this result.
@Zolomon, understood. Unfortunately, sx
-prop bindings I made are not so flexible as they are in TS/JS API. I tried to cover the most common scenarios, but it still lacks some features as, e.g., breakpoints per prop (this one is tricky to be expressed via current Feliz API and in terms of F# type system at all).
It easily could be a failure on my side because there are no automated tests for the bindings. Therefore, I haven't tested a lot of things simply because I haven't used them yet. And breakpoint styling is on of them, I suppose.
Regarding the provided example, it seems to me correct, that is how I expected it to work. So, I need to test it to find out what's wrong. Thank you for reporting it 👍
@Zolomon I've made a simple test. Seems like I made a mistake assuming that it's possible to set breakpoints-based styles in other than a per-prop manner. I.e. these aren't actually the equal definitions:
<AppBar
sx={{
width: { sm: `calc(100% - ${drawerWidth}px)` },
ml: { sm: `${drawerWidth}px` }
}}>
<AppBar
sx={{
sm: {
width: `calc(100% - ${drawerWidth}px)`,
ml: `${drawerWidth}px`
}
}}>
Probably, the 1st one is the correct option and the 2nd one is not. At least I don't see anything similar to the 2nd option in the MUI Docs article about sx-prop
usage. I suppose, I misunderstood this thing while I was writing the bindings last year 😕 Summing up, seems like the current bindings don't provide a way to set breakpoints-based styles, and it's necessary to come up with an appropriate solution.
As a workaround for now, to make things done, I'd try to define an sx
-prop extension overload that takes an obj
, and then use this overload to pass it JS object that fits the schema that MUI expects.
An example of such extension (that could be defined in any F# module in your code before the place where it is intended to be used):
type Feliz.MaterialUI.appBar with
static member inline sx (stylesObj: obj) = Feliz.Interop.mkAttr "sx" stylesObj
Actually, there is no need to define it for each component type. Instead, it could be done just once on some other type, as Feliz's prop
, for example:
type Feliz.prop with
static member inline sx (stylesObj: obj) = Feliz.Interop.mkAttr "sx" stylesObj
Or define it in a new erased type:
[<Erase>]
type muiProp =
static member inline sx (stylesObj: obj) = Feliz.Interop.mkAttr "sx" stylesObj
It totally doesn't matter for the output JS.
Hi!
Thank you for making this fork, so far everything is working great. 👍
I am curious what and how much work is required to create the Emotion bindings?