Swapping Variants Using Variables | A Figma Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so today's lesson is inspired by one of her longtime UI collective.co community members Joe who had a question around radio button toggling where selecting one radio button will deselect another uh so first off excuse my auto layout and the fact that the radio buttons are the same color uh we're just going to be focusing on uh the variable logic today and getting this set up um so again a great lesson a very real world realistic scenario and one thing I would like to highlight is we do have some awesome new courses coming up on UIC collective.com apologies for the delay at releasing a video on YouTube been busy working on these such as our introduction Design Systems implementing Design Systems Design Systems for business rules and much much more um so with that said let's dive into the lesson all right so I've just got a really simple basic UI here for something like a settings page I have two radio buttons so one is my uh active State and the other is my inactive state so you have the option to choose between active or inactive now pay really close attention to this because these values right here are what we're going to be using uh to build our prototyping functionality or logic actually logic's probably the wrong term because we're not going to be using conditional logic but more so just the logic of our prototype and how to get it the way that to work the way that we want so let's go ahead and get started here so let's look open up our local variables and let's create a couple variables however before we do that that one thing I'd like to note is if I click into our component on screen I see my my state but I don't have the option to actually assign a variable to it now it's a little bit of a weird bug something different I'm not too sure figma's thought and logic there and not being able to apply or connect different components symbols to individual variables at least when they're inside a frame I found that a little bit strange what you actually have to do and what we're going to do today is actually work with components that are outside of the individual frame itself and then just paste them in later on so it's a little bit of a unique Sigma trick for you if you can't get something up and running so here I now have the option to attribute the variable whereas if with the component inside the frame that's currently not an option so just something to make note of so here we have our active radio button and our inactive radio button so let's open up our local variables and let's create two string variables let's create a string and we're going to create two different string variables today one for our starting active radio button and another for our starting inactive radio button so let's create a string variable for our starting active and of course because it's starting active we want our string value to match that of the state variant value in this case active and the second option that this could be so if I was to select this radio button this would then become deselected so that will be our inactive just like that and let's then go ahead and create another string variable actually before we do that let's uh let's assign so we have our starting octave let's assign starting active to the symbol and I can see that because we have active as a mode and active is one of our states variants I can see that figma draws the connection if I was to change this to active one look what happens there's a downstream break break because the variable value doesn't map to a specific variant so let's change that back to one there we go and then let's create another oops not another mode excuse me let's create another string variable so starting inactive this time so the same type of um oops inactive keep it consistent um so the same type of methodology here because it's starting inactive this one is it will our first mode will be inactive and we have the option to change it to active there we go so now let's go ahead and assign that to inactive there we go so now that we have our variable set up and applied to our specific symbols of our components for our radio button next let's look at actually setting up the Prototype itself so now that we have our variables all set up let's go ahead and start adding the prototyping logic that's going to allow us to toggle on and off our radio buttons and connect the two so that when one is turned on the other is turned off or active and inactive so let's start off with our inactive so there's two things that we're going to need to do here I'm just going to move this down a little bit just to give it some breathing room so what we want to have happen is that when this radio button is clicked our active radio button is going to become inactive in our inactive radio button is going to become active so let's go ahead and click in so let's add an interaction that states that on click we're going to set the variable scroll all the way down our starting active so this radio button right here and we're going to set that to inactive oops inactive there we go so what I just did is I set our starting variable they go to our local variables here so our starting active where it's currently at the Active mode we're setting it to inactive now there are a couple different ways that you can do this All following a similar format so if you have another way to do it feel free to leave that in the description below I'm sure there's a more efficient way to do things the designers always seem to find a way but this is the way that I'm going to show today so we just set this to inactive and another thing that we want to do oops let me click in here is set are inactive to active so let's set the variable scroll up here sorry that was just hidden at the bottom set the variable oops let's try that one more time let's set the variable inactive so we're starting inactive which again is this one and we're going to set that to active there we go and let me just add a quick frame um again it usually doesn't work if it's nested to to uh too deep in so let me just paste this inside the frame and let's maybe just do a lightning quick uh preview here quick preview there we go and I can see that that adjusts and the only reason why the color changed is just because uh I altered the color of original radio button so something I always have to go back and manually fix later on so now that we see that that's working let's do the same for our active so let's add an interaction that states that when on click our radio status on set the variable so our radio status starting active becomes active there we go and again add another set variable that sets our radio status inactive to inactive active there we go so essentially again what this is saying is that when this is clicked it's going to become active and um when are starting inactive is Click clicked this is going to become inactive so let's uh again let's preview the functionality here so nice toggle nice toggle beautiful just like that loving the way that that looks so let me go ahead and just paste this in here and again the only reason why the color is different is just because I altered the color and I didn't set the variable properly so if you've set up your design system again let me just quick do a quick preview of that oops of this Frame so again the only reason why this is just different color is just some of the the changes that I made I didn't set the variable properly but if you're working within a design system uh with a standard set of colors you won't have this issue so I wouldn't worry too much about that so now I'm going to go ahead and just paste this in under Auto layout's all off here so let me just clean that up that's fine for now I won't fix it right here so now when I present it I can see that that toggles very nicely and there you have it that's how you create an interactive prototype to swap between states everyone and this is your friendly reminder sign up for UI collective.com you can join our slack Community which is totally free to converse with myself or Mike directly chat with other designers with Design Systems so on and so forth we also offer Design Systems import our own custom design system and design system training as well which is perfect for Enterprises Freelancers uh whoever is interested in learning to build components Master Auto layouts or just learn the basics of a design system and of course our design system looks like this where do you get access to all these amazing components across both light mode and dark mode however this is a paid template hope to see on our slack Channel if you have any questions feel free to leave them in the comments see you soon
Info
Channel: UI Collective
Views: 6,895
Rating: undefined out of 5
Keywords: figma variables
Id: Tmc1LlRqgOM
Channel Id: undefined
Length: 10min 10sec (610 seconds)
Published: Fri Sep 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.