10

Create a button component with Figma Variants + Auto Layout

 3 years ago
source link: https://uxdesign.cc/create-a-button-component-with-figma-variants-auto-layout-ac636ea1db76
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Responses (2)

Great article Justin.
To Batch Create Components you can select multiple items and the "Create Master Component" will reveal a dropdown in the top bar to "Create Multiple Components". I think this achieves this same results as the plugin.
Say a change…...
This is a general lack of variants. A design system canvas becoming a total mess.

Create a button component with Figma Variants + Auto Layout

Early this year, I posted an article about create button components using Figma’s Auto Layout. Over the past few months, Figma had dramatically improved their Auto Layout. YES! They finally allow you to adjust the spacing individually!! That was my biggest complaint about Auto Layout at that time.

They also introduce its newest feature — Variants, which help you clean up your components.

Today, I’m going to show you how to use these two features to build a robust component that helps you focus on crafting your own product's experience and be more efficient.

1. Define properties

Button is one of the most complex components in a design system. It has so many different variants. Now with dark mode, you need to double the number of components. It can quickly go over 100 combinations. To define all the properties and their orders, it is critical, and you should have a clear understanding of how you want to structure it before the next step.

In this example, I have the following properties:

Image for post
Image for post
List of properties and variants

When all properties listed, I start thinking about organising this component in Figma, so it is manageable and scalable.

My idea is to break it down to multiple tables:

  • One button type per table
  • Table rows are different button states and sizes
  • Table columns are different shapes and styles

then grouping tables based on different themes. Layout similar to 👇

Image for post
Image for post

Why are themes not included in the table?

From my experiences, Some properties are rarely changed for a single component during the design process. Normally those properties were decided at an earlier stage (i.e. at the beginning of the Project), so excluding them from the table can reduce the table's size.

2. Setup the table

After all the properties defined, then start with a new frame, build the tables, and fill all properties to the table row and column headers.

Tip: apply auto layouts to the frame to expand itself while you are adding more properties.

3. Create the component, finally!

Finally, we can start filling the empty cells with the variants 😅.

But first, make sure we have all the colours ready.

Image for post
Image for post

Then, start with an empty frame, let’s name it “Button template”.

Image for post
Image for post

Next, add the placeholder label, and use Figma’s auto-layout to maintain the button's padding.

Image for post
Image for post
Example of the button label’s text style

Then we can start applying some colours to it:

Image for post
Image for post

Til now, we have finished the first variant of the button. Before we turn it into a component, we should check if it works as what we were expecting:

Image for post
Image for post

Looks good! Let’s duplicate it and make a few more templates for different sizes and button type.

Image for post
Image for post
Templates of different button types and sizes
Image for post
Image for post

After copy and fill all variants into the table, we can then change the variants' colours to match the state.

After a few times, all variants for the different states of the Rectangle style is now finished.

Image for post
Image for post

Now we can finally create components for our button. Before converting the frame to a component, make sure the layer’s name has all the variants separated by “/”.

Image for post
Image for post

Next, use the Batch Create Componentplug in to create all components at once.

Image for post
Image for post

Then, combine all components as variants,

Image for post
Image for post

Wait. What?!🤯

Once we combined as variants, Figma moves all components to a new frame, which break our table.

My walkaround is carefully overlaying the variant on top of the table. Remember, lock the table frame when you do that. Otherwise, the variants will go into the table’s frame!

Image for post
Image for post

4. Name the variant’s properties and values

Before we create more variants for different styles, let’s make sure the properties and values are correct.

From this:

Image for post
Image for post
Before rename

To this:

Image for post
Image for post
After rename

Let’s test it out, looks great!

Image for post
Image for post

Next is to create more components for different shapes and types. Select all components and click the “+” on the right button corner. Figma then duplicates all selected components and what we need to do is rename the value of the property.

Image for post
Image for post
Image for post
Image for post

Very quickly we should able to get the full set of variants for the “Primary” type.

Image for post
Image for post

After a few more copy & paste, we should be able to get all variants done!

Image for post
Image for post

And yep we just created a component with 1134 variants in total.😅

Image for post
Image for post

Feel free to grab my Figma file and try it out.

Thanks for reading!

Image for post
Image for post
The UX Collective donates US$1 for each article published on our platform. This story contributed to Bay Area Black Designers: a professional development community for Black people who are digital designers and researchers in the San Francisco Bay Area. By joining together in community, members share inspiration, connection, peer mentorship, professional development, resources, feedback, support, and resilience. Silence against systemic racism is not an option. Build the design community you believe in.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK