Skip to content

Commit defb438

Browse files
committed
added option to use grid row/column gaps, if name ends with either -y or -x gridRowGap or gridColumnGap is used instead of gridGap
1 parent a81ba56 commit defb438

File tree

1 file changed

+61
-50
lines changed

1 file changed

+61
-50
lines changed

index.js

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,65 @@
11
const _ = require('lodash')
22

3-
module.exports = function ({
4-
grids = _.range(1, 12),
5-
gaps = {},
6-
autoMinWidths = {},
7-
variants = ['responsive']
3+
module.exports = function({
4+
grids = _.range(1, 12),
5+
gaps = {},
6+
autoMinWidths = {},
7+
variants = ['responsive']
88
}) {
9-
return function ({ e, addUtilities }) {
10-
addUtilities([
11-
{ '.grid': { display: 'grid' } },
12-
{ '.grid-dense': { gridAutoFlow: 'dense' } },
13-
..._.map(gaps, (size, name) => ({
14-
[`.${e(`grid-gap-${name}`)}`]: { gridGap: size },
15-
})),
16-
...grids.map(columns => ({
17-
[`.grid-columns-${columns}`]: {
18-
gridTemplateColumns: `repeat(${columns}, 1fr)`,
19-
}
20-
})),
21-
..._.map(autoMinWidths, (size, name) => ({
22-
[`.${e(`grid-automin-${name}`)}`]: {
23-
gridTemplateColumns: `repeat(auto-fit, minmax(${size}, 1fr))`
24-
},
25-
})),
26-
..._.range(1, _.max(grids) + 1).map(span => ({
27-
[`.col-span-${span}`]: {
28-
gridColumnStart: `span ${span}`,
29-
}
30-
})),
31-
..._.range(1, _.max(grids) + 2).map(line => ({
32-
[`.col-start-${line}`]: {
33-
gridColumnStart: `${line}`,
34-
},
35-
[`.col-end-${line}`]: {
36-
gridColumnEnd: `${line}`,
37-
},
38-
})),
39-
..._.range(1, _.max(grids) + 1).map(span => ({
40-
[`.row-span-${span}`]: {
41-
gridRowStart: `span ${span}`,
42-
}
43-
})),
44-
..._.range(1, _.max(grids) + 2).map(line => ({
45-
[`.row-start-${line}`]: {
46-
gridRowStart: `${line}`,
47-
},
48-
[`.row-end-${line}`]: {
49-
gridRowEnd: `${line}`,
50-
},
51-
})),
52-
], variants)
53-
}
9+
return function({ e, addUtilities }) {
10+
addUtilities(
11+
[
12+
{ '.grid': { display: 'grid' } },
13+
{ '.grid-dense': { gridAutoFlow: 'dense' } },
14+
..._.map(gaps, (size, name) => {
15+
const gridGap = name.endsWith('-y')
16+
? 'gridRowGap'
17+
: name.endsWith('-x')
18+
? 'gridColumnGap'
19+
: 'gridGap'
20+
21+
return {
22+
[`.${e(`grid-gap-${name}`)}`]: { [gridGap]: size }
23+
}
24+
}),
25+
...grids.map(columns => ({
26+
[`.grid-columns-${columns}`]: {
27+
gridTemplateColumns: `repeat(${columns}, 1fr)`
28+
}
29+
})),
30+
..._.map(autoMinWidths, (size, name) => ({
31+
[`.${e(`grid-automin-${name}`)}`]: {
32+
gridTemplateColumns: `repeat(auto-fit, minmax(${size}, 1fr))`
33+
}
34+
})),
35+
..._.range(1, _.max(grids) + 1).map(span => ({
36+
[`.col-span-${span}`]: {
37+
gridColumnStart: `span ${span}`
38+
}
39+
})),
40+
..._.range(1, _.max(grids) + 2).map(line => ({
41+
[`.col-start-${line}`]: {
42+
gridColumnStart: `${line}`
43+
},
44+
[`.col-end-${line}`]: {
45+
gridColumnEnd: `${line}`
46+
}
47+
})),
48+
..._.range(1, _.max(grids) + 1).map(span => ({
49+
[`.row-span-${span}`]: {
50+
gridRowStart: `span ${span}`
51+
}
52+
})),
53+
..._.range(1, _.max(grids) + 2).map(line => ({
54+
[`.row-start-${line}`]: {
55+
gridRowStart: `${line}`
56+
},
57+
[`.row-end-${line}`]: {
58+
gridRowEnd: `${line}`
59+
}
60+
}))
61+
],
62+
variants
63+
)
64+
}
5465
}

0 commit comments

Comments
 (0)