MediaQuery
Apply styles to children if media query matches
Import
Source
Docs
Package
Usage
MediaQuery component adds styles to child element if given media query matches:
(max-width: 1200px) and (min-width: 800px) breakpoints
Usage with theme
(max-width: 1200px) and (min-width: 800px) breakpoints
largerThan and smallerThan props
largerThan
and smallerThan
props lets you use theme.breakpoints
:
- larger than lg
- Smaller than lg
- Smaller than xl, larger than sm
- Smaller than 1500px, larger than 800px
Configure breakpoints
Default breakpoints:
Breakpoint | Viewport width |
---|---|
xs | 576px |
sm | 768px |
md | 992px |
lg | 1200px |
xl | 1400px |
To change these values wrap your application with MantineProvider and set breakpoints
prop on theme:
MediaQuery children
MediaQuery always work with single child and uses className
prop to add styles,
child component must accept it otherwise styles will not be applied the element:
!important MediaQuery will work only with React elements. Strings, numbers, fragments and other parts will not have correct styles:
MediaQuery component props
Name | Type | Description |
---|---|---|
children * | ReactNode | Child that should be shown at given breakpoint, it must accept className prop |
largerThan | number | "xs" | "sm" | "md" | "lg" | "xl" | Styles applied to child when viewport is larger than given breakpoint |
query | string | Any other media query |
smallerThan | number | "xs" | "sm" | "md" | "lg" | "xl" | Styles applied to child when viewport is smaller than given breakpoint |