How you can create really flexible and reusable components in Figma.

Godwin John
4 min readJul 18, 2023

--

Detaching components is considered sacrilege in the world of UI design. If detaching a component could save the world from collapsing, still don’t do it.

But you might ask —

“If I don’t detach these components, how do I make them highly flexible and still reusable?”

I got you!

In this article, I will show you how I’ve been creating seriously customizable components [without detaching them ofc]. For instance, the modals below were made from one component —

All modals are made from the same component

So, how did I do this? Slots!

What are slots?

They aren’t anything big. Slots are elements you add to your component for the sole reason to replace them with something else. As simple as that.

How is a slot made?

Slots are pretty easy to make. You can customize them to your taste but here are some things I love to check out —

  • Must be a frame
  • Must have autolayout applied [critical]
  • Must be a component [so you can swap]
  • Must look different from other components [this is personal though]

That’s it!

The part about it being an autolayout is really critical. Things can go wrong if it isn’t. Here is what my typical slot looks like—

My typical slot

Where do I put this slot?

Here is where it gets fun. The big idea is to anticipate where you might change the content of a component and add a slot there. For instance, I have a modal component down here. I know I will be changing the content of the space below. So, I add a slot there.

And oh! You can have multiple slots in one component. 1–2 slot work in most simple components.

My slot in the modal component

“So, I have added the slot, it should work now right?”

Umm, not exactly. There is just one more thing you need to do.

You need to add a swap property to the slot on the modal component. This tells Figma to give you the option to swap this slot for something else. Read more about Swap property here

Adding a swap property

Changing the content of your modal

Now that you’ve—

  • added your slot to the component
  • added a swap property to the slot

You are good to go! One thing to note though —

You can only swap your slot with another component

[Now, the above might be obvious for a lot of people but I still had to get it off my chest.]

What does this mean? Let’s say I want my modal to have this nice-looking error message below. I have to make sure this error message is a component. Else, I won’t see an option to swap it.

Nice-looking error message

Now that you have done everything, the main stuff remains. If you want to swap your slot for that error message, here’s what you have to do —

  • Create an instance of your modal by duplicating it.
  • On the Right Hand Side, you should see a swap property like below
  • Select the dropdown
  • Locate the success message [make sure to give it a name you can easily find]
  • …and click to swap!

Here is a quick walkthrough…

Voila!

You have a different looking modal. As simple as that! You can go on to create as many variations of your modal content as you want. You just have to swap them out just like you did here. Tbh, you can use slots to create really complex components in so many ways. This just gives you the foundation. Go ye forth and explore!

And that’s it…

If you found this helpful, I suggest you subscribe to get similar content. I would also love to connect on LinkedIn or Twitter.

--

--

Godwin John

I write about design, productivity, and ideas I am fascinated with