Skip to content

Commit 1ab233e

Browse files
author
Sean King
committed
init
0 parents  commit 1ab233e

9 files changed

Lines changed: 7012 additions & 0 deletions

File tree

.eslintrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"plugins": [
4+
"jest"
5+
],
6+
"env": {
7+
"es6": true,
8+
"node": true,
9+
"jest/globals": true
10+
},
11+
"rules": {
12+
"no-console": "warn",
13+
"no-undefined": "error",
14+
"no-unused-vars": "warn",
15+
"indent": ["error", 2, {
16+
"SwitchCase": 1,
17+
"VariableDeclarator": { "var": 2, "let": 2, "const": 3 }
18+
}],
19+
"linebreak-style": ["error", "unix"],
20+
"semi": ["error", "always"],
21+
"valid-jsdoc": 2
22+
}
23+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
*.log

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
cache: yarn
3+
node_js:
4+
- node
5+
- "8"
6+
- "6"
7+
- "4"

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright 2018 Sean King <sean@seanking.org>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# PostCSS Subgrid
2+
![ci-img][ci]
3+
4+
[PostCSS] plugin that shims some _very_ basic behavior of the proposed CSS grid `display: subgrid` [spec].
5+
6+
**Note:** This plugin only provides a shorthand for mimicing a single use-case for CSS subgrids: inheriting the parent grid for full-width containers with placed children.
7+
8+
See [this Codepen][codepen] for a demonstration.
9+
10+
```css
11+
.foo {
12+
display: subgrid;
13+
}
14+
```
15+
16+
```css
17+
.foo {
18+
grid-column: 1 / -1;
19+
display: grid;
20+
grid-template-columns: inherit;
21+
grid-gap: inherit;
22+
margin: 0;
23+
padding: 0;
24+
}
25+
```
26+
27+
## Usage
28+
29+
```js
30+
postcss([ require('postcss-subgrid') ])
31+
```
32+
33+
See [PostCSS] docs for examples for your environment.
34+
35+
[spec]: https://www.w3.org/TR/css-grid-2/#subgrids
36+
[PostCSS]: https://github.com/postcss/postcss
37+
[codepen]: https://codepen.io/seaneking/pen/MVePPv
38+
[ci-img]: https://travis-ci.org/seaneking/postcss-subgrid.svg
39+
[ci]: https://travis-ci.org/seaneking/postcss-subgrid

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var postcss = require('postcss');
2+
3+
const PROPS = [
4+
{ prop: 'grid-column', value: '1 / -1' },
5+
{ prop: 'grid-template-columns', value: 'inherit' },
6+
{ prop: 'grid-gap', value: 'inherit' },
7+
{ prop: 'margin', value: '0' },
8+
{ prop: 'padding', value: '0' },
9+
];
10+
11+
module.exports = postcss.plugin('postcss-subgrid', () => {
12+
13+
return root => {
14+
root.walkRules(rule => {
15+
rule.walkDecls('display', decl => {
16+
if (decl.value === 'subgrid') {
17+
decl.value = 'grid';
18+
PROPS.reverse().forEach(prop => decl.after(prop));
19+
}
20+
});
21+
});
22+
};
23+
});

index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const postcss = require('postcss');
2+
const plugin = require('./');
3+
4+
function run(input, output, opts) {
5+
return postcss([ plugin(opts) ]).process(input)
6+
.then(result => {
7+
expect(result.css).toEqual(output);
8+
expect(result.warnings().length).toBe(0);
9+
});
10+
}
11+
12+
it('shims display: subgrid', () => {
13+
return run('a{ display: subgrid; }', 'a{ display: grid; grid-column: 1 / -1; grid-template-columns: inherit; grid-gap: inherit; margin: 0; padding: 0; }', {});
14+
});

0 commit comments

Comments
 (0)