Multiple/modular/decoupled layer styles

I was browsing around and this has been brought up in many places in many different angles. I figured I might as well add my own take. This only goes to show how important it is.

Currently layer style includes all five parameters: 1) fill 2) border 3) shadow 4) inner-shadow 5) blur.

That creates a problem: you have to create a ton of layer styles to accommodate all different combinations. Text styles are even bigger monoliths.

Instead, why not create an additional decoupled and modular option store them all separately?

Example: I could have 2 styles for shadows, 9 styles for colour and 1 style for blur. I would love if I could 1) apply only the blur style to a layer 2) add both shadow and colour styles to one layer (multiple styles on a single layer) 3) freely adjust other untouched parameters and not break the layer style with that * asterisk.

In a sense, it actually wouldn’t be a layer style anymore (the monolithic layer style could still stay for some use-cases and backwards compatibility), but it would introduce fill style, border style, shadow style, etc. If we go really deep, then layer style could consist of these sub-styles. Would be awesome to see them alongside with Symbols and Colour Variables under the Components tab too.

In recent years TailwindCSS has gained a ton of popularity. It takes a very modular, utility-first approach to applying styles in CSS. Whether you like Tailwind or not, is not the point. But it has popularised a very modular approach to styling elements. For example, I have rectangle that I want to be round and green: I simply apply the specific roundness and colour tokens to it. There is no need to create a separate monolithic style class for specifically this case only. This allows you to stay nimble.

It has brought me to a point where I’m not using layer styles at all. Nor am I using text styles. Making and maintaining them (been there, done that) is taking the fun and focus away from what’s important: sketching and designing. I can allow myself to do that, because I’m using Sketch for my personal project, and as a developer, I’m keeping all of the shadow, colour, etc. tokens in the code. However, in an ideal world, I’d love if it would be correct and re-usable within Sketch too. And my gut tells me it could benefit others too.

Hey @itsmetarvi, thanks for taking the time to share this! It’s super insighful and we appreciate it a lot!

Of course, I agree with you and we hear you. This topic has been discussed and we’re aware we can make improvements here.

You brought up a really interesting comparison, Tailwind. I’ve never used it, but I’ve used other CSS frameworks and in all of them, me and my colleagues back then found the same problem: it’s all about balance.

Sure, having a huge class that adds a ton of styles will likely force you to repetition and redundant classes, so you start creating smaller ones, and then you add even smaller ones, many times getting to single rule classes (some call them helper classes). Sometimes that led to some folks merging some small classes into bigger ones… and you get the picture.

My point here is to ask you how are you currently handling this balance? Even if you’re keeping it in code, that task happens there, what helps you keep it manageable?

Back then, we resorted to identifying common patterns for the specific project we were working with and merged some styles into bigger classes and that did help a lot.

Thanks again for sharing this. Cheers :raised_hands: