Skip to content

Commit f0c11b1

Browse files
committed
Cleanup
1 parent 8f1b769 commit f0c11b1

File tree

9 files changed

+76
-40
lines changed

9 files changed

+76
-40
lines changed

README.md

+32-33
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,37 @@
55
[![Code Climate](https://codeclimate.com/github/ZeeCoder/container-query/badges/gpa.svg)](https://codeclimate.com/github/ZeeCoder/container-query)
66
[![Coverage Status](https://coveralls.io/repos/github/ZeeCoder/container-query/badge.svg?branch=master)](https://coveralls.io/github/ZeeCoder/container-query?branch=master)
77

8-
A PostCSS plugin and Javascript runtime combination, which allows you to write @container queries in your CSS the same way you would write @media queries.
9-
10-
# Milestones
11-
12-
## 1.0.0
13-
- Short description, also in package.json
14-
- Documented solutions for SASS / LESS and just PostCSS
15-
- Turn all milestone notes in the README to github issues and write a proper README
16-
17-
## 1.1.0
18-
- introduce vmin/vmax-like functionality
19-
- Optionally detect container resizing (polling solution?) instead of adjusting on window resize only
20-
21-
## 1.2.0
22-
- Support "or" in queries
23-
24-
## 1.3.0
25-
- Allow for nested @container queries, like it's with @media queries in other preprocessors
26-
27-
## 1.4.0
28-
- Ease usage with React, by hooking into Component refs
29-
- Webpack loader
30-
- compatibility with CSS-modules
31-
32-
# README notes
33-
34-
- Example function to save all container configurations in separate JSON files in a dir
35-
- lib/* is not considered to be a part of the public API, and hence breaking
36-
change can be introduced in any release. (even patch)
37-
- a container can have more than one instance of its elements
38-
- the container units are relative to the container's "inner" height / width, so without the borders.
8+
A PostCSS plugin and Javascript runtime combination, which allows you to write
9+
@container queries in your CSS the same way you would write @media queries.
10+
11+
## PublicAPI
12+
- `Container.js` - JS Runtime
13+
- `containerQuery.js` - PostCSS Plugin
14+
- `initialiseAllContainers.js` - helper function
15+
16+
The rest is not considered to be a part of the Public API, which means they can
17+
change at any time. (Including minor / patch releases.)
18+
19+
## Limitations
20+
- No "or" for @container queries right now, so this is not possible:
21+
`@container ( ... ) or ( ... ) { ... }`
22+
- `@container` queries cannot be nested
23+
- LESS doesn't compile with the current syntax
24+
25+
## Notes
26+
- BEM-inspiration: Block -> inside of which are elements (unique classnames!)
27+
- @container queries must always be preceded by a @define-container
28+
- All @containers following a @defined-container will be related to that
3929
- @define-container declarations will be ignored inside @container declarations
30+
- Example function to save all container configurations in separate JSON files in a dir
31+
- Gulp example
32+
- PostCSS example
33+
- SASS example
34+
- Less -> no-go
35+
- Containers can have more than one instance of their elements
36+
- The container units are relative to the container's "inner" height / width.
37+
(Without the borders.)
4038
- Note possible circular issues
41-
- A container cannot use container units for properties that would affect
42-
its width / height.
39+
- A container should not use container units for properties that would affect
40+
its width / height. These situations are not currently handled, so try to
41+
avoid them.

demo/containers.css

+6
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@
141141
background: #999;
142142
}
143143
}
144+
145+
.asd {
146+
@define-container;
147+
148+
font-size: 100chpx;
149+
}

demo/containers.css.json

-1
This file was deleted.

demo/containers/asd.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"selector":".asd","queries":[{"elements":[{"selector":".asd","styles":{"fontSize":"100chpx"}}]}]}

demo/containers/user.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"selector":".user","queries":[{"elements":[{"selector":".user","styles":{"border":"calc(1chpx + 1cwpx) solid","background":""}},{"selector":".user__tag","styles":{"height":"1ch%","width":"5cw%"}},{"selector":".user__line1","styles":{"height":"100chpx","flexDirection":""}},{"selector":".user__image-wrapper","styles":{"flex":"","height":""}},{"selector":".user__image","styles":{"border":"calc(1chpx + 1cwpx / 5) solid #ccc","maxWidth":"","maxHeight":""}},{"selector":".user__name","styles":{"fontSize":"calc(4chpx + 4cwpx)","display":"","margin":"","lineHeight":"","flex":"","textAlign":""}}]},{"conditions":[["width",">=","250"],["height",">=","250"]],"elements":[{"selector":".user__image-wrapper","styles":{"flex":"0 0 40%","height":"auto"}},{"selector":".user__image","styles":{"maxWidth":"100%","maxHeight":"100ch"}},{"selector":".user__name","styles":{"display":"block"}}]},{"conditions":[["orientation",":","landscape"]],"elements":[{"selector":".user__name","styles":{"margin":"0 5cwpx","lineHeight":"100chpx"}}]},{"conditions":[["orientation",":","portrait"]],"elements":[{"selector":".user__line1","styles":{"flexDirection":"column","height":"100chpx"}},{"selector":".user__image-wrapper","styles":{"flex":"1 0 0"}},{"selector":".user__image","styles":{"maxHeight":"75chpx"}},{"selector":".user__name","styles":{"flex":"0 0 20chpx","lineHeight":"20chpx","textAlign":"center"}}]},{"conditions":[["width",">","300"]],"elements":[{"selector":".user","styles":{"background":"#ccc"}}]},{"conditions":[["width",">","400"]],"elements":[{"selector":".user","styles":{"background":"#bbb"}}]},{"conditions":[["width",">","500"]],"elements":[{"selector":".user","styles":{"background":"#aaa"}}]},{"conditions":[["width",">","600"]],"elements":[{"selector":".user","styles":{"background":"#999"}}]},{"conditions":[["width",">","700"]],"elements":[{"selector":".user","styles":{"background":"#888"}}]},{"conditions":[["width",">","800"]],"elements":[{"selector":".user","styles":{"background":"#999"}}]}]}

demo/gulpfile.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1+
'use strict';
2+
13
const gulp = require('gulp');
24
const fs = require('fs');
35
const path = require('path');
46
const nested = require('postcss-nested');
57
const containerQuery = require('../containerQuery');
8+
const writeFileSync = require('fs').writeFileSync;
9+
const camelCase = require('lodash.camelCase');
610

711
gulp.task('css', function () {
812
const postcss = require('gulp-postcss');
913

1014
return gulp.src('containers.css')
1115
.pipe(postcss([
1216
nested(),
13-
containerQuery(),
17+
containerQuery({
18+
getJSON: (cssPath, containers) => {
19+
for (let containerSelector in containers) {
20+
writeFileSync(
21+
`${__dirname}/containers/${ camelCase(containerSelector) }.json`,
22+
JSON.stringify(containers[containerSelector])
23+
);
24+
}
25+
}
26+
}),
1427
]))
1528
.pipe( gulp.dest('dist') );
1629
});

demo/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<body>
1111

1212

13-
<div class="user">
13+
<div class="user" id="user">
1414
<div class="user__tag">tag</div>
1515
<div class="user__line1">
1616
<div class="user__image-wrapper">

demo/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "",
55
"author": "Viktor Hubert <[email protected]>",
66
"license": "MIT",
7-
"dependencies": {},
7+
"dependencies": {
8+
"lodash.camelcase": "^4.3.0"
9+
},
810
"devDependencies": {
911
"babel-core": "^6.23.1",
1012
"babel-loader": "^6.3.2",
@@ -13,5 +15,8 @@
1315
"postcss": "^5.2.13",
1416
"postcss-nested": "^1.0.0",
1517
"webpack": "^2.2.1"
18+
},
19+
"scripts": {
20+
"build": "gulp css && webpack"
1621
}
1722
}

demo/scripts.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import initialiseAllContainers from '../initialiseAllContainers';
1+
import Container from '../Container';
22

3-
const containers = require('./containers.css.json');
3+
const userJSON = require('./containers/user.json');
44

5-
initialiseAllContainers(containers);
5+
const userContainer = new Container(
6+
document.getElementById('user'),
7+
userJSON
8+
);
9+
10+
window.addEventListener('resize', userContainer.adjust);
11+
12+
13+
// import initialiseAllContainers from '../initialiseAllContainers';
14+
15+
// const containers = require('./containers.css.json');
16+
17+
// initialiseAllContainers(containers);

0 commit comments

Comments
 (0)