mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
35 lines
971 B
JavaScript
35 lines
971 B
JavaScript
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))
|
|
}
|
|
}
|