tailwindcss/src/util/createUtilityPlugin.js

28 lines
661 B
JavaScript
Raw Normal View History

2019-12-22 15:25:34 -05:00
import fromPairs from 'lodash/fromPairs'
import toPairs from 'lodash/toPairs'
function className(classPrefix, key) {
if (key === 'default') {
return classPrefix
}
if (key.startsWith('-')) {
return `-${classPrefix}${key}`
}
return `${classPrefix}-${key}`
}
2019-12-23 14:26:14 -05:00
export default function createUtilityPlugin(classPrefix, themeKey, property = themeKey) {
2019-12-22 15:25:34 -05:00
return function({ e, addUtilities, variants, theme }) {
return addUtilities(
fromPairs(
toPairs(theme(themeKey)).map(([key, value]) => {
return [`.${e(className(classPrefix, key))}`, { [property]: value }]
})
),
variants(themeKey)
)
}
}