tailwindcss/src/plugins/divideColor.js

35 lines
1,004 B
JavaScript
Raw Normal View History

2020-04-16 11:01:24 -04:00
import _ from 'lodash'
import flattenColorPalette from '../util/flattenColorPalette'
import nameClass from '../util/nameClass'
import toColorValue from '../util/toColorValue'
import withAlphaVariable from '../util/withAlphaVariable'
2020-04-16 11:01:24 -04:00
2020-10-16 13:30:06 -04:00
export default function () {
return function ({ addUtilities, theme, variants, corePlugins }) {
2020-04-16 11:01:24 -04:00
const colors = flattenColorPalette(theme('divideColor'))
const getProperties = (value) => {
2020-05-07 00:27:00 +10:00
if (corePlugins('divideOpacity')) {
return withAlphaVariable({
color: value,
property: 'border-color',
variable: '--tw-divide-opacity',
2020-05-07 00:27:00 +10:00
})
}
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 [
`${nameClass('divide', modifier)} > :not([hidden]) ~ :not([hidden])`,
2020-05-07 00:27:00 +10:00
getProperties(value),
2020-04-16 11:01:24 -04:00
]
})
)
addUtilities(utilities, variants('divideColor'))
}
}