@@ -15,7 +15,7 @@ npm install --save @zeecoder/react-container-query
15
15
### Set up PostCSS with webpack
16
16
17
17
[ 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
19
19
been using.
20
20
21
21
## Usage
@@ -39,35 +39,13 @@ Assuming the following CSS:
39
39
And assuming that ` meta ` is the object obtained by running the above CSS
40
40
through the [ postcss plugin] ( https://github.com/ZeeCoder/container-query/tree/master/packages/postcss-container-query ) .
41
41
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
-
62
42
### ` <ContainerQuery> `
63
43
64
44
A render-prop approach.
65
45
66
46
``` js
67
47
import { 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" ;
71
49
72
50
const App = () => (
73
51
< ContainerQuery meta= {meta}>
@@ -82,16 +60,13 @@ If you're also interested in the component's size:
82
60
83
61
``` js
84
62
import { 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" ;
88
64
89
65
const App = () => (
90
66
< ContainerQuery meta= {meta}>
91
67
{size => (
92
- // size can be "null" when size is still not available
93
68
< div className= " App" >
94
- My size is: {size ? ` ${ size .width } x$ {size .height } ` : " ? " }
69
+ My size is: {size .width }x{size .height }
95
70
< / div>
96
71
)}
97
72
< / ContainerQuery>
@@ -100,28 +75,17 @@ const App = () => (
100
75
export default App ;
101
76
```
102
77
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 `
109
79
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:
111
81
112
82
``` js
113
- import { ResizeObserver } from " @zeecoder/react-container-query" ;
83
+ import { withContainerQuery } from " @zeecoder/react-container-query" ;
84
+ import { meta } from " ./App.pcss" ;
114
85
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> ;
123
87
124
- export default App ;
88
+ export default withContainerQuery ( App, meta) ;
125
89
```
126
90
127
91
## License
0 commit comments