mui / mui-design-kits

The public feature and bug tracker for the MUI Design kits and Connect Figma plugin.
https://mui.com/design-kits/
111 stars 16 forks source link

[figma] Show React code snippets in Figma #111

Closed oliviertassinari closed 8 months ago

oliviertassinari commented 2 years ago

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 🔦

adrianmanea commented 2 years ago

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 commented 2 years ago

We can make this a vote:

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

oliviertassinari commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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

HowardStredwick commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

https://github.com/mui/mui-design-kits/assets/5917515/74a0944d-8472-4614-b196-db488d48cee7

adrianmanea commented 10 months ago

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 commented 6 months ago

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 commented 6 months ago

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