tailwindcss/src/plugins/backgroundColor.js

35 lines
993 B
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() {
2020-04-28 15:31:57 -04:00
return function({ addUtilities, e, theme, variants, target }) {
if (target('backgroundColor') === 'ie11') {
2020-04-26 15:10:12 -04:00
const utilities = _.fromPairs(
_.map(flattenColorPalette(theme('backgroundColor')), (value, modifier) => {
return [`.${e(`bg-${modifier}`)}`, { 'background-color': value }]
})
)
addUtilities(utilities, variants('backgroundColor'))
return
}
2019-01-11 12:29:33 -05:00
const utilities = _.fromPairs(
_.map(flattenColorPalette(theme('backgroundColor')), (value, modifier) => {
2019-01-11 12:29:33 -05:00
return [
`.${e(`bg-${modifier}`)}`,
withAlphaVariable({
color: value,
property: 'background-color',
variable: '--bg-opacity',
}),
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
}
}