2020-04-16 11:01:24 -04:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
import flattenColorPalette from '../util/flattenColorPalette'
|
2020-10-09 21:03:23 -04:00
|
|
|
import toColorValue from '../util/toColorValue'
|
2020-04-26 09:48:54 -04:00
|
|
|
import withAlphaVariable from '../util/withAlphaVariable'
|
2021-04-30 16:58:40 +02:00
|
|
|
import nameClass from '../util/nameClass'
|
|
|
|
|
import { asColor } from '../util/pluginUtils'
|
2020-04-16 11:01:24 -04:00
|
|
|
|
2020-10-16 13:30:06 -04:00
|
|
|
export default function () {
|
2021-04-30 16:58:40 +02:00
|
|
|
return function ({ config, matchUtilities, addUtilities, theme, variants, corePlugins }) {
|
|
|
|
|
if (config('mode') === 'jit') {
|
|
|
|
|
let colorPalette = flattenColorPalette(theme('divideColor'))
|
2020-04-27 08:27:32 -04:00
|
|
|
|
2021-04-30 16:58:40 +02:00
|
|
|
matchUtilities({
|
|
|
|
|
divide: (modifier) => {
|
|
|
|
|
if (modifier === 'DEFAULT') {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let value = asColor(modifier, colorPalette)
|
|
|
|
|
|
|
|
|
|
if (value === undefined) {
|
|
|
|
|
return []
|
|
|
|
|
}
|
2020-04-27 08:27:32 -04:00
|
|
|
|
2021-04-30 16:58:40 +02:00
|
|
|
if (!corePlugins('divideOpacity')) {
|
|
|
|
|
return {
|
|
|
|
|
[`${nameClass('divide', modifier)} > :not([hidden]) ~ :not([hidden])`]: {
|
|
|
|
|
'border-color': value,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
[`${nameClass(
|
|
|
|
|
'divide',
|
|
|
|
|
modifier
|
|
|
|
|
)} > :not([hidden]) ~ :not([hidden])`]: withAlphaVariable({
|
|
|
|
|
color: colorPalette[modifier],
|
|
|
|
|
property: 'border-color',
|
|
|
|
|
variable: '--tw-divide-opacity',
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-04-16 11:01:24 -04:00
|
|
|
})
|
2021-04-30 16:58:40 +02:00
|
|
|
} else {
|
|
|
|
|
const colors = flattenColorPalette(theme('divideColor'))
|
|
|
|
|
|
|
|
|
|
const getProperties = (value) => {
|
|
|
|
|
if (corePlugins('divideOpacity')) {
|
|
|
|
|
return withAlphaVariable({
|
|
|
|
|
color: value,
|
|
|
|
|
property: 'border-color',
|
|
|
|
|
variable: '--tw-divide-opacity',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { 'border-color': toColorValue(value) }
|
|
|
|
|
}
|
2020-04-16 11:01:24 -04:00
|
|
|
|
2021-04-30 16:58:40 +02:00
|
|
|
const utilities = _.fromPairs(
|
|
|
|
|
_.map(_.omit(colors, 'DEFAULT'), (value, modifier) => {
|
|
|
|
|
return [
|
|
|
|
|
`${nameClass('divide', modifier)} > :not([hidden]) ~ :not([hidden])`,
|
|
|
|
|
getProperties(value),
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
addUtilities(utilities, variants('divideColor'))
|
|
|
|
|
}
|
2020-04-16 11:01:24 -04:00
|
|
|
}
|
|
|
|
|
}
|