Skip to main content
Martin_Marinov
New Participant
January 29, 2024
Question

Change variant on resizing a component

  • January 29, 2024
  • 25 replies
  • 4943 views

Hey all. I was wondering is it possible to use min and max width/height of an component and use it for trigger to change a variant. For example: I have a proerty Size, and I have a component with 3 sizes. I want whaen I use the component when resizing it to automatically switch to 1 of the 3 sizes using height/width as a trigger. Is this possible.

This topic has been closed for replies.

25 replies

Ellwood
Active Member
August 20, 2024

You certainly can!

If your component has 3 size variants, say Desktop, Tablet and Mobile and you have a page / frame that you want to adjust across the device widths without having to individually change each component within… You can create a page width variable (screen-size) with different modes as above (Large, Medium, Small) to correspond to your defined breakpoints.

Screenshot 2024-08-20 at 13.50.04

If your component variable uses the same values, i.e. Desktop, Tablet, Mobile you can map the components state to use the same variable as the frame (screen-size). This way, when you change the frame size it automatically changes all the components in the frame to use the same variant ie Desktop, Tablet or Mobile.
Screenshot 2024-08-20 at 13.53.33

Hope this helps.

August 21, 2024

How did you monitor the component width? Can you show more detail?

Ellwood
Active Member
August 22, 2024

You don’t need to monitor component widths, as the component variant is mapped to the screen-width variable.

So, on my design frame I assign min and max width variables plus assign the screen-size var to the frame. This allows me to adjust the frames width within the breakpoints. ie. if I select desktop the frame can be resized from 991px to 4000px and the screen-size var == large.

Screenshot 2024-08-22 at 09.36.12

Now, if the components used within the frame also reference the screen-size var to determine which variant they display then you are controlling all the components with one frame option.

Hope that helps.

August 22, 2024

I see how this would work if you manual change the “Sizing” mode of a frame but what about for a responsive prototype that gets resized?

Ellwood
Active Member
August 23, 2024

I see what you’re getting at. I’ll take a little time to look into it more but as far as I know this is the easiest way to implement something close to it.

I don’t think there’s a feedback mechanism to get the frame width and push it to a variable you could use to control the component variant states, but I think that would be the ideal solution.