postcss-color-function icon indicating copy to clipboard operation
postcss-color-function copied to clipboard

Support Custom Properties

Open jonathantneal opened this issue 6 years ago • 6 comments

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

jonathantneal avatar Feb 20 '18 15:02 jonathantneal

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

rvergara92 avatar May 15 '18 06:05 rvergara92

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

marcofugaro avatar May 29 '18 17:05 marcofugaro

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!

marcofugaro avatar May 29 '18 19:05 marcofugaro

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
    },
  },
};

ar53n avatar Mar 29 '19 23:03 ar53n

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

blowsie avatar Dec 19 '19 16:12 blowsie