Skip to content

Commit c0436fb

Browse files
authored
Merge pull request #3 from saidsl/master
Added auto-grid function with ability to specify the minimum width of…
2 parents 33dd012 + e2c5b6c commit c0436fb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ In `plugins/css-grid/index.js` you'll find an example of a plugin that adds new
88

99
![](https://user-images.githubusercontent.com/4323180/37525015-fb5c78f2-2901-11e8-97be-18c66d12bf84.png)
1010

11-
It exposes three configuration options:
11+
It exposes four configuration options:
1212

1313
- `grids`, for specifying all of the grid sizes you'd like to generate
1414
- `gaps`, for specifying the gap sizes you'd like to generate
15+
- `autoMinWidths` for specifying min width to columns using auto-fit and minmax
1516
- `variants`, for specifying which variants to generate
1617

1718
```js
@@ -27,6 +28,11 @@ module.exports = {
2728
4: '1rem',
2829
8: '2rem',
2930
},
31+
autoMinWidths: {
32+
'16': '4rem',
33+
'24': '6rem',
34+
'300px': '300px'
35+
},
3036
variants: ['responsive'],
3137
}),
3238
],
@@ -39,10 +45,12 @@ The plugin generates the following sets of classes:
3945

4046
- `.grid`, for setting `display: grid` on an element
4147
- `.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
4348
- `.col-span-{columns}`, for specifying how wide a cell should be
49+
- `.grid-gap-{size}`, for specifying the size of the gap between columns/rows
50+
- `.grid-automin-{size}`, for applying the minimum width of the columns using auto-fit and minmax (the max is 1fr)
4451
- `.col-start-{line}` and `.col-end-{line}`, for specifying a cell's start and end points explicitly (useful for reordering cells or leaving gaps)
4552
- `.row-span-{columns}`, for specifying how tall a cell should be
4653
- `.row-start-{line}` and `.row-end-{line}`, for specifying a cell's start and end points explicitly (useful for reordering cells or leaving gaps)
54+
- `.grid-dense` applies `grid-auto-flow: dense`
4755

4856
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 cell-only float or Flexbox grid.

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const _ = require('lodash')
22

3-
module.exports = function ({ grids = _.range(1, 12), gaps = {}, variants = ['responsive']}) {
3+
module.exports = function ({
4+
grids = _.range(1, 12),
5+
gaps = {},
6+
autoMinWidths = {},
7+
variants = ['responsive']
8+
}) {
49
return function ({ e, addUtilities }) {
510
addUtilities([
611
{ '.grid': { display: 'grid' } },
@@ -13,6 +18,11 @@ module.exports = function ({ grids = _.range(1, 12), gaps = {}, variants = ['res
1318
gridTemplateColumns: `repeat(${columns}, 1fr)`,
1419
}
1520
})),
21+
..._.map(autoMinWidths, (size, name) => ({
22+
[`.${e(`grid-automin-${name}`)}`]: {
23+
gridTemplateColumns: `repeat(auto-fit, minmax(${size}, 1fr))`
24+
},
25+
})),
1626
..._.range(1, _.max(grids) + 1).map(span => ({
1727
[`.col-span-${span}`]: {
1828
gridColumnStart: `span ${span}`,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
"devDependencies": {
2626
"lodash": "^4.17.5"
2727
}
28-
}
28+
}

0 commit comments

Comments
 (0)