tailwindcss/src/plugins/divideColor.js

34 lines
953 B
JavaScript
Raw Normal View History

2020-04-16 11:01:24 -04:00
import _ from 'lodash'
import flattenColorPalette from '../util/flattenColorPalette'
import toColorValue from '../util/toColorValue'
import withAlphaVariable from '../util/withAlphaVariable'
2020-04-16 11:01:24 -04:00
export default function() {
2020-10-15 12:29:50 -04:00
return function({ addUtilities, e, theme, variants, corePlugins }) {
2020-04-16 11:01:24 -04:00
const colors = flattenColorPalette(theme('divideColor'))
2020-05-07 00:27:00 +10:00
const getProperties = value => {
if (corePlugins('divideOpacity')) {
return withAlphaVariable({
color: value,
property: 'border-color',
variable: '--divide-opacity',
})
}
return { 'border-color': toColorValue(value) }
}
2020-04-16 11:01:24 -04:00
const utilities = _.fromPairs(
_.map(_.omit(colors, 'DEFAULT'), (value, modifier) => {
2020-04-16 11:01:24 -04:00
return [
`.${e(`divide-${modifier}`)} > :not(template) ~ :not(template)`,
2020-05-07 00:27:00 +10:00
getProperties(value),
2020-04-16 11:01:24 -04:00
]
})
)
addUtilities(utilities, variants('divideColor'))
}
}