diff --git a/src/plugins/backgroundColor.js b/src/plugins/backgroundColor.js index b9f443c0c..2b129e949 100644 --- a/src/plugins/backgroundColor.js +++ b/src/plugins/backgroundColor.js @@ -4,30 +4,27 @@ import withAlphaVariable from '../util/withAlphaVariable' export default function() { return function({ addUtilities, e, theme, variants, target, corePlugins }) { - if (target('backgroundColor') === 'ie11') { - const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('backgroundColor')), (value, modifier) => { - return [`.${e(`bg-${modifier}`)}`, { 'background-color': value }] + const colors = flattenColorPalette(theme('backgroundColor')) + + const getProperties = value => { + if (target('backgroundColor') === 'ie11') { + return { 'background-color': value } + } + + if (corePlugins('backgroundOpacity')) { + return withAlphaVariable({ + color: value, + property: 'background-color', + variable: '--bg-opacity', }) - ) + } - addUtilities(utilities, variants('backgroundColor')) - - return + return { 'background-color': value } } const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('backgroundColor')), (value, modifier) => { - return [ - `.${e(`bg-${modifier}`)}`, - corePlugins('backgroundOpacity') - ? withAlphaVariable({ - color: value, - property: 'background-color', - variable: '--bg-opacity', - }) - : { 'background-color': value }, - ] + _.map(colors, (value, modifier) => { + return [`.${e(`bg-${modifier}`)}`, getProperties(value)] }) ) diff --git a/src/plugins/borderColor.js b/src/plugins/borderColor.js index 175b83b25..ac855c382 100644 --- a/src/plugins/borderColor.js +++ b/src/plugins/borderColor.js @@ -4,34 +4,27 @@ import withAlphaVariable from '../util/withAlphaVariable' export default function() { return function({ addUtilities, e, theme, variants, target, corePlugins }) { - if (target('borderColor') === 'ie11') { - const colors = flattenColorPalette(theme('borderColor')) - - const utilities = _.fromPairs( - _.map(_.omit(colors, 'default'), (value, modifier) => { - return [`.${e(`border-${modifier}`)}`, { 'border-color': value }] - }) - ) - - addUtilities(utilities, variants('borderColor')) - - return - } - const colors = flattenColorPalette(theme('borderColor')) + const getProperties = value => { + if (target('borderColor') === 'ie11') { + return { 'border-color': value } + } + + if (corePlugins('borderOpacity')) { + return withAlphaVariable({ + color: value, + property: 'border-color', + variable: '--border-opacity', + }) + } + + return { 'border-color': value } + } + const utilities = _.fromPairs( _.map(_.omit(colors, 'default'), (value, modifier) => { - return [ - `.${e(`border-${modifier}`)}`, - corePlugins('borderOpacity') - ? withAlphaVariable({ - color: value, - property: 'border-color', - variable: '--border-opacity', - }) - : { 'border-color': value }, - ] + return [`.${e(`border-${modifier}`)}`, getProperties(value)] }) ) diff --git a/src/plugins/divideColor.js b/src/plugins/divideColor.js index 915aba9cd..5b8922ab1 100644 --- a/src/plugins/divideColor.js +++ b/src/plugins/divideColor.js @@ -6,32 +6,27 @@ export default function() { return function({ addUtilities, e, theme, variants, target, corePlugins }) { const colors = flattenColorPalette(theme('divideColor')) - if (target('divideColor') === 'ie11') { - const utilities = _.fromPairs( - _.map(_.omit(colors, 'default'), (value, modifier) => { - return [ - `.${e(`divide-${modifier}`)} > :not(template) ~ :not(template)`, - { 'border-color': value }, - ] + const getProperties = value => { + if (target('divideColor') === 'ie11') { + return { 'border-color': value } + } + + if (corePlugins('divideOpacity')) { + return withAlphaVariable({ + color: value, + property: 'border-color', + variable: '--divide-opacity', }) - ) + } - addUtilities(utilities, variants('divideColor')) - - return + return { 'border-color': value } } const utilities = _.fromPairs( _.map(_.omit(colors, 'default'), (value, modifier) => { return [ `.${e(`divide-${modifier}`)} > :not(template) ~ :not(template)`, - corePlugins('divideOpacity') - ? withAlphaVariable({ - color: value, - property: 'border-color', - variable: '--divide-opacity', - }) - : { 'border-color': value }, + getProperties(value), ] }) ) diff --git a/src/plugins/fill.js b/src/plugins/fill.js index 93b6804e3..ce0d208bb 100644 --- a/src/plugins/fill.js +++ b/src/plugins/fill.js @@ -3,14 +3,11 @@ import flattenColorPalette from '../util/flattenColorPalette' export default function() { return function({ addUtilities, e, theme, variants }) { + const colors = flattenColorPalette(theme('fill')) + const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('fill')), (value, modifier) => { - return [ - `.${e(`fill-${modifier}`)}`, - { - fill: value, - }, - ] + _.map(colors, (value, modifier) => { + return [`.${e(`fill-${modifier}`)}`, { fill: value }] }) ) diff --git a/src/plugins/placeholderColor.js b/src/plugins/placeholderColor.js index a7e0e9194..fea66ba4b 100644 --- a/src/plugins/placeholderColor.js +++ b/src/plugins/placeholderColor.js @@ -4,30 +4,27 @@ import withAlphaVariable from '../util/withAlphaVariable' export default function() { return function({ addUtilities, e, theme, variants, target, corePlugins }) { - if (target('placeholderColor') === 'ie11') { - const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('placeholderColor')), (value, modifier) => { - return [`.${e(`placeholder-${modifier}`)}::placeholder`, { color: value }] + const colors = flattenColorPalette(theme('placeholderColor')) + + const getProperties = value => { + if (target('placeholderColor') === 'ie11') { + return { color: value } + } + + if (corePlugins('placeholderOpacity')) { + return withAlphaVariable({ + color: value, + property: 'color', + variable: '--placeholder-opacity', }) - ) + } - addUtilities(utilities, variants('placeholderColor')) - - return + return { color: value } } const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('placeholderColor')), (value, modifier) => { - return [ - `.${e(`placeholder-${modifier}`)}::placeholder`, - corePlugins('placeholderOpacity') - ? withAlphaVariable({ - color: value, - property: 'color', - variable: '--placeholder-opacity', - }) - : { color: value }, - ] + _.map(colors, (value, modifier) => { + return [`.${e(`placeholder-${modifier}`)}::placeholder`, getProperties(value)] }) ) diff --git a/src/plugins/stroke.js b/src/plugins/stroke.js index 0dd862a29..1944a84e9 100644 --- a/src/plugins/stroke.js +++ b/src/plugins/stroke.js @@ -3,14 +3,11 @@ import flattenColorPalette from '../util/flattenColorPalette' export default function() { return function({ addUtilities, e, theme, variants }) { + const colors = flattenColorPalette(theme('stroke')) + const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('stroke')), (value, modifier) => { - return [ - `.${e(`stroke-${modifier}`)}`, - { - stroke: value, - }, - ] + _.map(colors, (value, modifier) => { + return [`.${e(`stroke-${modifier}`)}`, { stroke: value }] }) ) diff --git a/src/plugins/textColor.js b/src/plugins/textColor.js index 89f8e0aa0..f52c27dcd 100644 --- a/src/plugins/textColor.js +++ b/src/plugins/textColor.js @@ -4,26 +4,27 @@ import withAlphaVariable from '../util/withAlphaVariable' export default function() { return function({ addUtilities, e, theme, variants, target, corePlugins }) { - if (target('textColor') === 'ie11') { - const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('textColor')), (value, modifier) => { - return [`.${e(`text-${modifier}`)}`, { color: value }] + const colors = flattenColorPalette(theme('textColor')) + + const getProperties = value => { + if (target('textColor') === 'ie11') { + return { color: value } + } + + if (corePlugins('textOpacity')) { + return withAlphaVariable({ + color: value, + property: 'color', + variable: '--text-opacity', }) - ) + } - addUtilities(utilities, variants('textColor')) - - return + return { color: value } } const utilities = _.fromPairs( - _.map(flattenColorPalette(theme('textColor')), (value, modifier) => { - return [ - `.${e(`text-${modifier}`)}`, - corePlugins('textOpacity') - ? withAlphaVariable({ color: value, property: 'color', variable: '--text-opacity' }) - : { color: value }, - ] + _.map(colors, (value, modifier) => { + return [`.${e(`text-${modifier}`)}`, getProperties(value)] }) )