postcss / postcss-color-function

PostCSS plugin to transform W3C CSS color function to more compatible CSS
MIT License
323 stars 31 forks source link

Support Custom Properties #49

Open jonathantneal opened 6 years ago

jonathantneal commented 6 years ago

If a developer wants to use Custom Properties with this plugin, could this plugin lookup the variables for them? Even if it’s just on :root?

Currently, this plugin relies on PostCSS Custom Properties to remove var() usage, but 1. that’s not very future-leaning, and 2. the new major release of PostCSS Custom Properties preserves var() usage by default.

:root {
  --brand: #00bdbd;
  --dark-brand: color(var(--brand) shade(20%));
}

becomes

:root {
  --brand: #00bdbd;
  --dark-brand: color(var(--brand) shade(20%));
}

Unfortunately, it seems this plugin was never tested against Custom Properties with the preserve option enabled.

https://github.com/postcss/postcss-custom-properties/issues/99 https://github.com/postcss/postcss-custom-properties/issues/98

rvergara92 commented 6 years ago

I have the same issue, do you find a way to do that?

marcofugaro commented 6 years ago

Yes, I don't use postcss-custom-properties anymore because of browser support and would love to use this plugin.

marcofugaro commented 6 years ago

The solution was using color-mod() instead, which is more spec-compliant and supports :root css custom properties out of the box!

Thank you @jonathantneal it worked flawlessy!

ar53n commented 5 years ago

add PR or we can use postcss-color-function-remover You can use chain postcss plugins, like a

module.exports = {
  plugins: {
    'postcss-css-variables': { // or 'postcss-custom-properties'
      preserve: true,
    },
    'postcss-color-function': {
      preserveCustomProps: false // delete color function with custom properties
    },
  },
};
blowsie commented 4 years ago

I think it would be great for this plugin to support custom properties, its flawed without.

HolisticPeanut commented 2 years ago

Possible workaround: https://github.com/csstools/postcss-color-mod-function/issues/41#issuecomment-1007309849