figma / code-connect

A tool for connecting your design system components in code with your design system in Figma
MIT License
490 stars 45 forks source link

Possible to connect component libraries like Mantine or Mui? #20

Closed Arcade1080 closed 1 month ago

Arcade1080 commented 1 month ago

Is there a way to connect component libraries like Mantine or Mui?

ptomas-figma commented 1 month ago

Hi, thanks for the question! You should be able to annotate components from those libraries using the current React API.

For example to annotate a Button component from the MUI Material library and assuming you have a copy of their community file as your design system library in Figma. you could run npx figma create "https://..." using the the link to the component in that library file. This will generate a Button.figma.tsx file in your codebase that you can modify and publish.

The file could look something like this

import figma from "@figma/code-connect";
import Button from "@mui/material/Button";
import React from "react";

figma.connect(
  Button,
  "https://www.figma.com/...",
  {
    props: {
      size: figma.enum("Size", {
        Large: "large",
        Medium: "medium",
        Small: "small",
      }),
      // ... other prop mapping here
    },
    example: (props) => <Button size={props.size} />,
  }
);

once published with npx figma publish it'd look like this in Figma

image

Let us know if you have any questions!

Arcade1080 commented 1 month ago

Hey! Thank you!