tailwindcss/src/plugins/backgroundColor.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-01-09 21:50:03 -05:00
import _ from 'lodash'
import flattenColorPalette from '../util/flattenColorPalette'
import withAlphaVariable from '../util/withAlphaVariable'
export default function() {
return function({ addUtilities, e, theme, variants, target, corePlugins }) {
2020-05-07 00:22:07 +10:00
const colors = flattenColorPalette(theme('backgroundColor'))
2020-04-28 15:31:57 -04:00
if (target('backgroundColor') === 'ie11') {
2020-04-26 15:10:12 -04:00
const utilities = _.fromPairs(
2020-05-07 00:22:07 +10:00
_.map(colors, (value, modifier) => {
2020-05-07 00:23:43 +10:00
return [
`.${e(`bg-${modifier}`)}`,
{ 'background-color': value },
]
2020-04-26 15:10:12 -04:00
})
)
addUtilities(utilities, variants('backgroundColor'))
return
}
2019-01-11 12:29:33 -05:00
const utilities = _.fromPairs(
2020-05-07 00:22:07 +10:00
_.map(colors, (value, modifier) => {
2019-01-11 12:29:33 -05:00
return [
`.${e(`bg-${modifier}`)}`,
corePlugins('backgroundOpacity')
? withAlphaVariable({
color: value,
property: 'background-color',
variable: '--bg-opacity',
})
: { 'background-color': value },
2019-01-11 12:29:33 -05:00
]
})
)
2019-01-09 21:50:03 -05:00
addUtilities(utilities, variants('backgroundColor'))
2019-01-09 21:50:03 -05:00
}
}