forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateUtilityPlugin.js
More file actions
31 lines (30 loc) · 1003 Bytes
/
createUtilityPlugin.js
File metadata and controls
31 lines (30 loc) · 1003 Bytes
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
import fromPairs from 'lodash/fromPairs'
import toPairs from 'lodash/toPairs'
import castArray from 'lodash/castArray'
import nameClass from './nameClass'
import transformThemeValue from './transformThemeValue'
export default function createUtilityPlugin(
themeKey,
utilityVariations,
{ filterDefault = false } = {}
) {
const transformValue = transformThemeValue(themeKey)
return function ({ addUtilities, variants, theme }) {
const pairs = toPairs(theme(themeKey))
const utilities = utilityVariations.map(([classPrefix, properties]) => {
return fromPairs(
pairs
.filter(([key]) => {
return filterDefault ? key !== 'DEFAULT' : true
})
.map(([key, value]) => {
return [
nameClass(classPrefix, key),
fromPairs(castArray(properties).map((property) => [property, transformValue(value)])),
]
})
)
})
return addUtilities(utilities, variants(themeKey))
}
}