Media query props
Customize the props you pass with the full power of native CSS media queries.
No higher-order components, no run-time resize events, full power of arbitrary media queries, fully type-checked.
<MyComponent ="Hi, John" ="left" = >
If you add more than one media query at once, see the mediaQueriesExclusive gotcha.
Usage
After the initial configuration described below, use this module when authoring your components. Decide which props you want to allow to customize by media queries and wrap them in the MediaQueries type. The values of these props are not limited to any css values.
;;
Use these props when rendering your component using your mediaQueries helper function. It takes all props of the component and calls your callback multiple times, once for the main props and once for every passed in media query.
;;return ;
If your component props are defined as a union of multiple other components, each of which has its own mediaQueries, you need to add a special type to correctly merge mediaQueries prop:
// Will not merge mediaQueries prop correctly; // Will merge mediaQueries prop correctly;;
Add to your project
The package is available on npm as media-query-props
.
Configure it for your CSS tooling by calling the factory function with a type parameter describing what your callback functions are supposed to return, and a function parameter transforming a list of nested style objects into a single result, most likely a class name you will apply to elements.
For an example, here is how I configure it to use with Emotion.
;;;;;
You can customize the factory with options:
createMediaQueriesFunctioncss, ;