Search

design

start

design

scroll

design

navigation

design

effects

design

cms

design

localization

design

insert

design

templates

design

management

design

integrations

design

code

design

courses

Stack Variables

Stack Variables

Turn properties like Gap, Padding, Direction, Distribute, and Align into customizable controls, allowing you to design much more flexible Components.

Intermediate

Understanding Stack Variables in Framer: Enhancing Component Customization

In this tutorial, we delve into the exciting world of stack variables in Framer. The addition of variable support for layout properties in components is a game-changer, allowing for more customizable components such as navigations. This feature is especially handy for controlling layout via a CMS.

Case Study: Pop-Out Navigation Menu

Let’s examine a practical example: a pop-out navigation menu from Nav Do Supply. This menu showcases a dynamic layout that changes based on the screen size. On a desktop view, it displays a horizontal layout of links. However, when resized to a phone breakpoint, the layout shifts to a vertical arrangement, and the gap between elements adjusts accordingly.

Simplifying Layouts with Variables

Traditionally, achieving this kind of layout customization required multiple variants: open, closed, mobile open, and mobile closed. This approach, while effective, could lead to errors and complications, particularly in collaborative environments. The risk of creating unintended layout overrides was high.

To streamline this process, we can reduce the variants to just two: open and closed. This simplification eliminates the need for mobile-specific variants. We focus on two key properties for customization on the phone breakpoint: direction (horizontal or vertical) and gap (distance between elements).

Implementing Layout Variables

To implement these changes using variables, we follow these steps:

  1. Creating Variables: We start by selecting the stack containing the links. For the 'direction' property, we create a variable with the default set to 'horizontal' for desktop and tablet breakpoints. Similarly, for the 'Gap' property, we set the default to 10, and customize the stepper control for better adjustment.

  2. Applying Variables on Different Breakpoints: Back on the homepage, we notice that our phone breakpoint variant resets to the primary variant due to the deletion of the mobile-specific variants. But now, any instance of our component has new controls for 'Direction' and 'Gap'. For the phone breakpoint, we set the direction to vertical and the gap to 20.

  3. Preview and Testing: After adjusting the variables and setting the variant back to closed, we preview the navigation. The result is a seamless transition between a vertical layout on mobile and a horizontal layout on desktop. The interactions are driven by the two variants, while the responsiveness is managed by the two variables.

This approach provides a flexible and easily customizable setup. By leveraging stack variables, we can significantly reduce the complexity and potential errors associated with managing multiple layout variants. This feature not only simplifies the design process but also enhances the adaptability and functionality of components in Framer.

Stay tuned for more updates and insights into leveraging Framer's capabilities to create dynamic and responsive designs!