verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 68 forks source link

Support CSS Layers #1933

Open MattWilcox opened 1 week ago

MattWilcox commented 1 week ago

What are you trying to do?

I just want to override the default CSS from my own CSS.

Because of the way Formie adds its own CSS files, I'm having to fight specificity because my own CSS is trying to apply on the :root but Formie's stuff comes later and smashes it.

If it wrapped its own code in a named CSS layer, I could slot Formie's CSS anywhere in my preferred layer ordering, negating cascade issues.

https://developer.mozilla.org/en-US/docs/Web/CSS/@layer

What's your proposed solution?

Wrap all the Formis CSS in

@layer formie {
    ...
}

So that in my own CSS I can more easily over-ride things without the crutch of loading order or chaining specificity.

Additional context

No response

engram-design commented 1 week ago

I've actually had zero experience with CSS Layers so far, so I'll have to do some reading and check browser compatibility!

MattWilcox commented 1 week ago

Been using it for a while, just in the one specific way - I believe it'd be just "wrap your existing CSS in a named layer", but yeah... not 100% confident on that.

For example, my initial CSS has

@layers reset, default, design, utilities;

Which sets the order that they apply in, and specificity between them doesn't matter. Whichever layer was last declared in that list wins regardless.

So ideally, if Formie came wrapped in one named formie I'd set my own CSS layer order as

@layers reset, formie, default, design, utilities

So your code is loaded with less priority than my own code, meaning I could easily over-write it from any of my later layers (default, design, utilities).

https://caniuse.com/css-cascade-layers

engram-design commented 1 week ago

I've just added this as a plugin setting for the next release, to allow it as an opt-in setting while we continue to test it a bit more.

To get this early, run composer require verbb/formie:"dev-craft-5 as 3.0.0-beta.15".

Then, add 'useCssLayers' => true, to your configuration file.