Skip to content

Commit 84ee94f

Browse files
authored
Updated README (#276)
* chore: Updated README * chore: Added changeset
1 parent 54416bd commit 84ee94f

File tree

3 files changed

+74
-255
lines changed

3 files changed

+74
-255
lines changed

.changeset/good-terms-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ember-container-query": patch
3+
---
4+
5+
Updated README

README.md

Lines changed: 34 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,28 @@ _Make container queries that harness the power of Ember_
99
## Installation
1010

1111
```sh
12-
ember install ember-container-query
12+
pnpm add -D ember-container-query
1313
```
1414

1515
<details>
16-
<summary>Use Glint or <code>&lt;template&gt;</code> tag? ✨</summary>
1716

18-
- Update your template registry to extend this addon's. Check the [Glint documentation](https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons#using-glint-enabled-addons) for more information.
17+
<summary>Use Glint and <code>*.hbs</code> files?</summary>
1918

20-
```ts
21-
/* types/index.d.ts */
19+
Extend this addon's template registry to get native types.
2220

23-
import '@glint/environment-ember-loose';
24-
25-
import type EmberContainerQueryRegistry from 'ember-container-query/template-registry';
26-
27-
declare module '@glint/environment-ember-loose/registry' {
28-
export default interface Registry extends EmberContainerQueryRegistry, /* other addon registries */ {
29-
// local entries
30-
}
31-
}
32-
```
33-
34-
- If you are using [`<template>` tag](https://github.com/ember-template-imports/ember-template-imports), you are good to go! Use the named import to consume things.
35-
36-
```ts
37-
/* app/components/tracks.{gjs,gts} */
21+
```ts
22+
/* types/index.d.ts */
23+
import '@glint/environment-ember-loose';
24+
import '@glint/environment-ember-template-imports';
3825

39-
import { hash } from '@ember/helper';
40-
import { ContainerQuery, height, width } from 'ember-container-query';
26+
import type EmberContainerQueryRegistry from 'ember-container-query/template-registry';
4127

42-
<template>
43-
<ContainerQuery
44-
@features={{hash
45-
small=(width max=480)
46-
medium=(width min=480 max=640)
47-
large=(width min=640)
48-
tall=(height min=320)
49-
}}
50-
as |CQ|
51-
>
52-
...
53-
</ContainerQuery>
54-
</template>
55-
```
28+
declare module '@glint/environment-ember-loose/registry' {
29+
export default interface Registry extends EmberContainerQueryRegistry, /* other addon registries */ {
30+
// local entries
31+
}
32+
}
33+
```
5634

5735
</details>
5836

@@ -62,6 +40,7 @@ ember install ember-container-query
6240
Where can you use container queries? Here are real-life (and some theoretical) applications!
6341

6442
<details>
43+
6544
<summary>Create reusable components that are independent of screen size ♻️</summary>
6645

6746
1. Components form a core of an Ember app. We love components!
@@ -86,6 +65,7 @@ Where can you use container queries? Here are real-life (and some theoretical) a
8665

8766

8867
<details>
68+
8969
<summary>To table or not to table? That is the question. 🤔</summary>
9070

9171
1. A table is great for showing structured data. On mobile, with a limited width, not so much.
@@ -98,45 +78,53 @@ Where can you use container queries? Here are real-life (and some theoretical) a
9878

9979

10080
<details>
81+
10182
<summary>Create a customizable dashboard 🎛️ 🎚️</summary>
10283

10384
1. It's difficult to create dashboard widgets that can be placed anywhere and look good.
10485

10586
1. As a result, you may artificially constrain your users from customizing their dashboard.
10687

10788
1. If you _combine_ media and container queries, you can better meet the wants of designers, developers, and users.
89+
10890
</details>
10991

11092

11193
<details>
94+
11295
<summary>Responsive images, videos, and D3 visualizations 🖼️ 📽️ 📈</summary>
11396

11497
1. Currently, you have to use [`srcset`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/srcset) to load images with the optimal file size. Alternatively, you can [use container queries to decide which images to load](https://crunchingnumbers.live/2020/06/03/container-queries-adaptive-images/).
11598

11699
2. Similarly, for videos, you could use container queries to decide format and display resolution.
117100

118101
3. D3 components can use container queries to decide what's the best way to show data. Do you show larger chart elements, show legends, allow scrolling, show text summary? etc.
102+
119103
</details>
120104

121105

122106
<details>
107+
123108
<summary>Create beautiful, printable pages 🖨️</summary>
124109

125110
1. You may be able to compose this addon with others to arrive at something ambitious and unique.
126111

127112
1. For example, [`ember-printable-pages`](https://github.com/forge512/ember-printable-pages) lets us reuse components to make a printable document. The components could focus on presenting data with container queries, while `ember-printable-pages` could focus on deciding page layouts and lazily rendering components.
113+
128114
</details>
129115

130116

131117
<details>
118+
132119
<summary>Hide secrets in games 🎮</summary>
133120

134121
1. You're designing [a game in Ember](https://www.youtube.com/watch?v=Ld1xnQWkqPU).
135122

136123
1. Maybe a secret, most powerful item appears when the game world is at a certain size? :)
124+
137125
</details>
138126

139-
Not convinced? Open the [demo app](https://ember-container-query.netlify.app/) to see `ember-container-query` in action. (There's even a 404 page!)
127+
You will find plenty of examples in [`docs-app`](https://github.com/ijlee2/ember-container-query/tree/main/docs-app). Visit https://ember-container-query.netlify.app/ to see the app in action!
140128

141129
<div align="left">
142130
<img alt="A demo of ember-container-query shows a smooth transition when using a list or table to display data" src="https://user-images.githubusercontent.com/16869656/82177207-72699c00-989e-11ea-9cb6-2e388c5e98c0.gif" width="600" />
@@ -161,6 +149,7 @@ Expand the items below to learn more about the API.
161149

162150

163151
<details>
152+
164153
<summary><code>&lt;ContainerQuery&gt;</code></summary>
165154

166155
### Arguments
@@ -189,7 +178,7 @@ You _may_<sup>1</sup> pass attributes to the component for these reasons:
189178

190179
<sup>2. When an [ARIA attribute has multiple values](https://github.com/ijlee2/ember-container-query/issues/38#issuecomment-647017665), the order of values can matter. At the moment, splattributes doesn't guarantee the order.</sup>
191180

192-
### Outputs
181+
### Output
193182

194183
You can consume these values in your app or addon.
195184

@@ -203,6 +192,7 @@ You can consume these values in your app or addon.
203192

204193

205194
<details>
195+
206196
<summary><code>{{aspect-ratio}}</code>, <code>{{height}}</code>, <code>{{width}}</code></summary>
207197

208198
### Arguments
@@ -222,6 +212,7 @@ All helpers accept these arguments:
222212

223213

224214
<details>
215+
225216
<summary><code>{{container-query}}</code></summary>
226217

227218
### Arguments
@@ -236,23 +227,22 @@ You can pass these arguments to the modifier.
236227
For more information, refer to [the arguments of `<ContainerQuery>` component](#arguments).
237228

238229

239-
### Outputs
230+
### Output
240231

241-
The outputs are similar to [those of `<ContainerQuery>` component](#outputs).
232+
The output is similar to [those of `<ContainerQuery>` component](#output).
242233

243234
Data attributes are automatically applied to the HTML element. To get `dimensions` and `features`, you will need to pass the argument `@onQuery` (a function) to the modifier.
244235

245236
```ts
246237
/* app/components/chart.gts */
247-
248238
import { action } from '@ember/object';
249239
import Component from '@glimmer/component';
250240
import { tracked } from '@glimmer/tracking';
251241
import { containerQuery, type Dimensions } from 'ember-container-query';
252242

253-
export default class ChartComponent extends Component {
254-
@tracked height!: number;
255-
@tracked width!: number;
243+
export default class Chart extends Component {
244+
@tracked height: number;
245+
@tracked width: number;
256246

257247
@action updateDimensions({ dimensions }: { dimensions: Dimensions }) {
258248
const { height, width } = dimensions;
@@ -274,89 +264,6 @@ export default class ChartComponent extends Component {
274264
</details>
275265

276266

277-
## Example
278-
279-
Let's look at the code that created the video demo above.
280-
281-
<details>
282-
<summary><code>app/templates/album.hbs</code></summary>
283-
284-
```hbs
285-
<ContainerQuery
286-
@features={{hash
287-
large=(width min=960)
288-
tall=(height min=400)
289-
}}
290-
as |CQ|
291-
>
292-
{{#let
293-
(and CQ.features.large CQ.features.tall)
294-
as |showLyrics|
295-
}}
296-
<section local-class="container {{if showLyrics "with-lyrics"}}">
297-
<header local-class="album-header">
298-
<h1>{{@model.name}}</h1>
299-
<p>by <strong>{{@model.band.name}}</strong></p>
300-
</header>
301-
302-
<div local-class="album-tracks">
303-
<Tracks
304-
@tracks={{@model.tracks}}
305-
/>
306-
</div>
307-
308-
{{#if showLyrics}}
309-
<div local-class="track-lyrics" tabindex="0">
310-
<Lyrics
311-
@lyrics={{this.currentTrack.lyrics}}
312-
/>
313-
</div>
314-
{{/if}}
315-
</section>
316-
{{/let}}
317-
</ContainerQuery>
318-
```
319-
320-
</details>
321-
322-
<details>
323-
<summary><code>app/components/tracks.hbs</code></summary>
324-
325-
```hbs
326-
<ContainerQuery
327-
@features={{hash
328-
small=(width max=480)
329-
medium=(width min=480 max=640)
330-
large=(width min=640)
331-
tall=(height min=320)
332-
}}
333-
as |CQ|
334-
>
335-
{{#if (and CQ.features.large CQ.features.tall)}}
336-
<Tracks::Table
337-
@tracks={{@tracks}}
338-
/>
339-
340-
{{else}}
341-
<Tracks::List
342-
@numColumns={{
343-
if CQ.features.small 1
344-
(if CQ.features.medium 2 3)
345-
}}
346-
@tracks={{@tracks}}
347-
/>
348-
349-
{{/if}}
350-
</ContainerQuery>
351-
```
352-
353-
</details>
354-
355-
You can see that the album page uses 2 `<ContainerQuery>` components. Rest assured, they act independently of each other. When you pair `<ContainerQuery>` with some CSS, you can create layouts beyond the dreams of others! 🙌
356-
357-
For more examples, I encourage you to check out the code for my demo app. It is located under the [`docs-app`](https://github.com/ijlee2/ember-container-query/tree/main/docs-app) folder and is structured like a typical Ember app.
358-
359-
360267
## Compatibility
361268

362269
- Ember.js v4.12 or above

0 commit comments

Comments
 (0)