Docs
  • Introduction
  • 🚀Get started
    • 1️⃣Install the plugin
    • 2️⃣Load Clapy in your file
    • 3️⃣Sign in/up to Clapy
    • 4️⃣Get code in 1 click
    • Online code preview/editor, Github, and more
  • 🖌️Figma Basics
    • Components
    • Your first Figma component
    • Add auto-layout in Frames
    • Groups vs Frames
  • ⚙️The generated code
    • The project structure
    • Components
    • Instances
    • Figma Tokens integration
    • Responsive code
  • ℹ️Extras
    • Changelog
      • 01/08/2022
      • 25/07/2022
      • 15/07/2022
    • Github
Powered by GitBook
On this page

Was this helpful?

  1. The generated code

Responsive code

By default, the generated code is as responsive as it is in Figma, i.e. if you use the auto layout and constraints in Figma settings, the code equivalent will be generated.

To check if your design is responsive, the first thing you can try is to resize it in Figma and see what happens. Looks good? Your design should be ready!

Another aspect of the responsiveness is the ability to switch from a desktop design to a mobile design if the device screen is small enough. Figma doesn't support it natively. What people typically do is to prepare 2 separate designs: one for desktop, another for mobile (sometimes more than 2 designs).

In the code, you can rely on a CSS rule, media queries, to operate this switch automatically. While generating the media queries is not automated by Clapy (yet), you can follow these steps to add them manually:

  • Group the 2 designs in a parent frame, ideally auto-layout (e.g. horizontal).

  • Generate the code selecting the parent frame. In the generated code, you will have the 2 views rendered next to each other.

  • In the generated code, you will find the 2 components rendered next to each other. Ensure each component has a className you can use.

  • Add CSS with media queries to render the right block, something like:

.desktopView { display: flex; }
.mobileView { display: none; }

@media (max-width: 768px) {
  .desktopView { display: none; }
  .mobileView { display: flex; }
}

Once the media queries take effect, it should render the component matching the screen size, giving a responsive effect.

The same technique applies to 3 or more screen sizes, if required.

PreviousFigma Tokens integrationNextChangelog

Last updated 2 years ago

Was this helpful?

⚙️