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: 75em) and (min-width: 50em) breakpoints
Usage with theme
(max-width: 75em) and (min-width: 50em) 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 1500, larger than 800
Configure breakpoints
Default breakpoints:
Breakpoint | Viewport width |
---|---|
xs | 36em |
sm | 48em |
md | 62em |
lg | 75em |
xl | 88em |
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 |