Skip to content

Commit c4fb6a9

Browse files
committed
doc updates
1 parent 2961eb7 commit c4fb6a9

File tree

6 files changed

+165
-2
lines changed

6 files changed

+165
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ addons:
66
script:
77
- lerna bootstrap --ignore={demos}
88
- yarn test:unit
9-
- lerna run test
9+
- yarn test:packages
1010
- node ./tests/bin/run-on-first-ci-job.js yarn test:integration:build
1111
- node ./tests/bin/run-on-first-ci-job.js yarn test:integration
1212
after_success: "yarn coveralls"

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# How to Contribute
2+
3+
This project uses [Lerna](https://lernajs.io/) to manage its packages.
4+
5+
## Getting Started
6+
7+
I recommend [yarn](http://yarnpkg.com) for development.
8+
9+
- Run `yarn`
10+
- Run `yarn bootstrap` (This will install all dependencies, build the packages
11+
and links any cross-dependencies. It also allows packages to import each other
12+
using their published package names.)
13+
- Run `yarn test:unit` to run the unit tests.
14+
- Run `yarn test:packages` to run the "test" scripts inside all packages.
15+
- Run `yarn test:integration:build` to build the integration test files.
16+
- Run `yarn test:integration` to run the integration tests in headless Chrome.
17+
18+
## Testing
19+
20+
Unit tests are using [Jest](https://jestjs.io/), while integration tests are using
21+
[Karma](https://karma-runner.github.io). (And [Sauce Labs](https://saucelabs.com/)
22+
in the CI to run in multiple browsers.)
23+
24+
During development, you can run:
25+
26+
- `yarn test:unit:watch` and,
27+
- `KARMA_CHROME=true yarn test:integration --singleRun=false`
28+
29+
to run the tests on code changes.
30+
31+
Note that you'll also need to run the build in watch mode in the package you're
32+
working on, as integration tests use the built code.)

docs/css-in-js.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# CSS-in-JS
2+
3+
**This is not a "CSS-in-JS" library.**
4+
5+
The sole purpose of this solution is to allow you to conditionally apply styles
6+
to child elements, inside a containing element.
7+
8+
You can still use your regular CSS processing tool - be that PostCSS, SASS or LESS -
9+
to process your CSS files, and when certain styles are tied to a @container query
10+
with a certain condition, then it's the JS runtime that'll decide when to apply
11+
your them to the applicable elements.
12+
13+
## Does it work with CSS-in-JS libraries?
14+
15+
As I'm not using any of those libraries, I'm not exactly sure how the setup would
16+
look like, but it's quite possible to apply your regular / static styles with your
17+
library of choice, and then use the [meta builder](https://github.com/ZeeCoder/container-query/tree/master/packages/container-query-meta-builder)
18+
to build the meta object containing the styles that need to be applied runtime.
19+
20+
Feeding such a meta object to the runtime is already what we're doing, the only
21+
difference being that this meta object is being conveniently generated for us by
22+
the [postcss-plugin](https://github.com/ZeeCoder/container-query/tree/master/packages/postcss-container-query).
23+
24+
Looking into the tests for the meta builder might help you figure out how exactly
25+
this could be implemented.
26+
27+
Don't hesitate to post in [issues](https://github.com/ZeeCoder/container-query/issues)
28+
if you feel like you have a good solution!

docs/css-modules.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# CSS Modules
2+
3+
To make this library work with CSS Modules, we need to rewrite the class names in
4+
our meta object based on the styles object we get from CSS Modules on import.
5+
6+
## Parcel
7+
8+
With parcel, the setup is quite simple, as it supports PostCSS configuration
9+
files.
10+
11+
The following shows a usual PostCSS setup, with container queries and CSS modules:
12+
13+
```sh
14+
yarn add postcss-nested \
15+
postcss-media-minmax \
16+
@zeecoder/postcss-container-query \
17+
postcss-modules --dev
18+
19+
# or with NPM:
20+
21+
npm install postcss-nested \
22+
postcss-media-minmax \
23+
@zeecoder/postcss-container-query \
24+
postcss-modules --save-dev
25+
```
26+
27+
Then put the following `.postcssrc` file in your root directory:
28+
29+
```json
30+
{
31+
"modules": true,
32+
"plugins": {
33+
"postcss-nested": { "bubble": ["container"] },
34+
"postcss-media-minmax": {},
35+
"@zeecoder/postcss-container-query": {},
36+
"postcss-modules": {}
37+
}
38+
}
39+
```
40+
41+
Now you can do the following:
42+
43+
```js
44+
import React, { Component } from "react";
45+
import styles, { meta as rawMeta } from "./App.css";
46+
import { ContainerQuery } from "@zeecoder/react-container-query";
47+
import { remapMetaSelectors } from "@zeecoder/container-query-meta-builder";
48+
49+
// Since the container query postcss plugin comes before css-modules - and which
50+
// order we cannot change for technical reasons -, we need to remap class names
51+
// to the hashed class names CSS modules generates in the styles object.
52+
const meta = remapMetaSelectors(rawMeta, styles);
53+
54+
class App extends Component {
55+
render() {
56+
return (
57+
<ContainerQuery className={styles.App} meta={meta}>
58+
My app.
59+
</ContainerQuery>
60+
);
61+
}
62+
}
63+
64+
export default App;
65+
```
66+
67+
This would work the same way without react React, or without any component
68+
library for that matter.
69+
70+
## With webpack
71+
72+
Usage is the same with webpack, just add something like the following to your config:
73+
74+
```js
75+
{
76+
// ...
77+
test: /\.css$/,
78+
use: [
79+
"style-loader",
80+
{
81+
loader: "css-loader",
82+
options: {
83+
modules: true
84+
}
85+
},
86+
{
87+
loader: "postcss-loader",
88+
options: {
89+
plugins: [
90+
require("postcss-nested")({ bubble: ["container"] }),
91+
require("postcss-media-minmax")(),
92+
require("autoprefixer")(),
93+
require("../packages/postcss-container-query/dist")()
94+
]
95+
}
96+
}
97+
]
98+
// ...
99+
}
100+
```
101+
102+
You can of course have the PostCSS setup in a config file for webpack as well.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"webpack-cli": "^3.1.2"
5050
},
5151
"scripts": {
52+
"test:packages": "lerna run test",
5253
"test:unit": "jest --coverage",
5354
"test:unit:watch": "jest --watch",
5455
"test:integration": "karma start",

tests/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
]
3131
},
3232
{
33-
test: /module.css$/,
33+
test: /module\.css$/,
3434
use: [
3535
"style-loader",
3636
{

0 commit comments

Comments
 (0)