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
34 lines (30 loc) · 971 Bytes
/
createUtilityPlugin.js
File metadata and controls
34 lines (30 loc) · 971 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
32
33
34
import identity from 'lodash/identity'
import fromPairs from 'lodash/fromPairs'
import toPairs from 'lodash/toPairs'
import castArray from 'lodash/castArray'
function className(classPrefix, key) {
if (key === 'default') {
return classPrefix
}
if (key.startsWith('-')) {
return `-${classPrefix}${key}`
}
return `${classPrefix}-${key}`
}
export default function createUtilityPlugin(themeKey, utilityVariations) {
return function({ e, addUtilities, variants, theme }) {
const utilities = utilityVariations.map(
([classPrefix, properties, transformValue = identity]) => {
return fromPairs(
toPairs(theme(themeKey)).map(([key, value]) => {
return [
`.${e(className(classPrefix, key))}`,
fromPairs(castArray(properties).map(property => [property, transformValue(value)])),
]
})
)
}
)
return addUtilities(utilities, variants(themeKey))
}
}