This is, without a doubt, the coolest Sketch technique you’ll see all day.
Warning: More GIFs than the peanut butter aisle.
Yes, I pronounce it “Jiff”. Go away.
Huge shout out to Lloyd Humphreys for inspiring this method of deep nesting, particularly as it relates to text.
When Sketch launched resizing rules in Sketch 39, it was such a game changer that I wanted to bake a cake with the Sketch logo on it just so I could present it back to myself.
So it goes without saying that when symbol overrides came around in Sketch 41, they had me yodeling out of pure jubilation and ecstasy. It was a pretty big deal.
After much trial-and-error, I’ve created some of the most flexible, customizable, and maintainable components ever using nested symbols, overrides, and what I’m dubbing Cascading Symbol Styles…aka CSS.
To be frank, this technique isn’t particularly novel. It’s just a set of nested symbols, painstakingly organized to appear more organized in Sketch’s Inspector panel. But I thought you all might find it interesting anyway, so buckle up and grab some popcorn 🍿
Let’s dive in to this symbol:
It’s a list item that I’m using in a chat panel. I want to have their photo and name, plus a badge for new messages, and an indicator for whether or not they’re typing (these are stacked so I can turn them on/off depending on which one I need).
This is a renamed reference of the “Avatar Image” symbol. Why is it renamed? Because this is what shows up in the Inspector panel when I use this symbol elsewhere. I’d much rather that name be nice and clean instead of something like “Avatar/Image” which just ends up getting truncated anyway. No bueno.
Secondly, to cover the use case where a user hasn’t set a profile photo, I created a default avatar that I want to show instead.
Now pay attention, because this next point is important: Because the sizes of the Avatar/Image and Avatar/Default symbols are the exact same (see above), I will be able to choose which symbol I want to show in the Inspector dropdown:
Notice that I’m not bothered by hundreds of my other symbols. That’s because those other symbols don’t match the dimensions of the base symbol nested inside of the list item symbol. Make sense?
The name layer is somewhat counterintuitive, but incredibly powerful. I created symbols of all of my text styles in Sketch so that I could swap colors inside of symbols. It took a while:
But now that I have these, it makes it easy to change the color of the text in my symbol without having to create an entirely new symbol instance:
Since the text symbol is…well…text…that’s why it gives me the option to edit the content. I’ve just gotten fancy and named the actual text layer in that symbol to “↳🖊Content” so that I know it’s changing that content.
Again, this is all a single symbol, so if I edit the base symbol, all of these instances will still update:
The badge is yet another symbol, but this one also has some interesting properties. Let’s have a look:
Inside of the badge symbol, I have my text symbol (so I can swap that out later), and a “Container” symbol. Here’s what that looks like:
The “Container” layer in the badge symbol is just a renamed reference to the Rounded container symbol above. Each of these containers has a state symbol (so I can override the state of the badge)…
…a color symbol (so I can override the color)…
…and a mask that determines its shape.
Side note to Sketch: It would be rad if we could use symbols as masks.
Notice that my state symbols and color symbols are different widths. This is to “protect” their dropdowns in the Inspector panel when I’m customizing my list item symbol later. If I’m picking a color for the background, I don’t want to see other symbols in that list. I just want colors.
Keep all symbols a consistent size that you want to appear in a dropdown together, and make sure that anything else is at least 1px bigger or smaller. That way they won’t ever show up together 🤓
This is just a small symbol that shows when someone is typing.
ProTip™: Set all icons as masks and use a color symbol on top of it. That way you can just override the color symbol if you want to change the color. One icon symbol…any color you want 😍
This technique was first introduced by Free&Willing:
Last layer! This one is just a renamed instance of a “Mixin/Fill” color symbol. I added this so I can easily toggle a selected state on and off:
So that’s it! As you can see, these can get pretty sophisticated and require some thought and organization to get right, but the fact that we can now apply literally thousands of different treatments to a single symbol is pretty innovative. It’s singlehandedly the biggest time-saver I’ve ever created.
Pretty cool, huh? I’ve done this with dozens of other symbols, too:
That’s a lot of work for just one symbol, and app designs have dozens, if not hundreds of them.
I went ahead and did all of that dirty for you, and made it look nice: