Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[figma] Show React code snippets in Figma #111

Closed
oliviertassinari opened this issue Oct 10, 2022 · 11 comments
Closed

[figma] Show React code snippets in Figma #111

oliviertassinari opened this issue Oct 10, 2022 · 11 comments
Labels
figma new feature New feature or request

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 10, 2022

Summary 馃挕

This issue is about extending the built-in feature of Figma to see React rather than CSS code:

Screenshot 2022-10-10 at 17 20 40

Examples 馃寛

Motivation 馃敠

  • We have recently started working with a customer who uses MUI Design Kits and have those in Figma libraries, but from a Development stand point, they don't have the component libraries built out for the Engineers. The Engineers are going to the documentation in MUI to find the code snippets but want a fast way to access those, which is where Zeplin's Connected Components capability comes in.

@oliviertassinari oliviertassinari added figma new feature New feature or request labels Oct 10, 2022
@adrianmanea
Copy link
Collaborator

adrianmanea commented Oct 11, 2022

What would be the best format for the code snippet? I think we have two strong examples described above, one would be the extended snippet with the imports:

import * as React from 'react';
import Avatar from '@mui/material/Avatar';

export default function ImageAvatars() {
  return (
    <Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" />
  );
}

or simply

<Avatar
   alt={string}
   component={elementType}
   src={string}
   sizes={string}
   src={string}
   variant={string}
/>

I'm more in favor of the second option.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Oct 11, 2022

We can make this a vote:

  • 馃帀 is full import
  • 馃殌 is only component.

I'm personally leaning more toward the former option (馃帀) so it be copied & paste and work directly.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Oct 19, 2022

An interesting attempt at this: https://twitter.com/jake_albaugh/status/1582404765597646848. It converts the Figma props to how they would look in code based on their name and type.

Screenshot 2022-10-19 at 23 28 23

We could at least use this to normalize all the APIs used in Figma to be closer to the code, e.g. Primary -> primary, Medium* -> medium.

@adrianmanea adrianmanea moved this from Q4 Oct-Dec to Future in MUI Design kits public roadmap Dec 22, 2022
@adrianmanea adrianmanea added this to the Figma next milestone Apr 11, 2023
@adrianmanea
Copy link
Collaborator

adrianmanea commented May 18, 2023

arobert93 created a custom Figma plugin that enables bulk changes to component configurations. It uses LiquidJS as the templating engine to automatically obtain the prop names. The task went from 1 month of work to 1 week 馃. Let me know if someone needs the plugin!

Input:

import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from '@mui/material/FormControlLabel';

export default function CheckboxDemo() {
  return (
    <>
      {%- assign label = Label -%}
      {% if label %}
      <FormControlLabel
        control={
          <Checkbox
            {%- assign checked = Checked -%}
            {% if checked %}
            checked{% endif %}
            color="{{Color | downcase}}"
            {%- assign indeterminate = Indeterminate -%}
            {% if indeterminate %}
            indeterminate{% endif %}
            size="{{Size | downcase}}"
          />
        }
        label="Label"
      />
      {% else %}
      <Checkbox
        {%- assign checked = Checked -%}
        {% if checked %}
        checked{% endif %}
        color="{{Color | downcase}}"
        {%- assign indeterminate = Indeterminate -%}
        {% if indeterminate %}
        indeterminate{% endif %}
        size="{{Size | downcase}}"
      />{% endif %}
    </>
  );
}

Outputs:

import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from '@mui/material/FormControlLabel';

export default function CheckboxDemo() {
  return (
    <>
      <Checkbox
        checked
        color="primary"
        size="medium"
      />
    </>
  );
}

@oliviertassinari
Copy link
Member Author

Interesting, It sounds like something we we could push further.

@HowardStredwick
Copy link

HowardStredwick commented Jun 22, 2023

I'd die in a ditch for this. Our engineers (full stack) just want boilerplate React code, they don't want to have to poke through figma diagrams looking at how something is put together.

The code generated by Anima and the new Figma dev feature is jokes with Material UI, etc, in fact, it's actually dangerous, as we want folks to adopt all the useful stuff in MUI, and Figma's new dev feature pushes them down the vanilla HTML route.

@adrianmanea adrianmanea moved this from Future to Q4 Oct-Dec in MUI Design kits public roadmap Jul 13, 2023
@adrianmanea adrianmanea moved this from Q4 Oct-Dec to Q3 July-Sep in MUI Design kits public roadmap Jul 13, 2023
@adrianmanea
Copy link
Collaborator

We experienced a small setback due to a recently introduced bug. It appears that Figma trimmed some lines of the description, causing us to lose most of the completed components. This is unfortunate. We plan to re-do this feature during Q3, but it will not be included in the July update.

image

@adrianmanea
Copy link
Collaborator

adrianmanea commented Jul 19, 2023

Another issue when copying the code. It exports brake lines.

MUI.for.Figma.-.v5.14.0.-.Code.Snippets.Bug.mov

@adrianmanea adrianmanea removed this from Q3 July-Sep in MUI Design kits public roadmap Jul 25, 2023
@adrianmanea adrianmanea modified the milestones: Figma v5.14.0, Figma next Jul 25, 2023
@adrianmanea
Copy link
Collaborator

An update has been developed in collaboration with Figma using a plugin: https://github.com/figma/code-snippet-editor-plugin. It appears to use a templating language similar to what we've used, but it's directly integrated into the Dev Mode. This is a significant improvement over our current method of using component descriptions.

I think we should move the code snippets we have into the Code Snippet Editor.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Apr 19, 2024

To consider if we should do a v2 on this with https://github.com/figma/code-connect

SCR-20240419-rimk

https://www.figma.com/blog/introducing-code-connect/

@adrianmanea
Copy link
Collaborator

This is definitely a better option then adding the code snippet in the component description haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
figma new feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants