Figma controller components & prepping for variants
Published: 2020-12-30 17:04:47

---
title: Figma controller components & prepping for variants
published: true
date: 2020-12-29 00:00:00 UTC
tags: 
canonical_url: https://langermank.com/blog/blog/figma-variants-with-controller-components/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/57tpbif2efztstqghb5j.jpg
---

I've seen figma variants done with and without component nesting, and at this point made a button both ways. Having gone through the process a few times _sigh_ I feel pretty confident in using controller components to build out variants. My key takeaway: **variants are like props and should be used to toggle states**. You don't want to be building core UI within the variant setup, you just want to hook it all up. Either way its a tedious process– but the end result is pretty rad.

Along with using controller components, it's important to do some prep work before you start building out each variant. I'll go through how I plan for variants before touching my figma file.

## Controller component

Build a base level component to act as a "controller" for each variant. This is where you could control **border radius, margins/padding, size, autolayout, and ordering/layout.**

It's great if you have a rough idea for reach property before you start, but as you build out variants you can easily make new controllers. I started with my default button height and sizing, then later added specific controllers for icon buttons so I could utilize autolayout. Once I was happy with my default set, I made copies of each controller and added `small` and `large` sizes. Now if I want to make my large buttons GIANT, I only have to change it in 6 places (vs 34)

[![controller component](https://langermank.com/static/b9bd4ad164c5ecf9e0c724438ddaca6c/b4294/figma-controller-component.jpg "controller component")](/static/b9bd4ad164c5ecf9e0c724438ddaca6c/eea4a/figma-controller-component.jpg)

## Planning for variants

Step away from your figma file for a minute. Maybe do a little research by looking at [other design systems](https://designsystemsrepo.com/design-systems/). **Make a list of every variant you think you might need**. I'm usually a build only what you need when you need it person, but in this case its much easier to have a little plan before you start. The same goes for actually architecting a component with code– the clearer picture you have of the different props, the better.

Here's my list for Button

- state [default, hover, disabled]
- size [small, default, large]
- variant [primary, secondary]
- outlineBtn [true/false]
- loading [true/false]
- iconLeft [true/false]
- iconRight [true/false]
- iconOnly [true/false]
- fullWidth [true/false]

Use whatever naming convention feels good. I'm using camelCase to make it easier to transfer this to JS.

Take that list and define every property for the first Button variant. Figma is looking for a specific format. It should look like this:

```
state=default, size=default, variant=primary, outlineBtn=false, loading=false, iconLeft=false, iconRight=false, iconOnly=false, fullWidth=false

```

## Alright, back to your figma file

Make a new frame and copy your button\_controller into it. Do not detach instance. It should look something like this:

[![create a new component frame](https://langermank.com/static/4dbcd5a396662c3805581171c7dfaf32/b4294/first-component.jpg "create a new component frame")](/static/4dbcd5a396662c3805581171c7dfaf32/eea4a/first-component.jpg)

Make that new frame Button a component. This is what we will base our variants off of. Style this first component while still using the controller. The only changes I really made to Button are colors and some autolayout to allow for fullWidth. Click the plus sign under Variants to enable, but instead of manually adding props (it takes forever) just copy paste the list above into the name of the first button in the layers panel.

![adding prop names to component](https://dev-to-uploads.s3.amazonaws.com/i/5slt1nrri3p5w00pfon1.gif)

You can do the same thing here but it will take 5x longer (Add New Property)

[![add new props via sidebar](https://langermank.com/static/3a6e2ee879a82351712a2de05ff971cd/b4294/add-new-prop.jpg "add new props via sidebar")](/static/3a6e2ee879a82351712a2de05ff971cd/eea4a/add-new-prop.jpg)

## Onward

Now when you make a new variant, you can simply make whatever design adjustments you want and change any of the props you already created! You can continue changing props via text in the variant name or through the variants panel. Having a prop-plan ahead of time will allow you to more easily build each variant and hopefully prevent any major oversights that generally mean you have to start over.

Feel free to check out my [figma file](https://www.figma.com/file/WOrTkNOlTlHPpqt4b0n9cc/Button-Components-with-Controllers-Full-Variants?node-id=0%3A1) for Button as a reference or to use in your own system!