MadLittleMods / postcss-css-variables

PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation
https://madlittlemods.github.io/postcss-css-variables/playground/
Other
536 stars 62 forks source link

Add option for @apply syntax #10

Open michaelcpuckett opened 9 years ago

michaelcpuckett commented 9 years ago

According to this video, the Polymer team at Google has been working with the CSS standards body to add the ability to @apply a group of properties, as you would @include a Sass @mixin.

Here's the syntax:

--ui-message-header-theme: {
    color: #297187;
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 7px;
};
.header {
    @apply(--ui-message-header-theme)
}

If I were interested in using this functionality, do you think it would make sense to add it here, or to a different plugin, or should it be a separate plugin?

Cheers.

MadLittleMods commented 9 years ago

@michaelcpuckett Thank you for the heads up on the @apply mixins :) - A very useful feature!

Seems straight-forward but do you have a link to the working draft/spec?

@ben-eb convinced me that this would be better as a separate plugin. The variable resolution code(checking if under the same scope) would be shared between this module and that one. I want to rewrite and tackle the variable resolution with postcss-selector-parser.

For usage with custom properties(css variables): Inherit from where it is @apply'ed seems correct. In which case the mixin plugin would run first, then postcss-css-variables

:root {
    --ui-message-header-theme: {
        color: var(--foo);
    };
}

.header {
    --foo: #ff0000;
    @apply(--ui-message-header-theme)
}
MadLittleMods commented 9 years ago

I sent a tweet to @robdodson asking for any documentation on CSS mixin syntax, etc.

I did manage to find some Polymer documentation on Custom CSS mixins.

robdodson commented 9 years ago

I've sent a message to the Polymer team to see if it's spec'd somewhere

robdodson commented 9 years ago

It sounds like it's been discussed but there hasn't been any sort of formal proposal yet.

loktar00 commented 8 years ago

:+1: this would be great!

cabarclay commented 8 years ago

:+1:! Would definitely decrease code written, while maintaining readability. I'm all for it. Although I'm not understanding why it would be a separate plugin, you're just giving a variable a stylesheet, no?

MoOx commented 8 years ago

https://github.com/pascalduez/postcss-apply

stephenway commented 8 years ago

This issue can be closed.

MadLittleMods commented 8 years ago

@stephenway I'd like to tackle the @apply syntax in another plugin with the same logic in inheritance that we have here with postcss-css-variables but just haven't got around to tackle it. This issue serves as a reminder for me to refactor and split out in order to make postcss-css-variables cleaner and allow for the shared logic with the @apply syntax plugin.

stephenway commented 8 years ago

Oh, in that case, nevermind, that sounds like a great idea!