postcss-css-variables icon indicating copy to clipboard operation
postcss-css-variables copied to clipboard

Add option for @apply syntax

Open michaelcpuckett opened this issue 10 years ago • 10 comments

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.

michaelcpuckett avatar Jun 13 '15 22:06 michaelcpuckett

@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 avatar Jun 14 '15 01:06 MadLittleMods

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.

MadLittleMods avatar Jun 19 '15 21:06 MadLittleMods

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

robdodson avatar Jun 20 '15 03:06 robdodson

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

robdodson avatar Jun 20 '15 05:06 robdodson

:+1: this would be great!

loktar00 avatar Aug 19 '15 23:08 loktar00

:+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?

cabarclay avatar Aug 19 '15 23:08 cabarclay

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

MoOx avatar Sep 16 '15 04:09 MoOx

This issue can be closed.

stephenway avatar May 13 '16 16:05 stephenway

@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.

MadLittleMods avatar May 13 '16 16:05 MadLittleMods

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

stephenway avatar May 13 '16 17:05 stephenway