How do I access the responsive values in the style...
# javascript
h
How do I access the responsive values in the style properties? (https://mui.com/system/getting-started/usage/#responsive-values) I tried the following and other stuff, but cannot seem to find out how:
Copy code
sx {
    xs {
        paddingLeft = spacing(1)
    }
    paddingLeft {
        xs = spacing(1)
    }
}
It seems the example I looked up there is only for setting up the breakpoints. But how do I set different styles for these breakpoints on a component? So that I can say under 600px do this and over 600px do that? In the MUI Showcase they do it with a mediaQuery and
isMobile
, but the Toolbar Component for example sets
paddingLeft
to
24px
in the
@media(width:600px)
style, but when I do
Copy code
sx { paddingLeft = 8.px }
it's not overwritten there, just in the normal style of the Toolbar.
Illustrating the Problem:
This seems to work somewhat:
Copy code
sx { breakpoints.up(<http://Breakpoint.sm|Breakpoint.sm>)) { paddingLeft = spacing(1) } }
Which seems to be the same as
Copy code
sx { "@media(min-width:600px)" { paddingLeft = spacing(1) } }
or
Copy code
media(MediaQuery((breakpoints.up(Breakpoint.sm)))) { paddingLeft = spacing(1) }
Is there a better/shorter way available? (if not I'll just make an extension function)
t
breakpoints.up(<http://Breakpoint.sm|Breakpoint.sm>)
Looks like return type of expression should be
MediaQuery
😞
h
Just as a note,
MediaQuery
seems to just be a wrapped String. And `breakpoints.up(Breakpoint.sm)`already returns
@media (min-width: 600px)
the
media
function already adds a
@media
though, so
Copy code
media(MediaQuery((breakpoints.up(<http://Breakpoint.sm|Breakpoint.sm>)))) { paddingLeft = spacing(1) }
actually doesn't work since it applies
@media @media (min-width: 600px)
.
For the time being I use helper functions like these:
Copy code
context(Theme)
fun PropertiesBuilder.xs(
    block: PropertiesBuilder.() -> Unit
) = (breakpoints.up(<http://Breakpoint.sm|Breakpoint.sm>)) {
    block()
}
Resulting in this usage:
Copy code
sx {
    xs { paddingLeft = spacing(2) }
    sm { paddingLeft = spacing(4) }
    xl { paddingLeft = spacing(6) }
}