@@ -15,7 +15,7 @@ npm install --save @zeecoder/react-container-query
1515### Set up PostCSS with webpack
1616
1717[ Here] ( https://github.com/ZeeCoder/container-query/blob/master/docs/postcss.md )
18- is a documentiation on how to do just that, in order to get the same syntax I've
18+ is a documentation on how to do just that, in order to get the same syntax I've
1919been using.
2020
2121## Usage
@@ -39,35 +39,13 @@ Assuming the following CSS:
3939And assuming that ` meta ` is the object obtained by running the above CSS
4040through the [ postcss plugin] ( https://github.com/ZeeCoder/container-query/tree/master/packages/postcss-container-query ) .
4141
42- The one thing you need to keep in mind is that the container css class
43- (".App" in this case) has to be present on the root element.
44-
45- (A limitation [ soon to be addressed] ( https://github.com/ZeeCoder/container-query/issues/89 ) .)
46-
47- ### ` withContainerQuery `
48-
49- This is probably the easiest way of enabling container queries.
50-
51- ``` js
52- import { withContainerQuery } from " @zeecoder/react-container-query" ;
53- // Assuming postcss-loader to be set up
54- import " ./App.pcss" ;
55- import meta from " ./App.pcss.json" ;
56-
57- const App = () => < div className= " App" > My App< / div> ;
58-
59- export default withContainerQuery (App, meta);
60- ```
61-
6242### ` <ContainerQuery> `
6343
6444A render-prop approach.
6545
6646``` js
6747import { ContainerQuery } from " @zeecoder/react-container-query" ;
68- // Assuming postcss-loader to be set up
69- import " ./App.pcss" ;
70- import meta from " ./App.pcss.json" ;
48+ import { meta } from " ./App.pcss" ;
7149
7250const App = () => (
7351 < ContainerQuery meta= {meta}>
@@ -82,16 +60,13 @@ If you're also interested in the component's size:
8260
8361``` js
8462import { ContainerQuery } from " @zeecoder/react-container-query" ;
85- // Assuming postcss-loader to be set up
86- import " ./App.pcss" ;
87- import meta from " ./App.pcss.json" ;
63+ import { meta } from " ./App.pcss" ;
8864
8965const App = () => (
9066 < ContainerQuery meta= {meta}>
9167 {size => (
92- // size can be "null" when size is still not available
9368 < div className= " App" >
94- My size is: {size ? ` ${ size .width } x$ {size .height } ` : " ? " }
69+ My size is: {size .width }x{size .height }
9570 < / div>
9671 )}
9772 < / ContainerQuery>
@@ -100,28 +75,17 @@ const App = () => (
10075export default App ;
10176```
10277
103- ### ` <ResizeObserver> `
104-
105- This component simply observes an element's size changes using ` ResizeObserver ` .
106-
107- Useful to allow for rendering parts of the component conditionally, based
108- on its size.
78+ ### ` withContainerQuery `
10979
110- (It uses a [ polyfill ] ( https://github.com/que-etc/resize-observer-polyfill ) , if a native implementation is not available.)
80+ If you prefer Higher-Order Components:
11181
11282``` js
113- import { ResizeObserver } from " @zeecoder/react-container-query" ;
83+ import { withContainerQuery } from " @zeecoder/react-container-query" ;
84+ import { meta } from " ./App.pcss" ;
11485
115- const App = () => (
116- < ResizeObserver>
117- {size => (
118- // size can be "null" when size is still not available
119- < div> My size is: {size ? ` ${ size .width } x${ size .height } ` : " ?" }< / div>
120- )}
121- < / ResizeObserver>
122- );
86+ const App = () => < div className= " App" > My App< / div> ;
12387
124- export default App ;
88+ export default withContainerQuery ( App, meta) ;
12589```
12690
12791## License
0 commit comments