Skip to content

Commit 7382f7f

Browse files
committed
Added auto-grid function with ability to specify the minimum width of the column
1 parent 762f76c commit 7382f7f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ 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
14+
- `colwidth` for applying min width for the auto-grid
1415
- `gaps`, for specifying the gap sizes you'd like to generate
1516
- `variants`, for specifying which variants to generate
1617

@@ -22,6 +23,7 @@ module.exports = {
2223
// ...
2324
require('./plugins/css-grid')({
2425
grids: [2, 3, 5, 6, 8, 10, 12],
26+
colwidth: [5, 10, 15, 20], // in REM
2527
gaps: {
2628
0: '0',
2729
4: '1rem',
@@ -39,6 +41,7 @@ The plugin generates the following sets of classes:
3941

4042
- `.grid`, for setting `display: grid` on an element
4143
- `.grid-columns-{size}`, for specifying the number of columns in the grid
44+
- `.auto-grid-{size}`, for specifying the minimum width of the columns generated with auto-grid
4245
- `.grid-gap-{size}`, for specifying the size of the gap between columns/rows
4346
- `.col-span-{columns}`, for specifying how wide a cell should be
4447
- `.col-start-{line}` and `.col-end-{line}`, for specifying a cell's start and end points explicitly (useful for reordering cells or leaving gaps)

index.js

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

3-
module.exports = function ({ grids = _.range(1, 12), gaps = {}, variants = ['responsive']}) {
3+
module.exports = function ({ grids = _.range(1, 12), gaps = {}, colwidth = {}, variants = ['responsive']}) {
44
return function ({ e, addUtilities }) {
55
addUtilities([
66
{ '.grid': { display: 'grid' } },
@@ -13,6 +13,11 @@ module.exports = function ({ grids = _.range(1, 12), gaps = {}, variants = ['res
1313
gridTemplateColumns: `repeat(${columns}, 1fr)`,
1414
}
1515
})),
16+
...colwidth.map(gridwidth => ({
17+
[`.auto-grid-${gridwidth}`]: {
18+
gridTemplateColumns: `repeat(auto-fit, minmax(${gridwidth}rem, 1fr))`,
19+
}
20+
})),
1621
..._.range(1, _.max(grids) + 1).map(span => ({
1722
[`.col-span-${span}`]: {
1823
gridColumnStart: `span ${span}`,

0 commit comments

Comments
 (0)