Skip to content

Commit 5d989bb

Browse files
committed
Initial component implementation
1 parent 25542fe commit 5d989bb

File tree

9 files changed

+1784
-314
lines changed

9 files changed

+1784
-314
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
# IDE
2626
/.idea/
2727
/.history/
28+
/.vscode/

README.md

Lines changed: 91 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ For example, if you put a responsive component into a tight sidebar, it will ali
2323
- [onResize callback](#onresize-callback)
2424
- [Custom sizes](#custom-sizes)
2525
- [Using height instead of width](#using-height-instead-of-width)
26+
- [Using both width and height](#using-both-width-and-height)
2627
- [Customizing attribute prefix](#customizing-attribute-prefix)
2728
- [Using multiple modifiers on the same element](#using-multiple-modifiers-on-the-same-element)
28-
- [Using both width and height on the Element Query component](#using-both-width-and-height-on-the-element-query-component)
2929
- [Disabling](#disabling)
3030
- [FastBoot fallback](#fastboot-fallback)
3131
- [Browser support](#browser-support)
@@ -65,13 +65,13 @@ This addon is in active development.
6565
* [x] Add fool-proof exceptions
6666
* [x] Disabling
6767
* [ ] `<ElementQuery>` component
68-
* [ ] Exists
69-
* [ ] Applies attributes to itself
68+
* [x] Exists
69+
* [x] Applies attributes to itself
7070
* [ ] Yields block params
71-
* [ ] Accepts `sizes`
72-
* [ ] Accepts `prefix`
73-
* [ ] Accepts `dimension`
74-
* [ ] Disabling
71+
* [x] Accepts `sizes`
72+
* [x] Accepts `prefix`
73+
* [x] Accepts `dimension`
74+
* [x] Disabling
7575
* [ ] Expose types
7676
* [ ] CI
7777
* [ ] npm package
@@ -397,81 +397,127 @@ Use the `dimension="height"` argument to make attributes get applied based on el
397397
<ElementQuery @dimension="height"></ElementQuery>
398398
```
399399

400+
Attributes representing height sizes will be postifed with `-height`: `xxs-height`, `xl-height`, etc.
400401

401-
402-
### Customizing attribute prefix
403-
404-
Use the `prefix` argument to adjust attribute prefix:
402+
You can customize height sizes into `@sizesHeight`. Make sure that height size names are different from width sizes!
405403

406404
```html
407-
<img {{element-query prefix="data-foo-"}}>
405+
<div
406+
{{element-query
407+
dimension="height"
408+
sizesHeight=(hash small-height=0 medium-height=200 large-height=400)
409+
}}
410+
>
411+
</div>
408412
```
409413

410414
```html
411-
<ElementQuery @prefix="data-foo-"></ElementQuery>
415+
<ElementQuery
416+
@dimension="height"
417+
@sizesHeight={{hash small-height=0 medium-height=200 large-height=400}}
418+
as |at from to|
419+
>
420+
<to.small-width><from.large-height>
421+
I am thin and tall.
422+
</from.large-height></to.small-width>
423+
</ElementQuery>
412424
```
413425

414-
This will result in attributes like `data-foo-at-xl`, `data-foo-from-m`, etc.
426+
Specifying `heightSizes` has no effect unless `dimension` is either `"height"` or `"both"`.
415427

416428

417429

418-
### Using multiple modifiers on the same element
430+
### Using both width and height
419431

420-
You can use both width and height element queries on the same element like this:
432+
Use the `dimension="both"` argument:
421433

422434
```html
423-
<img
424-
class="foo"
425-
{{element-query dimension="width" prefix="width-"}}
426-
{{element-query dimension="height" prefix="height-"}}
427-
>
435+
<img {{element-query dimension="both"}}>
436+
```
437+
438+
```html
439+
<ElementQuery @dimension="both"></ElementQuery>
428440
```
429441

442+
This will cause two sets of attributes get applied. Attributes representing width sizes will be the same as [usual](#concept-of-sizes). Attributes representing height sizes will be postifed with `-height`: `xxs-height`, `xl-height`, etc.
443+
430444
This lets you apply CSS like this:
431445

432-
```
433-
.foo[width-at-m][height-from-m] {}
446+
```css
447+
.foo[to-s][from-xl-height] {
448+
/* I am thin and tall */
449+
}
434450
```
435451

436-
Another use case is when you already have many styles written for default attributes, and then your designer tells you to apply a new style based on non-default breakpoints. Multiple modifiers lets you do this without rewriting existing styles:
452+
You can customize height sizes into `@sizesHeight`. Make sure that height size names are different from width sizes!
437453

438454
```html
439-
<img
440-
{{element-query}}
441-
{{element-query prefix="new-" sizes=(hash small=0 large=768)}}
455+
<div
456+
{{element-query
457+
@dimension="both"
458+
sizes=(hash small-width=0 medium-width=350 large-width=700)
459+
sizesHeight=(hash small-height=0 medium-height=200 large-height=400)
460+
}}
461+
>
462+
</div>
463+
```
464+
465+
```html
466+
<ElementQuery
467+
@sizes={{hash smallWidth=0 mediumWidth=350 largeWidth=700}}
468+
@sizesHeight={{hash small-height=0 medium-height=200 large-height=400}}
469+
as |at from to|
442470
>
471+
<to.small-width><from.large-height>
472+
I am thin and tall.
473+
</from.large-height></to.small-width>
474+
</ElementQuery>
443475
```
444476

445-
⚠ Never apply two or more modifiers with the same prefix to the same element. The `{{element-query}}` modifier adds and removes attributes aggressively and will interfere with other modifiers/libraries manipulating same attributes.
446477

447478

479+
### Customizing attribute prefix
448480

449-
### Using both width and height on the Element Query component
481+
Use the `prefix` argument to adjust attribute prefix:
450482

451-
You can pass your height sizes into `@sizesHeight`. Make sure that height size names are different from [width sizes](#concept-of-sizes)!
483+
```html
484+
<img {{element-query prefix="data-foo-"}}>
485+
```
452486

453487
```html
454-
<ElementQuery
455-
@sizes=(hash smallWidth=0 mediumWidth=350 largeWidth=700)
456-
@heightSizes=(hash smallHeight=0 mediumHeight=200 largeHeight=400)
457-
as |at from to|
488+
<ElementQuery @prefix="data-foo-"></ElementQuery>
489+
```
490+
491+
This will result in attributes like `data-foo-at-xl`, `data-foo-from-m`, etc.
492+
493+
494+
495+
### Using multiple modifiers on the same element
496+
497+
One use case for this is to apply new styles based on new breakpoints without breaking (and refactoring) existing styles.
498+
499+
You can use both width and height element queries on the same element like this:
500+
501+
```html
502+
<img
503+
class="foo"
504+
{{element-query}}
505+
{{element-query sizes=(new-small=0 new-large=700)}}
458506
>
459-
<to.smallWidth><from.largeHeight>
460-
I am thin and tall.
461-
</from.largeHeight></to.smallWidth>
462-
</ElementQuery>
463507
```
464508

465-
You can also pass `true` to `@sizesHeight`, which will enable default sizes. They are the same as [width sizes](#concept-of-sizes) but postfixed with `Height`: `xxsHeight`, `xlHeight`, etc.
509+
or
466510

467511
```html
468-
<ElementQuery @heightRules=true as |at from to|>
469-
<to.s><from.lHeight>
470-
I am thin and tall.
471-
</from.lHeight></to.s>
472-
</ElementQuery>
512+
<img
513+
class="foo"
514+
{{element-query}}
515+
{{element-query prefix="new-"}}
516+
>
473517
```
474518

519+
⚠ The `{{element-query}}` modifier adds and removes attributes aggressively and will interfere with other modifiers/libraries manipulating same attributes. It is your duty to ensure there is no conflict in attribute names. Adjust `sizes`, `sizesHeight` and `prefix` arguments to avoid conflicts.
520+
475521

476522

477523
### Disabling
@@ -896,7 +942,7 @@ Given breakpoints 350, 700 and 1050:
896942
```html
897943
<ElementQuery
898944
@sizes=(hash smallWidth=0 mediumWidth=350 largeWidth=700)
899-
@heightSizes=(hash smallHeight=0 mediumHeight=200 largeHeight=400)
945+
@sizesHeight=(hash smallHeight=0 mediumHeight=200 largeHeight=400)
900946
as |at from to|
901947
>
902948
<at.smallWidth><at.largeHeight>

addon/-private/component.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Component from '@glimmer/component';
2+
import { Yield, Sizes, Dimension } from './modifier';
3+
4+
interface ElementQueryArgs {
5+
dimension?: Dimension;
6+
isDisabled?: boolean;
7+
prefix?: string;
8+
sizes?: Sizes;
9+
sizesHeight?: Sizes | true;
10+
onResize?: (params: Yield) => void;
11+
}
12+
13+
export default class ElementQuery extends Component<ElementQueryArgs> {}

0 commit comments

Comments
 (0)