Skip to content

Commit 97fec53

Browse files
committed
more updates to the docs
1 parent 779c915 commit 97fec53

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

docs/api.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
**Instantiation**
66

7-
`new Container(element, stats, options)`
7+
```js
8+
new Container(element, meta, options)
9+
```
810

9-
Where `element` is an HTMLElement, `stats` is a json object from the PostCSS
11+
Where `element` is an HTMLElement, `meta` is a json object from the PostCSS
1012
plugin, and options are extra options about how the instance should behave.
1113

1214
**Default options:**
@@ -49,10 +51,10 @@ window resize, if that fits your needs.
4951
```js
5052
postCSS([
5153
containerQuery({
52-
getJSON: function(cssFilePath, stats) {
54+
getJSON: function(cssFilePath, meta) {
5355
// `cssFilePath`: the original css file's path that was processed. Useful
5456
// if you want to save the JSON relative to the original css.
55-
// `stats`: the json stats having all the container-related data
57+
// `meta`: the JSON metadata having all the container-related data
5658
// needed for the Container instances.
5759
// It's structure was previously described in the "Multiple Containers"
5860
// section.

docs/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This solution consists of a PostCSS plugin and a JS (`Container`) class.
44

5-
> PostCSS plugin → Metadata → Runtime
5+
> PostCSS → Metadata → Runtime
66
77
The plugin analyses your CSS and extracts all container query related
88
data, producing a metadata JSON file.

docs/gulp.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ gulp.task("styles", () => {
3131
The above CSS can include multiple containers thanks to `singleContainer: false`,
3232
and [@define-container](docs/define-container.md) declarations.
3333

34-
This task creates a styles.css and styles.json file, which can then be used by
35-
webpack as [you've seen it before](webpack-and-react.md).
34+
This task creates a `styles.css` and `styles.css.json` file, which can then be
35+
used by webpack as [you've seen it before](webpack-and-react.md).
3636

3737
**Next:** [Multiple Containers](multiple-containers.md)

docs/multiple-containers.md

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# Multiple Containers
22

3-
Instead of processing each container individually, you might want to instead
4-
import all styles containing containers in a single file, and then process that.
5-
6-
(This is the case described in [Usage with Gulp](gulp.md))
3+
Instead of processing each container individually, you might want to import all
4+
styles containing container query syntax in a single file, and process that.
75

86
To do so, you'll have to switch off container auto-detection (which takes the
97
first class found in a processed file as the selector for a container) to allow
108
for the `@define-container;` declaration instead.
119

1210
With that, you'll be able to declare multiple containers in a single file.
1311

14-
This is as simple as setting the `singleContainer` option to false, when using
15-
the postcss plugin.
12+
This is as simple as setting the `singleContainer` option to false.
13+
14+
(Also showcased in the [Usage with Gulp](gulp.md)) section.)
1615

1716
### Example
1817

@@ -30,21 +29,19 @@ the postcss plugin.
3029
// etc
3130
```
3231

33-
**JSON structure**
32+
**Metadata structure**
3433

35-
Normally you don't have to care about the structure of the JSON file.
34+
Normally you don't have to care about the structure of the JSON meta file.
3635
(In fact, I encourage you not to depend on anything in it, as it could potentially
3736
change with new releases.)
3837

39-
However, if you incorporate all you styles into a single file before processing
40-
it with the PostCSS plugin - using a workflow similar to what's described in
41-
[Usage with Gulp](gulp.md) for example -, you'll instead have the extracted
42-
container stats grouped by component selector in the resulting JSON:
38+
However, if you run the plugin in `singleContainer: false` mode, you'll have the
39+
extracted container metadata grouped by component selector in the resulting JSON:
4340

4441
```json
4542
{
46-
".Component1": {},
47-
".Component2": {}
43+
".Component1": {...},
44+
".Component2": {...}
4845
}
4946
```
5047

docs/syntax.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
As previous examples show, containers can be declared by adding
66
`@define-container;` inside a rule that's meant to be used as a container.
77

8-
(Unnecessary in `singleContainer` mode)
8+
(Unnecessary in `singleContainer` mode.)
99

1010
Multiple such definitions in a single CSS file are allowed. All container
1111
queries and units will be relative to the previous declaration.
@@ -137,8 +137,7 @@ done on each resize event (or `adjust` call).
137137

138138
### CSS Custom Properties
139139

140-
Setting custom properties are supported, which you can use to improve
141-
performance.
140+
Setting custom properties are supported, which can be used to improve performance.
142141

143142
```pcss
144143
.User {

docs/without-webpack.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Without webpack
22

33
Even though the library was made with webpack in mind, there's no reason why
4-
other bundlers wouldn't work, or other UI libraries for that matter. (Instead
5-
of React.)
4+
other bundlers wouldn't work, or other UI libraries for that matter.
5+
(Ones other than of React.)
66

77
**Just follow the same steps**
88

99
1. Process your styles with the PostCSS plugin, to extract all container-related
1010
information
11-
2. Save the JSON(s) somewhere
12-
3. Serve the JSON(s) to the JS some way
13-
4. Create a Container instance for all container html elements
11+
2. Save the metadata file(s) somewhere
12+
3. Serve the file(s) to the runtime some way
13+
4. Create a `Container` instance for all container html elements
1414

1515
For instance, imagine you have a `main.pcss` file, which imports all other
1616
components.
@@ -25,19 +25,19 @@ all elements found:
2525
// Assumptions:
2626
// - Browserify as the bundler
2727
// - JSON is available in a script tag, served by the backend:
28-
// `<script type="application/json" id="container-stats">{ ... }</script>`
28+
// `<script type="application/json" id="container-metadata">{ ... }</script>`
2929

3030
import Container from "@zeecoder/container-query";
3131

32-
const containerStats = JSON.parse(
33-
document.getElementById("container-stats").textContent
32+
const meta = JSON.parse(
33+
document.getElementById("container-metadata").textContent
3434
);
3535

3636
// Initialising all containers by finding all instances based on the selectors
37-
for (let containerSelector in containerStats) {
37+
for (let containerSelector in meta) {
3838
document.querySelectorAll(containerSelector).forEach(element => {
39-
// Initialising all HTML Elements with the right json stats
40-
new Container(element, containerStats[containerSelector]);
39+
// Initialising all HTML Elements with the right json metadata
40+
new Container(element, meta[containerSelector]);
4141
});
4242
}
4343
```

0 commit comments

Comments
 (0)