pascalduez / postcss-apply

PostCSS plugin enabling custom properties sets references
The Unlicense
164 stars 12 forks source link

Is there some way to assign !important to a declaration block at apply-time? #6

Closed wc-matteo closed 7 years ago

wc-matteo commented 8 years ago

e.g. @apply --foo !important;

Would it go against "the spec"?

JayGeorge commented 8 years ago

I’d be very surprised if this worked because Applys can have multiple properties. You would have to set the important declarations within the foo apply itself.

e.g.

--foo: {
    position: absolute!important;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
};

@apply --foo;
wc-matteo commented 8 years ago

@JayGeorge Yes, I meant that calling @apply with important would set it for all properties.

The proplem with setting important within the declaration block is that if you need the same properties without it, you have to duplicate all of them.

I know that this is not a common use case.

JayGeorge commented 8 years ago

Hm, well effectively setting !important on all the all the properties would be a bit of a sledgehammer approach.

I would suggest increasing the specificity of the class that you’re calling the apply to e.g.

body .some-class {
  @apply --foo;
};

I’m not involved in the spec but I would be surprised if they made it possible to add !important to Applies.

wc-matteo commented 8 years ago

In this case, being a style inclued in a (possibly) hostile environment, I need the (relative) security afforded by imporant.