2019-12-22 15:25:34 -05:00
|
|
|
import fromPairs from 'lodash/fromPairs'
|
|
|
|
|
import toPairs from 'lodash/toPairs'
|
2019-12-24 06:52:55 -05:00
|
|
|
import castArray from 'lodash/castArray'
|
2020-10-16 10:24:16 -04:00
|
|
|
import nameClass from './nameClass'
|
2020-10-19 11:32:22 -04:00
|
|
|
import transformThemeValue from './transformThemeValue'
|
2019-12-22 15:25:34 -05:00
|
|
|
|
2019-12-24 06:52:55 -05:00
|
|
|
export default function createUtilityPlugin(themeKey, utilityVariations) {
|
2020-10-19 11:32:22 -04:00
|
|
|
const transformValue = transformThemeValue(themeKey)
|
2020-10-16 13:30:06 -04:00
|
|
|
return function ({ addUtilities, variants, theme }) {
|
2020-10-19 11:32:22 -04:00
|
|
|
const pairs = toPairs(theme(themeKey))
|
|
|
|
|
const utilities = utilityVariations.map(([classPrefix, properties]) => {
|
|
|
|
|
return fromPairs(
|
|
|
|
|
pairs.map(([key, value]) => {
|
|
|
|
|
return [
|
|
|
|
|
nameClass(classPrefix, key),
|
|
|
|
|
fromPairs(castArray(properties).map((property) => [property, transformValue(value)])),
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
})
|
2019-12-24 06:52:55 -05:00
|
|
|
return addUtilities(utilities, variants(themeKey))
|
2019-12-22 15:25:34 -05:00
|
|
|
}
|
|
|
|
|
}
|