Skip to content

Commit 5724f4c

Browse files
committed
Initial Commit
0 parents  commit 5724f4c

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

.gitignore

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

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# CSS Grid Tailwind Plugin
2+
3+
Isolated from [https://github.com/tailwindcss/plugin-examples](https://github.com/tailwindcss/plugin-examples)
4+
5+
[View demo](https://tailwindcss.github.io/plugin-examples/#css-grid) · [View source](https://github.com/tailwindcss/plugin-examples/blob/master/plugins/css-grid/index.js)
6+
7+
In `plugins/css-grid/index.js` you'll find an example of a plugin that adds new utilities for using [CSS Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout).
8+
9+
![](https://user-images.githubusercontent.com/4323180/37525015-fb5c78f2-2901-11e8-97be-18c66d12bf84.png)
10+
11+
It exposes three configuration options:
12+
13+
- `grids`, for specifying all of the grid sizes you'd like to generate
14+
- `gaps`, for specifying the gap sizes you'd like to generate
15+
- `variants`, for specifying which variants to generate
16+
17+
```js
18+
module.exports = {
19+
// ...
20+
21+
plugins: [
22+
// ...
23+
require('./plugins/css-grid')({
24+
grids: [2, 3, 5, 6, 8, 10, 12],
25+
gaps: {
26+
0: '0',
27+
4: '1rem',
28+
8: '2rem',
29+
},
30+
variants: ['responsive'],
31+
}),
32+
],
33+
}
34+
```
35+
36+
With zero configuration, it will generate grids from 1 to 12 columns in size, no gap sizes, and `responsive` variants for each new utility.
37+
38+
The plugin generates the following sets of classes:
39+
40+
- `.grid`, for setting `display: grid` on an element
41+
- `.grid-columns-{size}`, for specifying the number of columns in the grid
42+
- `.grid-gap-{size}`, for specifying the size of the gap between columns/rows
43+
- `.col-span-{columns}`, for specifying how wide a column should be
44+
- `.col-start-{line}` and `.col-end-{line}`, for specifying a column's start and end points explicitly (useful for reordering columns or leaving gaps)
45+
46+
It's not really practical to expose all of the power of CSS Grid through utilities, but this plugin is a good example of using CSS Grid to replace a column-only float or Flexbox grid.

index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const _ = require('lodash')
2+
3+
module.exports = function ({ grids = _.range(1, 12), gaps = {}, variants = ['responsive']}) {
4+
return function ({ e, addUtilities }) {
5+
addUtilities([
6+
{ '.grid': { display: 'grid' } },
7+
{ '.grid-dense': { gridAutoFlow: 'dense' } },
8+
..._.map(gaps, (size, name) => ({
9+
[`.grid-gap-${e(name)}`]: { gridGap: size },
10+
})),
11+
...grids.map(columns => ({
12+
[`.grid-columns-${columns}`]: {
13+
gridTemplateColumns: `repeat(${columns}, 1fr)`,
14+
}
15+
})),
16+
..._.range(1, _.max(grids) + 1).map(span => ({
17+
[`.col-span-${span}`]: {
18+
gridColumnStart: `span ${span}`,
19+
}
20+
})),
21+
..._.range(1, _.max(grids) + 2).map(line => ({
22+
[`.col-start-${line}`]: {
23+
gridColumnStart: `${line}`,
24+
},
25+
[`.col-end-${line}`]: {
26+
gridColumnEnd: `${line}`,
27+
},
28+
})),
29+
], variants)
30+
}
31+
}

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "tailwindcss-grid",
3+
"version": "1.0.0",
4+
"description": "CSS grid plugin for tailwindcss framework",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/chrisrowe/tailwindcss-grid.git"
12+
},
13+
"keywords": [
14+
"tailwind",
15+
"tailwindcss",
16+
"plugin",
17+
"tailwindcss-plugin"
18+
],
19+
"author": "chrisrowe",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/chrisrowe/tailwindcss-grid/issues"
23+
},
24+
"homepage": "https://github.com/chrisrowe/tailwindcss-grid#readme",
25+
"devDependencies": {
26+
"lodash": "^4.17.5"
27+
}
28+
}

0 commit comments

Comments
 (0)