Replies: 4 comments 1 reply
-
This is currently how we're trying to make sense of Mantine's MediaQuery component usage: // Making our breakpoint sizes work with Mantine is a bit tricky and unintuitive since breakpoint sizes indicate
// ranges—a lower boundary and an upper boundary. Mantine uses a single value to represent a breakpoint size. To work
// around this, we chose to set the upper boundary for each size. This means passing a value for `largerThan` is
// "intuitive" because we can use named string values.
// Example:
// Show "large" up (larger than "medium"): <MediaQuery largerThan="md">…</MediaQuery> 👌
// But values for `smallerThan` aren't so easy—we can't pass named string values. Instead, we derive a value by
// adding one to the "previous size" that is smaller than the named string value we would want to pass from our theme.
// Examples:
// Show "medium" down (smaller than "large"): <MediaQuery smallerThan={theme.breakpoints.md + 1}>…</MediaQuery> 🙃
// Show "small" only: <MediaQuery largerThan="xs" smallerThan={theme.breakpoints.sm + 1}>…</MediaQuery> 🙃
breakpoints: {
xs: 599,
sm: 899,
md: 1199,
lg: 1799,
xl: 99999,
}, |
Beta Was this translation helpful? Give feedback.
-
Hi @dallanlee thanks for feedback! I like breakpoints the way they are represented now. This allows us to build responsive styles for Grid and SimpleGrid components easily. I guess the better idea here is just to add 1 to |
Beta Was this translation helpful? Give feedback.
-
I appreciate the consideration and I do agree that calculating I think the MediaQuery component is a little confusing because it's only for showing and hiding based on screen min- and max-widths. But media queries are used for much more. So the implied hiding and showing based on |
Beta Was this translation helpful? Give feedback.
-
I think such an api will provide all features that you would expect from MediaQuery: <MediaQuery
query="(max-width: 1200px) and (min-width: 800px)"
styles={{ fontSize: 20, '&:hover': { backgroundColor: 'silver' } }}
>
<Text>(max-width: 1200px) and (min-width: 800px) breakpoints</Text>
</MediaQuery> |
Beta Was this translation helpful? Give feedback.
-
Hi 👋
I would like to see breakpoints implemented as actual ranges—two values representing the boundaries of the breakpoint size's range. Something like:
(Or derive the range from an adjacent size's value.)
I personally like the implementation of
css-media-vars
. As explained in their docs, using naming such as"sm"
(only "small breakpoint" range),"lte-sm"
(small and down – lte = less than or equal to), and"gte-sm"
(small and up – gte = greater than or equal to) feels more declarative and precise. Then I imagine using Mantine's MediaQuery component something like:or
(The sizes in my example are from another article (also linked to in the
css-media-vars
docs) and are also my preference. But as that can be defined in my Mantine theme overrides, the important proposal here is the idea of breakpoint ranges.)Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions