You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-43Lines changed: 63 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,10 +64,11 @@ This addon is in active development.
64
64
*[x] Updates on arugments change
65
65
*[x] Add fool-proof exceptions
66
66
*[x] Disabling
67
-
*[]`<ElementQuery>` component
67
+
*[x]`<ElementQuery>` component
68
68
*[x] Exists
69
69
*[x] Applies attributes to itself
70
-
*[ ] Yields block params
70
+
*[x] Calls the `onResize` callback with params
71
+
*[x] Yields block params
71
72
*[x] Accepts `sizes`
72
73
*[x] Accepts `prefix`
73
74
*[x] Accepts `dimension`
@@ -272,7 +273,7 @@ Usage
272
273
273
274
### As a modifier
274
275
275
-
Using the modifier is preferred if you only do CSS transformations.
276
+
Using the modifier is preferred if you only do **CSS transformations**, which is recommended according to the Responsiv Web Design doctrine.
276
277
277
278
Simply apply the `{{element-query}}` modifier to any element or angle bracket component like this:
278
279
@@ -290,30 +291,45 @@ As a result, element query attributes will be applied to the element. The result
290
291
291
292
### As a component
292
293
293
-
The component is useful when you need to do template transformations.
294
+
The component is useful when you need to do **template transformations**.
294
295
295
-
Use it like this:
296
+
If you want to render chunks of template conditionally, use this syntax:
296
297
297
298
```html
298
-
<ElementQueryas|atfromto|>
299
-
<at.m>
299
+
<ElementQueryas|EQ|>
300
+
<EQ.at-m>
300
301
{{! This will only be rendered when the `<ElementQuery>` component is of size `m`. }}
301
302
</at.m>
302
303
303
-
<from.m>
304
+
<EQ.from-m>
304
305
{{! This will only be rendered when the `<ElementQuery>` component is of size `m` or larger. }}
305
-
</from.m>
306
+
</EQ.from-m>
306
307
307
-
<to.m>
308
+
<EQ.to-m>
308
309
{{! This will only be rendered when the `<ElementQuery>` component is of size `m` or smaller. }}
309
-
</to.m>
310
+
</EQ.to-m>
310
311
311
-
<from.s><to.l>
312
+
<EQ.from-s><EQ.to-l>
312
313
{{! This will only be rendered when the `<ElementQuery>` component is of size `s`, `m` or `l`. }}
313
-
</to.l></from.s>
314
+
</EQ.to-l></EQ.from-s>
315
+
</ElementQuery>
316
+
```
317
+
318
+
If you want to "sprinke" your tempalte with small responsive bits, you may find it more convenient to use the `{{#if}}` syntax together with [ember-truth-helpers](https://github.com/jmurphyau/ember-truth-helpers):
319
+
320
+
```html
321
+
<ElementQueryas|EQEQInfo|>
322
+
<SomeOtherComponent
323
+
@isMedium={{eqEQInfo.size"s"}}
324
+
@isMediumOrLarger={{boolEQ.from-m}}
325
+
>
314
326
</ElementQuery>
315
327
```
316
328
329
+
The first yield argument `EQ` is a hash of current element query attributes. Keys are attribute names and values are truthy strings, so `{{bool EQ.from-m}}` gives you `true` when the element is of size `m` or larger, and `false` when the element is smaller than `m`.
330
+
331
+
The second argument `EQInfo` is the same hash that is passed to the [onResize callback](#onresize-callback).
332
+
317
333
318
334
319
335
Advanced usage
@@ -325,12 +341,16 @@ You can pass a callback to the `onResize` argument and it will be called wheneve
325
341
326
342
```js
327
343
@action
328
-
reportResize(data) {
329
-
data.element// => current element
330
-
data.width// => current element's width in px (number)
331
-
data.height// => current element's height in px (number)
332
-
data.ratio// => current element's aspect ratio (width/height, number)
333
-
data.size// => current element's size (string)
344
+
reportResize(info) {
345
+
info.element// => current element
346
+
info.width// => current element's width in px (number)
347
+
info.height// => current element's height in px (number)
348
+
info.ratio// => current element's aspect ratio (width/height, number)
349
+
info.size// => current element's width size (string or undefined)
350
+
info.sizeHeight// => current element's height size (string or undefined)
351
+
info.dimension// => current dimension ('width', 'height' or 'both')
352
+
info.prefix// => current prefix (string or undefined)
353
+
info.attributes// => element query attributes used on the element (array of strings)
334
354
}
335
355
```
336
356
@@ -415,11 +435,11 @@ You can customize height sizes into `@sizesHeight`. Make sure that height size n
0 commit comments