-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.js
48 lines (39 loc) · 1.02 KB
/
grid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ####################################
// ##### GRID (TAILWIND PLUGIN)
// ####################################
module.exports = function({ addUtilities, config }) {
const directions = [ 'r', 'c' ] // row, column
const sizes = [ 'px', '2px', 0, 1, 2, 3, 4, 5, 6 ].map(x => x.toString())
const margins = config('theme.margin')
const gapProps = {
r: 'grid-row-gap',
c: 'grid-column-gap'
}
const utilities = {
'.grid': {
'display': 'grid'
}
}
directions.forEach(dir => {
sizes.forEach(sz => {
const key = `.grid-${dir}g-${sz}`
utilities[key] = {
[gapProps[dir]]: margins[sz]
}
})
})
const counts = Array.from(Array(10).keys()).map(x => x + 1)
const templateProps = {
r: 'grid-template-rows',
c: 'grid-template-columns',
}
directions.forEach(dir => {
counts.forEach(count => {
const key = `.grid-${dir}-${count}`
utilities[key] = {
[templateProps[dir]]: `repeat(${count}, 1fr)`
}
})
})
addUtilities(utilities)
}